From c3cee5b6afb9820507d1f1cd12cd522e21a36bc0 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Wed, 8 Nov 2023 00:59:18 +0400 Subject: [PATCH] Implement `zio-jdbc` backend (#57) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Init * Implement zio-jdbc backend * clean * clean * Naively implement `Const::render` * Fix compilation * Clean * Init `DbLibZioJdbc` * Implement `DbLibZioJdbc::repoImpl` and `JsonLibZioJson` && Generate code * Remove generated code for now * Ignore generated code for now * Ignore generated code for now * Ignore generated code for now * scalafmt * Init tests * fix tests * Fix scripts * clean * fix `sqlInterpolator` import * Fix json decoding * Improve gitignore * clean PR * Use latest snapshot of zio-jdbc, containing the `insertReturning`, etc. methods * clean PR * fix test * fix test * Implement `runtimeInterpolateValue` * Implement and fix more stuff * Fix `UpdateFieldValues` * Fix more stuff * Fix zio-json array encoders * Fix zio-json `defaultedInstance` for encoder * Fix zio-json generator * Implement `Setter` support * Fix zio-json decoder * Fix `stringEnumInstances` `JdbcDecoder` implementation * Use fixed zio-jdbc version See https://github.com/zio/zio-jdbc/pull/162 * Implement row decoders and encoders without zio-schema * Fix `bigDecimalDecoder` decoder * Remove warnings && improve generated code * Remove warnings * Implement basic `customTypeInstances` * clean * Improve `customTypeInstances` * Improve `customTypeInstances` * Fix Scala BigDecimal JDBC decoder * clean * Implement `mockRepoImpl` * Remove warning * Fix tests * Remove warning * clean * Fix test * Fix test * Fix test * Fix test * Fix test * Fix test * Fix test * clean * clean * Fix tests * Implement basic `Array` `JdbcDecoder` instance * Fix tests * review * Init primitive Array encoder * clean * Implement `Setter` for complex custom types * Update zio-jdbc * Fix instances of `TypoPolygon` * Fix `FirstName` and `CustomCreditcardId` * Implement `primitiveArraySetter` * Add `TypoHStore` encoder/decoder/setter * Add basic Array encoder * Fix TypoStore encoder * clean * Improve TypoHStore decoder * clean * Improve `primitiveArrayDecoder` * Clean * Clean * towards custom types I thought it was better to communicate this in code than to try to explain it. the custom types rely on the default types produced and consumed by the postgres driver, so we effectively just use `{get|set}Object`. Then there are functions which transform those types to/from the custom types exposed in typo. I'm not entirely sure this will all work as I couldn't test it, but we can iterate on it note that for unary types we can produce `JdbcEncoder` from a `Setter`: ```scala JdbcEncoder.singleParamEncoder(jdbcSetter) ``` * fmt * Fix `TypoXml` decoder instance. See https://github.com/oyvindberg/typo/pull/57/commits/abd0b9698c1fd134622ad0e9b880840ea0e39e69#r1372648959 * Remove warning * Clean * Clean * build with published snapshot I think enough PR's are merged now, so I can test as well without publishLocal * Update to the latest zio-jdbc snapshot * Fix forever hanging of tests * Fix DB config in tests * Improve error message * Implement Array encoders/decoders/setters * Clean * Fix decoders and encoders * Fix decoders and encoders * Fix decoders and encoders * Fix `withConnection` * Fix `ScalaBigDecimalArrayEncoder` * Update to latest snapshot of zio-jdbc * Fix zio-json `defaultedInstance` * Improve tests * disable auto-commit earlier * fix runtimeInterpolateValue in the no inline case. Fixes for instance `selectByIds` * remove isEmpty check for arrays * fmt * remove leading `|` in fragments since there is no `stripMargin` * towards adding some spaces in sql * fix usage of columIndex * quote column names * Fix * mkFragment * towards `Setter[Array[T]]` * quote column names * fix `InsertUnsaved` * use `JdbcDecoder.apply` instead of `new JdbcDecoder` for unary types * use `JdbcEncoder.contramap` instead of `new JdbcEncoder` for unary types * Improve zio-json encoder and decoder instances for unary types * Revert "Improve zio-json encoder and decoder instances for unary types" This reverts commit c04add0aba2a8fa8b62f8912bdffe62a60171b14. * Fix doobie test * Fix zio-jdbc test * Fix `Const` implementation by copying `ParameterMetaData` from Anorm * Update to latest zio-jdbc snapshot * Fix `ParameterMetaData` instances for `java.time.Instant` and `java.time.ZonedDateTime` * Add `ParameterMetaData` instances for `java.time.OffsetDateTime` * Fix Scal 2.12 compilation * Do not use macro in zio-json `JsonDecoder` instances * Do not use macro in zio-json `JsonEncoder` instances * Drop the `UpdateResult` from the `insert` methods return type * Remove `JdbcEncoder` for row types * Fix Scala3 compilation * Improve `JsonEncoder` code * Fix Scala 2.12 compilation * Fix `JdbcDecoder` instances * Update to latest zio-jdbc snapshot * faster to compile code * avoid long flatmaps in jsonDecoder * Add support for `vector` extension (zio) * extend `ArrayTest` with more than just custom types (zio) * style * comment out nulls test * add generated files - let's see if we can get a green build * only generate `ParameterMetaData` instances if DSL is enabled. - lose explicit `ClassTag` in `arrayJdbcDecoder`. will add it everywhere if we determine that it makes a big difference - try a somewhat new code style in DbLibZioJdbc. a bit less nesting and a bit more naming. try to line up `|` in code fragments at least. - compress `arrayJdbcDecoder` for custom types - add `ParameterMetadata.instance` to avoid generating some bytecode and slightly nicer looking generated code * update docs * merge * stable version of zio-jdbc * inline implicit for `Setter` for generated types --------- Co-authored-by: Øyvind Raddum Berg --- .../compositepk/person/PersonFieldValue.scala | 20 + .../compositepk/person/PersonFields.scala | 20 + .../compositepk/person/PersonId.scala | 38 + .../compositepk/person/PersonRepo.scala | 32 + .../compositepk/person/PersonRepoImpl.scala | 119 +++ .../compositepk/person/PersonRepoMock.scala | 104 +++ .../compositepk/person/PersonRow.scala | 58 ++ .../compositepk/person/PersonRowUnsaved.scala | 61 ++ .../compositepk/person/PersonStructure.scala | 29 + .../hardcoded/customtypes/Defaulted.scala | 45 + .../testdb/hardcoded/myschema/Number.scala | 65 ++ .../testdb/hardcoded/myschema/Sector.scala | 65 ++ .../FootballClubFieldValue.scala | 19 + .../football_club/FootballClubFields.scala | 19 + .../football_club/FootballClubId.scala | 31 + .../football_club/FootballClubRepo.scala | 32 + .../football_club/FootballClubRepoImpl.scala | 94 ++ .../football_club/FootballClubRepoMock.scala | 102 +++ .../football_club/FootballClubRow.scala | 50 ++ .../football_club/FootballClubStructure.scala | 28 + .../MaritalStatusFieldValue.scala | 18 + .../marital_status/MaritalStatusFields.scala | 17 + .../marital_status/MaritalStatusId.scala | 31 + .../marital_status/MaritalStatusRepo.scala | 30 + .../MaritalStatusRepoImpl.scala | 72 ++ .../MaritalStatusRepoMock.scala | 73 ++ .../marital_status/MaritalStatusRow.scala | 37 + .../MaritalStatusStructure.scala | 26 + .../myschema/person/PersonFieldValue.scala | 32 + .../myschema/person/PersonFields.scala | 34 + .../hardcoded/myschema/person/PersonId.scala | 31 + .../myschema/person/PersonRepo.scala | 33 + .../myschema/person/PersonRepoImpl.scala | 189 ++++ .../myschema/person/PersonRepoMock.scala | 126 +++ .../hardcoded/myschema/person/PersonRow.scala | 116 +++ .../myschema/person/PersonRowUnsaved.scala | 129 +++ .../myschema/person/PersonStructure.scala | 43 + .../testdb/hardcoded/package.scala | 243 +++++ .../testdb/hardcoded/testInsert.scala | 31 + .../compositepk/person/PersonFieldValue.scala | 20 + .../compositepk/person/PersonFields.scala | 20 + .../compositepk/person/PersonId.scala | 38 + .../compositepk/person/PersonRepo.scala | 32 + .../compositepk/person/PersonRepoImpl.scala | 119 +++ .../compositepk/person/PersonRepoMock.scala | 104 +++ .../compositepk/person/PersonRow.scala | 58 ++ .../compositepk/person/PersonRowUnsaved.scala | 61 ++ .../compositepk/person/PersonStructure.scala | 29 + .../hardcoded/customtypes/Defaulted.scala | 45 + .../testdb/hardcoded/myschema/Number.scala | 65 ++ .../testdb/hardcoded/myschema/Sector.scala | 65 ++ .../FootballClubFieldValue.scala | 19 + .../football_club/FootballClubFields.scala | 19 + .../football_club/FootballClubId.scala | 31 + .../football_club/FootballClubRepo.scala | 32 + .../football_club/FootballClubRepoImpl.scala | 94 ++ .../football_club/FootballClubRepoMock.scala | 102 +++ .../football_club/FootballClubRow.scala | 50 ++ .../football_club/FootballClubStructure.scala | 28 + .../MaritalStatusFieldValue.scala | 18 + .../marital_status/MaritalStatusFields.scala | 17 + .../marital_status/MaritalStatusId.scala | 31 + .../marital_status/MaritalStatusRepo.scala | 30 + .../MaritalStatusRepoImpl.scala | 72 ++ .../MaritalStatusRepoMock.scala | 73 ++ .../marital_status/MaritalStatusRow.scala | 37 + .../MaritalStatusStructure.scala | 26 + .../myschema/person/PersonFieldValue.scala | 32 + .../myschema/person/PersonFields.scala | 34 + .../hardcoded/myschema/person/PersonId.scala | 31 + .../myschema/person/PersonRepo.scala | 33 + .../myschema/person/PersonRepoImpl.scala | 189 ++++ .../myschema/person/PersonRepoMock.scala | 126 +++ .../hardcoded/myschema/person/PersonRow.scala | 116 +++ .../myschema/person/PersonRowUnsaved.scala | 129 +++ .../myschema/person/PersonStructure.scala | 43 + .../testdb/hardcoded/package.scala | 243 +++++ .../testdb/hardcoded/testInsert.scala | 31 + .../compositepk/person/PersonFieldValue.scala | 20 + .../compositepk/person/PersonFields.scala | 20 + .../compositepk/person/PersonId.scala | 38 + .../compositepk/person/PersonRepo.scala | 32 + .../compositepk/person/PersonRepoImpl.scala | 119 +++ .../compositepk/person/PersonRepoMock.scala | 104 +++ .../compositepk/person/PersonRow.scala | 58 ++ .../compositepk/person/PersonRowUnsaved.scala | 61 ++ .../compositepk/person/PersonStructure.scala | 29 + .../hardcoded/customtypes/Defaulted.scala | 45 + .../testdb/hardcoded/myschema/Number.scala | 65 ++ .../testdb/hardcoded/myschema/Sector.scala | 65 ++ .../FootballClubFieldValue.scala | 19 + .../football_club/FootballClubFields.scala | 19 + .../football_club/FootballClubId.scala | 31 + .../football_club/FootballClubRepo.scala | 32 + .../football_club/FootballClubRepoImpl.scala | 94 ++ .../football_club/FootballClubRepoMock.scala | 102 +++ .../football_club/FootballClubRow.scala | 50 ++ .../football_club/FootballClubStructure.scala | 28 + .../MaritalStatusFieldValue.scala | 18 + .../marital_status/MaritalStatusFields.scala | 17 + .../marital_status/MaritalStatusId.scala | 31 + .../marital_status/MaritalStatusRepo.scala | 30 + .../MaritalStatusRepoImpl.scala | 72 ++ .../MaritalStatusRepoMock.scala | 73 ++ .../marital_status/MaritalStatusRow.scala | 37 + .../MaritalStatusStructure.scala | 26 + .../myschema/person/PersonFieldValue.scala | 32 + .../myschema/person/PersonFields.scala | 34 + .../hardcoded/myschema/person/PersonId.scala | 31 + .../myschema/person/PersonRepo.scala | 33 + .../myschema/person/PersonRepoImpl.scala | 189 ++++ .../myschema/person/PersonRepoMock.scala | 126 +++ .../hardcoded/myschema/person/PersonRow.scala | 116 +++ .../myschema/person/PersonRowUnsaved.scala | 129 +++ .../myschema/person/PersonStructure.scala | 43 + .../testdb/hardcoded/package.scala | 243 +++++ .../testdb/hardcoded/testInsert.scala | 31 + .gitignore | 2 +- bleep.yaml | 28 + site-in/customization/overview.md | 2 +- site-in/other-features/flexible.md | 2 +- site-in/other-features/json.md | 4 +- site-in/setup.md | 3 +- .../src/scala/typo/dsl/DeleteBuilder.scala | 73 ++ .../scala/typo/dsl/ParameterMetaData.scala | 248 ++++++ .../src/scala/typo/dsl/SelectBuilder.scala | 99 ++ .../scala/typo/dsl/SelectBuilderMock.scala | 65 ++ .../src/scala/typo/dsl/SelectBuilderSql.scala | 212 +++++ .../src/scala/typo/dsl/SelectParams.scala | 57 ++ .../src/scala/typo/dsl/SortOrder.scala | 18 + .../src/scala/typo/dsl/SqlExpr.scala | 269 ++++++ .../src/scala/typo/dsl/UpdateBuilder.scala | 112 +++ .../src/scala/typo/dsl/extensions.scala | 21 + .../src/scala/scripts/CompileBenchmark.scala | 2 + .../src/scala/scripts/GenHardcodedFiles.scala | 2 + .../scripts/GeneratedAdventureWorks.scala | 5 +- .../src/scala/scripts/projectsToPublish.scala | 9 +- .../production/product/ProductTest.scala | 3 +- .../customtypes/Defaulted.scala | 44 + .../customtypes/TypoAclItem.scala | 76 ++ .../customtypes/TypoAnyArray.scala | 76 ++ .../adventureworks/customtypes/TypoBox.scala | 90 ++ .../customtypes/TypoBytea.scala | 45 + .../customtypes/TypoCircle.scala | 82 ++ .../customtypes/TypoHStore.scala | 54 ++ .../adventureworks/customtypes/TypoInet.scala | 76 ++ .../customtypes/TypoInstant.scala | 75 ++ .../customtypes/TypoInt2Vector.scala | 76 ++ .../customtypes/TypoInterval.scala | 98 ++ .../adventureworks/customtypes/TypoJson.scala | 76 ++ .../customtypes/TypoJsonb.scala | 76 ++ .../adventureworks/customtypes/TypoLine.scala | 86 ++ .../customtypes/TypoLineSegment.scala | 83 ++ .../customtypes/TypoLocalDate.scala | 68 ++ .../customtypes/TypoLocalDateTime.scala | 74 ++ .../customtypes/TypoLocalTime.scala | 70 ++ .../customtypes/TypoMoney.scala | 65 ++ .../customtypes/TypoOffsetTime.scala | 74 ++ .../customtypes/TypoOidVector.scala | 76 ++ .../adventureworks/customtypes/TypoPath.scala | 83 ++ .../customtypes/TypoPgNodeTree.scala | 76 ++ .../customtypes/TypoPoint.scala | 82 ++ .../customtypes/TypoPolygon.scala | 67 ++ .../customtypes/TypoRecord.scala | 76 ++ .../customtypes/TypoRegproc.scala | 76 ++ .../customtypes/TypoRegtype.scala | 76 ++ .../customtypes/TypoShort.scala | 79 ++ .../adventureworks/customtypes/TypoUUID.scala | 68 ++ .../customtypes/TypoUnknownCitext.scala | 65 ++ .../TypoUnknownPgDependencies.scala | 65 ++ .../customtypes/TypoUnknownPgMcvList.scala | 65 ++ .../customtypes/TypoUnknownPgNdistinct.scala | 65 ++ .../customtypes/TypoUnknownPgStatistic.scala | 65 ++ .../customtypes/TypoVector.scala | 46 + .../adventureworks/customtypes/TypoXid.scala | 76 ++ .../adventureworks/customtypes/TypoXml.scala | 72 ++ .../adventureworks/hr/d/DViewFields.scala | 23 + .../adventureworks/hr/d/DViewRepo.scala | 17 + .../adventureworks/hr/d/DViewRepoImpl.scala | 23 + .../adventureworks/hr/d/DViewRow.scala | 75 ++ .../adventureworks/hr/d/DViewStructure.scala | 32 + .../adventureworks/hr/e/EViewFields.scala | 38 + .../adventureworks/hr/e/EViewRepo.scala | 17 + .../adventureworks/hr/e/EViewRepoImpl.scala | 23 + .../adventureworks/hr/e/EViewRow.scala | 155 ++++ .../adventureworks/hr/e/EViewStructure.scala | 47 + .../adventureworks/hr/edh/EdhViewFields.scala | 28 + .../adventureworks/hr/edh/EdhViewRepo.scala | 17 + .../hr/edh/EdhViewRepoImpl.scala | 23 + .../adventureworks/hr/edh/EdhViewRow.scala | 91 ++ .../hr/edh/EdhViewStructure.scala | 37 + .../adventureworks/hr/eph/EphViewFields.scala | 24 + .../adventureworks/hr/eph/EphViewRepo.scala | 17 + .../hr/eph/EphViewRepoImpl.scala | 23 + .../adventureworks/hr/eph/EphViewRow.scala | 82 ++ .../hr/eph/EphViewStructure.scala | 33 + .../adventureworks/hr/jc/JcViewFields.scala | 25 + .../adventureworks/hr/jc/JcViewRepo.scala | 17 + .../adventureworks/hr/jc/JcViewRepoImpl.scala | 23 + .../adventureworks/hr/jc/JcViewRow.scala | 76 ++ .../hr/jc/JcViewStructure.scala | 34 + .../adventureworks/hr/s/SViewFields.scala | 25 + .../adventureworks/hr/s/SViewRepo.scala | 17 + .../adventureworks/hr/s/SViewRepoImpl.scala | 23 + .../adventureworks/hr/s/SViewRow.scala | 83 ++ .../adventureworks/hr/s/SViewStructure.scala | 34 + .../department/DepartmentFields.scala | 22 + .../department/DepartmentId.scala | 30 + .../department/DepartmentRepo.scala | 30 + .../department/DepartmentRepoImpl.scala | 102 +++ .../department/DepartmentRepoMock.scala | 80 ++ .../department/DepartmentRow.scala | 66 ++ .../department/DepartmentRowUnsaved.scala | 71 ++ .../department/DepartmentStructure.scala | 31 + .../employee/EmployeeFields.scala | 38 + .../employee/EmployeeRepo.scala | 31 + .../employee/EmployeeRepoImpl.scala | 166 ++++ .../employee/EmployeeRepoMock.scala | 81 ++ .../humanresources/employee/EmployeeRow.scala | 153 ++++ .../employee/EmployeeRowUnsaved.scala | 178 ++++ .../employee/EmployeeStructure.scala | 47 + .../EmployeedepartmenthistoryFields.scala | 28 + .../EmployeedepartmenthistoryId.scala | 49 + .../EmployeedepartmenthistoryRepo.scala | 29 + .../EmployeedepartmenthistoryRepoImpl.scala | 102 +++ .../EmployeedepartmenthistoryRepoMock.scala | 77 ++ .../EmployeedepartmenthistoryRow.scala | 90 ++ .../EmployeedepartmenthistoryRowUnsaved.scala | 89 ++ .../EmployeedepartmenthistoryStructure.scala | 37 + .../EmployeepayhistoryFields.scala | 24 + .../EmployeepayhistoryId.scala | 39 + .../EmployeepayhistoryRepo.scala | 29 + .../EmployeepayhistoryRepoImpl.scala | 100 +++ .../EmployeepayhistoryRepoMock.scala | 77 ++ .../EmployeepayhistoryRow.scala | 79 ++ .../EmployeepayhistoryRowUnsaved.scala | 78 ++ .../EmployeepayhistoryStructure.scala | 33 + .../jobcandidate/JobcandidateFields.scala | 24 + .../jobcandidate/JobcandidateId.scala | 30 + .../jobcandidate/JobcandidateRepo.scala | 30 + .../jobcandidate/JobcandidateRepoImpl.scala | 104 +++ .../jobcandidate/JobcandidateRepoMock.scala | 80 ++ .../jobcandidate/JobcandidateRow.scala | 68 ++ .../jobcandidate/JobcandidateRowUnsaved.scala | 73 ++ .../jobcandidate/JobcandidateStructure.scala | 33 + .../humanresources/shift/ShiftFields.scala | 24 + .../humanresources/shift/ShiftId.scala | 30 + .../humanresources/shift/ShiftRepo.scala | 30 + .../humanresources/shift/ShiftRepoImpl.scala | 107 +++ .../humanresources/shift/ShiftRepoMock.scala | 80 ++ .../humanresources/shift/ShiftRow.scala | 74 ++ .../shift/ShiftRowUnsaved.scala | 79 ++ .../humanresources/shift/ShiftStructure.scala | 33 + .../vemployee/VemployeeViewFields.scala | 39 + .../vemployee/VemployeeViewRepo.scala | 17 + .../vemployee/VemployeeViewRepoImpl.scala | 23 + .../vemployee/VemployeeViewRow.scala | 168 ++++ .../vemployee/VemployeeViewStructure.scala | 48 + .../VemployeedepartmentViewFields.scala | 30 + .../VemployeedepartmentViewRepo.scala | 17 + .../VemployeedepartmentViewRepoImpl.scala | 23 + .../VemployeedepartmentViewRow.scala | 111 +++ .../VemployeedepartmentViewStructure.scala | 39 + ...VemployeedepartmenthistoryViewFields.scala | 31 + .../VemployeedepartmenthistoryViewRepo.scala | 17 + ...mployeedepartmenthistoryViewRepoImpl.scala | 23 + .../VemployeedepartmenthistoryViewRow.scala | 118 +++ ...ployeedepartmenthistoryViewStructure.scala | 40 + .../VjobcandidateViewFields.scala | 35 + .../vjobcandidate/VjobcandidateViewRepo.scala | 17 + .../VjobcandidateViewRepoImpl.scala | 23 + .../vjobcandidate/VjobcandidateViewRow.scala | 139 +++ .../VjobcandidateViewStructure.scala | 44 + .../VjobcandidateeducationViewFields.scala | 31 + .../VjobcandidateeducationViewRepo.scala | 17 + .../VjobcandidateeducationViewRepoImpl.scala | 23 + .../VjobcandidateeducationViewRow.scala | 118 +++ .../VjobcandidateeducationViewStructure.scala | 40 + .../VjobcandidateemploymentViewFields.scala | 29 + .../VjobcandidateemploymentViewRepo.scala | 17 + .../VjobcandidateemploymentViewRepoImpl.scala | 23 + .../VjobcandidateemploymentViewRow.scala | 106 +++ ...VjobcandidateemploymentViewStructure.scala | 38 + .../information_schema/CardinalNumber.scala | 31 + .../information_schema/CharacterData.scala | 31 + .../information_schema/YesOrNo.scala | 31 + .../PgForeignDataWrappersViewFields.scala | 24 + .../PgForeignDataWrappersViewRepo.scala | 17 + .../PgForeignDataWrappersViewRepoImpl.scala | 23 + .../PgForeignDataWrappersViewRow.scala | 83 ++ .../PgForeignDataWrappersViewStructure.scala | 33 + .../PgForeignServersViewFields.scala | 26 + .../PgForeignServersViewRepo.scala | 17 + .../PgForeignServersViewRepoImpl.scala | 23 + .../PgForeignServersViewRow.scala | 94 ++ .../PgForeignServersViewStructure.scala | 35 + .../PgForeignTableColumnsViewFields.scala | 20 + .../PgForeignTableColumnsViewRepo.scala | 17 + .../PgForeignTableColumnsViewRepoImpl.scala | 23 + .../PgForeignTableColumnsViewRow.scala | 65 ++ .../PgForeignTableColumnsViewStructure.scala | 29 + .../PgForeignTablesViewFields.scala | 22 + .../PgForeignTablesViewRepo.scala | 17 + .../PgForeignTablesViewRepoImpl.scala | 23 + .../PgForeignTablesViewRow.scala | 80 ++ .../PgForeignTablesViewStructure.scala | 31 + .../PgUserMappingsViewFields.scala | 24 + .../PgUserMappingsViewRepo.scala | 17 + .../PgUserMappingsViewRepoImpl.scala | 23 + .../PgUserMappingsViewRow.scala | 86 ++ .../PgUserMappingsViewStructure.scala | 33 + ...istrableRoleAuthorizationsViewFields.scala | 18 + ...inistrableRoleAuthorizationsViewRepo.scala | 17 + ...trableRoleAuthorizationsViewRepoImpl.scala | 23 + ...ministrableRoleAuthorizationsViewRow.scala | 58 ++ ...rableRoleAuthorizationsViewStructure.scala | 27 + .../ApplicableRolesViewFields.scala | 18 + .../ApplicableRolesViewRepo.scala | 17 + .../ApplicableRolesViewRepoImpl.scala | 23 + .../ApplicableRolesViewRow.scala | 55 ++ .../ApplicableRolesViewStructure.scala | 27 + .../attributes/AttributesViewFields.scala | 46 + .../attributes/AttributesViewRepo.scala | 17 + .../attributes/AttributesViewRepoImpl.scala | 23 + .../attributes/AttributesViewRow.scala | 223 +++++ .../attributes/AttributesViewStructure.scala | 55 ++ .../CharacterSetsViewFields.scala | 23 + .../CharacterSetsViewRepo.scala | 17 + .../CharacterSetsViewRepoImpl.scala | 23 + .../character_sets/CharacterSetsViewRow.scala | 85 ++ .../CharacterSetsViewStructure.scala | 32 + ...heckConstraintRoutineUsageViewFields.scala | 21 + .../CheckConstraintRoutineUsageViewRepo.scala | 17 + ...ckConstraintRoutineUsageViewRepoImpl.scala | 23 + .../CheckConstraintRoutineUsageViewRow.scala | 73 ++ ...kConstraintRoutineUsageViewStructure.scala | 30 + .../CheckConstraintsViewFields.scala | 19 + .../CheckConstraintsViewRepo.scala | 17 + .../CheckConstraintsViewRepoImpl.scala | 23 + .../CheckConstraintsViewRow.scala | 61 ++ .../CheckConstraintsViewStructure.scala | 28 + ...nCharacterSetApplicabilityViewFields.scala | 21 + ...ionCharacterSetApplicabilityViewRepo.scala | 17 + ...haracterSetApplicabilityViewRepoImpl.scala | 23 + ...tionCharacterSetApplicabilityViewRow.scala | 73 ++ ...aracterSetApplicabilityViewStructure.scala | 30 + .../collations/CollationsViewFields.scala | 19 + .../collations/CollationsViewRepo.scala | 17 + .../collations/CollationsViewRepoImpl.scala | 23 + .../collations/CollationsViewRow.scala | 61 ++ .../collations/CollationsViewStructure.scala | 28 + .../ColumnColumnUsageViewFields.scala | 20 + .../ColumnColumnUsageViewRepo.scala | 17 + .../ColumnColumnUsageViewRepoImpl.scala | 23 + .../ColumnColumnUsageViewRow.scala | 67 ++ .../ColumnColumnUsageViewStructure.scala | 29 + .../ColumnDomainUsageViewFields.scala | 22 + .../ColumnDomainUsageViewRepo.scala | 17 + .../ColumnDomainUsageViewRepoImpl.scala | 23 + .../ColumnDomainUsageViewRow.scala | 79 ++ .../ColumnDomainUsageViewStructure.scala | 31 + .../ColumnOptionsViewFields.scala | 21 + .../ColumnOptionsViewRepo.scala | 17 + .../ColumnOptionsViewRepoImpl.scala | 23 + .../column_options/ColumnOptionsViewRow.scala | 73 ++ .../ColumnOptionsViewStructure.scala | 30 + .../ColumnPrivilegesViewFields.scala | 23 + .../ColumnPrivilegesViewRepo.scala | 17 + .../ColumnPrivilegesViewRepoImpl.scala | 23 + .../ColumnPrivilegesViewRow.scala | 85 ++ .../ColumnPrivilegesViewStructure.scala | 32 + .../ColumnUdtUsageViewFields.scala | 22 + .../ColumnUdtUsageViewRepo.scala | 17 + .../ColumnUdtUsageViewRepoImpl.scala | 23 + .../ColumnUdtUsageViewRow.scala | 79 ++ .../ColumnUdtUsageViewStructure.scala | 31 + .../columns/ColumnsViewFields.scala | 59 ++ .../columns/ColumnsViewRepo.scala | 17 + .../columns/ColumnsViewRepoImpl.scala | 23 + .../columns/ColumnsViewRow.scala | 301 +++++++ .../columns/ColumnsViewStructure.scala | 68 ++ .../ConstraintColumnUsageViewFields.scala | 22 + .../ConstraintColumnUsageViewRepo.scala | 17 + .../ConstraintColumnUsageViewRepoImpl.scala | 23 + .../ConstraintColumnUsageViewRow.scala | 79 ++ .../ConstraintColumnUsageViewStructure.scala | 31 + .../ConstraintTableUsageViewFields.scala | 21 + .../ConstraintTableUsageViewRepo.scala | 17 + .../ConstraintTableUsageViewRepoImpl.scala | 23 + .../ConstraintTableUsageViewRow.scala | 73 ++ .../ConstraintTableUsageViewStructure.scala | 30 + .../DataTypePrivilegesViewFields.scala | 20 + .../DataTypePrivilegesViewRepo.scala | 17 + .../DataTypePrivilegesViewRepoImpl.scala | 23 + .../DataTypePrivilegesViewRow.scala | 67 ++ .../DataTypePrivilegesViewStructure.scala | 29 + .../DomainConstraintsViewFields.scala | 23 + .../DomainConstraintsViewRepo.scala | 17 + .../DomainConstraintsViewRepoImpl.scala | 23 + .../DomainConstraintsViewRow.scala | 85 ++ .../DomainConstraintsViewStructure.scala | 32 + .../DomainUdtUsageViewFields.scala | 21 + .../DomainUdtUsageViewRepo.scala | 17 + .../DomainUdtUsageViewRepoImpl.scala | 23 + .../DomainUdtUsageViewRow.scala | 73 ++ .../DomainUdtUsageViewStructure.scala | 30 + .../domains/DomainsViewFields.scala | 42 + .../domains/DomainsViewRepo.scala | 17 + .../domains/DomainsViewRepoImpl.scala | 23 + .../domains/DomainsViewRow.scala | 199 +++++ .../domains/DomainsViewStructure.scala | 51 ++ .../ElementTypesViewFields.scala | 44 + .../element_types/ElementTypesViewRepo.scala | 17 + .../ElementTypesViewRepoImpl.scala | 23 + .../element_types/ElementTypesViewRow.scala | 211 +++++ .../ElementTypesViewStructure.scala | 53 ++ .../EnabledRolesViewFields.scala | 16 + .../enabled_roles/EnabledRolesViewRepo.scala | 17 + .../EnabledRolesViewRepoImpl.scala | 23 + .../enabled_roles/EnabledRolesViewRow.scala | 36 + .../EnabledRolesViewStructure.scala | 25 + .../ForeignDataWrapperOptionsViewFields.scala | 19 + .../ForeignDataWrapperOptionsViewRepo.scala | 17 + ...oreignDataWrapperOptionsViewRepoImpl.scala | 23 + .../ForeignDataWrapperOptionsViewRow.scala | 63 ++ ...reignDataWrapperOptionsViewStructure.scala | 28 + .../ForeignDataWrappersViewFields.scala | 20 + .../ForeignDataWrappersViewRepo.scala | 17 + .../ForeignDataWrappersViewRepoImpl.scala | 23 + .../ForeignDataWrappersViewRow.scala | 71 ++ .../ForeignDataWrappersViewStructure.scala | 29 + .../ForeignServerOptionsViewFields.scala | 19 + .../ForeignServerOptionsViewRepo.scala | 17 + .../ForeignServerOptionsViewRepoImpl.scala | 23 + .../ForeignServerOptionsViewRow.scala | 63 ++ .../ForeignServerOptionsViewStructure.scala | 28 + .../ForeignServersViewFields.scala | 22 + .../ForeignServersViewRepo.scala | 17 + .../ForeignServersViewRepoImpl.scala | 23 + .../ForeignServersViewRow.scala | 86 ++ .../ForeignServersViewStructure.scala | 31 + .../ForeignTableOptionsViewFields.scala | 20 + .../ForeignTableOptionsViewRepo.scala | 17 + .../ForeignTableOptionsViewRepoImpl.scala | 23 + .../ForeignTableOptionsViewRow.scala | 70 ++ .../ForeignTableOptionsViewStructure.scala | 29 + .../ForeignTablesViewFields.scala | 20 + .../ForeignTablesViewRepo.scala | 17 + .../ForeignTablesViewRepoImpl.scala | 23 + .../foreign_tables/ForeignTablesViewRow.scala | 72 ++ .../ForeignTablesViewStructure.scala | 29 + ...formationSchemaCatalogNameViewFields.scala | 16 + ...InformationSchemaCatalogNameViewRepo.scala | 17 + ...rmationSchemaCatalogNameViewRepoImpl.scala | 23 + .../InformationSchemaCatalogNameViewRow.scala | 36 + ...mationSchemaCatalogNameViewStructure.scala | 25 + .../KeyColumnUsageViewFields.scala | 24 + .../KeyColumnUsageViewRepo.scala | 17 + .../KeyColumnUsageViewRepoImpl.scala | 23 + .../KeyColumnUsageViewRow.scala | 91 ++ .../KeyColumnUsageViewStructure.scala | 33 + .../parameters/ParametersViewFields.scala | 47 + .../parameters/ParametersViewRepo.scala | 17 + .../parameters/ParametersViewRepoImpl.scala | 23 + .../parameters/ParametersViewRow.scala | 229 +++++ .../parameters/ParametersViewStructure.scala | 56 ++ .../ReferentialConstraintsViewFields.scala | 24 + .../ReferentialConstraintsViewRepo.scala | 17 + .../ReferentialConstraintsViewRepoImpl.scala | 23 + .../ReferentialConstraintsViewRow.scala | 91 ++ .../ReferentialConstraintsViewStructure.scala | 33 + .../RoleColumnGrantsViewFields.scala | 23 + .../RoleColumnGrantsViewRepo.scala | 17 + .../RoleColumnGrantsViewRepoImpl.scala | 23 + .../RoleColumnGrantsViewRow.scala | 93 ++ .../RoleColumnGrantsViewStructure.scala | 32 + .../RoleRoutineGrantsViewFields.scala | 25 + .../RoleRoutineGrantsViewRepo.scala | 17 + .../RoleRoutineGrantsViewRepoImpl.scala | 23 + .../RoleRoutineGrantsViewRow.scala | 107 +++ .../RoleRoutineGrantsViewStructure.scala | 34 + .../RoleTableGrantsViewFields.scala | 23 + .../RoleTableGrantsViewRepo.scala | 17 + .../RoleTableGrantsViewRepoImpl.scala | 23 + .../RoleTableGrantsViewRow.scala | 93 ++ .../RoleTableGrantsViewStructure.scala | 32 + .../RoleUdtGrantsViewFields.scala | 22 + .../RoleUdtGrantsViewRepo.scala | 17 + .../RoleUdtGrantsViewRepoImpl.scala | 23 + .../RoleUdtGrantsViewRow.scala | 86 ++ .../RoleUdtGrantsViewStructure.scala | 31 + .../RoleUsageGrantsViewFields.scala | 23 + .../RoleUsageGrantsViewRepo.scala | 17 + .../RoleUsageGrantsViewRepoImpl.scala | 23 + .../RoleUsageGrantsViewRow.scala | 93 ++ .../RoleUsageGrantsViewStructure.scala | 32 + .../RoutineColumnUsageViewFields.scala | 25 + .../RoutineColumnUsageViewRepo.scala | 17 + .../RoutineColumnUsageViewRepoImpl.scala | 23 + .../RoutineColumnUsageViewRow.scala | 97 ++ .../RoutineColumnUsageViewStructure.scala | 34 + .../RoutinePrivilegesViewFields.scala | 25 + .../RoutinePrivilegesViewRepo.scala | 17 + .../RoutinePrivilegesViewRepoImpl.scala | 23 + .../RoutinePrivilegesViewRow.scala | 97 ++ .../RoutinePrivilegesViewStructure.scala | 34 + .../RoutineRoutineUsageViewFields.scala | 21 + .../RoutineRoutineUsageViewRepo.scala | 17 + .../RoutineRoutineUsageViewRepoImpl.scala | 23 + .../RoutineRoutineUsageViewRow.scala | 73 ++ .../RoutineRoutineUsageViewStructure.scala | 30 + .../RoutineSequenceUsageViewFields.scala | 24 + .../RoutineSequenceUsageViewRepo.scala | 17 + .../RoutineSequenceUsageViewRepoImpl.scala | 23 + .../RoutineSequenceUsageViewRow.scala | 91 ++ .../RoutineSequenceUsageViewStructure.scala | 33 + .../RoutineTableUsageViewFields.scala | 24 + .../RoutineTableUsageViewRepo.scala | 17 + .../RoutineTableUsageViewRepoImpl.scala | 23 + .../RoutineTableUsageViewRow.scala | 91 ++ .../RoutineTableUsageViewStructure.scala | 33 + .../routines/RoutinesViewFields.scala | 98 ++ .../routines/RoutinesViewRepo.scala | 17 + .../routines/RoutinesViewRepoImpl.scala | 23 + .../routines/RoutinesViewRow.scala | 530 +++++++++++ .../routines/RoutinesViewStructure.scala | 107 +++ .../schemata/SchemataViewFields.scala | 22 + .../schemata/SchemataViewRepo.scala | 17 + .../schemata/SchemataViewRepoImpl.scala | 23 + .../schemata/SchemataViewRow.scala | 79 ++ .../schemata/SchemataViewStructure.scala | 31 + .../sequences/SequencesViewFields.scala | 27 + .../sequences/SequencesViewRepo.scala | 17 + .../sequences/SequencesViewRepoImpl.scala | 23 + .../sequences/SequencesViewRow.scala | 109 +++ .../sequences/SequencesViewStructure.scala | 36 + .../sql_features/SqlFeaturesFields.scala | 24 + .../sql_features/SqlFeaturesRepo.scala | 23 + .../sql_features/SqlFeaturesRepoImpl.scala | 42 + .../sql_features/SqlFeaturesRow.scala | 81 ++ .../sql_features/SqlFeaturesStructure.scala | 33 + .../SqlImplementationInfoFields.scala | 22 + .../SqlImplementationInfoRepo.scala | 23 + .../SqlImplementationInfoRepoImpl.scala | 42 + .../SqlImplementationInfoRow.scala | 69 ++ .../SqlImplementationInfoStructure.scala | 31 + .../sql_parts/SqlPartsFields.scala | 22 + .../sql_parts/SqlPartsRepo.scala | 23 + .../sql_parts/SqlPartsRepoImpl.scala | 42 + .../sql_parts/SqlPartsRow.scala | 69 ++ .../sql_parts/SqlPartsStructure.scala | 31 + .../sql_sizing/SqlSizingFields.scala | 21 + .../sql_sizing/SqlSizingRepo.scala | 23 + .../sql_sizing/SqlSizingRepoImpl.scala | 42 + .../sql_sizing/SqlSizingRow.scala | 63 ++ .../sql_sizing/SqlSizingStructure.scala | 30 + .../TableConstraintsViewFields.scala | 25 + .../TableConstraintsViewRepo.scala | 17 + .../TableConstraintsViewRepoImpl.scala | 23 + .../TableConstraintsViewRow.scala | 97 ++ .../TableConstraintsViewStructure.scala | 34 + .../TablePrivilegesViewFields.scala | 23 + .../TablePrivilegesViewRepo.scala | 17 + .../TablePrivilegesViewRepoImpl.scala | 23 + .../TablePrivilegesViewRow.scala | 85 ++ .../TablePrivilegesViewStructure.scala | 32 + .../tables/TablesViewFields.scala | 27 + .../tables/TablesViewRepo.scala | 17 + .../tables/TablesViewRepoImpl.scala | 23 + .../tables/TablesViewRow.scala | 109 +++ .../tables/TablesViewStructure.scala | 36 + .../transforms/TransformsViewFields.scala | 23 + .../transforms/TransformsViewRepo.scala | 17 + .../transforms/TransformsViewRepoImpl.scala | 23 + .../transforms/TransformsViewRow.scala | 85 ++ .../transforms/TransformsViewStructure.scala | 32 + .../TriggeredUpdateColumnsViewFields.scala | 22 + .../TriggeredUpdateColumnsViewRepo.scala | 17 + .../TriggeredUpdateColumnsViewRepoImpl.scala | 23 + .../TriggeredUpdateColumnsViewRow.scala | 79 ++ .../TriggeredUpdateColumnsViewStructure.scala | 31 + .../triggers/TriggersViewFields.scala | 33 + .../triggers/TriggersViewRepo.scala | 17 + .../triggers/TriggersViewRepoImpl.scala | 23 + .../triggers/TriggersViewRow.scala | 140 +++ .../triggers/TriggersViewStructure.scala | 42 + .../UdtPrivilegesViewFields.scala | 22 + .../UdtPrivilegesViewRepo.scala | 17 + .../UdtPrivilegesViewRepoImpl.scala | 23 + .../udt_privileges/UdtPrivilegesViewRow.scala | 79 ++ .../UdtPrivilegesViewStructure.scala | 31 + .../UsagePrivilegesViewFields.scala | 23 + .../UsagePrivilegesViewRepo.scala | 17 + .../UsagePrivilegesViewRepoImpl.scala | 23 + .../UsagePrivilegesViewRow.scala | 85 ++ .../UsagePrivilegesViewStructure.scala | 32 + .../UserDefinedTypesViewFields.scala | 44 + .../UserDefinedTypesViewRepo.scala | 17 + .../UserDefinedTypesViewRepoImpl.scala | 23 + .../UserDefinedTypesViewRow.scala | 211 +++++ .../UserDefinedTypesViewStructure.scala | 53 ++ .../UserMappingOptionsViewFields.scala | 20 + .../UserMappingOptionsViewRepo.scala | 17 + .../UserMappingOptionsViewRepoImpl.scala | 23 + .../UserMappingOptionsViewRow.scala | 70 ++ .../UserMappingOptionsViewStructure.scala | 29 + .../UserMappingsViewFields.scala | 18 + .../user_mappings/UserMappingsViewRepo.scala | 17 + .../UserMappingsViewRepoImpl.scala | 23 + .../user_mappings/UserMappingsViewRow.scala | 58 ++ .../UserMappingsViewStructure.scala | 27 + .../ViewColumnUsageViewFields.scala | 22 + .../ViewColumnUsageViewRepo.scala | 17 + .../ViewColumnUsageViewRepoImpl.scala | 23 + .../ViewColumnUsageViewRow.scala | 79 ++ .../ViewColumnUsageViewStructure.scala | 31 + .../ViewRoutineUsageViewFields.scala | 21 + .../ViewRoutineUsageViewRepo.scala | 17 + .../ViewRoutineUsageViewRepoImpl.scala | 23 + .../ViewRoutineUsageViewRow.scala | 73 ++ .../ViewRoutineUsageViewStructure.scala | 30 + .../ViewTableUsageViewFields.scala | 21 + .../ViewTableUsageViewRepo.scala | 17 + .../ViewTableUsageViewRepoImpl.scala | 23 + .../ViewTableUsageViewRow.scala | 73 ++ .../ViewTableUsageViewStructure.scala | 30 + .../views/ViewsViewFields.scala | 25 + .../views/ViewsViewRepo.scala | 17 + .../views/ViewsViewRepoImpl.scala | 23 + .../views/ViewsViewRow.scala | 97 ++ .../views/ViewsViewStructure.scala | 34 + .../adventureworks/package.scala | 243 +++++ .../adventureworks/pe/a/AViewFields.scala | 31 + .../adventureworks/pe/a/AViewRepo.scala | 17 + .../adventureworks/pe/a/AViewRepoImpl.scala | 23 + .../adventureworks/pe/a/AViewRow.scala | 112 +++ .../adventureworks/pe/a/AViewStructure.scala | 40 + .../adventureworks/pe/at/AtViewFields.scala | 24 + .../adventureworks/pe/at/AtViewRepo.scala | 17 + .../adventureworks/pe/at/AtViewRepoImpl.scala | 23 + .../adventureworks/pe/at/AtViewRow.scala | 76 ++ .../pe/at/AtViewStructure.scala | 33 + .../adventureworks/pe/be/BeViewFields.scala | 22 + .../adventureworks/pe/be/BeViewRepo.scala | 17 + .../adventureworks/pe/be/BeViewRepoImpl.scala | 23 + .../adventureworks/pe/be/BeViewRow.scala | 68 ++ .../pe/be/BeViewStructure.scala | 31 + .../adventureworks/pe/bea/BeaViewFields.scala | 26 + .../adventureworks/pe/bea/BeaViewRepo.scala | 17 + .../pe/bea/BeaViewRepoImpl.scala | 23 + .../adventureworks/pe/bea/BeaViewRow.scala | 84 ++ .../pe/bea/BeaViewStructure.scala | 35 + .../adventureworks/pe/bec/BecViewFields.scala | 25 + .../adventureworks/pe/bec/BecViewRepo.scala | 17 + .../pe/bec/BecViewRepoImpl.scala | 23 + .../adventureworks/pe/bec/BecViewRow.scala | 83 ++ .../pe/bec/BecViewStructure.scala | 34 + .../adventureworks/pe/cr/CrViewFields.scala | 21 + .../adventureworks/pe/cr/CrViewRepo.scala | 17 + .../adventureworks/pe/cr/CrViewRepoImpl.scala | 23 + .../adventureworks/pe/cr/CrViewRow.scala | 61 ++ .../pe/cr/CrViewStructure.scala | 30 + .../adventureworks/pe/ct/CtViewFields.scala | 22 + .../adventureworks/pe/ct/CtViewRepo.scala | 17 + .../adventureworks/pe/ct/CtViewRepoImpl.scala | 23 + .../adventureworks/pe/ct/CtViewRow.scala | 68 ++ .../pe/ct/CtViewStructure.scala | 31 + .../adventureworks/pe/e/EViewFields.scala | 25 + .../adventureworks/pe/e/EViewRepo.scala | 17 + .../adventureworks/pe/e/EViewRepoImpl.scala | 23 + .../adventureworks/pe/e/EViewRow.scala | 82 ++ .../adventureworks/pe/e/EViewStructure.scala | 34 + .../adventureworks/pe/p/PViewFields.scala | 37 + .../adventureworks/pe/p/PViewRepo.scala | 17 + .../adventureworks/pe/p/PViewRepoImpl.scala | 23 + .../adventureworks/pe/p/PViewRow.scala | 142 +++ .../adventureworks/pe/p/PViewStructure.scala | 46 + .../adventureworks/pe/pa/PaViewFields.scala | 24 + .../adventureworks/pe/pa/PaViewRepo.scala | 17 + .../adventureworks/pe/pa/PaViewRepoImpl.scala | 23 + .../adventureworks/pe/pa/PaViewRow.scala | 82 ++ .../pe/pa/PaViewStructure.scala | 33 + .../adventureworks/pe/pnt/PntViewFields.scala | 22 + .../adventureworks/pe/pnt/PntViewRepo.scala | 17 + .../pe/pnt/PntViewRepoImpl.scala | 23 + .../adventureworks/pe/pnt/PntViewRow.scala | 68 ++ .../pe/pnt/PntViewStructure.scala | 31 + .../adventureworks/pe/pp/PpViewFields.scala | 24 + .../adventureworks/pe/pp/PpViewRepo.scala | 17 + .../adventureworks/pe/pp/PpViewRepoImpl.scala | 23 + .../adventureworks/pe/pp/PpViewRow.scala | 76 ++ .../pe/pp/PpViewStructure.scala | 33 + .../adventureworks/pe/sp/SpViewFields.scala | 31 + .../adventureworks/pe/sp/SpViewRepo.scala | 17 + .../adventureworks/pe/sp/SpViewRepoImpl.scala | 23 + .../adventureworks/pe/sp/SpViewRow.scala | 107 +++ .../pe/sp/SpViewStructure.scala | 40 + .../person/address/AddressFields.scala | 30 + .../person/address/AddressId.scala | 30 + .../person/address/AddressRepo.scala | 30 + .../person/address/AddressRepoImpl.scala | 128 +++ .../person/address/AddressRepoMock.scala | 80 ++ .../person/address/AddressRow.scala | 103 +++ .../person/address/AddressRowUnsaved.scala | 112 +++ .../person/address/AddressStructure.scala | 39 + .../addresstype/AddresstypeFields.scala | 23 + .../person/addresstype/AddresstypeId.scala | 30 + .../person/addresstype/AddresstypeRepo.scala | 30 + .../addresstype/AddresstypeRepoImpl.scala | 106 +++ .../addresstype/AddresstypeRepoMock.scala | 80 ++ .../person/addresstype/AddresstypeRow.scala | 66 ++ .../addresstype/AddresstypeRowUnsaved.scala | 75 ++ .../addresstype/AddresstypeStructure.scala | 32 + .../businessentity/BusinessentityFields.scala | 21 + .../businessentity/BusinessentityId.scala | 30 + .../businessentity/BusinessentityRepo.scala | 30 + .../BusinessentityRepoImpl.scala | 101 +++ .../BusinessentityRepoMock.scala | 80 ++ .../businessentity/BusinessentityRow.scala | 58 ++ .../BusinessentityRowUnsaved.scala | 67 ++ .../BusinessentityStructure.scala | 30 + .../BusinessentityaddressFields.scala | 26 + .../BusinessentityaddressId.scala | 44 + .../BusinessentityaddressRepo.scala | 29 + .../BusinessentityaddressRepoImpl.scala | 102 +++ .../BusinessentityaddressRepoMock.scala | 77 ++ .../BusinessentityaddressRow.scala | 80 ++ .../BusinessentityaddressRowUnsaved.scala | 83 ++ .../BusinessentityaddressStructure.scala | 35 + .../BusinessentitycontactFields.scala | 25 + .../BusinessentitycontactId.scala | 43 + .../BusinessentitycontactRepo.scala | 29 + .../BusinessentitycontactRepoImpl.scala | 101 +++ .../BusinessentitycontactRepoMock.scala | 77 ++ .../BusinessentitycontactRow.scala | 79 ++ .../BusinessentitycontactRowUnsaved.scala | 82 ++ .../BusinessentitycontactStructure.scala | 34 + .../contacttype/ContacttypeFields.scala | 21 + .../person/contacttype/ContacttypeId.scala | 30 + .../person/contacttype/ContacttypeRepo.scala | 30 + .../contacttype/ContacttypeRepoImpl.scala | 98 ++ .../contacttype/ContacttypeRepoMock.scala | 80 ++ .../person/contacttype/ContacttypeRow.scala | 59 ++ .../contacttype/ContacttypeRowUnsaved.scala | 64 ++ .../contacttype/ContacttypeStructure.scala | 30 + .../countryregion/CountryregionFields.scala | 21 + .../countryregion/CountryregionId.scala | 30 + .../countryregion/CountryregionRepo.scala | 30 + .../countryregion/CountryregionRepoImpl.scala | 95 ++ .../countryregion/CountryregionRepoMock.scala | 80 ++ .../countryregion/CountryregionRow.scala | 59 ++ .../CountryregionRowUnsaved.scala | 60 ++ .../CountryregionStructure.scala | 30 + .../emailaddress/EmailaddressFields.scala | 25 + .../person/emailaddress/EmailaddressId.scala | 38 + .../emailaddress/EmailaddressRepo.scala | 29 + .../emailaddress/EmailaddressRepoImpl.scala | 106 +++ .../emailaddress/EmailaddressRepoMock.scala | 77 ++ .../person/emailaddress/EmailaddressRow.scala | 76 ++ .../emailaddress/EmailaddressRowUnsaved.scala | 83 ++ .../emailaddress/EmailaddressStructure.scala | 34 + .../person/password/PasswordFields.scala | 24 + .../person/password/PasswordRepo.scala | 31 + .../person/password/PasswordRepoImpl.scala | 108 +++ .../person/password/PasswordRepoMock.scala | 81 ++ .../person/password/PasswordRow.scala | 73 ++ .../person/password/PasswordRowUnsaved.scala | 78 ++ .../person/password/PasswordStructure.scala | 33 + .../person/person/PersonFields.scala | 37 + .../person/person/PersonRepo.scala | 31 + .../person/person/PersonRepoImpl.scala | 150 ++++ .../person/person/PersonRepoMock.scala | 81 ++ .../person/person/PersonRow.scala | 136 +++ .../person/person/PersonRowUnsaved.scala | 149 ++++ .../person/person/PersonStructure.scala | 46 + .../personphone/PersonphoneFields.scala | 24 + .../person/personphone/PersonphoneId.scala | 44 + .../person/personphone/PersonphoneRepo.scala | 29 + .../personphone/PersonphoneRepoImpl.scala | 94 ++ .../personphone/PersonphoneRepoMock.scala | 77 ++ .../person/personphone/PersonphoneRow.scala | 72 ++ .../personphone/PersonphoneRowUnsaved.scala | 71 ++ .../personphone/PersonphoneStructure.scala | 33 + .../PhonenumbertypeFields.scala | 21 + .../phonenumbertype/PhonenumbertypeId.scala | 30 + .../phonenumbertype/PhonenumbertypeRepo.scala | 30 + .../PhonenumbertypeRepoImpl.scala | 98 ++ .../PhonenumbertypeRepoMock.scala | 80 ++ .../phonenumbertype/PhonenumbertypeRow.scala | 59 ++ .../PhonenumbertypeRowUnsaved.scala | 64 ++ .../PhonenumbertypeStructure.scala | 30 + .../stateprovince/StateprovinceFields.scala | 30 + .../stateprovince/StateprovinceId.scala | 30 + .../stateprovince/StateprovinceRepo.scala | 30 + .../stateprovince/StateprovinceRepoImpl.scala | 129 +++ .../stateprovince/StateprovinceRepoMock.scala | 80 ++ .../stateprovince/StateprovinceRow.scala | 99 ++ .../StateprovinceRowUnsaved.scala | 112 +++ .../StateprovinceStructure.scala | 39 + .../VadditionalcontactinfoViewFields.scala | 39 + .../VadditionalcontactinfoViewRepo.scala | 17 + .../VadditionalcontactinfoViewRepoImpl.scala | 23 + .../VadditionalcontactinfoViewRow.scala | 151 ++++ .../VadditionalcontactinfoViewStructure.scala | 48 + .../VstateprovincecountryregionMVFields.scala | 27 + .../VstateprovincecountryregionMVRepo.scala | 17 + ...stateprovincecountryregionMVRepoImpl.scala | 23 + .../VstateprovincecountryregionMVRow.scala | 91 ++ ...tateprovincecountryregionMVStructure.scala | 36 + .../person_detail/PersonDetailSqlRepo.scala | 16 + .../PersonDetailSqlRepoImpl.scala | 38 + .../person_detail/PersonDetailSqlRow.scala | 109 +++ .../person_dynamic/PersonDynamicSqlRepo.scala | 14 + .../PersonDynamicSqlRepoImpl.scala | 24 + .../person_dynamic/PersonDynamicSqlRow.scala | 66 ++ .../PersonRowJoinSqlRepo.scala | 14 + .../PersonRowJoinSqlRepoImpl.scala | 23 + .../person_row_join/PersonRowJoinSqlRow.scala | 57 ++ .../pg_aggregate/PgAggregateFields.scala | 41 + .../pg_aggregate/PgAggregateId.scala | 31 + .../pg_aggregate/PgAggregateRepo.scala | 29 + .../pg_aggregate/PgAggregateRepoImpl.scala | 129 +++ .../pg_aggregate/PgAggregateRepoMock.scala | 76 ++ .../pg_aggregate/PgAggregateRow.scala | 171 ++++ .../pg_aggregate/PgAggregateStructure.scala | 50 ++ .../pg_catalog/pg_am/PgAmFields.scala | 21 + .../pg_catalog/pg_am/PgAmId.scala | 30 + .../pg_catalog/pg_am/PgAmRepo.scala | 30 + .../pg_catalog/pg_am/PgAmRepoImpl.scala | 80 ++ .../pg_catalog/pg_am/PgAmRepoMock.scala | 79 ++ .../pg_catalog/pg_am/PgAmRow.scala | 62 ++ .../pg_catalog/pg_am/PgAmStructure.scala | 30 + .../pg_catalog/pg_amop/PgAmopFields.scala | 26 + .../pg_catalog/pg_amop/PgAmopId.scala | 30 + .../pg_catalog/pg_amop/PgAmopRepo.scala | 32 + .../pg_catalog/pg_amop/PgAmopRepoImpl.scala | 101 +++ .../pg_catalog/pg_amop/PgAmopRepoMock.scala | 83 ++ .../pg_catalog/pg_amop/PgAmopRow.scala | 92 ++ .../pg_catalog/pg_amop/PgAmopStructure.scala | 35 + .../pg_catalog/pg_amproc/PgAmprocFields.scala | 24 + .../pg_catalog/pg_amproc/PgAmprocId.scala | 30 + .../pg_catalog/pg_amproc/PgAmprocRepo.scala | 31 + .../pg_amproc/PgAmprocRepoImpl.scala | 87 ++ .../pg_amproc/PgAmprocRepoMock.scala | 80 ++ .../pg_catalog/pg_amproc/PgAmprocRow.scala | 75 ++ .../pg_amproc/PgAmprocStructure.scala | 33 + .../pg_attrdef/PgAttrdefFields.scala | 22 + .../pg_catalog/pg_attrdef/PgAttrdefId.scala | 30 + .../pg_catalog/pg_attrdef/PgAttrdefRepo.scala | 31 + .../pg_attrdef/PgAttrdefRepoImpl.scala | 81 ++ .../pg_attrdef/PgAttrdefRepoMock.scala | 80 ++ .../pg_catalog/pg_attrdef/PgAttrdefRow.scala | 63 ++ .../pg_attrdef/PgAttrdefStructure.scala | 31 + .../pg_attribute/PgAttributeFields.scala | 46 + .../pg_attribute/PgAttributeId.scala | 38 + .../pg_attribute/PgAttributeRepo.scala | 29 + .../pg_attribute/PgAttributeRepoImpl.scala | 143 +++ .../pg_attribute/PgAttributeRepoMock.scala | 76 ++ .../pg_attribute/PgAttributeRow.scala | 198 ++++ .../pg_attribute/PgAttributeStructure.scala | 55 ++ .../pg_auth_members/PgAuthMembersFields.scala | 20 + .../pg_auth_members/PgAuthMembersId.scala | 37 + .../pg_auth_members/PgAuthMembersRepo.scala | 29 + .../PgAuthMembersRepoImpl.scala | 74 ++ .../PgAuthMembersRepoMock.scala | 76 ++ .../pg_auth_members/PgAuthMembersRow.scala | 63 ++ .../PgAuthMembersStructure.scala | 29 + .../pg_catalog/pg_authid/PgAuthidFields.scala | 30 + .../pg_catalog/pg_authid/PgAuthidId.scala | 30 + .../pg_catalog/pg_authid/PgAuthidRepo.scala | 30 + .../pg_authid/PgAuthidRepoImpl.scala | 104 +++ .../pg_authid/PgAuthidRepoMock.scala | 79 ++ .../pg_catalog/pg_authid/PgAuthidRow.scala | 110 +++ .../pg_authid/PgAuthidStructure.scala | 39 + ...AvailableExtensionVersionsViewFields.scala | 24 + ...PgAvailableExtensionVersionsViewRepo.scala | 17 + ...ailableExtensionVersionsViewRepoImpl.scala | 23 + .../PgAvailableExtensionVersionsViewRow.scala | 91 ++ ...ilableExtensionVersionsViewStructure.scala | 33 + .../PgAvailableExtensionsViewFields.scala | 19 + .../PgAvailableExtensionsViewRepo.scala | 17 + .../PgAvailableExtensionsViewRepoImpl.scala | 23 + .../PgAvailableExtensionsViewRow.scala | 62 ++ .../PgAvailableExtensionsViewStructure.scala | 28 + .../PgBackendMemoryContextsViewFields.scala | 24 + .../PgBackendMemoryContextsViewRepo.scala | 17 + .../PgBackendMemoryContextsViewRepoImpl.scala | 23 + .../PgBackendMemoryContextsViewRow.scala | 91 ++ ...PgBackendMemoryContextsViewStructure.scala | 33 + .../pg_catalog/pg_cast/PgCastFields.scala | 22 + .../pg_catalog/pg_cast/PgCastId.scala | 30 + .../pg_catalog/pg_cast/PgCastRepo.scala | 30 + .../pg_catalog/pg_cast/PgCastRepoImpl.scala | 85 ++ .../pg_catalog/pg_cast/PgCastRepoMock.scala | 79 ++ .../pg_catalog/pg_cast/PgCastRow.scala | 73 ++ .../pg_catalog/pg_cast/PgCastStructure.scala | 31 + .../pg_catalog/pg_class/PgClassFields.scala | 54 ++ .../pg_catalog/pg_class/PgClassId.scala | 30 + .../pg_catalog/pg_class/PgClassRepo.scala | 30 + .../pg_catalog/pg_class/PgClassRepoImpl.scala | 170 ++++ .../pg_catalog/pg_class/PgClassRepoMock.scala | 79 ++ .../pg_catalog/pg_class/PgClassRow.scala | 239 +++++ .../pg_class/PgClassStructure.scala | 63 ++ .../pg_collation/PgCollationFields.scala | 27 + .../pg_collation/PgCollationId.scala | 30 + .../pg_collation/PgCollationRepo.scala | 30 + .../pg_collation/PgCollationRepoImpl.scala | 97 ++ .../pg_collation/PgCollationRepoMock.scala | 79 ++ .../pg_collation/PgCollationRow.scala | 97 ++ .../pg_collation/PgCollationStructure.scala | 36 + .../pg_config/PgConfigViewFields.scala | 17 + .../pg_config/PgConfigViewRepo.scala | 17 + .../pg_config/PgConfigViewRepoImpl.scala | 23 + .../pg_config/PgConfigViewRow.scala | 49 + .../pg_config/PgConfigViewStructure.scala | 26 + .../pg_constraint/PgConstraintFields.scala | 44 + .../pg_constraint/PgConstraintId.scala | 30 + .../pg_constraint/PgConstraintRepo.scala | 30 + .../pg_constraint/PgConstraintRepoImpl.scala | 144 +++ .../pg_constraint/PgConstraintRepoMock.scala | 79 ++ .../pg_constraint/PgConstraintRow.scala | 189 ++++ .../pg_constraint/PgConstraintStructure.scala | 53 ++ .../pg_conversion/PgConversionFields.scala | 25 + .../pg_conversion/PgConversionId.scala | 30 + .../pg_conversion/PgConversionRepo.scala | 31 + .../pg_conversion/PgConversionRepoImpl.scala | 98 ++ .../pg_conversion/PgConversionRepoMock.scala | 82 ++ .../pg_conversion/PgConversionRow.scala | 86 ++ .../pg_conversion/PgConversionStructure.scala | 34 + .../pg_cursors/PgCursorsViewFields.scala | 22 + .../pg_cursors/PgCursorsViewRepo.scala | 17 + .../pg_cursors/PgCursorsViewRepoImpl.scala | 23 + .../pg_cursors/PgCursorsViewRow.scala | 74 ++ .../pg_cursors/PgCursorsViewStructure.scala | 31 + .../pg_database/PgDatabaseFields.scala | 33 + .../pg_catalog/pg_database/PgDatabaseId.scala | 30 + .../pg_database/PgDatabaseRepo.scala | 30 + .../pg_database/PgDatabaseRepoImpl.scala | 111 +++ .../pg_database/PgDatabaseRepoMock.scala | 79 ++ .../pg_database/PgDatabaseRow.scala | 123 +++ .../pg_database/PgDatabaseStructure.scala | 42 + .../PgDbRoleSettingFields.scala | 19 + .../PgDbRoleSettingId.scala | 37 + .../PgDbRoleSettingRepo.scala | 28 + .../PgDbRoleSettingRepoImpl.scala | 65 ++ .../PgDbRoleSettingRepoMock.scala | 73 ++ .../PgDbRoleSettingRow.scala | 57 ++ .../PgDbRoleSettingStructure.scala | 28 + .../pg_default_acl/PgDefaultAclFields.scala | 22 + .../pg_default_acl/PgDefaultAclId.scala | 30 + .../pg_default_acl/PgDefaultAclRepo.scala | 30 + .../pg_default_acl/PgDefaultAclRepoImpl.scala | 83 ++ .../pg_default_acl/PgDefaultAclRepoMock.scala | 79 ++ .../pg_default_acl/PgDefaultAclRow.scala | 68 ++ .../PgDefaultAclStructure.scala | 31 + .../pg_catalog/pg_depend/PgDependFields.scala | 22 + .../pg_catalog/pg_depend/PgDependRepo.scala | 23 + .../pg_depend/PgDependRepoImpl.scala | 40 + .../pg_catalog/pg_depend/PgDependRow.scala | 79 ++ .../pg_depend/PgDependStructure.scala | 31 + .../pg_description/PgDescriptionFields.scala | 20 + .../pg_description/PgDescriptionId.scala | 41 + .../pg_description/PgDescriptionRepo.scala | 28 + .../PgDescriptionRepoImpl.scala | 66 ++ .../PgDescriptionRepoMock.scala | 73 ++ .../pg_description/PgDescriptionRow.scala | 63 ++ .../PgDescriptionStructure.scala | 29 + .../pg_catalog/pg_enum/PgEnumFields.scala | 20 + .../pg_catalog/pg_enum/PgEnumId.scala | 30 + .../pg_catalog/pg_enum/PgEnumRepo.scala | 31 + .../pg_catalog/pg_enum/PgEnumRepoImpl.scala | 85 ++ .../pg_catalog/pg_enum/PgEnumRepoMock.scala | 82 ++ .../pg_catalog/pg_enum/PgEnumRow.scala | 61 ++ .../pg_catalog/pg_enum/PgEnumStructure.scala | 29 + .../PgEventTriggerFields.scala | 24 + .../pg_event_trigger/PgEventTriggerId.scala | 30 + .../pg_event_trigger/PgEventTriggerRepo.scala | 30 + .../PgEventTriggerRepoImpl.scala | 88 ++ .../PgEventTriggerRepoMock.scala | 79 ++ .../pg_event_trigger/PgEventTriggerRow.scala | 79 ++ .../PgEventTriggerStructure.scala | 33 + .../pg_extension/PgExtensionFields.scala | 25 + .../pg_extension/PgExtensionId.scala | 30 + .../pg_extension/PgExtensionRepo.scala | 30 + .../pg_extension/PgExtensionRepoImpl.scala | 91 ++ .../pg_extension/PgExtensionRepoMock.scala | 79 ++ .../pg_extension/PgExtensionRow.scala | 85 ++ .../pg_extension/PgExtensionStructure.scala | 34 + .../PgFileSettingsViewFields.scala | 22 + .../PgFileSettingsViewRepo.scala | 17 + .../PgFileSettingsViewRepoImpl.scala | 23 + .../PgFileSettingsViewRow.scala | 79 ++ .../PgFileSettingsViewStructure.scala | 31 + .../PgForeignDataWrapperFields.scala | 25 + .../PgForeignDataWrapperId.scala | 30 + .../PgForeignDataWrapperRepo.scala | 30 + .../PgForeignDataWrapperRepoImpl.scala | 89 ++ .../PgForeignDataWrapperRepoMock.scala | 79 ++ .../PgForeignDataWrapperRow.scala | 80 ++ .../PgForeignDataWrapperStructure.scala | 34 + .../PgForeignServerFields.scala | 26 + .../pg_foreign_server/PgForeignServerId.scala | 30 + .../PgForeignServerRepo.scala | 30 + .../PgForeignServerRepoImpl.scala | 92 ++ .../PgForeignServerRepoMock.scala | 79 ++ .../PgForeignServerRow.scala | 86 ++ .../PgForeignServerStructure.scala | 35 + .../PgForeignTableFields.scala | 20 + .../pg_foreign_table/PgForeignTableId.scala | 30 + .../pg_foreign_table/PgForeignTableRepo.scala | 29 + .../PgForeignTableRepoImpl.scala | 70 ++ .../PgForeignTableRepoMock.scala | 76 ++ .../pg_foreign_table/PgForeignTableRow.scala | 55 ++ .../PgForeignTableStructure.scala | 29 + .../pg_group/PgGroupViewFields.scala | 20 + .../pg_catalog/pg_group/PgGroupViewRepo.scala | 17 + .../pg_group/PgGroupViewRepoImpl.scala | 23 + .../pg_catalog/pg_group/PgGroupViewRow.scala | 58 ++ .../pg_group/PgGroupViewStructure.scala | 29 + .../PgHbaFileRulesViewFields.scala | 24 + .../PgHbaFileRulesViewRepo.scala | 17 + .../PgHbaFileRulesViewRepoImpl.scala | 23 + .../PgHbaFileRulesViewRow.scala | 91 ++ .../PgHbaFileRulesViewStructure.scala | 33 + .../pg_catalog/pg_index/PgIndexFields.scala | 41 + .../pg_catalog/pg_index/PgIndexId.scala | 30 + .../pg_catalog/pg_index/PgIndexRepo.scala | 29 + .../pg_catalog/pg_index/PgIndexRepoImpl.scala | 125 +++ .../pg_catalog/pg_index/PgIndexRepoMock.scala | 76 ++ .../pg_catalog/pg_index/PgIndexRow.scala | 161 ++++ .../pg_index/PgIndexStructure.scala | 50 ++ .../pg_indexes/PgIndexesViewFields.scala | 21 + .../pg_indexes/PgIndexesViewRepo.scala | 17 + .../pg_indexes/PgIndexesViewRepoImpl.scala | 23 + .../pg_indexes/PgIndexesViewRow.scala | 71 ++ .../pg_indexes/PgIndexesViewStructure.scala | 30 + .../pg_inherits/PgInheritsFields.scala | 20 + .../pg_catalog/pg_inherits/PgInheritsId.scala | 37 + .../pg_inherits/PgInheritsRepo.scala | 28 + .../pg_inherits/PgInheritsRepoImpl.scala | 68 ++ .../pg_inherits/PgInheritsRepoMock.scala | 73 ++ .../pg_inherits/PgInheritsRow.scala | 63 ++ .../pg_inherits/PgInheritsStructure.scala | 29 + .../pg_init_privs/PgInitPrivsFields.scala | 22 + .../pg_init_privs/PgInitPrivsId.scala | 41 + .../pg_init_privs/PgInitPrivsRepo.scala | 28 + .../pg_init_privs/PgInitPrivsRepoImpl.scala | 70 ++ .../pg_init_privs/PgInitPrivsRepoMock.scala | 73 ++ .../pg_init_privs/PgInitPrivsRow.scala | 70 ++ .../pg_init_privs/PgInitPrivsStructure.scala | 31 + .../pg_language/PgLanguageFields.scala | 27 + .../pg_catalog/pg_language/PgLanguageId.scala | 30 + .../pg_language/PgLanguageRepo.scala | 30 + .../pg_language/PgLanguageRepoImpl.scala | 95 ++ .../pg_language/PgLanguageRepoMock.scala | 79 ++ .../pg_language/PgLanguageRow.scala | 92 ++ .../pg_language/PgLanguageStructure.scala | 36 + .../pg_largeobject/PgLargeobjectFields.scala | 20 + .../pg_largeobject/PgLargeobjectId.scala | 37 + .../pg_largeobject/PgLargeobjectRepo.scala | 28 + .../PgLargeobjectRepoImpl.scala | 66 ++ .../PgLargeobjectRepoMock.scala | 73 ++ .../pg_largeobject/PgLargeobjectRow.scala | 58 ++ .../PgLargeobjectStructure.scala | 29 + .../PgLargeobjectMetadataFields.scala | 21 + .../PgLargeobjectMetadataId.scala | 30 + .../PgLargeobjectMetadataRepo.scala | 29 + .../PgLargeobjectMetadataRepoImpl.scala | 71 ++ .../PgLargeobjectMetadataRepoMock.scala | 76 ++ .../PgLargeobjectMetadataRow.scala | 56 ++ .../PgLargeobjectMetadataStructure.scala | 30 + .../pg_locks/PgLocksViewFields.scala | 34 + .../pg_catalog/pg_locks/PgLocksViewRepo.scala | 17 + .../pg_locks/PgLocksViewRepoImpl.scala | 23 + .../pg_catalog/pg_locks/PgLocksViewRow.scala | 136 +++ .../pg_locks/PgLocksViewStructure.scala | 43 + .../pg_matviews/PgMatviewsViewFields.scala | 23 + .../pg_matviews/PgMatviewsViewRepo.scala | 17 + .../pg_matviews/PgMatviewsViewRepoImpl.scala | 23 + .../pg_matviews/PgMatviewsViewRow.scala | 84 ++ .../pg_matviews/PgMatviewsViewStructure.scala | 32 + .../pg_namespace/PgNamespaceFields.scala | 22 + .../pg_namespace/PgNamespaceId.scala | 30 + .../pg_namespace/PgNamespaceRepo.scala | 30 + .../pg_namespace/PgNamespaceRepoImpl.scala | 80 ++ .../pg_namespace/PgNamespaceRepoMock.scala | 79 ++ .../pg_namespace/PgNamespaceRow.scala | 62 ++ .../pg_namespace/PgNamespaceStructure.scala | 31 + .../pg_opclass/PgOpclassFields.scala | 25 + .../pg_catalog/pg_opclass/PgOpclassId.scala | 30 + .../pg_catalog/pg_opclass/PgOpclassRepo.scala | 30 + .../pg_opclass/PgOpclassRepoImpl.scala | 94 ++ .../pg_opclass/PgOpclassRepoMock.scala | 79 ++ .../pg_catalog/pg_opclass/PgOpclassRow.scala | 91 ++ .../pg_opclass/PgOpclassStructure.scala | 34 + .../pg_operator/PgOperatorFields.scala | 32 + .../pg_catalog/pg_operator/PgOperatorId.scala | 30 + .../pg_operator/PgOperatorRepo.scala | 30 + .../pg_operator/PgOperatorRepoImpl.scala | 113 +++ .../pg_operator/PgOperatorRepoMock.scala | 79 ++ .../pg_operator/PgOperatorRow.scala | 128 +++ .../pg_operator/PgOperatorStructure.scala | 41 + .../pg_opfamily/PgOpfamilyFields.scala | 21 + .../pg_catalog/pg_opfamily/PgOpfamilyId.scala | 30 + .../pg_opfamily/PgOpfamilyRepo.scala | 30 + .../pg_opfamily/PgOpfamilyRepoImpl.scala | 82 ++ .../pg_opfamily/PgOpfamilyRepoMock.scala | 79 ++ .../pg_opfamily/PgOpfamilyRow.scala | 67 ++ .../pg_opfamily/PgOpfamilyStructure.scala | 30 + .../PgPartitionedTableFields.scala | 29 + .../PgPartitionedTableId.scala | 30 + .../PgPartitionedTableRepo.scala | 29 + .../PgPartitionedTableRepoImpl.scala | 89 ++ .../PgPartitionedTableRepoMock.scala | 76 ++ .../PgPartitionedTableRow.scala | 89 ++ .../PgPartitionedTableStructure.scala | 38 + .../pg_policies/PgPoliciesViewFields.scala | 24 + .../pg_policies/PgPoliciesViewRepo.scala | 17 + .../pg_policies/PgPoliciesViewRepoImpl.scala | 23 + .../pg_policies/PgPoliciesViewRow.scala | 88 ++ .../pg_policies/PgPoliciesViewStructure.scala | 33 + .../pg_catalog/pg_policy/PgPolicyFields.scala | 26 + .../pg_catalog/pg_policy/PgPolicyId.scala | 30 + .../pg_catalog/pg_policy/PgPolicyRepo.scala | 30 + .../pg_policy/PgPolicyRepoImpl.scala | 92 ++ .../pg_policy/PgPolicyRepoMock.scala | 79 ++ .../pg_catalog/pg_policy/PgPolicyRow.scala | 86 ++ .../pg_policy/PgPolicyStructure.scala | 35 + .../PgPreparedStatementsViewFields.scala | 24 + .../PgPreparedStatementsViewRepo.scala | 17 + .../PgPreparedStatementsViewRepoImpl.scala | 23 + .../PgPreparedStatementsViewRow.scala | 81 ++ .../PgPreparedStatementsViewStructure.scala | 33 + .../PgPreparedXactsViewFields.scala | 22 + .../PgPreparedXactsViewRepo.scala | 17 + .../PgPreparedXactsViewRepoImpl.scala | 23 + .../PgPreparedXactsViewRow.scala | 71 ++ .../PgPreparedXactsViewStructure.scala | 31 + .../pg_catalog/pg_proc/PgProcFields.scala | 52 ++ .../pg_catalog/pg_proc/PgProcId.scala | 30 + .../pg_catalog/pg_proc/PgProcRepo.scala | 31 + .../pg_catalog/pg_proc/PgProcRepoImpl.scala | 162 ++++ .../pg_catalog/pg_proc/PgProcRepoMock.scala | 80 ++ .../pg_catalog/pg_proc/PgProcRow.scala | 222 +++++ .../pg_catalog/pg_proc/PgProcStructure.scala | 61 ++ .../pg_publication/PgPublicationFields.scala | 25 + .../pg_publication/PgPublicationId.scala | 30 + .../pg_publication/PgPublicationRepo.scala | 30 + .../PgPublicationRepoImpl.scala | 94 ++ .../PgPublicationRepoMock.scala | 79 ++ .../pg_publication/PgPublicationRow.scala | 91 ++ .../PgPublicationStructure.scala | 34 + .../PgPublicationRelFields.scala | 19 + .../PgPublicationRelId.scala | 30 + .../PgPublicationRelRepo.scala | 30 + .../PgPublicationRelRepoImpl.scala | 76 ++ .../PgPublicationRelRepoMock.scala | 79 ++ .../PgPublicationRelRow.scala | 55 ++ .../PgPublicationRelStructure.scala | 28 + .../PgPublicationTablesViewFields.scala | 18 + .../PgPublicationTablesViewRepo.scala | 17 + .../PgPublicationTablesViewRepoImpl.scala | 23 + .../PgPublicationTablesViewRow.scala | 58 ++ .../PgPublicationTablesViewStructure.scala | 27 + .../pg_catalog/pg_range/PgRangeFields.scala | 24 + .../pg_catalog/pg_range/PgRangeId.scala | 30 + .../pg_catalog/pg_range/PgRangeRepo.scala | 30 + .../pg_catalog/pg_range/PgRangeRepoImpl.scala | 89 ++ .../pg_catalog/pg_range/PgRangeRepoMock.scala | 79 ++ .../pg_catalog/pg_range/PgRangeRow.scala | 80 ++ .../pg_range/PgRangeStructure.scala | 33 + .../PgReplicationOriginFields.scala | 18 + .../PgReplicationOriginId.scala | 30 + .../PgReplicationOriginRepo.scala | 30 + .../PgReplicationOriginRepoImpl.scala | 73 ++ .../PgReplicationOriginRepoMock.scala | 79 ++ .../PgReplicationOriginRow.scala | 49 + .../PgReplicationOriginStructure.scala | 27 + .../PgReplicationOriginStatusViewFields.scala | 19 + .../PgReplicationOriginStatusViewRepo.scala | 17 + ...gReplicationOriginStatusViewRepoImpl.scala | 23 + .../PgReplicationOriginStatusViewRow.scala | 61 ++ ...ReplicationOriginStatusViewStructure.scala | 28 + .../PgReplicationSlotsViewFields.scala | 31 + .../PgReplicationSlotsViewRepo.scala | 17 + .../PgReplicationSlotsViewRepoImpl.scala | 23 + .../PgReplicationSlotsViewRow.scala | 129 +++ .../PgReplicationSlotsViewStructure.scala | 40 + .../pg_rewrite/PgRewriteFields.scala | 25 + .../pg_catalog/pg_rewrite/PgRewriteId.scala | 30 + .../pg_catalog/pg_rewrite/PgRewriteRepo.scala | 30 + .../pg_rewrite/PgRewriteRepoImpl.scala | 92 ++ .../pg_rewrite/PgRewriteRepoMock.scala | 79 ++ .../pg_catalog/pg_rewrite/PgRewriteRow.scala | 86 ++ .../pg_rewrite/PgRewriteStructure.scala | 34 + .../pg_roles/PgRolesViewFields.scala | 31 + .../pg_catalog/pg_roles/PgRolesViewRepo.scala | 17 + .../pg_roles/PgRolesViewRepoImpl.scala | 23 + .../pg_catalog/pg_roles/PgRolesViewRow.scala | 129 +++ .../pg_roles/PgRolesViewStructure.scala | 40 + .../pg_rules/PgRulesViewFields.scala | 20 + .../pg_catalog/pg_rules/PgRulesViewRepo.scala | 17 + .../pg_rules/PgRulesViewRepoImpl.scala | 23 + .../pg_catalog/pg_rules/PgRulesViewRow.scala | 64 ++ .../pg_rules/PgRulesViewStructure.scala | 29 + .../pg_seclabel/PgSeclabelFields.scala | 21 + .../pg_catalog/pg_seclabel/PgSeclabelId.scala | 45 + .../pg_seclabel/PgSeclabelRepo.scala | 28 + .../pg_seclabel/PgSeclabelRepoImpl.scala | 67 ++ .../pg_seclabel/PgSeclabelRepoMock.scala | 73 ++ .../pg_seclabel/PgSeclabelRow.scala | 69 ++ .../pg_seclabel/PgSeclabelStructure.scala | 30 + .../pg_seclabels/PgSeclabelsViewFields.scala | 23 + .../pg_seclabels/PgSeclabelsViewRepo.scala | 17 + .../PgSeclabelsViewRepoImpl.scala | 23 + .../pg_seclabels/PgSeclabelsViewRow.scala | 85 ++ .../PgSeclabelsViewStructure.scala | 32 + .../pg_sequence/PgSequenceFields.scala | 24 + .../pg_catalog/pg_sequence/PgSequenceId.scala | 30 + .../pg_sequence/PgSequenceRepo.scala | 29 + .../pg_sequence/PgSequenceRepoImpl.scala | 85 ++ .../pg_sequence/PgSequenceRepoMock.scala | 76 ++ .../pg_sequence/PgSequenceRow.scala | 85 ++ .../pg_sequence/PgSequenceStructure.scala | 33 + .../pg_sequences/PgSequencesViewFields.scala | 28 + .../pg_sequences/PgSequencesViewRepo.scala | 17 + .../PgSequencesViewRepoImpl.scala | 23 + .../pg_sequences/PgSequencesViewRow.scala | 112 +++ .../PgSequencesViewStructure.scala | 37 + .../pg_settings/PgSettingsViewFields.scala | 32 + .../pg_settings/PgSettingsViewRepo.scala | 17 + .../pg_settings/PgSettingsViewRepoImpl.scala | 23 + .../pg_settings/PgSettingsViewRow.scala | 139 +++ .../pg_settings/PgSettingsViewStructure.scala | 41 + .../pg_shadow/PgShadowViewFields.scala | 27 + .../pg_shadow/PgShadowViewRepo.scala | 17 + .../pg_shadow/PgShadowViewRepoImpl.scala | 23 + .../pg_shadow/PgShadowViewRow.scala | 102 +++ .../pg_shadow/PgShadowViewStructure.scala | 36 + .../pg_shdepend/PgShdependFields.scala | 22 + .../pg_shdepend/PgShdependRepo.scala | 23 + .../pg_shdepend/PgShdependRepoImpl.scala | 40 + .../pg_shdepend/PgShdependRow.scala | 79 ++ .../pg_shdepend/PgShdependStructure.scala | 31 + .../PgShdescriptionFields.scala | 19 + .../pg_shdescription/PgShdescriptionId.scala | 37 + .../PgShdescriptionRepo.scala | 28 + .../PgShdescriptionRepoImpl.scala | 65 ++ .../PgShdescriptionRepoMock.scala | 73 ++ .../pg_shdescription/PgShdescriptionRow.scala | 57 ++ .../PgShdescriptionStructure.scala | 28 + .../PgShmemAllocationsViewFields.scala | 19 + .../PgShmemAllocationsViewRepo.scala | 17 + .../PgShmemAllocationsViewRepoImpl.scala | 23 + .../PgShmemAllocationsViewRow.scala | 61 ++ .../PgShmemAllocationsViewStructure.scala | 28 + .../pg_shseclabel/PgShseclabelFields.scala | 20 + .../pg_shseclabel/PgShseclabelId.scala | 41 + .../pg_shseclabel/PgShseclabelRepo.scala | 28 + .../pg_shseclabel/PgShseclabelRepoImpl.scala | 66 ++ .../pg_shseclabel/PgShseclabelRepoMock.scala | 73 ++ .../pg_shseclabel/PgShseclabelRow.scala | 63 ++ .../pg_shseclabel/PgShseclabelStructure.scala | 29 + .../PgStatActivityViewFields.scala | 40 + .../PgStatActivityViewRepo.scala | 17 + .../PgStatActivityViewRepoImpl.scala | 23 + .../PgStatActivityViewRow.scala | 174 ++++ .../PgStatActivityViewStructure.scala | 49 + .../PgStatAllIndexesViewFields.scala | 25 + .../PgStatAllIndexesViewRepo.scala | 17 + .../PgStatAllIndexesViewRepoImpl.scala | 23 + .../PgStatAllIndexesViewRow.scala | 91 ++ .../PgStatAllIndexesViewStructure.scala | 34 + .../PgStatAllTablesViewFields.scala | 41 + .../PgStatAllTablesViewRepo.scala | 17 + .../PgStatAllTablesViewRepoImpl.scala | 23 + .../PgStatAllTablesViewRow.scala | 180 ++++ .../PgStatAllTablesViewStructure.scala | 50 ++ .../PgStatArchiverViewFields.scala | 23 + .../PgStatArchiverViewRepo.scala | 17 + .../PgStatArchiverViewRepoImpl.scala | 23 + .../PgStatArchiverViewRow.scala | 80 ++ .../PgStatArchiverViewStructure.scala | 32 + .../PgStatBgwriterViewFields.scala | 27 + .../PgStatBgwriterViewRepo.scala | 17 + .../PgStatBgwriterViewRepoImpl.scala | 23 + .../PgStatBgwriterViewRow.scala | 104 +++ .../PgStatBgwriterViewStructure.scala | 36 + .../PgStatDatabaseViewFields.scala | 44 + .../PgStatDatabaseViewRepo.scala | 17 + .../PgStatDatabaseViewRepoImpl.scala | 23 + .../PgStatDatabaseViewRow.scala | 206 +++++ .../PgStatDatabaseViewStructure.scala | 53 ++ .../PgStatDatabaseConflictsViewFields.scala | 24 + .../PgStatDatabaseConflictsViewRepo.scala | 17 + .../PgStatDatabaseConflictsViewRepoImpl.scala | 23 + .../PgStatDatabaseConflictsViewRow.scala | 82 ++ ...PgStatDatabaseConflictsViewStructure.scala | 33 + .../PgStatGssapiViewFields.scala | 19 + .../pg_stat_gssapi/PgStatGssapiViewRepo.scala | 17 + .../PgStatGssapiViewRepoImpl.scala | 23 + .../pg_stat_gssapi/PgStatGssapiViewRow.scala | 61 ++ .../PgStatGssapiViewStructure.scala | 28 + .../PgStatProgressAnalyzeViewFields.scala | 27 + .../PgStatProgressAnalyzeViewRepo.scala | 17 + .../PgStatProgressAnalyzeViewRepoImpl.scala | 23 + .../PgStatProgressAnalyzeViewRow.scala | 110 +++ .../PgStatProgressAnalyzeViewStructure.scala | 36 + .../PgStatProgressBasebackupViewFields.scala | 21 + .../PgStatProgressBasebackupViewRepo.scala | 17 + ...PgStatProgressBasebackupViewRepoImpl.scala | 23 + .../PgStatProgressBasebackupViewRow.scala | 73 ++ ...gStatProgressBasebackupViewStructure.scala | 30 + .../PgStatProgressClusterViewFields.scala | 27 + .../PgStatProgressClusterViewRepo.scala | 17 + .../PgStatProgressClusterViewRepoImpl.scala | 23 + .../PgStatProgressClusterViewRow.scala | 110 +++ .../PgStatProgressClusterViewStructure.scala | 36 + .../PgStatProgressCopyViewFields.scala | 25 + .../PgStatProgressCopyViewRepo.scala | 17 + .../PgStatProgressCopyViewRepoImpl.scala | 23 + .../PgStatProgressCopyViewRow.scala | 98 ++ .../PgStatProgressCopyViewStructure.scala | 34 + .../PgStatProgressCreateIndexViewFields.scala | 31 + .../PgStatProgressCreateIndexViewRepo.scala | 17 + ...gStatProgressCreateIndexViewRepoImpl.scala | 23 + .../PgStatProgressCreateIndexViewRow.scala | 134 +++ ...StatProgressCreateIndexViewStructure.scala | 40 + .../PgStatProgressVacuumViewFields.scala | 26 + .../PgStatProgressVacuumViewRepo.scala | 17 + .../PgStatProgressVacuumViewRepoImpl.scala | 23 + .../PgStatProgressVacuumViewRow.scala | 104 +++ .../PgStatProgressVacuumViewStructure.scala | 35 + .../PgStatReplicationViewFields.scala | 39 + .../PgStatReplicationViewRepo.scala | 17 + .../PgStatReplicationViewRepoImpl.scala | 23 + .../PgStatReplicationViewRow.scala | 162 ++++ .../PgStatReplicationViewStructure.scala | 48 + .../PgStatReplicationSlotsViewFields.scala | 26 + .../PgStatReplicationSlotsViewRepo.scala | 17 + .../PgStatReplicationSlotsViewRepoImpl.scala | 23 + .../PgStatReplicationSlotsViewRow.scala | 98 ++ .../PgStatReplicationSlotsViewStructure.scala | 35 + .../pg_stat_slru/PgStatSlruViewFields.scala | 25 + .../pg_stat_slru/PgStatSlruViewRepo.scala | 17 + .../pg_stat_slru/PgStatSlruViewRepoImpl.scala | 23 + .../pg_stat_slru/PgStatSlruViewRow.scala | 92 ++ .../PgStatSlruViewStructure.scala | 34 + .../pg_stat_ssl/PgStatSslViewFields.scala | 23 + .../pg_stat_ssl/PgStatSslViewRepo.scala | 17 + .../pg_stat_ssl/PgStatSslViewRepoImpl.scala | 23 + .../pg_stat_ssl/PgStatSslViewRow.scala | 85 ++ .../pg_stat_ssl/PgStatSslViewStructure.scala | 32 + .../PgStatSubscriptionViewFields.scala | 27 + .../PgStatSubscriptionViewRepo.scala | 17 + .../PgStatSubscriptionViewRepoImpl.scala | 23 + .../PgStatSubscriptionViewRow.scala | 95 ++ .../PgStatSubscriptionViewStructure.scala | 36 + .../PgStatSysIndexesViewFields.scala | 24 + .../PgStatSysIndexesViewRepo.scala | 17 + .../PgStatSysIndexesViewRepoImpl.scala | 23 + .../PgStatSysIndexesViewRow.scala | 94 ++ .../PgStatSysIndexesViewStructure.scala | 33 + .../PgStatSysTablesViewFields.scala | 40 + .../PgStatSysTablesViewRepo.scala | 17 + .../PgStatSysTablesViewRepoImpl.scala | 23 + .../PgStatSysTablesViewRow.scala | 200 +++++ .../PgStatSysTablesViewStructure.scala | 49 + .../PgStatUserFunctionsViewFields.scala | 23 + .../PgStatUserFunctionsViewRepo.scala | 17 + .../PgStatUserFunctionsViewRepoImpl.scala | 23 + .../PgStatUserFunctionsViewRow.scala | 77 ++ .../PgStatUserFunctionsViewStructure.scala | 32 + .../PgStatUserIndexesViewFields.scala | 24 + .../PgStatUserIndexesViewRepo.scala | 17 + .../PgStatUserIndexesViewRepoImpl.scala | 23 + .../PgStatUserIndexesViewRow.scala | 94 ++ .../PgStatUserIndexesViewStructure.scala | 33 + .../PgStatUserTablesViewFields.scala | 40 + .../PgStatUserTablesViewRepo.scala | 17 + .../PgStatUserTablesViewRepoImpl.scala | 23 + .../PgStatUserTablesViewRow.scala | 200 +++++ .../PgStatUserTablesViewStructure.scala | 49 + .../pg_stat_wal/PgStatWalViewFields.scala | 25 + .../pg_stat_wal/PgStatWalViewRepo.scala | 17 + .../pg_stat_wal/PgStatWalViewRepoImpl.scala | 23 + .../pg_stat_wal/PgStatWalViewRow.scala | 92 ++ .../pg_stat_wal/PgStatWalViewStructure.scala | 34 + .../PgStatWalReceiverViewFields.scala | 31 + .../PgStatWalReceiverViewRepo.scala | 17 + .../PgStatWalReceiverViewRepoImpl.scala | 23 + .../PgStatWalReceiverViewRow.scala | 128 +++ .../PgStatWalReceiverViewStructure.scala | 40 + .../PgStatXactAllTablesViewFields.scala | 28 + .../PgStatXactAllTablesViewRepo.scala | 17 + .../PgStatXactAllTablesViewRepoImpl.scala | 23 + .../PgStatXactAllTablesViewRow.scala | 107 +++ .../PgStatXactAllTablesViewStructure.scala | 37 + .../PgStatXactSysTablesViewFields.scala | 27 + .../PgStatXactSysTablesViewRepo.scala | 17 + .../PgStatXactSysTablesViewRepoImpl.scala | 23 + .../PgStatXactSysTablesViewRow.scala | 115 +++ .../PgStatXactSysTablesViewStructure.scala | 36 + .../PgStatXactUserFunctionsViewFields.scala | 23 + .../PgStatXactUserFunctionsViewRepo.scala | 17 + .../PgStatXactUserFunctionsViewRepoImpl.scala | 23 + .../PgStatXactUserFunctionsViewRow.scala | 77 ++ ...PgStatXactUserFunctionsViewStructure.scala | 32 + .../PgStatXactUserTablesViewFields.scala | 27 + .../PgStatXactUserTablesViewRepo.scala | 17 + .../PgStatXactUserTablesViewRepoImpl.scala | 23 + .../PgStatXactUserTablesViewRow.scala | 115 +++ .../PgStatXactUserTablesViewStructure.scala | 36 + .../PgStatioAllIndexesViewFields.scala | 24 + .../PgStatioAllIndexesViewRepo.scala | 17 + .../PgStatioAllIndexesViewRepoImpl.scala | 23 + .../PgStatioAllIndexesViewRow.scala | 85 ++ .../PgStatioAllIndexesViewStructure.scala | 33 + .../PgStatioAllSequencesViewFields.scala | 22 + .../PgStatioAllSequencesViewRepo.scala | 17 + .../PgStatioAllSequencesViewRepoImpl.scala | 23 + .../PgStatioAllSequencesViewRow.scala | 71 ++ .../PgStatioAllSequencesViewStructure.scala | 31 + .../PgStatioAllTablesViewFields.scala | 28 + .../PgStatioAllTablesViewRepo.scala | 17 + .../PgStatioAllTablesViewRepoImpl.scala | 23 + .../PgStatioAllTablesViewRow.scala | 107 +++ .../PgStatioAllTablesViewStructure.scala | 37 + .../PgStatioSysIndexesViewFields.scala | 23 + .../PgStatioSysIndexesViewRepo.scala | 17 + .../PgStatioSysIndexesViewRepoImpl.scala | 23 + .../PgStatioSysIndexesViewRow.scala | 87 ++ .../PgStatioSysIndexesViewStructure.scala | 32 + .../PgStatioSysSequencesViewFields.scala | 21 + .../PgStatioSysSequencesViewRepo.scala | 17 + .../PgStatioSysSequencesViewRepoImpl.scala | 23 + .../PgStatioSysSequencesViewRow.scala | 73 ++ .../PgStatioSysSequencesViewStructure.scala | 30 + .../PgStatioSysTablesViewFields.scala | 27 + .../PgStatioSysTablesViewRepo.scala | 17 + .../PgStatioSysTablesViewRepoImpl.scala | 23 + .../PgStatioSysTablesViewRow.scala | 115 +++ .../PgStatioSysTablesViewStructure.scala | 36 + .../PgStatioUserIndexesViewFields.scala | 23 + .../PgStatioUserIndexesViewRepo.scala | 17 + .../PgStatioUserIndexesViewRepoImpl.scala | 23 + .../PgStatioUserIndexesViewRow.scala | 87 ++ .../PgStatioUserIndexesViewStructure.scala | 32 + .../PgStatioUserSequencesViewFields.scala | 21 + .../PgStatioUserSequencesViewRepo.scala | 17 + .../PgStatioUserSequencesViewRepoImpl.scala | 23 + .../PgStatioUserSequencesViewRow.scala | 73 ++ .../PgStatioUserSequencesViewStructure.scala | 30 + .../PgStatioUserTablesViewFields.scala | 27 + .../PgStatioUserTablesViewRepo.scala | 17 + .../PgStatioUserTablesViewRepoImpl.scala | 23 + .../PgStatioUserTablesViewRow.scala | 115 +++ .../PgStatioUserTablesViewStructure.scala | 36 + .../pg_statistic/PgStatisticFields.scala | 50 ++ .../pg_statistic/PgStatisticId.scala | 42 + .../pg_statistic/PgStatisticRepo.scala | 28 + .../pg_statistic/PgStatisticRepoImpl.scala | 149 ++++ .../pg_statistic/PgStatisticRepoMock.scala | 73 ++ .../pg_statistic/PgStatisticRow.scala | 227 +++++ .../pg_statistic/PgStatisticStructure.scala | 59 ++ .../PgStatisticExtFields.scala | 28 + .../pg_statistic_ext/PgStatisticExtId.scala | 30 + .../pg_statistic_ext/PgStatisticExtRepo.scala | 30 + .../PgStatisticExtRepoImpl.scala | 96 ++ .../PgStatisticExtRepoMock.scala | 79 ++ .../pg_statistic_ext/PgStatisticExtRow.scala | 93 ++ .../PgStatisticExtStructure.scala | 37 + .../PgStatisticExtDataFields.scala | 25 + .../PgStatisticExtDataId.scala | 30 + .../PgStatisticExtDataRepo.scala | 29 + .../PgStatisticExtDataRepoImpl.scala | 80 ++ .../PgStatisticExtDataRepoMock.scala | 76 ++ .../PgStatisticExtDataRow.scala | 71 ++ .../PgStatisticExtDataStructure.scala | 34 + .../pg_stats/PgStatsViewFields.scala | 31 + .../pg_catalog/pg_stats/PgStatsViewRepo.scala | 17 + .../pg_stats/PgStatsViewRepoImpl.scala | 23 + .../pg_catalog/pg_stats/PgStatsViewRow.scala | 129 +++ .../pg_stats/PgStatsViewStructure.scala | 40 + .../pg_stats_ext/PgStatsExtViewFields.scala | 32 + .../pg_stats_ext/PgStatsExtViewRepo.scala | 17 + .../pg_stats_ext/PgStatsExtViewRepoImpl.scala | 23 + .../pg_stats_ext/PgStatsExtViewRow.scala | 130 +++ .../PgStatsExtViewStructure.scala | 41 + .../PgStatsExtExprsViewFields.scala | 33 + .../PgStatsExtExprsViewRepo.scala | 17 + .../PgStatsExtExprsViewRepoImpl.scala | 23 + .../PgStatsExtExprsViewRow.scala | 138 +++ .../PgStatsExtExprsViewStructure.scala | 42 + .../PgSubscriptionFields.scala | 28 + .../pg_subscription/PgSubscriptionId.scala | 30 + .../pg_subscription/PgSubscriptionRepo.scala | 30 + .../PgSubscriptionRepoImpl.scala | 100 +++ .../PgSubscriptionRepoMock.scala | 79 ++ .../pg_subscription/PgSubscriptionRow.scala | 103 +++ .../PgSubscriptionStructure.scala | 37 + .../PgSubscriptionRelFields.scala | 21 + .../PgSubscriptionRelId.scala | 37 + .../PgSubscriptionRelRepo.scala | 28 + .../PgSubscriptionRelRepoImpl.scala | 68 ++ .../PgSubscriptionRelRepoMock.scala | 73 ++ .../PgSubscriptionRelRow.scala | 63 ++ .../PgSubscriptionRelStructure.scala | 30 + .../pg_tables/PgTablesViewFields.scala | 24 + .../pg_tables/PgTablesViewRepo.scala | 17 + .../pg_tables/PgTablesViewRepoImpl.scala | 23 + .../pg_tables/PgTablesViewRow.scala | 92 ++ .../pg_tables/PgTablesViewStructure.scala | 33 + .../pg_tablespace/PgTablespaceFields.scala | 23 + .../pg_tablespace/PgTablespaceId.scala | 30 + .../pg_tablespace/PgTablespaceRepo.scala | 30 + .../pg_tablespace/PgTablespaceRepoImpl.scala | 83 ++ .../pg_tablespace/PgTablespaceRepoMock.scala | 79 ++ .../pg_tablespace/PgTablespaceRow.scala | 68 ++ .../pg_tablespace/PgTablespaceStructure.scala | 32 + .../PgTimezoneAbbrevsViewFields.scala | 19 + .../PgTimezoneAbbrevsViewRepo.scala | 17 + .../PgTimezoneAbbrevsViewRepoImpl.scala | 23 + .../PgTimezoneAbbrevsViewRow.scala | 56 ++ .../PgTimezoneAbbrevsViewStructure.scala | 28 + .../PgTimezoneNamesViewFields.scala | 20 + .../PgTimezoneNamesViewRepo.scala | 17 + .../PgTimezoneNamesViewRepoImpl.scala | 23 + .../PgTimezoneNamesViewRow.scala | 62 ++ .../PgTimezoneNamesViewStructure.scala | 29 + .../pg_transform/PgTransformFields.scala | 22 + .../pg_transform/PgTransformId.scala | 30 + .../pg_transform/PgTransformRepo.scala | 30 + .../pg_transform/PgTransformRepoImpl.scala | 83 ++ .../pg_transform/PgTransformRepoMock.scala | 79 ++ .../pg_transform/PgTransformRow.scala | 68 ++ .../pg_transform/PgTransformStructure.scala | 31 + .../pg_trigger/PgTriggerFields.scala | 40 + .../pg_catalog/pg_trigger/PgTriggerId.scala | 30 + .../pg_catalog/pg_trigger/PgTriggerRepo.scala | 30 + .../pg_trigger/PgTriggerRepoImpl.scala | 128 +++ .../pg_trigger/PgTriggerRepoMock.scala | 79 ++ .../pg_catalog/pg_trigger/PgTriggerRow.scala | 155 ++++ .../pg_trigger/PgTriggerStructure.scala | 49 + .../pg_ts_config/PgTsConfigFields.scala | 21 + .../pg_ts_config/PgTsConfigId.scala | 30 + .../pg_ts_config/PgTsConfigRepo.scala | 30 + .../pg_ts_config/PgTsConfigRepoImpl.scala | 82 ++ .../pg_ts_config/PgTsConfigRepoMock.scala | 79 ++ .../pg_ts_config/PgTsConfigRow.scala | 67 ++ .../pg_ts_config/PgTsConfigStructure.scala | 30 + .../PgTsConfigMapFields.scala | 20 + .../pg_ts_config_map/PgTsConfigMapId.scala | 41 + .../pg_ts_config_map/PgTsConfigMapRepo.scala | 28 + .../PgTsConfigMapRepoImpl.scala | 66 ++ .../PgTsConfigMapRepoMock.scala | 73 ++ .../pg_ts_config_map/PgTsConfigMapRow.scala | 63 ++ .../PgTsConfigMapStructure.scala | 29 + .../pg_ts_dict/PgTsDictFields.scala | 23 + .../pg_catalog/pg_ts_dict/PgTsDictId.scala | 30 + .../pg_catalog/pg_ts_dict/PgTsDictRepo.scala | 30 + .../pg_ts_dict/PgTsDictRepoImpl.scala | 85 ++ .../pg_ts_dict/PgTsDictRepoMock.scala | 79 ++ .../pg_catalog/pg_ts_dict/PgTsDictRow.scala | 73 ++ .../pg_ts_dict/PgTsDictStructure.scala | 32 + .../pg_ts_parser/PgTsParserFields.scala | 25 + .../pg_ts_parser/PgTsParserId.scala | 30 + .../pg_ts_parser/PgTsParserRepo.scala | 30 + .../pg_ts_parser/PgTsParserRepoImpl.scala | 92 ++ .../pg_ts_parser/PgTsParserRepoMock.scala | 79 ++ .../pg_ts_parser/PgTsParserRow.scala | 86 ++ .../pg_ts_parser/PgTsParserStructure.scala | 34 + .../pg_ts_template/PgTsTemplateFields.scala | 22 + .../pg_ts_template/PgTsTemplateId.scala | 30 + .../pg_ts_template/PgTsTemplateRepo.scala | 30 + .../pg_ts_template/PgTsTemplateRepoImpl.scala | 83 ++ .../pg_ts_template/PgTsTemplateRepoMock.scala | 79 ++ .../pg_ts_template/PgTsTemplateRow.scala | 68 ++ .../PgTsTemplateStructure.scala | 31 + .../pg_catalog/pg_type/PgTypeFields.scala | 53 ++ .../pg_catalog/pg_type/PgTypeId.scala | 30 + .../pg_catalog/pg_type/PgTypeRepo.scala | 30 + .../pg_catalog/pg_type/PgTypeRepoImpl.scala | 167 ++++ .../pg_catalog/pg_type/PgTypeRepoMock.scala | 79 ++ .../pg_catalog/pg_type/PgTypeRow.scala | 233 +++++ .../pg_catalog/pg_type/PgTypeStructure.scala | 62 ++ .../pg_catalog/pg_user/PgUserViewFields.scala | 26 + .../pg_catalog/pg_user/PgUserViewRepo.scala | 17 + .../pg_user/PgUserViewRepoImpl.scala | 23 + .../pg_catalog/pg_user/PgUserViewRow.scala | 101 +++ .../pg_user/PgUserViewStructure.scala | 35 + .../pg_user_mapping/PgUserMappingFields.scala | 21 + .../pg_user_mapping/PgUserMappingId.scala | 30 + .../pg_user_mapping/PgUserMappingRepo.scala | 30 + .../PgUserMappingRepoImpl.scala | 79 ++ .../PgUserMappingRepoMock.scala | 79 ++ .../pg_user_mapping/PgUserMappingRow.scala | 61 ++ .../PgUserMappingStructure.scala | 30 + .../PgUserMappingsViewFields.scala | 24 + .../PgUserMappingsViewRepo.scala | 17 + .../PgUserMappingsViewRepoImpl.scala | 23 + .../PgUserMappingsViewRow.scala | 79 ++ .../PgUserMappingsViewStructure.scala | 33 + .../pg_views/PgViewsViewFields.scala | 20 + .../pg_catalog/pg_views/PgViewsViewRepo.scala | 17 + .../pg_views/PgViewsViewRepoImpl.scala | 23 + .../pg_catalog/pg_views/PgViewsViewRow.scala | 63 ++ .../pg_views/PgViewsViewStructure.scala | 29 + .../adventureworks/pr/bom/BomViewFields.scala | 31 + .../adventureworks/pr/bom/BomViewRepo.scala | 17 + .../pr/bom/BomViewRepoImpl.scala | 23 + .../adventureworks/pr/bom/BomViewRow.scala | 112 +++ .../pr/bom/BomViewStructure.scala | 40 + .../adventureworks/pr/c/CViewFields.scala | 22 + .../adventureworks/pr/c/CViewRepo.scala | 17 + .../adventureworks/pr/c/CViewRepoImpl.scala | 23 + .../adventureworks/pr/c/CViewRow.scala | 68 ++ .../adventureworks/pr/c/CViewStructure.scala | 31 + .../adventureworks/pr/d/DViewFields.scala | 36 + .../adventureworks/pr/d/DViewRepo.scala | 17 + .../adventureworks/pr/d/DViewRepoImpl.scala | 23 + .../adventureworks/pr/d/DViewRow.scala | 135 +++ .../adventureworks/pr/d/DViewStructure.scala | 45 + .../adventureworks/pr/i/IViewFields.scala | 23 + .../adventureworks/pr/i/IViewRepo.scala | 17 + .../adventureworks/pr/i/IViewRepoImpl.scala | 23 + .../adventureworks/pr/i/IViewRow.scala | 68 ++ .../adventureworks/pr/i/IViewStructure.scala | 32 + .../adventureworks/pr/l/LViewFields.scala | 24 + .../adventureworks/pr/l/LViewRepo.scala | 17 + .../adventureworks/pr/l/LViewRepoImpl.scala | 23 + .../adventureworks/pr/l/LViewRow.scala | 82 ++ .../adventureworks/pr/l/LViewStructure.scala | 33 + .../adventureworks/pr/p/PViewFields.scala | 51 ++ .../adventureworks/pr/p/PViewRepo.scala | 17 + .../adventureworks/pr/p/PViewRepoImpl.scala | 23 + .../adventureworks/pr/p/PViewRow.scala | 228 +++++ .../adventureworks/pr/p/PViewStructure.scala | 60 ++ .../adventureworks/pr/pc/PcViewFields.scala | 24 + .../adventureworks/pr/pc/PcViewRepo.scala | 17 + .../adventureworks/pr/pc/PcViewRepoImpl.scala | 23 + .../adventureworks/pr/pc/PcViewRow.scala | 76 ++ .../pr/pc/PcViewStructure.scala | 33 + .../adventureworks/pr/pch/PchViewFields.scala | 24 + .../adventureworks/pr/pch/PchViewRepo.scala | 17 + .../pr/pch/PchViewRepoImpl.scala | 23 + .../adventureworks/pr/pch/PchViewRow.scala | 81 ++ .../pr/pch/PchViewStructure.scala | 33 + .../adventureworks/pr/pd/PdViewFields.scala | 23 + .../adventureworks/pr/pd/PdViewRepo.scala | 17 + .../adventureworks/pr/pd/PdViewRepoImpl.scala | 23 + .../adventureworks/pr/pd/PdViewRow.scala | 75 ++ .../pr/pd/PdViewStructure.scala | 32 + .../pr/pdoc/PdocViewFields.scala | 22 + .../adventureworks/pr/pdoc/PdocViewRepo.scala | 17 + .../pr/pdoc/PdocViewRepoImpl.scala | 23 + .../adventureworks/pr/pdoc/PdocViewRow.scala | 68 ++ .../pr/pdoc/PdocViewStructure.scala | 31 + .../adventureworks/pr/pi/PiViewFields.scala | 28 + .../adventureworks/pr/pi/PiViewRepo.scala | 17 + .../adventureworks/pr/pi/PiViewRepoImpl.scala | 23 + .../adventureworks/pr/pi/PiViewRow.scala | 98 ++ .../pr/pi/PiViewStructure.scala | 37 + .../pr/plph/PlphViewFields.scala | 24 + .../adventureworks/pr/plph/PlphViewRepo.scala | 17 + .../pr/plph/PlphViewRepoImpl.scala | 23 + .../adventureworks/pr/plph/PlphViewRow.scala | 81 ++ .../pr/plph/PlphViewStructure.scala | 33 + .../adventureworks/pr/pm/PmViewFields.scala | 28 + .../adventureworks/pr/pm/PmViewRepo.scala | 17 + .../adventureworks/pr/pm/PmViewRepoImpl.scala | 23 + .../adventureworks/pr/pm/PmViewRow.scala | 91 ++ .../pr/pm/PmViewStructure.scala | 37 + .../adventureworks/pr/pmi/PmiViewFields.scala | 21 + .../adventureworks/pr/pmi/PmiViewRepo.scala | 17 + .../pr/pmi/PmiViewRepoImpl.scala | 23 + .../adventureworks/pr/pmi/PmiViewRow.scala | 61 ++ .../pr/pmi/PmiViewStructure.scala | 30 + .../pr/pmpdc/PmpdcViewFields.scala | 23 + .../pr/pmpdc/PmpdcViewRepo.scala | 17 + .../pr/pmpdc/PmpdcViewRepoImpl.scala | 23 + .../pr/pmpdc/PmpdcViewRow.scala | 69 ++ .../pr/pmpdc/PmpdcViewStructure.scala | 32 + .../adventureworks/pr/pp/PpViewFields.scala | 26 + .../adventureworks/pr/pp/PpViewRepo.scala | 17 + .../adventureworks/pr/pp/PpViewRepoImpl.scala | 23 + .../adventureworks/pr/pp/PpViewRow.scala | 89 ++ .../pr/pp/PpViewStructure.scala | 35 + .../adventureworks/pr/ppp/PppViewFields.scala | 23 + .../adventureworks/pr/ppp/PppViewRepo.scala | 17 + .../pr/ppp/PppViewRepoImpl.scala | 23 + .../adventureworks/pr/ppp/PppViewRow.scala | 69 ++ .../pr/ppp/PppViewStructure.scala | 32 + .../adventureworks/pr/pr/PrViewFields.scala | 29 + .../adventureworks/pr/pr/PrViewRepo.scala | 17 + .../adventureworks/pr/pr/PrViewRepoImpl.scala | 23 + .../adventureworks/pr/pr/PrViewRow.scala | 104 +++ .../pr/pr/PrViewStructure.scala | 38 + .../adventureworks/pr/psc/PscViewFields.scala | 26 + .../adventureworks/pr/psc/PscViewRepo.scala | 17 + .../pr/psc/PscViewRepoImpl.scala | 23 + .../adventureworks/pr/psc/PscViewRow.scala | 84 ++ .../pr/psc/PscViewStructure.scala | 35 + .../adventureworks/pr/sr/SrViewFields.scala | 22 + .../adventureworks/pr/sr/SrViewRepo.scala | 17 + .../adventureworks/pr/sr/SrViewRepoImpl.scala | 23 + .../adventureworks/pr/sr/SrViewRow.scala | 68 ++ .../pr/sr/SrViewStructure.scala | 31 + .../adventureworks/pr/th/ThViewFields.scala | 28 + .../adventureworks/pr/th/ThViewRepo.scala | 17 + .../adventureworks/pr/th/ThViewRepoImpl.scala | 23 + .../adventureworks/pr/th/ThViewRow.scala | 110 +++ .../pr/th/ThViewStructure.scala | 37 + .../adventureworks/pr/tha/ThaViewFields.scala | 27 + .../adventureworks/pr/tha/ThaViewRepo.scala | 17 + .../pr/tha/ThaViewRepoImpl.scala | 23 + .../adventureworks/pr/tha/ThaViewRow.scala | 109 +++ .../pr/tha/ThaViewStructure.scala | 36 + .../adventureworks/pr/um/UmViewFields.scala | 22 + .../adventureworks/pr/um/UmViewRepo.scala | 17 + .../adventureworks/pr/um/UmViewRepoImpl.scala | 23 + .../adventureworks/pr/um/UmViewRow.scala | 68 ++ .../pr/um/UmViewStructure.scala | 31 + .../adventureworks/pr/w/WViewFields.scala | 31 + .../adventureworks/pr/w/WViewRepo.scala | 17 + .../adventureworks/pr/w/WViewRepoImpl.scala | 23 + .../adventureworks/pr/w/WViewRow.scala | 112 +++ .../adventureworks/pr/w/WViewStructure.scala | 40 + .../adventureworks/pr/wr/WrViewFields.scala | 33 + .../adventureworks/pr/wr/WrViewRepo.scala | 17 + .../adventureworks/pr/wr/WrViewRepoImpl.scala | 23 + .../adventureworks/pr/wr/WrViewRow.scala | 132 +++ .../pr/wr/WrViewStructure.scala | 42 + .../BillofmaterialsFields.scala | 30 + .../billofmaterials/BillofmaterialsId.scala | 30 + .../billofmaterials/BillofmaterialsRepo.scala | 30 + .../BillofmaterialsRepoImpl.scala | 131 +++ .../BillofmaterialsRepoMock.scala | 80 ++ .../billofmaterials/BillofmaterialsRow.scala | 114 +++ .../BillofmaterialsRowUnsaved.scala | 127 +++ .../BillofmaterialsStructure.scala | 39 + .../production/culture/CultureFields.scala | 21 + .../production/culture/CultureId.scala | 30 + .../production/culture/CultureRepo.scala | 30 + .../production/culture/CultureRepoImpl.scala | 95 ++ .../production/culture/CultureRepoMock.scala | 80 ++ .../production/culture/CultureRow.scala | 59 ++ .../culture/CultureRowUnsaved.scala | 60 ++ .../production/culture/CultureStructure.scala | 30 + .../production/document/DocumentFields.scala | 36 + .../production/document/DocumentId.scala | 30 + .../production/document/DocumentRepo.scala | 32 + .../document/DocumentRepoImpl.scala | 158 ++++ .../document/DocumentRepoMock.scala | 84 ++ .../production/document/DocumentRow.scala | 135 +++ .../document/DocumentRowUnsaved.scala | 152 ++++ .../document/DocumentStructure.scala | 45 + .../illustration/IllustrationFields.scala | 22 + .../illustration/IllustrationId.scala | 30 + .../illustration/IllustrationRepo.scala | 30 + .../illustration/IllustrationRepoImpl.scala | 99 ++ .../illustration/IllustrationRepoMock.scala | 80 ++ .../illustration/IllustrationRow.scala | 59 ++ .../illustration/IllustrationRowUnsaved.scala | 64 ++ .../illustration/IllustrationStructure.scala | 31 + .../production/location/LocationFields.scala | 23 + .../production/location/LocationId.scala | 30 + .../production/location/LocationRepo.scala | 30 + .../location/LocationRepoImpl.scala | 113 +++ .../location/LocationRepoMock.scala | 80 ++ .../production/location/LocationRow.scala | 75 ++ .../location/LocationRowUnsaved.scala | 88 ++ .../location/LocationStructure.scala | 32 + .../production/product/ProductFields.scala | 50 ++ .../production/product/ProductId.scala | 30 + .../production/product/ProductRepo.scala | 30 + .../production/product/ProductRepoImpl.scala | 202 +++++ .../production/product/ProductRepoMock.scala | 80 ++ .../production/product/ProductRow.scala | 233 +++++ .../product/ProductRowUnsaved.scala | 250 ++++++ .../production/product/ProductStructure.scala | 59 ++ .../ProductcategoryFields.scala | 23 + .../productcategory/ProductcategoryId.scala | 30 + .../productcategory/ProductcategoryRepo.scala | 30 + .../ProductcategoryRepoImpl.scala | 106 +++ .../ProductcategoryRepoMock.scala | 80 ++ .../productcategory/ProductcategoryRow.scala | 66 ++ .../ProductcategoryRowUnsaved.scala | 75 ++ .../ProductcategoryStructure.scala | 32 + .../ProductcosthistoryFields.scala | 24 + .../ProductcosthistoryId.scala | 39 + .../ProductcosthistoryRepo.scala | 29 + .../ProductcosthistoryRepoImpl.scala | 99 ++ .../ProductcosthistoryRepoMock.scala | 77 ++ .../ProductcosthistoryRow.scala | 79 ++ .../ProductcosthistoryRowUnsaved.scala | 78 ++ .../ProductcosthistoryStructure.scala | 33 + .../ProductdescriptionFields.scala | 22 + .../ProductdescriptionId.scala | 30 + .../ProductdescriptionRepo.scala | 30 + .../ProductdescriptionRepoImpl.scala | 106 +++ .../ProductdescriptionRepoMock.scala | 80 ++ .../ProductdescriptionRow.scala | 65 ++ .../ProductdescriptionRowUnsaved.scala | 74 ++ .../ProductdescriptionStructure.scala | 31 + .../ProductdocumentFields.scala | 22 + .../productdocument/ProductdocumentId.scala | 39 + .../productdocument/ProductdocumentRepo.scala | 29 + .../ProductdocumentRepoImpl.scala | 94 ++ .../ProductdocumentRepoMock.scala | 77 ++ .../productdocument/ProductdocumentRow.scala | 64 ++ .../ProductdocumentRowUnsaved.scala | 67 ++ .../ProductdocumentStructure.scala | 31 + .../ProductinventoryFields.scala | 28 + .../productinventory/ProductinventoryId.scala | 39 + .../ProductinventoryRepo.scala | 29 + .../ProductinventoryRepoImpl.scala | 116 +++ .../ProductinventoryRepoMock.scala | 77 ++ .../ProductinventoryRow.scala | 94 ++ .../ProductinventoryRowUnsaved.scala | 101 +++ .../ProductinventoryStructure.scala | 37 + .../ProductlistpricehistoryFields.scala | 24 + .../ProductlistpricehistoryId.scala | 39 + .../ProductlistpricehistoryRepo.scala | 29 + .../ProductlistpricehistoryRepoImpl.scala | 99 ++ .../ProductlistpricehistoryRepoMock.scala | 77 ++ .../ProductlistpricehistoryRow.scala | 79 ++ .../ProductlistpricehistoryRowUnsaved.scala | 78 ++ .../ProductlistpricehistoryStructure.scala | 33 + .../productmodel/ProductmodelFields.scala | 27 + .../productmodel/ProductmodelId.scala | 30 + .../productmodel/ProductmodelRepo.scala | 30 + .../productmodel/ProductmodelRepoImpl.scala | 116 +++ .../productmodel/ProductmodelRepoMock.scala | 80 ++ .../productmodel/ProductmodelRow.scala | 81 ++ .../productmodel/ProductmodelRowUnsaved.scala | 90 ++ .../productmodel/ProductmodelStructure.scala | 36 + .../ProductmodelillustrationFields.scala | 22 + .../ProductmodelillustrationId.scala | 39 + .../ProductmodelillustrationRepo.scala | 29 + .../ProductmodelillustrationRepoImpl.scala | 91 ++ .../ProductmodelillustrationRepoMock.scala | 77 ++ .../ProductmodelillustrationRow.scala | 64 ++ .../ProductmodelillustrationRowUnsaved.scala | 63 ++ .../ProductmodelillustrationStructure.scala | 31 + ...modelproductdescriptioncultureFields.scala | 24 + ...ductmodelproductdescriptioncultureId.scala | 44 + ...ctmodelproductdescriptioncultureRepo.scala | 29 + ...delproductdescriptioncultureRepoImpl.scala | 94 ++ ...delproductdescriptioncultureRepoMock.scala | 77 ++ ...uctmodelproductdescriptioncultureRow.scala | 73 ++ ...lproductdescriptioncultureRowUnsaved.scala | 72 ++ ...elproductdescriptioncultureStructure.scala | 33 + .../productphoto/ProductphotoFields.scala | 25 + .../productphoto/ProductphotoId.scala | 30 + .../productphoto/ProductphotoRepo.scala | 30 + .../productphoto/ProductphotoRepoImpl.scala | 111 +++ .../productphoto/ProductphotoRepoMock.scala | 80 ++ .../productphoto/ProductphotoRow.scala | 80 ++ .../productphoto/ProductphotoRowUnsaved.scala | 85 ++ .../productphoto/ProductphotoStructure.scala | 34 + .../ProductproductphotoFields.scala | 24 + .../ProductproductphotoId.scala | 39 + .../ProductproductphotoRepo.scala | 29 + .../ProductproductphotoRepoImpl.scala | 99 ++ .../ProductproductphotoRepoMock.scala | 77 ++ .../ProductproductphotoRow.scala | 72 ++ .../ProductproductphotoRowUnsaved.scala | 75 ++ .../ProductproductphotoStructure.scala | 33 + .../productreview/ProductreviewFields.scala | 28 + .../productreview/ProductreviewId.scala | 30 + .../productreview/ProductreviewRepo.scala | 30 + .../productreview/ProductreviewRepoImpl.scala | 123 +++ .../productreview/ProductreviewRepoMock.scala | 80 ++ .../productreview/ProductreviewRow.scala | 97 ++ .../ProductreviewRowUnsaved.scala | 106 +++ .../ProductreviewStructure.scala | 37 + .../ProductsubcategoryFields.scala | 25 + .../ProductsubcategoryId.scala | 30 + .../ProductsubcategoryRepo.scala | 30 + .../ProductsubcategoryRepoImpl.scala | 111 +++ .../ProductsubcategoryRepoMock.scala | 80 ++ .../ProductsubcategoryRow.scala | 75 ++ .../ProductsubcategoryRowUnsaved.scala | 84 ++ .../ProductsubcategoryStructure.scala | 34 + .../scrapreason/ScrapreasonFields.scala | 21 + .../scrapreason/ScrapreasonId.scala | 30 + .../scrapreason/ScrapreasonRepo.scala | 30 + .../scrapreason/ScrapreasonRepoImpl.scala | 98 ++ .../scrapreason/ScrapreasonRepoMock.scala | 80 ++ .../scrapreason/ScrapreasonRow.scala | 59 ++ .../scrapreason/ScrapreasonRowUnsaved.scala | 64 ++ .../scrapreason/ScrapreasonStructure.scala | 30 + .../TransactionhistoryFields.scala | 27 + .../TransactionhistoryId.scala | 30 + .../TransactionhistoryRepo.scala | 30 + .../TransactionhistoryRepoImpl.scala | 129 +++ .../TransactionhistoryRepoMock.scala | 80 ++ .../TransactionhistoryRow.scala | 103 +++ .../TransactionhistoryRowUnsaved.scala | 116 +++ .../TransactionhistoryStructure.scala | 36 + .../TransactionhistoryarchiveFields.scala | 26 + .../TransactionhistoryarchiveId.scala | 30 + .../TransactionhistoryarchiveRepo.scala | 30 + .../TransactionhistoryarchiveRepoImpl.scala | 125 +++ .../TransactionhistoryarchiveRepoMock.scala | 80 ++ .../TransactionhistoryarchiveRow.scala | 101 +++ .../TransactionhistoryarchiveRowUnsaved.scala | 110 +++ .../TransactionhistoryarchiveStructure.scala | 35 + .../unitmeasure/UnitmeasureFields.scala | 21 + .../unitmeasure/UnitmeasureId.scala | 30 + .../unitmeasure/UnitmeasureRepo.scala | 30 + .../unitmeasure/UnitmeasureRepoImpl.scala | 95 ++ .../unitmeasure/UnitmeasureRepoMock.scala | 80 ++ .../unitmeasure/UnitmeasureRow.scala | 59 ++ .../unitmeasure/UnitmeasureRowUnsaved.scala | 60 ++ .../unitmeasure/UnitmeasureStructure.scala | 30 + .../VproductanddescriptionMVFields.scala | 23 + .../VproductanddescriptionMVRepo.scala | 17 + .../VproductanddescriptionMVRepoImpl.scala | 23 + .../VproductanddescriptionMVRow.scala | 75 ++ .../VproductanddescriptionMVStructure.scala | 32 + ...uctmodelcatalogdescriptionViewFields.scala | 45 + ...oductmodelcatalogdescriptionViewRepo.scala | 17 + ...tmodelcatalogdescriptionViewRepoImpl.scala | 23 + ...roductmodelcatalogdescriptionViewRow.scala | 195 ++++ ...modelcatalogdescriptionViewStructure.scala | 54 ++ .../VproductmodelinstructionsViewFields.scala | 31 + .../VproductmodelinstructionsViewRepo.scala | 17 + ...productmodelinstructionsViewRepoImpl.scala | 23 + .../VproductmodelinstructionsViewRow.scala | 111 +++ ...roductmodelinstructionsViewStructure.scala | 40 + .../workorder/WorkorderFields.scala | 30 + .../production/workorder/WorkorderId.scala | 30 + .../production/workorder/WorkorderRepo.scala | 30 + .../workorder/WorkorderRepoImpl.scala | 125 +++ .../workorder/WorkorderRepoMock.scala | 80 ++ .../production/workorder/WorkorderRow.scala | 109 +++ .../workorder/WorkorderRowUnsaved.scala | 114 +++ .../workorder/WorkorderStructure.scala | 39 + .../WorkorderroutingFields.scala | 33 + .../workorderrouting/WorkorderroutingId.scala | 43 + .../WorkorderroutingRepo.scala | 29 + .../WorkorderroutingRepoImpl.scala | 127 +++ .../WorkorderroutingRepoMock.scala | 77 ++ .../WorkorderroutingRow.scala | 135 +++ .../WorkorderroutingRowUnsaved.scala | 134 +++ .../WorkorderroutingStructure.scala | 42 + .../adventureworks/pu/pod/PodViewFields.scala | 29 + .../adventureworks/pu/pod/PodViewRepo.scala | 17 + .../pu/pod/PodViewRepoImpl.scala | 23 + .../adventureworks/pu/pod/PodViewRow.scala | 111 +++ .../pu/pod/PodViewStructure.scala | 38 + .../adventureworks/pu/poh/PohViewFields.scala | 34 + .../adventureworks/pu/poh/PohViewRepo.scala | 17 + .../pu/poh/PohViewRepoImpl.scala | 23 + .../adventureworks/pu/poh/PohViewRow.scala | 133 +++ .../pu/poh/PohViewStructure.scala | 43 + .../adventureworks/pu/pv/PvViewFields.scala | 32 + .../adventureworks/pu/pv/PvViewRepo.scala | 17 + .../adventureworks/pu/pv/PvViewRepoImpl.scala | 23 + .../adventureworks/pu/pv/PvViewRow.scala | 125 +++ .../pu/pv/PvViewStructure.scala | 41 + .../adventureworks/pu/sm/SmViewFields.scala | 26 + .../adventureworks/pu/sm/SmViewRepo.scala | 17 + .../adventureworks/pu/sm/SmViewRepoImpl.scala | 23 + .../adventureworks/pu/sm/SmViewRow.scala | 90 ++ .../pu/sm/SmViewStructure.scala | 35 + .../adventureworks/pu/v/VViewFields.scala | 31 + .../adventureworks/pu/v/VViewRepo.scala | 17 + .../adventureworks/pu/v/VViewRepoImpl.scala | 23 + .../adventureworks/pu/v/VViewRow.scala | 106 +++ .../adventureworks/pu/v/VViewStructure.scala | 40 + .../adventureworks/public/AccountNumber.scala | 31 + .../adventureworks/public/Flag.scala | 31 + .../adventureworks/public/Mydomain.scala | 31 + .../adventureworks/public/Myenum.scala | 64 ++ .../adventureworks/public/Name.scala | 31 + .../adventureworks/public/NameStyle.scala | 31 + .../adventureworks/public/OrderNumber.scala | 31 + .../adventureworks/public/Phone.scala | 31 + .../public/pgtest/PgtestFields.scala | 110 +++ .../public/pgtest/PgtestRepo.scala | 23 + .../public/pgtest/PgtestRepoImpl.scala | 66 ++ .../public/pgtest/PgtestRow.scala | 477 ++++++++++ .../public/pgtest/PgtestStructure.scala | 119 +++ .../public/pgtestnull/PgtestnullFields.scala | 110 +++ .../public/pgtestnull/PgtestnullRepo.scala | 23 + .../pgtestnull/PgtestnullRepoImpl.scala | 66 ++ .../public/pgtestnull/PgtestnullRow.scala | 477 ++++++++++ .../pgtestnull/PgtestnullStructure.scala | 119 +++ .../public/users/UsersFields.scala | 26 + .../adventureworks/public/users/UsersId.scala | 31 + .../public/users/UsersRepo.scala | 32 + .../public/users/UsersRepoImpl.scala | 118 +++ .../public/users/UsersRepoMock.scala | 84 ++ .../public/users/UsersRow.scala | 81 ++ .../public/users/UsersRowUnsaved.scala | 82 ++ .../public/users/UsersStructure.scala | 35 + .../productvendor/ProductvendorFields.scala | 32 + .../productvendor/ProductvendorId.scala | 39 + .../productvendor/ProductvendorRepo.scala | 29 + .../productvendor/ProductvendorRepoImpl.scala | 125 +++ .../productvendor/ProductvendorRepoMock.scala | 77 ++ .../productvendor/ProductvendorRow.scala | 128 +++ .../ProductvendorRowUnsaved.scala | 127 +++ .../ProductvendorStructure.scala | 41 + .../PurchaseorderdetailFields.scala | 29 + .../PurchaseorderdetailId.scala | 38 + .../PurchaseorderdetailRepo.scala | 19 + .../PurchaseorderdetailRepoImpl.scala | 30 + .../PurchaseorderdetailRepoMock.scala | 28 + .../PurchaseorderdetailRow.scala | 111 +++ .../PurchaseorderdetailRowUnsaved.scala | 114 +++ .../PurchaseorderdetailStructure.scala | 38 + .../PurchaseorderheaderFields.scala | 33 + .../PurchaseorderheaderId.scala | 30 + .../PurchaseorderheaderRepo.scala | 30 + .../PurchaseorderheaderRepoImpl.scala | 155 ++++ .../PurchaseorderheaderRepoMock.scala | 80 ++ .../PurchaseorderheaderRow.scala | 133 +++ .../PurchaseorderheaderRowUnsaved.scala | 162 ++++ .../PurchaseorderheaderStructure.scala | 42 + .../shipmethod/ShipmethodFields.scala | 25 + .../purchasing/shipmethod/ShipmethodId.scala | 30 + .../shipmethod/ShipmethodRepo.scala | 30 + .../shipmethod/ShipmethodRepoImpl.scala | 121 +++ .../shipmethod/ShipmethodRepoMock.scala | 80 ++ .../purchasing/shipmethod/ShipmethodRow.scala | 82 ++ .../shipmethod/ShipmethodRowUnsaved.scala | 99 ++ .../shipmethod/ShipmethodStructure.scala | 34 + .../purchasing/vendor/VendorFields.scala | 31 + .../purchasing/vendor/VendorRepo.scala | 31 + .../purchasing/vendor/VendorRepoImpl.scala | 126 +++ .../purchasing/vendor/VendorRepoMock.scala | 81 ++ .../purchasing/vendor/VendorRow.scala | 100 +++ .../purchasing/vendor/VendorRowUnsaved.scala | 109 +++ .../purchasing/vendor/VendorStructure.scala | 40 + .../VvendorwithaddressesViewFields.scala | 27 + .../VvendorwithaddressesViewRepo.scala | 17 + .../VvendorwithaddressesViewRepoImpl.scala | 23 + .../VvendorwithaddressesViewRow.scala | 102 +++ .../VvendorwithaddressesViewStructure.scala | 36 + .../VvendorwithcontactsViewFields.scala | 32 + .../VvendorwithcontactsViewRepo.scala | 17 + .../VvendorwithcontactsViewRepoImpl.scala | 23 + .../VvendorwithcontactsViewRow.scala | 125 +++ .../VvendorwithcontactsViewStructure.scala | 41 + .../adventureworks/sa/c/CViewFields.scala | 28 + .../adventureworks/sa/c/CViewRepo.scala | 17 + .../adventureworks/sa/c/CViewRepoImpl.scala | 23 + .../adventureworks/sa/c/CViewRow.scala | 91 ++ .../adventureworks/sa/c/CViewStructure.scala | 37 + .../adventureworks/sa/cc/CcViewFields.scala | 25 + .../adventureworks/sa/cc/CcViewRepo.scala | 17 + .../adventureworks/sa/cc/CcViewRepoImpl.scala | 23 + .../adventureworks/sa/cc/CcViewRow.scala | 89 ++ .../sa/cc/CcViewStructure.scala | 34 + .../adventureworks/sa/cr/CrViewFields.scala | 25 + .../adventureworks/sa/cr/CrViewRepo.scala | 17 + .../adventureworks/sa/cr/CrViewRepoImpl.scala | 23 + .../adventureworks/sa/cr/CrViewRow.scala | 89 ++ .../sa/cr/CrViewStructure.scala | 34 + .../adventureworks/sa/crc/CrcViewFields.scala | 21 + .../adventureworks/sa/crc/CrcViewRepo.scala | 17 + .../sa/crc/CrcViewRepoImpl.scala | 23 + .../adventureworks/sa/crc/CrcViewRow.scala | 61 ++ .../sa/crc/CrcViewStructure.scala | 30 + .../adventureworks/sa/cu/CuViewFields.scala | 22 + .../adventureworks/sa/cu/CuViewRepo.scala | 17 + .../adventureworks/sa/cu/CuViewRepoImpl.scala | 23 + .../adventureworks/sa/cu/CuViewRow.scala | 68 ++ .../sa/cu/CuViewStructure.scala | 31 + .../adventureworks/sa/pcc/PccViewFields.scala | 22 + .../adventureworks/sa/pcc/PccViewRepo.scala | 17 + .../sa/pcc/PccViewRepoImpl.scala | 23 + .../adventureworks/sa/pcc/PccViewRow.scala | 68 ++ .../sa/pcc/PccViewStructure.scala | 31 + .../adventureworks/sa/s/SViewFields.scala | 28 + .../adventureworks/sa/s/SViewRepo.scala | 17 + .../adventureworks/sa/s/SViewRepoImpl.scala | 23 + .../adventureworks/sa/s/SViewRow.scala | 91 ++ .../adventureworks/sa/s/SViewStructure.scala | 37 + .../adventureworks/sa/sci/SciViewFields.scala | 25 + .../adventureworks/sa/sci/SciViewRepo.scala | 17 + .../sa/sci/SciViewRepoImpl.scala | 23 + .../adventureworks/sa/sci/SciViewRow.scala | 89 ++ .../sa/sci/SciViewStructure.scala | 34 + .../adventureworks/sa/so/SoViewFields.scala | 31 + .../adventureworks/sa/so/SoViewRepo.scala | 17 + .../adventureworks/sa/so/SoViewRepoImpl.scala | 23 + .../adventureworks/sa/so/SoViewRow.scala | 124 +++ .../sa/so/SoViewStructure.scala | 40 + .../adventureworks/sa/sod/SodViewFields.scala | 33 + .../adventureworks/sa/sod/SodViewRepo.scala | 17 + .../sa/sod/SodViewRepoImpl.scala | 23 + .../adventureworks/sa/sod/SodViewRow.scala | 120 +++ .../sa/sod/SodViewStructure.scala | 42 + .../adventureworks/sa/soh/SohViewFields.scala | 56 ++ .../adventureworks/sa/soh/SohViewRepo.scala | 17 + .../sa/soh/SohViewRepoImpl.scala | 23 + .../adventureworks/sa/soh/SohViewRow.scala | 233 +++++ .../sa/soh/SohViewStructure.scala | 65 ++ .../sa/sohsr/SohsrViewFields.scala | 21 + .../sa/sohsr/SohsrViewRepo.scala | 17 + .../sa/sohsr/SohsrViewRepoImpl.scala | 23 + .../sa/sohsr/SohsrViewRow.scala | 61 ++ .../sa/sohsr/SohsrViewStructure.scala | 30 + .../adventureworks/sa/sop/SopViewFields.scala | 24 + .../adventureworks/sa/sop/SopViewRepo.scala | 17 + .../sa/sop/SopViewRepoImpl.scala | 23 + .../adventureworks/sa/sop/SopViewRow.scala | 76 ++ .../sa/sop/SopViewStructure.scala | 33 + .../adventureworks/sa/sp/SpViewFields.scala | 30 + .../adventureworks/sa/sp/SpViewRepo.scala | 17 + .../adventureworks/sa/sp/SpViewRepoImpl.scala | 23 + .../adventureworks/sa/sp/SpViewRow.scala | 111 +++ .../sa/sp/SpViewStructure.scala | 39 + .../sa/spqh/SpqhViewFields.scala | 24 + .../adventureworks/sa/spqh/SpqhViewRepo.scala | 17 + .../sa/spqh/SpqhViewRepoImpl.scala | 23 + .../adventureworks/sa/spqh/SpqhViewRow.scala | 82 ++ .../sa/spqh/SpqhViewStructure.scala | 33 + .../adventureworks/sa/sr/SrViewFields.scala | 23 + .../adventureworks/sa/sr/SrViewRepo.scala | 17 + .../adventureworks/sa/sr/SrViewRepoImpl.scala | 23 + .../adventureworks/sa/sr/SrViewRow.scala | 75 ++ .../sa/sr/SrViewStructure.scala | 32 + .../adventureworks/sa/st/StViewFields.scala | 31 + .../adventureworks/sa/st/StViewRepo.scala | 17 + .../adventureworks/sa/st/StViewRepoImpl.scala | 23 + .../adventureworks/sa/st/StViewRow.scala | 119 +++ .../sa/st/StViewStructure.scala | 40 + .../adventureworks/sa/sth/SthViewFields.scala | 27 + .../adventureworks/sa/sth/SthViewRepo.scala | 17 + .../sa/sth/SthViewRepoImpl.scala | 23 + .../adventureworks/sa/sth/SthViewRow.scala | 90 ++ .../sa/sth/SthViewStructure.scala | 36 + .../adventureworks/sa/tr/TrViewFields.scala | 29 + .../adventureworks/sa/tr/TrViewRepo.scala | 17 + .../adventureworks/sa/tr/TrViewRepoImpl.scala | 23 + .../adventureworks/sa/tr/TrViewRow.scala | 99 ++ .../sa/tr/TrViewStructure.scala | 38 + .../CountryregioncurrencyFields.scala | 22 + .../CountryregioncurrencyId.scala | 39 + .../CountryregioncurrencyRepo.scala | 29 + .../CountryregioncurrencyRepoImpl.scala | 91 ++ .../CountryregioncurrencyRepoMock.scala | 77 ++ .../CountryregioncurrencyRow.scala | 64 ++ .../CountryregioncurrencyRowUnsaved.scala | 63 ++ .../CountryregioncurrencyStructure.scala | 31 + .../sales/creditcard/CreditcardFields.scala | 25 + .../sales/creditcard/CreditcardRepo.scala | 32 + .../sales/creditcard/CreditcardRepoImpl.scala | 113 +++ .../sales/creditcard/CreditcardRepoMock.scala | 82 ++ .../sales/creditcard/CreditcardRow.scala | 81 ++ .../creditcard/CreditcardRowUnsaved.scala | 86 ++ .../creditcard/CreditcardStructure.scala | 34 + .../sales/currency/CurrencyFields.scala | 21 + .../sales/currency/CurrencyId.scala | 30 + .../sales/currency/CurrencyRepo.scala | 30 + .../sales/currency/CurrencyRepoImpl.scala | 95 ++ .../sales/currency/CurrencyRepoMock.scala | 80 ++ .../sales/currency/CurrencyRow.scala | 59 ++ .../sales/currency/CurrencyRowUnsaved.scala | 60 ++ .../sales/currency/CurrencyStructure.scala | 30 + .../currencyrate/CurrencyrateFields.scala | 25 + .../sales/currencyrate/CurrencyrateId.scala | 30 + .../sales/currencyrate/CurrencyrateRepo.scala | 30 + .../currencyrate/CurrencyrateRepoImpl.scala | 115 +++ .../currencyrate/CurrencyrateRepoMock.scala | 80 ++ .../sales/currencyrate/CurrencyrateRow.scala | 89 ++ .../currencyrate/CurrencyrateRowUnsaved.scala | 94 ++ .../currencyrate/CurrencyrateStructure.scala | 34 + .../sales/customer/CustomerFields.scala | 27 + .../sales/customer/CustomerId.scala | 30 + .../sales/customer/CustomerRepo.scala | 30 + .../sales/customer/CustomerRepoImpl.scala | 116 +++ .../sales/customer/CustomerRepoMock.scala | 80 ++ .../sales/customer/CustomerRow.scala | 84 ++ .../sales/customer/CustomerRowUnsaved.scala | 93 ++ .../sales/customer/CustomerStructure.scala | 36 + .../PersoncreditcardFields.scala | 22 + .../personcreditcard/PersoncreditcardId.scala | 39 + .../PersoncreditcardRepo.scala | 29 + .../PersoncreditcardRepoImpl.scala | 91 ++ .../PersoncreditcardRepoMock.scala | 77 ++ .../PersoncreditcardRow.scala | 64 ++ .../PersoncreditcardRowUnsaved.scala | 63 ++ .../PersoncreditcardStructure.scala | 31 + .../SalesorderdetailFields.scala | 33 + .../salesorderdetail/SalesorderdetailId.scala | 38 + .../SalesorderdetailRepo.scala | 29 + .../SalesorderdetailRepoImpl.scala | 132 +++ .../SalesorderdetailRepoMock.scala | 77 ++ .../SalesorderdetailRow.scala | 119 +++ .../SalesorderdetailRowUnsaved.scala | 130 +++ .../SalesorderdetailStructure.scala | 42 + .../SalesorderheaderFields.scala | 55 ++ .../salesorderheader/SalesorderheaderId.scala | 30 + .../SalesorderheaderRepo.scala | 30 + .../SalesorderheaderRepoImpl.scala | 222 +++++ .../SalesorderheaderRepoMock.scala | 80 ++ .../SalesorderheaderRow.scala | 239 +++++ .../SalesorderheaderRowUnsaved.scala | 276 ++++++ .../SalesorderheaderStructure.scala | 64 ++ .../SalesorderheadersalesreasonFields.scala | 22 + .../SalesorderheadersalesreasonId.scala | 39 + .../SalesorderheadersalesreasonRepo.scala | 29 + .../SalesorderheadersalesreasonRepoImpl.scala | 91 ++ .../SalesorderheadersalesreasonRepoMock.scala | 77 ++ .../SalesorderheadersalesreasonRow.scala | 64 ++ ...alesorderheadersalesreasonRowUnsaved.scala | 63 ++ ...SalesorderheadersalesreasonStructure.scala | 31 + .../sales/salesperson/SalespersonFields.scala | 30 + .../sales/salesperson/SalespersonRepo.scala | 31 + .../salesperson/SalespersonRepoImpl.scala | 137 +++ .../salesperson/SalespersonRepoMock.scala | 81 ++ .../sales/salesperson/SalespersonRow.scala | 109 +++ .../salesperson/SalespersonRowUnsaved.scala | 130 +++ .../salesperson/SalespersonStructure.scala | 39 + .../SalespersonquotahistoryFields.scala | 24 + .../SalespersonquotahistoryId.scala | 39 + .../SalespersonquotahistoryRepo.scala | 29 + .../SalespersonquotahistoryRepoImpl.scala | 103 +++ .../SalespersonquotahistoryRepoMock.scala | 77 ++ .../SalespersonquotahistoryRow.scala | 77 ++ .../SalespersonquotahistoryRowUnsaved.scala | 80 ++ .../SalespersonquotahistoryStructure.scala | 33 + .../sales/salesreason/SalesreasonFields.scala | 22 + .../sales/salesreason/SalesreasonId.scala | 30 + .../sales/salesreason/SalesreasonRepo.scala | 30 + .../salesreason/SalesreasonRepoImpl.scala | 102 +++ .../salesreason/SalesreasonRepoMock.scala | 80 ++ .../sales/salesreason/SalesreasonRow.scala | 66 ++ .../salesreason/SalesreasonRowUnsaved.scala | 71 ++ .../salesreason/SalesreasonStructure.scala | 31 + .../salestaxrate/SalestaxrateFields.scala | 28 + .../sales/salestaxrate/SalestaxrateId.scala | 30 + .../sales/salestaxrate/SalestaxrateRepo.scala | 30 + .../salestaxrate/SalestaxrateRepoImpl.scala | 124 +++ .../salestaxrate/SalestaxrateRepoMock.scala | 80 ++ .../sales/salestaxrate/SalestaxrateRow.scala | 91 ++ .../salestaxrate/SalestaxrateRowUnsaved.scala | 104 +++ .../salestaxrate/SalestaxrateStructure.scala | 37 + .../salesterritory/SalesterritoryFields.scala | 30 + .../salesterritory/SalesterritoryId.scala | 30 + .../salesterritory/SalesterritoryRepo.scala | 30 + .../SalesterritoryRepoImpl.scala | 144 +++ .../SalesterritoryRepoMock.scala | 80 ++ .../salesterritory/SalesterritoryRow.scala | 114 +++ .../SalesterritoryRowUnsaved.scala | 139 +++ .../SalesterritoryStructure.scala | 39 + .../SalesterritoryhistoryFields.scala | 27 + .../SalesterritoryhistoryId.scala | 44 + .../SalesterritoryhistoryRepo.scala | 29 + .../SalesterritoryhistoryRepoImpl.scala | 106 +++ .../SalesterritoryhistoryRepoMock.scala | 77 ++ .../SalesterritoryhistoryRow.scala | 87 ++ .../SalesterritoryhistoryRowUnsaved.scala | 90 ++ .../SalesterritoryhistoryStructure.scala | 36 + .../ShoppingcartitemFields.scala | 24 + .../shoppingcartitem/ShoppingcartitemId.scala | 30 + .../ShoppingcartitemRepo.scala | 30 + .../ShoppingcartitemRepoImpl.scala | 117 +++ .../ShoppingcartitemRepoMock.scala | 80 ++ .../ShoppingcartitemRow.scala | 82 ++ .../ShoppingcartitemRowUnsaved.scala | 95 ++ .../ShoppingcartitemStructure.scala | 33 + .../specialoffer/SpecialofferFields.scala | 30 + .../sales/specialoffer/SpecialofferId.scala | 30 + .../sales/specialoffer/SpecialofferRepo.scala | 30 + .../specialoffer/SpecialofferRepoImpl.scala | 140 +++ .../specialoffer/SpecialofferRepoMock.scala | 80 ++ .../sales/specialoffer/SpecialofferRow.scala | 119 +++ .../specialoffer/SpecialofferRowUnsaved.scala | 136 +++ .../specialoffer/SpecialofferStructure.scala | 39 + .../SpecialofferproductFields.scala | 24 + .../SpecialofferproductId.scala | 39 + .../SpecialofferproductRepo.scala | 29 + .../SpecialofferproductRepoImpl.scala | 99 ++ .../SpecialofferproductRepoMock.scala | 77 ++ .../SpecialofferproductRow.scala | 71 ++ .../SpecialofferproductRowUnsaved.scala | 74 ++ .../SpecialofferproductStructure.scala | 33 + .../sales/store/StoreFields.scala | 28 + .../sales/store/StoreRepo.scala | 31 + .../sales/store/StoreRepoImpl.scala | 114 +++ .../sales/store/StoreRepoMock.scala | 81 ++ .../adventureworks/sales/store/StoreRow.scala | 84 ++ .../sales/store/StoreRowUnsaved.scala | 89 ++ .../sales/store/StoreStructure.scala | 37 + .../VindividualcustomerViewFields.scala | 39 + .../VindividualcustomerViewRepo.scala | 17 + .../VindividualcustomerViewRepoImpl.scala | 23 + .../VindividualcustomerViewRow.scala | 168 ++++ .../VindividualcustomerViewStructure.scala | 48 + .../VpersondemographicsViewFields.scala | 32 + .../VpersondemographicsViewRepo.scala | 17 + .../VpersondemographicsViewRepoImpl.scala | 23 + .../VpersondemographicsViewRow.scala | 119 +++ .../VpersondemographicsViewStructure.scala | 41 + .../vsalesperson/VsalespersonViewFields.scala | 42 + .../vsalesperson/VsalespersonViewRepo.scala | 17 + .../VsalespersonViewRepoImpl.scala | 23 + .../vsalesperson/VsalespersonViewRow.scala | 195 ++++ .../VsalespersonViewStructure.scala | 51 ++ ...espersonsalesbyfiscalyearsViewFields.scala | 22 + ...alespersonsalesbyfiscalyearsViewRepo.scala | 17 + ...personsalesbyfiscalyearsViewRepoImpl.scala | 23 + ...salespersonsalesbyfiscalyearsViewRow.scala | 79 ++ ...ersonsalesbyfiscalyearsViewStructure.scala | 31 + ...rsonsalesbyfiscalyearsdataViewFields.scala | 24 + ...personsalesbyfiscalyearsdataViewRepo.scala | 17 + ...onsalesbyfiscalyearsdataViewRepoImpl.scala | 23 + ...spersonsalesbyfiscalyearsdataViewRow.scala | 78 ++ ...nsalesbyfiscalyearsdataViewStructure.scala | 33 + .../VstorewithaddressesViewFields.scala | 27 + .../VstorewithaddressesViewRepo.scala | 17 + .../VstorewithaddressesViewRepoImpl.scala | 23 + .../VstorewithaddressesViewRow.scala | 102 +++ .../VstorewithaddressesViewStructure.scala | 36 + .../VstorewithcontactsViewFields.scala | 32 + .../VstorewithcontactsViewRepo.scala | 17 + .../VstorewithcontactsViewRepoImpl.scala | 23 + .../VstorewithcontactsViewRow.scala | 125 +++ .../VstorewithcontactsViewStructure.scala | 41 + .../VstorewithdemographicsViewFields.scala | 31 + .../VstorewithdemographicsViewRepo.scala | 17 + .../VstorewithdemographicsViewRepoImpl.scala | 23 + .../VstorewithdemographicsViewRow.scala | 114 +++ .../VstorewithdemographicsViewStructure.scala | 40 + .../adventureworks/testInsert.scala | 629 +++++++++++++ .../update_person/UpdatePersonSqlRepo.scala | 15 + .../UpdatePersonSqlRepoImpl.scala | 22 + .../UpdatePersonReturningSqlRepo.scala | 15 + .../UpdatePersonReturningSqlRepoImpl.scala | 29 + .../UpdatePersonReturningSqlRow.scala | 52 ++ .../src/scala/adventureworks/ArrayTest.scala | 387 ++++++++ .../adventureworks/ReadPostgresTest.scala | 223 +++++ .../department/DepartmentTest.scala | 57 ++ .../employee/EmployeeTest.scala | 150 ++++ .../adventureworks/person/MultiRepoTest.scala | 65 ++ .../BusinessentityaddressTest.scala | 105 +++ .../person_detail/PersonDetailTest.scala | 15 + .../production/product/ProductTest.scala | 204 +++++ .../publicc/UsersRepoTest.scala | 38 + .../userdefined/CustomCreditcardId.scala | 23 + .../userdefined/FirstName.scala | 17 + .../scala/adventureworks/withConnection.scala | 44 + typo/src/scala/typo/DbLibName.scala | 1 + typo/src/scala/typo/JsonLibName.scala | 1 + .../typo/internal/codegen/DbLibZioJdbc.scala | 843 ++++++++++++++++++ .../internal/codegen/JsonLibZioJson.scala | 204 +++++ typo/src/scala/typo/internal/generate.scala | 6 +- typo/src/scala/typo/sc.scala | 4 +- 2356 files changed, 121682 insertions(+), 17 deletions(-) create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala create mode 100644 .bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/DeleteBuilder.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/ParameterMetaData.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilder.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderMock.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderSql.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectParams.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SortOrder.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/SqlExpr.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/UpdateBuilder.scala create mode 100644 typo-dsl-zio-jdbc/src/scala/typo/dsl/extensions.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/Defaulted.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAclItem.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAnyArray.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBox.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBytea.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoCircle.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoHStore.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInet.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInstant.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInt2Vector.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInterval.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJson.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJsonb.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLine.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLineSegment.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDate.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDateTime.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalTime.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoMoney.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOffsetTime.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOidVector.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPath.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPgNodeTree.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPoint.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPolygon.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRecord.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegproc.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegtype.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoShort.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUUID.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownCitext.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgDependencies.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgMcvList.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgNdistinct.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgStatistic.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoVector.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXid.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXml.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CardinalNumber.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CharacterData.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/YesOrNo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/package.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/AccountNumber.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Flag.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Mydomain.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Myenum.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Name.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/NameStyle.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/OrderNumber.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Phone.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductId.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoMock.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRowUnsaved.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewFields.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRow.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewStructure.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepo.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepoImpl.scala create mode 100644 typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRow.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/ArrayTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/ReadPostgresTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/department/DepartmentTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/employee/EmployeeTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/person/MultiRepoTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/person/businessentityaddress/BusinessentityaddressTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/person_detail/PersonDetailTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/production/product/ProductTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/publicc/UsersRepoTest.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/CustomCreditcardId.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/FirstName.scala create mode 100644 typo-tester-zio-jdbc/src/scala/adventureworks/withConnection.scala create mode 100644 typo/src/scala/typo/internal/codegen/DbLibZioJdbc.scala create mode 100644 typo/src/scala/typo/internal/codegen/JsonLibZioJson.scala diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala new file mode 100644 index 0000000000..31783a31bb --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + + + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class one(override val value: Long) extends PersonFieldOrIdValue("one", value) + case class two(override val value: Option[String]) extends PersonFieldOrIdValue("two", value) + case class name(override val value: Option[String]) extends PersonFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala new file mode 100644 index 0000000000..566037212d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val one: IdField[Long, Row] + val two: IdField[Option[String], Row] + val name: OptField[String, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala new file mode 100644 index 0000000000..a0d088a153 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala @@ -0,0 +1,38 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `compositepk.person` */ +case class PersonId(one: Long, two: Option[String]) +object PersonId { + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight) + Right(PersonId(one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = new JsonEncoder[PersonId] { + override def unsafeEncode(a: PersonId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[Option[String]]): Ordering[PersonId] = Ordering.by(x => (x.one, x.two)) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala new file mode 100644 index 0000000000..76c558c15d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..2cbf8c554e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala @@ -0,0 +1,119 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("compositepk.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into compositepk.person("one", "two", "name") + values (${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "one", "two", "name" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.one match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""one"""", sql"${Segment.paramSegment(value: Long)(Setter.longSetter)}::int8")) + }, + unsaved.two match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""two"""", sql"${Segment.paramSegment(value: Option[String])(Setter.optionParamSetter(Setter.stringSetter))}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into compositepk.person default values + returning "one", "two", "name" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into compositepk.person($names) values ($values) returning "one", "two", "name"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "one", "two", "name" from compositepk.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "one", "two", "name" from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.one(value) => sql""""one" = ${Segment.paramSegment(value)(Setter.longSetter)}""" + case PersonFieldValue.two(value) => sql""""two" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + } + ) + sql"""select "one", "two", "name" from compositepk.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update compositepk.person + set "name" = ${Segment.paramSegment(row.name)(Setter.optionParamSetter(Setter.stringSetter))} + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" }.mkFragment(SqlFragment(", ")) + sql"""update compositepk.person + set $updates + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into compositepk.person("one", "two", "name") + values ( + ${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("one", "two") + do update set + "name" = EXCLUDED."name" + returning "one", "two", "name"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala new file mode 100644 index 0000000000..be71d1f2ec --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala @@ -0,0 +1,104 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.one(value)) => acc.filter(_.one == value) + case (acc, PersonFieldValue.two(value)) => acc.filter(_.two == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(compositeId) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(compositeId, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala new file mode 100644 index 0000000000..d447951d01 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala @@ -0,0 +1,58 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + one: Long, + two: Option[String], + name: Option[String] +){ + val compositeId: PersonId = PersonId(one, two) + } + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 2 -> + PersonRow( + one = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + two = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight && name.isRight) + Right(PersonRow(one = one.toOption.get, two = two.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](one, two, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..752c398333 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala @@ -0,0 +1,61 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `compositepk.person` which has not been persisted yet */ +case class PersonRowUnsaved( + name: Option[String], + /** Default: auto-increment */ + one: Defaulted[Long] = Defaulted.UseDefault, + /** Default: auto-increment */ + two: Defaulted[Option[String]] = Defaulted.UseDefault +) { + def toRow(oneDefault: => Long, twoDefault: => Option[String]): PersonRow = + PersonRow( + name = name, + one = one match { + case Defaulted.UseDefault => oneDefault + case Defaulted.Provided(value) => value + }, + two = two match { + case Defaulted.UseDefault => twoDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.long))) + val two = jsonObj.get("two").toRight("Missing field 'two'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.option(JsonDecoder.string)))) + if (name.isRight && one.isRight && two.isRight) + Right(PersonRowUnsaved(name = name.toOption.get, one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](name, one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""one":""") + Defaulted.jsonEncoder(JsonEncoder.long).unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + Defaulted.jsonEncoder(JsonEncoder.option(JsonEncoder.string)).unsafeEncode(a.two, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala new file mode 100644 index 0000000000..19fe394b37 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala @@ -0,0 +1,29 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val one = new IdField[Long, Row](prefix, "one", None, Some("int8"))(x => extract(x).one, (row, value) => merge(row, extract(row).copy(one = value))) + override val two = new IdField[Option[String], Row](prefix, "two", None, None)(x => extract(x).two, (row, value) => merge(row, extract(row).copy(two = value))) + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](one, two, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala new file mode 100644 index 0000000000..fd75028067 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala @@ -0,0 +1,45 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package customtypes + +import scala.util.Success +import scala.util.Try +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.JsonError +import zio.json.internal.RetractReader +import zio.json.internal.Write + + +/** + * This signals a value where if you don't provide it, postgres will generate it for you + */ +sealed trait Defaulted[+T] + +object Defaulted { + case class Provided[T](value: T) extends Defaulted[T] + case object UseDefault extends Defaulted[Nothing] + implicit def jsonDecoder[T](implicit T: JsonDecoder[T]): JsonDecoder[Defaulted[T]] = new JsonDecoder[Defaulted[T]] { + override def unsafeDecode(trace: List[JsonError], in: RetractReader): Defaulted[T] = + Try(JsonDecoder.string.unsafeDecode(trace, in)) match { + case Success("defaulted") => UseDefault + case _ => Provided(T.unsafeDecode(trace, in)) + } + } + implicit def jsonEncoder[T](implicit T: JsonEncoder[T]): JsonEncoder[Defaulted[T]] = new JsonEncoder[Defaulted[T]] { + override def unsafeEncode(a: Defaulted[T], indent: Option[Int], out: Write): Unit = + a match { + case Provided(value) => + out.write("{") + out.write("\"provided\":") + T.unsafeEncode(value, None, out) + out.write("}") + case UseDefault => out.write("\"defaulted\"") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala new file mode 100644 index 0000000000..2dfe4cfdc0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.number` + * - one + * - two + * - three + */ +sealed abstract class Number(val value: String) + +object Number { + def apply(str: String): Either[String, Number] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Number = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_one` extends Number("one") + case object `_two` extends Number("two") + case object `_three` extends Number("three") + val All: List[Number] = List(`_one`, `_two`, `_three`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Number] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Number]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Number]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Number]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Number] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Number] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Number) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Number from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Number.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Number] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Number] = JsonDecoder.string.mapOrFail(Number.apply) + implicit lazy val jsonEncoder: JsonEncoder[Number] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Number] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Number] = ParameterMetaData.instance[Number](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Number] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala new file mode 100644 index 0000000000..062e811683 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.sector` + * - PUBLIC + * - PRIVATE + * - OTHER + */ +sealed abstract class Sector(val value: String) + +object Sector { + def apply(str: String): Either[String, Sector] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Sector = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_public` extends Sector("PUBLIC") + case object `_private` extends Sector("PRIVATE") + case object `_other` extends Sector("OTHER") + val All: List[Sector] = List(`_public`, `_private`, `_other`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Sector] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Sector]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Sector]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Sector]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Sector] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Sector] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Sector) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Sector from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Sector.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Sector] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Sector] = JsonDecoder.string.mapOrFail(Sector.apply) + implicit lazy val jsonEncoder: JsonEncoder[Sector] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Sector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Sector] = ParameterMetaData.instance[Sector](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Sector] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala new file mode 100644 index 0000000000..27dd576cf2 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + + + +sealed abstract class FootballClubFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class FootballClubFieldValue[T](name: String, value: T) extends FootballClubFieldOrIdValue(name, value) + +object FootballClubFieldValue { + case class id(override val value: FootballClubId) extends FootballClubFieldOrIdValue("id", value) + case class name(override val value: /* max 100 chars */ String) extends FootballClubFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala new file mode 100644 index 0000000000..f398781245 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait FootballClubFields[Row] { + val id: IdField[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] +} +object FootballClubFields extends FootballClubStructure[FootballClubRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala new file mode 100644 index 0000000000..87907ea3ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +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 `myschema.football_club` */ +case class FootballClubId(value: Long) extends AnyVal +object FootballClubId { + implicit lazy val arraySetter: Setter[Array[FootballClubId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[FootballClubId, Long] = Bijection[FootballClubId, Long](_.value)(FootballClubId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubId] = JdbcDecoder.longDecoder.map(FootballClubId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[FootballClubId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[FootballClubId] = JsonDecoder.long.map(FootballClubId.apply) + implicit lazy val jsonEncoder: JsonEncoder[FootballClubId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[FootballClubId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[FootballClubId] = ParameterMetaData.instance[FootballClubId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[FootballClubId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala new file mode 100644 index 0000000000..90bf603cb0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait FootballClubRepo { + def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[FootballClubFields, FootballClubRow] + def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] + def select: SelectBuilder[FootballClubFields, FootballClubRow] + def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] + def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] + def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] + def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] + def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[FootballClubFields, FootballClubRow] + def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala new file mode 100644 index 0000000000..a22fe92081 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object FootballClubRepoImpl extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilder("myschema.football_club", FootballClubFields) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + sql"""insert into myschema.football_club("id", "name") + values (${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}) + returning "id", "name" + """.insertReturning(FootballClubRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderSql("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + sql"""select "id", "name" from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".query(FootballClubRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club where "id" = ANY(${Segment.paramSegment(ids)(FootballClubId.arraySetter)})""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case FootballClubFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + } + ) + sql"""select "id", "name" from myschema.football_club where $wheres""".query(FootballClubRow.jdbcDecoder).selectStream + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.football_club + set "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)} + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilder("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.football_club + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + sql"""insert into myschema.football_club("id", "name") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)} + ) + on conflict ("id") + do update set + "name" = EXCLUDED."name" + returning "id", "name"""".insertReturning(FootballClubRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala new file mode 100644 index 0000000000..e3107ad1c5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala @@ -0,0 +1,102 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class FootballClubRepoMock(map: scala.collection.mutable.Map[FootballClubId, FootballClubRow] = scala.collection.mutable.Map.empty) extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilderMock(DeleteParams.empty, FootballClubFields, map) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderMock(FootballClubFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, FootballClubFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, FootballClubFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilderMock(UpdateParams.empty, FootballClubFields, map) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, FootballClubFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala new file mode 100644 index 0000000000..9466b904d5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala @@ -0,0 +1,50 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class FootballClubRow( + id: FootballClubId, + name: /* max 100 chars */ String +) + +object FootballClubRow { + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubRow] = new JdbcDecoder[FootballClubRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, FootballClubRow) = + columIndex + 1 -> + FootballClubRow( + id = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[FootballClubRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + if (id.isRight && name.isRight) + Right(FootballClubRow(id = id.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](id, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[FootballClubRow] = new JsonEncoder[FootballClubRow] { + override def unsafeEncode(a: FootballClubRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala new file mode 100644 index 0000000000..0a1540fc26 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala @@ -0,0 +1,28 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class FootballClubStructure[Row](val prefix: Option[String], val extract: Row => FootballClubRow, val merge: (Row, FootballClubRow) => Row) + extends Relation[FootballClubFields, FootballClubRow, Row] + with FootballClubFields[Row] { outer => + + override val id = new IdField[FootballClubId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => FootballClubRow, merge: (NewRow, FootballClubRow) => NewRow): FootballClubStructure[NewRow] = + new FootballClubStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala new file mode 100644 index 0000000000..35c6ebae67 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala @@ -0,0 +1,18 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + + + +sealed abstract class MaritalStatusFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class MaritalStatusFieldValue[T](name: String, value: T) extends MaritalStatusFieldOrIdValue(name, value) + +object MaritalStatusFieldValue { + case class id(override val value: MaritalStatusId) extends MaritalStatusFieldOrIdValue("id", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala new file mode 100644 index 0000000000..614cb66ff6 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala @@ -0,0 +1,17 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.IdField + +trait MaritalStatusFields[Row] { + val id: IdField[MaritalStatusId, Row] +} +object MaritalStatusFields extends MaritalStatusStructure[MaritalStatusRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala new file mode 100644 index 0000000000..7495cac342 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +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 `myschema.marital_status` */ +case class MaritalStatusId(value: Long) extends AnyVal +object MaritalStatusId { + implicit lazy val arraySetter: Setter[Array[MaritalStatusId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[MaritalStatusId, Long] = Bijection[MaritalStatusId, Long](_.value)(MaritalStatusId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusId] = JdbcDecoder.longDecoder.map(MaritalStatusId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[MaritalStatusId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusId] = JsonDecoder.long.map(MaritalStatusId.apply) + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[MaritalStatusId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[MaritalStatusId] = ParameterMetaData.instance[MaritalStatusId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[MaritalStatusId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala new file mode 100644 index 0000000000..b559a3fd93 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala @@ -0,0 +1,30 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait MaritalStatusRepo { + def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] + def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] + def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] + def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] + def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] + def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala new file mode 100644 index 0000000000..518d1399b1 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala @@ -0,0 +1,72 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object MaritalStatusRepoImpl extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilder("myschema.marital_status", MaritalStatusFields) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + sql"""insert into myschema.marital_status("id") + values (${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8) + returning "id" + """.insertReturning(MaritalStatusRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderSql("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + sql"""select "id" from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".query(MaritalStatusRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status where "id" = ANY(${Segment.paramSegment(ids)(MaritalStatusId.arraySetter)})""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case MaritalStatusFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + } + ) + sql"""select "id" from myschema.marital_status where $wheres""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilder("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + sql"""insert into myschema.marital_status("id") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8 + ) + on conflict ("id") + returning "id"""".insertReturning(MaritalStatusRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala new file mode 100644 index 0000000000..529a6f848b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class MaritalStatusRepoMock(map: scala.collection.mutable.Map[MaritalStatusId, MaritalStatusRow] = scala.collection.mutable.Map.empty) extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilderMock(DeleteParams.empty, MaritalStatusFields, map) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderMock(MaritalStatusFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, MaritalStatusFieldValue.id(value)) => acc.filter(_.id == value) + } + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilderMock(UpdateParams.empty, MaritalStatusFields, map) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala new file mode 100644 index 0000000000..1859f9c436 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala @@ -0,0 +1,37 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class MaritalStatusRow( + id: MaritalStatusId +) + +object MaritalStatusRow { + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusRow] = MaritalStatusId.jdbcDecoder.map(v => MaritalStatusRow(id = v)) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + if (id.isRight) + Right(MaritalStatusRow(id = id.toOption.get)) + else Left(List[Either[String, Any]](id).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusRow] = new JsonEncoder[MaritalStatusRow] { + override def unsafeEncode(a: MaritalStatusRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala new file mode 100644 index 0000000000..eeca5f848e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala @@ -0,0 +1,26 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class MaritalStatusStructure[Row](val prefix: Option[String], val extract: Row => MaritalStatusRow, val merge: (Row, MaritalStatusRow) => Row) + extends Relation[MaritalStatusFields, MaritalStatusRow, Row] + with MaritalStatusFields[Row] { outer => + + override val id = new IdField[MaritalStatusId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => MaritalStatusRow, merge: (NewRow, MaritalStatusRow) => NewRow): MaritalStatusStructure[NewRow] = + new MaritalStatusStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala new file mode 100644 index 0000000000..9b131a996b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class id(override val value: PersonId) extends PersonFieldOrIdValue("id", value) + case class favouriteFootballClubId(override val value: FootballClubId) extends PersonFieldValue("favourite_football_club_id", value) + case class name(override val value: /* max 100 chars */ String) extends PersonFieldValue("name", value) + case class nickName(override val value: Option[/* max 30 chars */ String]) extends PersonFieldValue("nick_name", value) + case class blogUrl(override val value: Option[/* max 100 chars */ String]) extends PersonFieldValue("blog_url", value) + case class email(override val value: /* max 254 chars */ String) extends PersonFieldValue("email", value) + case class phone(override val value: /* max 8 chars */ String) extends PersonFieldValue("phone", value) + case class likesPizza(override val value: Boolean) extends PersonFieldValue("likes_pizza", value) + case class maritalStatusId(override val value: MaritalStatusId) extends PersonFieldValue("marital_status_id", value) + case class workEmail(override val value: Option[/* max 254 chars */ String]) extends PersonFieldValue("work_email", value) + case class sector(override val value: Sector) extends PersonFieldValue("sector", value) + case class favoriteNumber(override val value: Number) extends PersonFieldValue("favorite_number", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala new file mode 100644 index 0000000000..29b9ae44ab --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala @@ -0,0 +1,34 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val id: IdField[PersonId, Row] + val favouriteFootballClubId: Field[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] + val nickName: OptField[/* max 30 chars */ String, Row] + val blogUrl: OptField[/* max 100 chars */ String, Row] + val email: Field[/* max 254 chars */ String, Row] + val phone: Field[/* max 8 chars */ String, Row] + val likesPizza: Field[Boolean, Row] + val maritalStatusId: Field[MaritalStatusId, Row] + val workEmail: OptField[/* max 254 chars */ String, Row] + val sector: Field[Sector, Row] + val favoriteNumber: Field[Number, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala new file mode 100644 index 0000000000..1f701b7740 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +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 `myschema.person` */ +case class PersonId(value: Long) extends AnyVal +object PersonId { + implicit lazy val arraySetter: Setter[Array[PersonId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PersonId, Long] = Bijection[PersonId, Long](_.value)(PersonId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PersonId] = JdbcDecoder.longDecoder.map(PersonId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PersonId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder.long.map(PersonId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PersonId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PersonId] = ParameterMetaData.instance[PersonId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PersonId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala new file mode 100644 index 0000000000..a7317acdde --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala @@ -0,0 +1,33 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..ad588b5827 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala @@ -0,0 +1,189 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("myschema.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values (${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number) + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""favourite_football_club_id"""", sql"${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}")), + Some((sql""""nick_name"""", sql"${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""blog_url"""", sql"${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""email"""", sql"${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}")), + Some((sql""""phone"""", sql"${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}")), + Some((sql""""likes_pizza"""", sql"${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}")), + Some((sql""""work_email"""", sql"${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.id match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""id"""", sql"${Segment.paramSegment(value: PersonId)(Setter[PersonId])}::int8")) + }, + unsaved.maritalStatusId match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""marital_status_id"""", sql"${Segment.paramSegment(value: MaritalStatusId)(Setter[MaritalStatusId])}")) + }, + unsaved.sector match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""sector"""", sql"${Segment.paramSegment(value: Sector)(Setter[Sector])}::myschema.sector")) + }, + unsaved.favoriteNumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""favorite_number"""", sql"${Segment.paramSegment(value: Number)(Setter[Number])}::myschema.number")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into myschema.person default values + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into myschema.person($names) values ($values) returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ANY(${Segment.paramSegment(ids)(PersonId.arraySetter)})""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[PersonId])}""" + case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}""" + } + ) + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.person + set "favourite_football_club_id" = ${Segment.paramSegment(row.favouriteFootballClubId)(Setter[FootballClubId])}, + "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)}, + "nick_name" = ${Segment.paramSegment(row.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + "blog_url" = ${Segment.paramSegment(row.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + "email" = ${Segment.paramSegment(row.email)(Setter.stringSetter)}, + "phone" = ${Segment.paramSegment(row.phone)(Setter.stringSetter)}, + "likes_pizza" = ${Segment.paramSegment(row.likesPizza)(Setter.booleanSetter)}, + "marital_status_id" = ${Segment.paramSegment(row.maritalStatusId)(Setter[MaritalStatusId])}, + "work_email" = ${Segment.paramSegment(row.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + "sector" = ${Segment.paramSegment(row.sector)(Setter[Sector])}::myschema.sector, + "favorite_number" = ${Segment.paramSegment(row.favoriteNumber)(Setter[Number])}::myschema.number + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}::myschema.sector""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}::myschema.number""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.person + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, + ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, + ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, + ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number + ) + on conflict ("id") + do update set + "favourite_football_club_id" = EXCLUDED."favourite_football_club_id", + "name" = EXCLUDED."name", + "nick_name" = EXCLUDED."nick_name", + "blog_url" = EXCLUDED."blog_url", + "email" = EXCLUDED."email", + "phone" = EXCLUDED."phone", + "likes_pizza" = EXCLUDED."likes_pizza", + "marital_status_id" = EXCLUDED."marital_status_id", + "work_email" = EXCLUDED."work_email", + "sector" = EXCLUDED."sector", + "favorite_number" = EXCLUDED."favorite_number" + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala new file mode 100644 index 0000000000..e11c0937ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala @@ -0,0 +1,126 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.filter(_.favouriteFootballClubId == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + case (acc, PersonFieldValue.nickName(value)) => acc.filter(_.nickName == value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.filter(_.blogUrl == value) + case (acc, PersonFieldValue.email(value)) => acc.filter(_.email == value) + case (acc, PersonFieldValue.phone(value)) => acc.filter(_.phone == value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.filter(_.likesPizza == value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.filter(_.maritalStatusId == value) + case (acc, PersonFieldValue.workEmail(value)) => acc.filter(_.workEmail == value) + case (acc, PersonFieldValue.sector(value)) => acc.filter(_.sector == value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.filter(_.favoriteNumber == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.copy(favouriteFootballClubId = value) + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + case (acc, PersonFieldValue.nickName(value)) => acc.copy(nickName = value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.copy(blogUrl = value) + case (acc, PersonFieldValue.email(value)) => acc.copy(email = value) + case (acc, PersonFieldValue.phone(value)) => acc.copy(phone = value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.copy(likesPizza = value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.copy(maritalStatusId = value) + case (acc, PersonFieldValue.workEmail(value)) => acc.copy(workEmail = value) + case (acc, PersonFieldValue.sector(value)) => acc.copy(sector = value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.copy(favoriteNumber = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala new file mode 100644 index 0000000000..4321795ca7 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala @@ -0,0 +1,116 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import java.sql.ResultSet +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + id: PersonId, + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + /** Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: MaritalStatusId, + workEmail: Option[/* max 254 chars */ String], + sector: Sector, + favoriteNumber: Number +) + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 11 -> + PersonRow( + id = PersonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + favouriteFootballClubId = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + nickName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + blogUrl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + email = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + phone = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + likesPizza = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + maritalStatusId = MaritalStatusId.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + workEmail = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + sector = Sector.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + favoriteNumber = Number.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(PersonId.jsonDecoder)) + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Sector.jsonDecoder)) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Number.jsonDecoder)) + if (id.isRight && favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && maritalStatusId.isRight && workEmail.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRow(id = id.toOption.get, favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, maritalStatusId = maritalStatusId.toOption.get, workEmail = workEmail.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + PersonId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""sector":""") + Sector.jsonEncoder.unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Number.jsonEncoder.unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..47897e8d14 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala @@ -0,0 +1,129 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `myschema.person` which has not been persisted yet */ +case class PersonRowUnsaved( + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + workEmail: Option[/* max 254 chars */ String], + /** Default: auto-increment */ + id: Defaulted[PersonId] = Defaulted.UseDefault, + /** Default: some-value + Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, + /** Default: PUBLIC */ + sector: Defaulted[Sector] = Defaulted.UseDefault, + /** Default: one */ + favoriteNumber: Defaulted[Number] = Defaulted.UseDefault +) { + def toRow(idDefault: => PersonId, maritalStatusIdDefault: => MaritalStatusId, sectorDefault: => Sector, favoriteNumberDefault: => Number): PersonRow = + PersonRow( + favouriteFootballClubId = favouriteFootballClubId, + name = name, + nickName = nickName, + blogUrl = blogUrl, + email = email, + phone = phone, + likesPizza = likesPizza, + workEmail = workEmail, + id = id match { + case Defaulted.UseDefault => idDefault + case Defaulted.Provided(value) => value + }, + maritalStatusId = maritalStatusId match { + case Defaulted.UseDefault => maritalStatusIdDefault + case Defaulted.Provided(value) => value + }, + sector = sector match { + case Defaulted.UseDefault => sectorDefault + case Defaulted.Provided(value) => value + }, + favoriteNumber = favoriteNumber match { + case Defaulted.UseDefault => favoriteNumberDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(Defaulted.jsonDecoder(PersonId.jsonDecoder))) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(Defaulted.jsonDecoder(MaritalStatusId.jsonDecoder))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Defaulted.jsonDecoder(Sector.jsonDecoder))) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Defaulted.jsonDecoder(Number.jsonDecoder))) + if (favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && workEmail.isRight && id.isRight && maritalStatusId.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, workEmail = workEmail.toOption.get, id = id.toOption.get, maritalStatusId = maritalStatusId.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, workEmail, id, maritalStatusId, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""id":""") + Defaulted.jsonEncoder(PersonId.jsonEncoder).unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + Defaulted.jsonEncoder(MaritalStatusId.jsonEncoder).unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""sector":""") + Defaulted.jsonEncoder(Sector.jsonEncoder).unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Defaulted.jsonEncoder(Number.jsonEncoder).unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala new file mode 100644 index 0000000000..1886c54182 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala @@ -0,0 +1,43 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val id = new IdField[PersonId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val favouriteFootballClubId = new Field[FootballClubId, Row](prefix, "favourite_football_club_id", None, None)(x => extract(x).favouriteFootballClubId, (row, value) => merge(row, extract(row).copy(favouriteFootballClubId = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val nickName = new OptField[/* max 30 chars */ String, Row](prefix, "nick_name", None, None)(x => extract(x).nickName, (row, value) => merge(row, extract(row).copy(nickName = value))) + override val blogUrl = new OptField[/* max 100 chars */ String, Row](prefix, "blog_url", None, None)(x => extract(x).blogUrl, (row, value) => merge(row, extract(row).copy(blogUrl = value))) + override val email = new Field[/* max 254 chars */ String, Row](prefix, "email", None, None)(x => extract(x).email, (row, value) => merge(row, extract(row).copy(email = value))) + override val phone = new Field[/* max 8 chars */ String, Row](prefix, "phone", None, None)(x => extract(x).phone, (row, value) => merge(row, extract(row).copy(phone = value))) + override val likesPizza = new Field[Boolean, Row](prefix, "likes_pizza", None, None)(x => extract(x).likesPizza, (row, value) => merge(row, extract(row).copy(likesPizza = value))) + override val maritalStatusId = new Field[MaritalStatusId, Row](prefix, "marital_status_id", None, None)(x => extract(x).maritalStatusId, (row, value) => merge(row, extract(row).copy(maritalStatusId = value))) + override val workEmail = new OptField[/* max 254 chars */ String, Row](prefix, "work_email", None, None)(x => extract(x).workEmail, (row, value) => merge(row, extract(row).copy(workEmail = value))) + override val sector = new Field[Sector, Row](prefix, "sector", None, Some("myschema.sector"))(x => extract(x).sector, (row, value) => merge(row, extract(row).copy(sector = value))) + override val favoriteNumber = new Field[Number, Row](prefix, "favorite_number", None, Some("myschema.number"))(x => extract(x).favoriteNumber, (row, value) => merge(row, extract(row).copy(favoriteNumber = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala new file mode 100644 index 0000000000..c8ffbefab4 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala @@ -0,0 +1,243 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb + +package object hardcoded { + implicit lazy val BigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] = new zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.math.BigDecimal]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.math.BigDecimal]) { + case (b, x: java.math.BigDecimal) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.math.BigDecimal] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.math.BigDecimal) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.math.BigDecimal). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.math.BigDecimal]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BigDecimalArraySetter) + implicit lazy val BigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.math.BigDecimal]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.math.BigDecimal]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("numeric", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val BooleanArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Boolean]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Boolean]) { + case (b, x: scala.Boolean) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Boolean] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Boolean) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Boolean). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BooleanArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Boolean]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BooleanArraySetter) + implicit lazy val BooleanArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Boolean]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Boolean]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("bool", v.map(x => boolean2Boolean(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val DoubleArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Double]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Double]) { + case (b, x: scala.Double) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Double] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Double) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Double). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val DoubleArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Double]] = zio.jdbc.JdbcEncoder.singleParamEncoder(DoubleArraySetter) + implicit lazy val DoubleArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Double]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Double]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float8", v.map(x => double2Double(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val FloatArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Float]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Float]) { + case (b, x: scala.Float) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Float] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Float) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Float). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val FloatArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Float]] = zio.jdbc.JdbcEncoder.singleParamEncoder(FloatArraySetter) + implicit lazy val FloatArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Float]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Float]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float4", v.map(x => float2Float(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val IntArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Int]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Int]) { + case (b, x: scala.Int) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Int] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Int) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Int). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val IntArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Int]] = zio.jdbc.JdbcEncoder.singleParamEncoder(IntArraySetter) + implicit lazy val IntArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Int]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Int]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int4", v.map(x => int2Integer(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val LongArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Long]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Long]) { + case (b, x: scala.Long) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Long] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Long) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Long). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val LongArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Long]] = zio.jdbc.JdbcEncoder.singleParamEncoder(LongArraySetter) + implicit lazy val LongArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Long]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Long]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int8", v.map(x => long2Long(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val ScalaBigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayDecoder.map(v => if (v eq null) null else v.map(scala.math.BigDecimal.apply)) + implicit lazy val ScalaBigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayEncoder.contramap(_.map(_.bigDecimal)) + implicit lazy val ScalaBigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.math.BigDecimal]] = BigDecimalArraySetter.contramap(_.map(_.bigDecimal)) + implicit lazy val StringArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] = new zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.lang.String]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.lang.String]) { + case (b, x: java.lang.String) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.lang.String] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.lang.String) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.lang.String). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val StringArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.lang.String]] = zio.jdbc.JdbcEncoder.singleParamEncoder(StringArraySetter) + implicit lazy val StringArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.lang.String]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.lang.String]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("varchar", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala new file mode 100644 index 0000000000..de77901c73 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm212/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded + +import scala.util.Random +import testdb.hardcoded.compositepk.person.PersonRepoImpl +import testdb.hardcoded.compositepk.person.PersonRow +import testdb.hardcoded.compositepk.person.PersonRowUnsaved +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.football_club.FootballClubRepoImpl +import testdb.hardcoded.myschema.football_club.FootballClubRow +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import testdb.hardcoded.myschema.marital_status.MaritalStatusRepoImpl +import testdb.hardcoded.myschema.marital_status.MaritalStatusRow +import testdb.hardcoded.myschema.person.PersonId +import zio.ZIO +import zio.jdbc.ZConnection + +class testInsert(random: Random) { + def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersonRow] = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two)) + def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, FootballClubRow] = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name)) + def myschemaMaritalStatus(id: MaritalStatusId): ZIO[ZConnection, Throwable, MaritalStatusRow] = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id)) + def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, testdb.hardcoded.myschema.person.PersonRow] = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber)) +} \ No newline at end of file diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala new file mode 100644 index 0000000000..31783a31bb --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + + + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class one(override val value: Long) extends PersonFieldOrIdValue("one", value) + case class two(override val value: Option[String]) extends PersonFieldOrIdValue("two", value) + case class name(override val value: Option[String]) extends PersonFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala new file mode 100644 index 0000000000..566037212d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val one: IdField[Long, Row] + val two: IdField[Option[String], Row] + val name: OptField[String, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala new file mode 100644 index 0000000000..a0d088a153 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala @@ -0,0 +1,38 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `compositepk.person` */ +case class PersonId(one: Long, two: Option[String]) +object PersonId { + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight) + Right(PersonId(one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = new JsonEncoder[PersonId] { + override def unsafeEncode(a: PersonId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[Option[String]]): Ordering[PersonId] = Ordering.by(x => (x.one, x.two)) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala new file mode 100644 index 0000000000..76c558c15d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..2cbf8c554e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala @@ -0,0 +1,119 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("compositepk.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into compositepk.person("one", "two", "name") + values (${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "one", "two", "name" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.one match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""one"""", sql"${Segment.paramSegment(value: Long)(Setter.longSetter)}::int8")) + }, + unsaved.two match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""two"""", sql"${Segment.paramSegment(value: Option[String])(Setter.optionParamSetter(Setter.stringSetter))}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into compositepk.person default values + returning "one", "two", "name" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into compositepk.person($names) values ($values) returning "one", "two", "name"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "one", "two", "name" from compositepk.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "one", "two", "name" from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.one(value) => sql""""one" = ${Segment.paramSegment(value)(Setter.longSetter)}""" + case PersonFieldValue.two(value) => sql""""two" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + } + ) + sql"""select "one", "two", "name" from compositepk.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update compositepk.person + set "name" = ${Segment.paramSegment(row.name)(Setter.optionParamSetter(Setter.stringSetter))} + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" }.mkFragment(SqlFragment(", ")) + sql"""update compositepk.person + set $updates + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into compositepk.person("one", "two", "name") + values ( + ${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("one", "two") + do update set + "name" = EXCLUDED."name" + returning "one", "two", "name"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala new file mode 100644 index 0000000000..be71d1f2ec --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala @@ -0,0 +1,104 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.one(value)) => acc.filter(_.one == value) + case (acc, PersonFieldValue.two(value)) => acc.filter(_.two == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(compositeId) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(compositeId, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala new file mode 100644 index 0000000000..d447951d01 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala @@ -0,0 +1,58 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + one: Long, + two: Option[String], + name: Option[String] +){ + val compositeId: PersonId = PersonId(one, two) + } + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 2 -> + PersonRow( + one = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + two = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight && name.isRight) + Right(PersonRow(one = one.toOption.get, two = two.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](one, two, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..752c398333 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala @@ -0,0 +1,61 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `compositepk.person` which has not been persisted yet */ +case class PersonRowUnsaved( + name: Option[String], + /** Default: auto-increment */ + one: Defaulted[Long] = Defaulted.UseDefault, + /** Default: auto-increment */ + two: Defaulted[Option[String]] = Defaulted.UseDefault +) { + def toRow(oneDefault: => Long, twoDefault: => Option[String]): PersonRow = + PersonRow( + name = name, + one = one match { + case Defaulted.UseDefault => oneDefault + case Defaulted.Provided(value) => value + }, + two = two match { + case Defaulted.UseDefault => twoDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.long))) + val two = jsonObj.get("two").toRight("Missing field 'two'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.option(JsonDecoder.string)))) + if (name.isRight && one.isRight && two.isRight) + Right(PersonRowUnsaved(name = name.toOption.get, one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](name, one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""one":""") + Defaulted.jsonEncoder(JsonEncoder.long).unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + Defaulted.jsonEncoder(JsonEncoder.option(JsonEncoder.string)).unsafeEncode(a.two, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala new file mode 100644 index 0000000000..19fe394b37 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala @@ -0,0 +1,29 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val one = new IdField[Long, Row](prefix, "one", None, Some("int8"))(x => extract(x).one, (row, value) => merge(row, extract(row).copy(one = value))) + override val two = new IdField[Option[String], Row](prefix, "two", None, None)(x => extract(x).two, (row, value) => merge(row, extract(row).copy(two = value))) + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](one, two, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala new file mode 100644 index 0000000000..fd75028067 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala @@ -0,0 +1,45 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package customtypes + +import scala.util.Success +import scala.util.Try +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.JsonError +import zio.json.internal.RetractReader +import zio.json.internal.Write + + +/** + * This signals a value where if you don't provide it, postgres will generate it for you + */ +sealed trait Defaulted[+T] + +object Defaulted { + case class Provided[T](value: T) extends Defaulted[T] + case object UseDefault extends Defaulted[Nothing] + implicit def jsonDecoder[T](implicit T: JsonDecoder[T]): JsonDecoder[Defaulted[T]] = new JsonDecoder[Defaulted[T]] { + override def unsafeDecode(trace: List[JsonError], in: RetractReader): Defaulted[T] = + Try(JsonDecoder.string.unsafeDecode(trace, in)) match { + case Success("defaulted") => UseDefault + case _ => Provided(T.unsafeDecode(trace, in)) + } + } + implicit def jsonEncoder[T](implicit T: JsonEncoder[T]): JsonEncoder[Defaulted[T]] = new JsonEncoder[Defaulted[T]] { + override def unsafeEncode(a: Defaulted[T], indent: Option[Int], out: Write): Unit = + a match { + case Provided(value) => + out.write("{") + out.write("\"provided\":") + T.unsafeEncode(value, None, out) + out.write("}") + case UseDefault => out.write("\"defaulted\"") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala new file mode 100644 index 0000000000..2dfe4cfdc0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.number` + * - one + * - two + * - three + */ +sealed abstract class Number(val value: String) + +object Number { + def apply(str: String): Either[String, Number] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Number = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_one` extends Number("one") + case object `_two` extends Number("two") + case object `_three` extends Number("three") + val All: List[Number] = List(`_one`, `_two`, `_three`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Number] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Number]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Number]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Number]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Number] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Number] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Number) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Number from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Number.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Number] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Number] = JsonDecoder.string.mapOrFail(Number.apply) + implicit lazy val jsonEncoder: JsonEncoder[Number] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Number] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Number] = ParameterMetaData.instance[Number](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Number] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala new file mode 100644 index 0000000000..062e811683 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.sector` + * - PUBLIC + * - PRIVATE + * - OTHER + */ +sealed abstract class Sector(val value: String) + +object Sector { + def apply(str: String): Either[String, Sector] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Sector = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_public` extends Sector("PUBLIC") + case object `_private` extends Sector("PRIVATE") + case object `_other` extends Sector("OTHER") + val All: List[Sector] = List(`_public`, `_private`, `_other`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Sector] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Sector]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Sector]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Sector]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Sector] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Sector] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Sector) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Sector from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Sector.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Sector] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Sector] = JsonDecoder.string.mapOrFail(Sector.apply) + implicit lazy val jsonEncoder: JsonEncoder[Sector] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Sector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Sector] = ParameterMetaData.instance[Sector](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Sector] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala new file mode 100644 index 0000000000..27dd576cf2 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + + + +sealed abstract class FootballClubFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class FootballClubFieldValue[T](name: String, value: T) extends FootballClubFieldOrIdValue(name, value) + +object FootballClubFieldValue { + case class id(override val value: FootballClubId) extends FootballClubFieldOrIdValue("id", value) + case class name(override val value: /* max 100 chars */ String) extends FootballClubFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala new file mode 100644 index 0000000000..f398781245 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait FootballClubFields[Row] { + val id: IdField[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] +} +object FootballClubFields extends FootballClubStructure[FootballClubRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala new file mode 100644 index 0000000000..87907ea3ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +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 `myschema.football_club` */ +case class FootballClubId(value: Long) extends AnyVal +object FootballClubId { + implicit lazy val arraySetter: Setter[Array[FootballClubId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[FootballClubId, Long] = Bijection[FootballClubId, Long](_.value)(FootballClubId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubId] = JdbcDecoder.longDecoder.map(FootballClubId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[FootballClubId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[FootballClubId] = JsonDecoder.long.map(FootballClubId.apply) + implicit lazy val jsonEncoder: JsonEncoder[FootballClubId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[FootballClubId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[FootballClubId] = ParameterMetaData.instance[FootballClubId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[FootballClubId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala new file mode 100644 index 0000000000..90bf603cb0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait FootballClubRepo { + def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[FootballClubFields, FootballClubRow] + def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] + def select: SelectBuilder[FootballClubFields, FootballClubRow] + def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] + def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] + def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] + def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] + def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[FootballClubFields, FootballClubRow] + def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala new file mode 100644 index 0000000000..a22fe92081 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object FootballClubRepoImpl extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilder("myschema.football_club", FootballClubFields) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + sql"""insert into myschema.football_club("id", "name") + values (${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}) + returning "id", "name" + """.insertReturning(FootballClubRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderSql("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + sql"""select "id", "name" from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".query(FootballClubRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club where "id" = ANY(${Segment.paramSegment(ids)(FootballClubId.arraySetter)})""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case FootballClubFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + } + ) + sql"""select "id", "name" from myschema.football_club where $wheres""".query(FootballClubRow.jdbcDecoder).selectStream + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.football_club + set "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)} + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilder("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.football_club + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + sql"""insert into myschema.football_club("id", "name") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)} + ) + on conflict ("id") + do update set + "name" = EXCLUDED."name" + returning "id", "name"""".insertReturning(FootballClubRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala new file mode 100644 index 0000000000..e3107ad1c5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala @@ -0,0 +1,102 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class FootballClubRepoMock(map: scala.collection.mutable.Map[FootballClubId, FootballClubRow] = scala.collection.mutable.Map.empty) extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilderMock(DeleteParams.empty, FootballClubFields, map) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderMock(FootballClubFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, FootballClubFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, FootballClubFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilderMock(UpdateParams.empty, FootballClubFields, map) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, FootballClubFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala new file mode 100644 index 0000000000..9466b904d5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala @@ -0,0 +1,50 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class FootballClubRow( + id: FootballClubId, + name: /* max 100 chars */ String +) + +object FootballClubRow { + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubRow] = new JdbcDecoder[FootballClubRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, FootballClubRow) = + columIndex + 1 -> + FootballClubRow( + id = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[FootballClubRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + if (id.isRight && name.isRight) + Right(FootballClubRow(id = id.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](id, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[FootballClubRow] = new JsonEncoder[FootballClubRow] { + override def unsafeEncode(a: FootballClubRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala new file mode 100644 index 0000000000..0a1540fc26 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala @@ -0,0 +1,28 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class FootballClubStructure[Row](val prefix: Option[String], val extract: Row => FootballClubRow, val merge: (Row, FootballClubRow) => Row) + extends Relation[FootballClubFields, FootballClubRow, Row] + with FootballClubFields[Row] { outer => + + override val id = new IdField[FootballClubId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => FootballClubRow, merge: (NewRow, FootballClubRow) => NewRow): FootballClubStructure[NewRow] = + new FootballClubStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala new file mode 100644 index 0000000000..35c6ebae67 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala @@ -0,0 +1,18 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + + + +sealed abstract class MaritalStatusFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class MaritalStatusFieldValue[T](name: String, value: T) extends MaritalStatusFieldOrIdValue(name, value) + +object MaritalStatusFieldValue { + case class id(override val value: MaritalStatusId) extends MaritalStatusFieldOrIdValue("id", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala new file mode 100644 index 0000000000..614cb66ff6 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala @@ -0,0 +1,17 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.IdField + +trait MaritalStatusFields[Row] { + val id: IdField[MaritalStatusId, Row] +} +object MaritalStatusFields extends MaritalStatusStructure[MaritalStatusRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala new file mode 100644 index 0000000000..7495cac342 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +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 `myschema.marital_status` */ +case class MaritalStatusId(value: Long) extends AnyVal +object MaritalStatusId { + implicit lazy val arraySetter: Setter[Array[MaritalStatusId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[MaritalStatusId, Long] = Bijection[MaritalStatusId, Long](_.value)(MaritalStatusId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusId] = JdbcDecoder.longDecoder.map(MaritalStatusId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[MaritalStatusId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusId] = JsonDecoder.long.map(MaritalStatusId.apply) + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[MaritalStatusId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[MaritalStatusId] = ParameterMetaData.instance[MaritalStatusId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[MaritalStatusId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala new file mode 100644 index 0000000000..b559a3fd93 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala @@ -0,0 +1,30 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait MaritalStatusRepo { + def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] + def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] + def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] + def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] + def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] + def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala new file mode 100644 index 0000000000..518d1399b1 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala @@ -0,0 +1,72 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object MaritalStatusRepoImpl extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilder("myschema.marital_status", MaritalStatusFields) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + sql"""insert into myschema.marital_status("id") + values (${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8) + returning "id" + """.insertReturning(MaritalStatusRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderSql("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + sql"""select "id" from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".query(MaritalStatusRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status where "id" = ANY(${Segment.paramSegment(ids)(MaritalStatusId.arraySetter)})""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case MaritalStatusFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + } + ) + sql"""select "id" from myschema.marital_status where $wheres""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilder("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + sql"""insert into myschema.marital_status("id") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8 + ) + on conflict ("id") + returning "id"""".insertReturning(MaritalStatusRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala new file mode 100644 index 0000000000..529a6f848b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class MaritalStatusRepoMock(map: scala.collection.mutable.Map[MaritalStatusId, MaritalStatusRow] = scala.collection.mutable.Map.empty) extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilderMock(DeleteParams.empty, MaritalStatusFields, map) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderMock(MaritalStatusFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, MaritalStatusFieldValue.id(value)) => acc.filter(_.id == value) + } + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilderMock(UpdateParams.empty, MaritalStatusFields, map) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala new file mode 100644 index 0000000000..1859f9c436 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala @@ -0,0 +1,37 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class MaritalStatusRow( + id: MaritalStatusId +) + +object MaritalStatusRow { + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusRow] = MaritalStatusId.jdbcDecoder.map(v => MaritalStatusRow(id = v)) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + if (id.isRight) + Right(MaritalStatusRow(id = id.toOption.get)) + else Left(List[Either[String, Any]](id).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusRow] = new JsonEncoder[MaritalStatusRow] { + override def unsafeEncode(a: MaritalStatusRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala new file mode 100644 index 0000000000..eeca5f848e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala @@ -0,0 +1,26 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class MaritalStatusStructure[Row](val prefix: Option[String], val extract: Row => MaritalStatusRow, val merge: (Row, MaritalStatusRow) => Row) + extends Relation[MaritalStatusFields, MaritalStatusRow, Row] + with MaritalStatusFields[Row] { outer => + + override val id = new IdField[MaritalStatusId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => MaritalStatusRow, merge: (NewRow, MaritalStatusRow) => NewRow): MaritalStatusStructure[NewRow] = + new MaritalStatusStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala new file mode 100644 index 0000000000..9b131a996b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class id(override val value: PersonId) extends PersonFieldOrIdValue("id", value) + case class favouriteFootballClubId(override val value: FootballClubId) extends PersonFieldValue("favourite_football_club_id", value) + case class name(override val value: /* max 100 chars */ String) extends PersonFieldValue("name", value) + case class nickName(override val value: Option[/* max 30 chars */ String]) extends PersonFieldValue("nick_name", value) + case class blogUrl(override val value: Option[/* max 100 chars */ String]) extends PersonFieldValue("blog_url", value) + case class email(override val value: /* max 254 chars */ String) extends PersonFieldValue("email", value) + case class phone(override val value: /* max 8 chars */ String) extends PersonFieldValue("phone", value) + case class likesPizza(override val value: Boolean) extends PersonFieldValue("likes_pizza", value) + case class maritalStatusId(override val value: MaritalStatusId) extends PersonFieldValue("marital_status_id", value) + case class workEmail(override val value: Option[/* max 254 chars */ String]) extends PersonFieldValue("work_email", value) + case class sector(override val value: Sector) extends PersonFieldValue("sector", value) + case class favoriteNumber(override val value: Number) extends PersonFieldValue("favorite_number", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala new file mode 100644 index 0000000000..29b9ae44ab --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala @@ -0,0 +1,34 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val id: IdField[PersonId, Row] + val favouriteFootballClubId: Field[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] + val nickName: OptField[/* max 30 chars */ String, Row] + val blogUrl: OptField[/* max 100 chars */ String, Row] + val email: Field[/* max 254 chars */ String, Row] + val phone: Field[/* max 8 chars */ String, Row] + val likesPizza: Field[Boolean, Row] + val maritalStatusId: Field[MaritalStatusId, Row] + val workEmail: OptField[/* max 254 chars */ String, Row] + val sector: Field[Sector, Row] + val favoriteNumber: Field[Number, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala new file mode 100644 index 0000000000..1f701b7740 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +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 `myschema.person` */ +case class PersonId(value: Long) extends AnyVal +object PersonId { + implicit lazy val arraySetter: Setter[Array[PersonId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PersonId, Long] = Bijection[PersonId, Long](_.value)(PersonId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PersonId] = JdbcDecoder.longDecoder.map(PersonId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PersonId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder.long.map(PersonId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PersonId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PersonId] = ParameterMetaData.instance[PersonId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PersonId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala new file mode 100644 index 0000000000..a7317acdde --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala @@ -0,0 +1,33 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..ad588b5827 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala @@ -0,0 +1,189 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("myschema.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values (${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number) + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""favourite_football_club_id"""", sql"${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}")), + Some((sql""""nick_name"""", sql"${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""blog_url"""", sql"${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""email"""", sql"${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}")), + Some((sql""""phone"""", sql"${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}")), + Some((sql""""likes_pizza"""", sql"${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}")), + Some((sql""""work_email"""", sql"${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.id match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""id"""", sql"${Segment.paramSegment(value: PersonId)(Setter[PersonId])}::int8")) + }, + unsaved.maritalStatusId match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""marital_status_id"""", sql"${Segment.paramSegment(value: MaritalStatusId)(Setter[MaritalStatusId])}")) + }, + unsaved.sector match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""sector"""", sql"${Segment.paramSegment(value: Sector)(Setter[Sector])}::myschema.sector")) + }, + unsaved.favoriteNumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""favorite_number"""", sql"${Segment.paramSegment(value: Number)(Setter[Number])}::myschema.number")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into myschema.person default values + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into myschema.person($names) values ($values) returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ANY(${Segment.paramSegment(ids)(PersonId.arraySetter)})""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[PersonId])}""" + case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}""" + } + ) + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.person + set "favourite_football_club_id" = ${Segment.paramSegment(row.favouriteFootballClubId)(Setter[FootballClubId])}, + "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)}, + "nick_name" = ${Segment.paramSegment(row.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + "blog_url" = ${Segment.paramSegment(row.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + "email" = ${Segment.paramSegment(row.email)(Setter.stringSetter)}, + "phone" = ${Segment.paramSegment(row.phone)(Setter.stringSetter)}, + "likes_pizza" = ${Segment.paramSegment(row.likesPizza)(Setter.booleanSetter)}, + "marital_status_id" = ${Segment.paramSegment(row.maritalStatusId)(Setter[MaritalStatusId])}, + "work_email" = ${Segment.paramSegment(row.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + "sector" = ${Segment.paramSegment(row.sector)(Setter[Sector])}::myschema.sector, + "favorite_number" = ${Segment.paramSegment(row.favoriteNumber)(Setter[Number])}::myschema.number + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}::myschema.sector""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}::myschema.number""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.person + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, + ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, + ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, + ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number + ) + on conflict ("id") + do update set + "favourite_football_club_id" = EXCLUDED."favourite_football_club_id", + "name" = EXCLUDED."name", + "nick_name" = EXCLUDED."nick_name", + "blog_url" = EXCLUDED."blog_url", + "email" = EXCLUDED."email", + "phone" = EXCLUDED."phone", + "likes_pizza" = EXCLUDED."likes_pizza", + "marital_status_id" = EXCLUDED."marital_status_id", + "work_email" = EXCLUDED."work_email", + "sector" = EXCLUDED."sector", + "favorite_number" = EXCLUDED."favorite_number" + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala new file mode 100644 index 0000000000..e11c0937ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala @@ -0,0 +1,126 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.filter(_.favouriteFootballClubId == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + case (acc, PersonFieldValue.nickName(value)) => acc.filter(_.nickName == value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.filter(_.blogUrl == value) + case (acc, PersonFieldValue.email(value)) => acc.filter(_.email == value) + case (acc, PersonFieldValue.phone(value)) => acc.filter(_.phone == value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.filter(_.likesPizza == value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.filter(_.maritalStatusId == value) + case (acc, PersonFieldValue.workEmail(value)) => acc.filter(_.workEmail == value) + case (acc, PersonFieldValue.sector(value)) => acc.filter(_.sector == value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.filter(_.favoriteNumber == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.copy(favouriteFootballClubId = value) + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + case (acc, PersonFieldValue.nickName(value)) => acc.copy(nickName = value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.copy(blogUrl = value) + case (acc, PersonFieldValue.email(value)) => acc.copy(email = value) + case (acc, PersonFieldValue.phone(value)) => acc.copy(phone = value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.copy(likesPizza = value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.copy(maritalStatusId = value) + case (acc, PersonFieldValue.workEmail(value)) => acc.copy(workEmail = value) + case (acc, PersonFieldValue.sector(value)) => acc.copy(sector = value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.copy(favoriteNumber = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala new file mode 100644 index 0000000000..4321795ca7 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala @@ -0,0 +1,116 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import java.sql.ResultSet +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + id: PersonId, + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + /** Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: MaritalStatusId, + workEmail: Option[/* max 254 chars */ String], + sector: Sector, + favoriteNumber: Number +) + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 11 -> + PersonRow( + id = PersonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + favouriteFootballClubId = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + nickName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + blogUrl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + email = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + phone = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + likesPizza = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + maritalStatusId = MaritalStatusId.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + workEmail = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + sector = Sector.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + favoriteNumber = Number.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(PersonId.jsonDecoder)) + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Sector.jsonDecoder)) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Number.jsonDecoder)) + if (id.isRight && favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && maritalStatusId.isRight && workEmail.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRow(id = id.toOption.get, favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, maritalStatusId = maritalStatusId.toOption.get, workEmail = workEmail.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + PersonId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""sector":""") + Sector.jsonEncoder.unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Number.jsonEncoder.unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..47897e8d14 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala @@ -0,0 +1,129 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `myschema.person` which has not been persisted yet */ +case class PersonRowUnsaved( + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + workEmail: Option[/* max 254 chars */ String], + /** Default: auto-increment */ + id: Defaulted[PersonId] = Defaulted.UseDefault, + /** Default: some-value + Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, + /** Default: PUBLIC */ + sector: Defaulted[Sector] = Defaulted.UseDefault, + /** Default: one */ + favoriteNumber: Defaulted[Number] = Defaulted.UseDefault +) { + def toRow(idDefault: => PersonId, maritalStatusIdDefault: => MaritalStatusId, sectorDefault: => Sector, favoriteNumberDefault: => Number): PersonRow = + PersonRow( + favouriteFootballClubId = favouriteFootballClubId, + name = name, + nickName = nickName, + blogUrl = blogUrl, + email = email, + phone = phone, + likesPizza = likesPizza, + workEmail = workEmail, + id = id match { + case Defaulted.UseDefault => idDefault + case Defaulted.Provided(value) => value + }, + maritalStatusId = maritalStatusId match { + case Defaulted.UseDefault => maritalStatusIdDefault + case Defaulted.Provided(value) => value + }, + sector = sector match { + case Defaulted.UseDefault => sectorDefault + case Defaulted.Provided(value) => value + }, + favoriteNumber = favoriteNumber match { + case Defaulted.UseDefault => favoriteNumberDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(Defaulted.jsonDecoder(PersonId.jsonDecoder))) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(Defaulted.jsonDecoder(MaritalStatusId.jsonDecoder))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Defaulted.jsonDecoder(Sector.jsonDecoder))) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Defaulted.jsonDecoder(Number.jsonDecoder))) + if (favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && workEmail.isRight && id.isRight && maritalStatusId.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, workEmail = workEmail.toOption.get, id = id.toOption.get, maritalStatusId = maritalStatusId.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, workEmail, id, maritalStatusId, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""id":""") + Defaulted.jsonEncoder(PersonId.jsonEncoder).unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + Defaulted.jsonEncoder(MaritalStatusId.jsonEncoder).unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""sector":""") + Defaulted.jsonEncoder(Sector.jsonEncoder).unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Defaulted.jsonEncoder(Number.jsonEncoder).unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala new file mode 100644 index 0000000000..1886c54182 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala @@ -0,0 +1,43 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val id = new IdField[PersonId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val favouriteFootballClubId = new Field[FootballClubId, Row](prefix, "favourite_football_club_id", None, None)(x => extract(x).favouriteFootballClubId, (row, value) => merge(row, extract(row).copy(favouriteFootballClubId = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val nickName = new OptField[/* max 30 chars */ String, Row](prefix, "nick_name", None, None)(x => extract(x).nickName, (row, value) => merge(row, extract(row).copy(nickName = value))) + override val blogUrl = new OptField[/* max 100 chars */ String, Row](prefix, "blog_url", None, None)(x => extract(x).blogUrl, (row, value) => merge(row, extract(row).copy(blogUrl = value))) + override val email = new Field[/* max 254 chars */ String, Row](prefix, "email", None, None)(x => extract(x).email, (row, value) => merge(row, extract(row).copy(email = value))) + override val phone = new Field[/* max 8 chars */ String, Row](prefix, "phone", None, None)(x => extract(x).phone, (row, value) => merge(row, extract(row).copy(phone = value))) + override val likesPizza = new Field[Boolean, Row](prefix, "likes_pizza", None, None)(x => extract(x).likesPizza, (row, value) => merge(row, extract(row).copy(likesPizza = value))) + override val maritalStatusId = new Field[MaritalStatusId, Row](prefix, "marital_status_id", None, None)(x => extract(x).maritalStatusId, (row, value) => merge(row, extract(row).copy(maritalStatusId = value))) + override val workEmail = new OptField[/* max 254 chars */ String, Row](prefix, "work_email", None, None)(x => extract(x).workEmail, (row, value) => merge(row, extract(row).copy(workEmail = value))) + override val sector = new Field[Sector, Row](prefix, "sector", None, Some("myschema.sector"))(x => extract(x).sector, (row, value) => merge(row, extract(row).copy(sector = value))) + override val favoriteNumber = new Field[Number, Row](prefix, "favorite_number", None, Some("myschema.number"))(x => extract(x).favoriteNumber, (row, value) => merge(row, extract(row).copy(favoriteNumber = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala new file mode 100644 index 0000000000..c8ffbefab4 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala @@ -0,0 +1,243 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb + +package object hardcoded { + implicit lazy val BigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] = new zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.math.BigDecimal]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.math.BigDecimal]) { + case (b, x: java.math.BigDecimal) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.math.BigDecimal] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.math.BigDecimal) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.math.BigDecimal). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.math.BigDecimal]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BigDecimalArraySetter) + implicit lazy val BigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.math.BigDecimal]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.math.BigDecimal]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("numeric", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val BooleanArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Boolean]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Boolean]) { + case (b, x: scala.Boolean) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Boolean] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Boolean) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Boolean). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BooleanArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Boolean]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BooleanArraySetter) + implicit lazy val BooleanArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Boolean]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Boolean]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("bool", v.map(x => boolean2Boolean(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val DoubleArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Double]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Double]) { + case (b, x: scala.Double) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Double] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Double) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Double). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val DoubleArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Double]] = zio.jdbc.JdbcEncoder.singleParamEncoder(DoubleArraySetter) + implicit lazy val DoubleArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Double]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Double]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float8", v.map(x => double2Double(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val FloatArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Float]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Float]) { + case (b, x: scala.Float) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Float] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Float) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Float). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val FloatArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Float]] = zio.jdbc.JdbcEncoder.singleParamEncoder(FloatArraySetter) + implicit lazy val FloatArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Float]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Float]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float4", v.map(x => float2Float(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val IntArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Int]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Int]) { + case (b, x: scala.Int) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Int] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Int) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Int). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val IntArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Int]] = zio.jdbc.JdbcEncoder.singleParamEncoder(IntArraySetter) + implicit lazy val IntArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Int]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Int]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int4", v.map(x => int2Integer(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val LongArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Long]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Long]) { + case (b, x: scala.Long) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Long] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Long) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Long). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val LongArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Long]] = zio.jdbc.JdbcEncoder.singleParamEncoder(LongArraySetter) + implicit lazy val LongArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Long]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Long]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int8", v.map(x => long2Long(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val ScalaBigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayDecoder.map(v => if (v eq null) null else v.map(scala.math.BigDecimal.apply)) + implicit lazy val ScalaBigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayEncoder.contramap(_.map(_.bigDecimal)) + implicit lazy val ScalaBigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.math.BigDecimal]] = BigDecimalArraySetter.contramap(_.map(_.bigDecimal)) + implicit lazy val StringArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] = new zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.lang.String]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.lang.String]) { + case (b, x: java.lang.String) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.lang.String] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.lang.String) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.lang.String). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val StringArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.lang.String]] = zio.jdbc.JdbcEncoder.singleParamEncoder(StringArraySetter) + implicit lazy val StringArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.lang.String]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.lang.String]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("varchar", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala new file mode 100644 index 0000000000..de77901c73 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm213/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded + +import scala.util.Random +import testdb.hardcoded.compositepk.person.PersonRepoImpl +import testdb.hardcoded.compositepk.person.PersonRow +import testdb.hardcoded.compositepk.person.PersonRowUnsaved +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.football_club.FootballClubRepoImpl +import testdb.hardcoded.myschema.football_club.FootballClubRow +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import testdb.hardcoded.myschema.marital_status.MaritalStatusRepoImpl +import testdb.hardcoded.myschema.marital_status.MaritalStatusRow +import testdb.hardcoded.myschema.person.PersonId +import zio.ZIO +import zio.jdbc.ZConnection + +class testInsert(random: Random) { + def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersonRow] = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two)) + def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, FootballClubRow] = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name)) + def myschemaMaritalStatus(id: MaritalStatusId): ZIO[ZConnection, Throwable, MaritalStatusRow] = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id)) + def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, testdb.hardcoded.myschema.person.PersonRow] = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber)) +} \ No newline at end of file diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala new file mode 100644 index 0000000000..31783a31bb --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFieldValue.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + + + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class one(override val value: Long) extends PersonFieldOrIdValue("one", value) + case class two(override val value: Option[String]) extends PersonFieldOrIdValue("two", value) + case class name(override val value: Option[String]) extends PersonFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala new file mode 100644 index 0000000000..566037212d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonFields.scala @@ -0,0 +1,20 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val one: IdField[Long, Row] + val two: IdField[Option[String], Row] + val name: OptField[String, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala new file mode 100644 index 0000000000..a0d088a153 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonId.scala @@ -0,0 +1,38 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `compositepk.person` */ +case class PersonId(one: Long, two: Option[String]) +object PersonId { + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight) + Right(PersonId(one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = new JsonEncoder[PersonId] { + override def unsafeEncode(a: PersonId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[Option[String]]): Ordering[PersonId] = Ordering.by(x => (x.one, x.two)) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala new file mode 100644 index 0000000000..76c558c15d --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..2cbf8c554e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoImpl.scala @@ -0,0 +1,119 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("compositepk.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into compositepk.person("one", "two", "name") + values (${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "one", "two", "name" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.one match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""one"""", sql"${Segment.paramSegment(value: Long)(Setter.longSetter)}::int8")) + }, + unsaved.two match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""two"""", sql"${Segment.paramSegment(value: Option[String])(Setter.optionParamSetter(Setter.stringSetter))}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into compositepk.person default values + returning "one", "two", "name" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into compositepk.person($names) values ($values) returning "one", "two", "name"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "one", "two", "name" from compositepk.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "one", "two", "name" from compositepk.person where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.one(value) => sql""""one" = ${Segment.paramSegment(value)(Setter.longSetter)}""" + case PersonFieldValue.two(value) => sql""""two" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + } + ) + sql"""select "one", "two", "name" from compositepk.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update compositepk.person + set "name" = ${Segment.paramSegment(row.name)(Setter.optionParamSetter(Setter.stringSetter))} + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("compositepk.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" }.mkFragment(SqlFragment(", ")) + sql"""update compositepk.person + set $updates + where "one" = ${Segment.paramSegment(compositeId.one)(Setter.longSetter)} AND "two" = ${Segment.paramSegment(compositeId.two)(Setter.optionParamSetter(Setter.stringSetter))} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into compositepk.person("one", "two", "name") + values ( + ${Segment.paramSegment(unsaved.one)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.two)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("one", "two") + do update set + "name" = EXCLUDED."name" + returning "one", "two", "name"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala new file mode 100644 index 0000000000..be71d1f2ec --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRepoMock.scala @@ -0,0 +1,104 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(compositeId: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.one(value)) => acc.filter(_.one == value) + case (acc, PersonFieldValue.two(value)) => acc.filter(_.two == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(compositeId: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(compositeId) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(compositeId, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala new file mode 100644 index 0000000000..d447951d01 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRow.scala @@ -0,0 +1,58 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + one: Long, + two: Option[String], + name: Option[String] +){ + val compositeId: PersonId = PersonId(one, two) + } + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 2 -> + PersonRow( + one = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + two = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(JsonDecoder.long)) + val two = jsonObj.get("two").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (one.isRight && two.isRight && name.isRight) + Right(PersonRow(one = one.toOption.get, two = two.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](one, two, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""one":""") + JsonEncoder.long.unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.two, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..752c398333 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonRowUnsaved.scala @@ -0,0 +1,61 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import testdb.hardcoded.customtypes.Defaulted +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `compositepk.person` which has not been persisted yet */ +case class PersonRowUnsaved( + name: Option[String], + /** Default: auto-increment */ + one: Defaulted[Long] = Defaulted.UseDefault, + /** Default: auto-increment */ + two: Defaulted[Option[String]] = Defaulted.UseDefault +) { + def toRow(oneDefault: => Long, twoDefault: => Option[String]): PersonRow = + PersonRow( + name = name, + one = one match { + case Defaulted.UseDefault => oneDefault + case Defaulted.Provided(value) => value + }, + two = two match { + case Defaulted.UseDefault => twoDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val one = jsonObj.get("one").toRight("Missing field 'one'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.long))) + val two = jsonObj.get("two").toRight("Missing field 'two'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.option(JsonDecoder.string)))) + if (name.isRight && one.isRight && two.isRight) + Right(PersonRowUnsaved(name = name.toOption.get, one = one.toOption.get, two = two.toOption.get)) + else Left(List[Either[String, Any]](name, one, two).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""one":""") + Defaulted.jsonEncoder(JsonEncoder.long).unsafeEncode(a.one, indent, out) + out.write(",") + out.write(""""two":""") + Defaulted.jsonEncoder(JsonEncoder.option(JsonEncoder.string)).unsafeEncode(a.two, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala new file mode 100644 index 0000000000..19fe394b37 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/compositepk/person/PersonStructure.scala @@ -0,0 +1,29 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package compositepk +package person + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val one = new IdField[Long, Row](prefix, "one", None, Some("int8"))(x => extract(x).one, (row, value) => merge(row, extract(row).copy(one = value))) + override val two = new IdField[Option[String], Row](prefix, "two", None, None)(x => extract(x).two, (row, value) => merge(row, extract(row).copy(two = value))) + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](one, two, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala new file mode 100644 index 0000000000..fd75028067 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/customtypes/Defaulted.scala @@ -0,0 +1,45 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package customtypes + +import scala.util.Success +import scala.util.Try +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.JsonError +import zio.json.internal.RetractReader +import zio.json.internal.Write + + +/** + * This signals a value where if you don't provide it, postgres will generate it for you + */ +sealed trait Defaulted[+T] + +object Defaulted { + case class Provided[T](value: T) extends Defaulted[T] + case object UseDefault extends Defaulted[Nothing] + implicit def jsonDecoder[T](implicit T: JsonDecoder[T]): JsonDecoder[Defaulted[T]] = new JsonDecoder[Defaulted[T]] { + override def unsafeDecode(trace: List[JsonError], in: RetractReader): Defaulted[T] = + Try(JsonDecoder.string.unsafeDecode(trace, in)) match { + case Success("defaulted") => UseDefault + case _ => Provided(T.unsafeDecode(trace, in)) + } + } + implicit def jsonEncoder[T](implicit T: JsonEncoder[T]): JsonEncoder[Defaulted[T]] = new JsonEncoder[Defaulted[T]] { + override def unsafeEncode(a: Defaulted[T], indent: Option[Int], out: Write): Unit = + a match { + case Provided(value) => + out.write("{") + out.write("\"provided\":") + T.unsafeEncode(value, None, out) + out.write("}") + case UseDefault => out.write("\"defaulted\"") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala new file mode 100644 index 0000000000..2dfe4cfdc0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Number.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.number` + * - one + * - two + * - three + */ +sealed abstract class Number(val value: String) + +object Number { + def apply(str: String): Either[String, Number] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Number = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_one` extends Number("one") + case object `_two` extends Number("two") + case object `_three` extends Number("three") + val All: List[Number] = List(`_one`, `_two`, `_three`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Number] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Number]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Number]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Number]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Number] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Number] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Number) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Number from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Number.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Number] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Number] = JsonDecoder.string.mapOrFail(Number.apply) + implicit lazy val jsonEncoder: JsonEncoder[Number] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Number] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Number] = ParameterMetaData.instance[Number](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Number] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala new file mode 100644 index 0000000000..062e811683 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/Sector.scala @@ -0,0 +1,65 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `myschema.sector` + * - PUBLIC + * - PRIVATE + * - OTHER + */ +sealed abstract class Sector(val value: String) + +object Sector { + def apply(str: String): Either[String, Sector] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Sector = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object `_public` extends Sector("PUBLIC") + case object `_private` extends Sector("PRIVATE") + case object `_other` extends Sector("OTHER") + val All: List[Sector] = List(`_public`, `_private`, `_other`) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Sector] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Sector]] = testdb.hardcoded.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Sector]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Sector]] = testdb.hardcoded.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Sector] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Sector] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Sector) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Sector from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Sector.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Sector] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Sector] = JsonDecoder.string.mapOrFail(Sector.apply) + implicit lazy val jsonEncoder: JsonEncoder[Sector] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Sector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Sector] = ParameterMetaData.instance[Sector](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Sector] = Setter.stringSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala new file mode 100644 index 0000000000..27dd576cf2 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFieldValue.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + + + +sealed abstract class FootballClubFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class FootballClubFieldValue[T](name: String, value: T) extends FootballClubFieldOrIdValue(name, value) + +object FootballClubFieldValue { + case class id(override val value: FootballClubId) extends FootballClubFieldOrIdValue("id", value) + case class name(override val value: /* max 100 chars */ String) extends FootballClubFieldValue("name", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala new file mode 100644 index 0000000000..f398781245 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubFields.scala @@ -0,0 +1,19 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait FootballClubFields[Row] { + val id: IdField[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] +} +object FootballClubFields extends FootballClubStructure[FootballClubRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala new file mode 100644 index 0000000000..87907ea3ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +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 `myschema.football_club` */ +case class FootballClubId(value: Long) extends AnyVal +object FootballClubId { + implicit lazy val arraySetter: Setter[Array[FootballClubId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[FootballClubId, Long] = Bijection[FootballClubId, Long](_.value)(FootballClubId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubId] = JdbcDecoder.longDecoder.map(FootballClubId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[FootballClubId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[FootballClubId] = JsonDecoder.long.map(FootballClubId.apply) + implicit lazy val jsonEncoder: JsonEncoder[FootballClubId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[FootballClubId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[FootballClubId] = ParameterMetaData.instance[FootballClubId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[FootballClubId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala new file mode 100644 index 0000000000..90bf603cb0 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepo.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait FootballClubRepo { + def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[FootballClubFields, FootballClubRow] + def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] + def select: SelectBuilder[FootballClubFields, FootballClubRow] + def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] + def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] + def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] + def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] + def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[FootballClubFields, FootballClubRow] + def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala new file mode 100644 index 0000000000..a22fe92081 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object FootballClubRepoImpl extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilder("myschema.football_club", FootballClubFields) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + sql"""insert into myschema.football_club("id", "name") + values (${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}) + returning "id", "name" + """.insertReturning(FootballClubRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderSql("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + sql"""select "id", "name" from myschema.football_club where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".query(FootballClubRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + sql"""select "id", "name" from myschema.football_club where "id" = ANY(${Segment.paramSegment(ids)(FootballClubId.arraySetter)})""".query(FootballClubRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case FootballClubFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + } + ) + sql"""select "id", "name" from myschema.football_club where $wheres""".query(FootballClubRow.jdbcDecoder).selectStream + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.football_club + set "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)} + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilder("myschema.football_club", FootballClubFields, FootballClubRow.jdbcDecoder) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case FootballClubFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.football_club + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[FootballClubId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + sql"""insert into myschema.football_club("id", "name") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[FootballClubId])}::int8, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)} + ) + on conflict ("id") + do update set + "name" = EXCLUDED."name" + returning "id", "name"""".insertReturning(FootballClubRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala new file mode 100644 index 0000000000..e3107ad1c5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRepoMock.scala @@ -0,0 +1,102 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class FootballClubRepoMock(map: scala.collection.mutable.Map[FootballClubId, FootballClubRow] = scala.collection.mutable.Map.empty) extends FootballClubRepo { + override def delete(id: FootballClubId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[FootballClubFields, FootballClubRow] = { + DeleteBuilderMock(DeleteParams.empty, FootballClubFields, map) + } + override def insert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, FootballClubRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[FootballClubFields, FootballClubRow] = { + SelectBuilderMock(FootballClubFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: FootballClubId): ZIO[ZConnection, Throwable, Option[FootballClubRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[FootballClubId]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[FootballClubFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, FootballClubRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, FootballClubFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, FootballClubFieldValue.name(value)) => acc.filter(_.name == value) + } + } + } + override def update(row: FootballClubRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[FootballClubFields, FootballClubRow] = { + UpdateBuilderMock(UpdateParams.empty, FootballClubFields, map) + } + override def updateFieldValues(id: FootballClubId, fieldValues: List[FootballClubFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, FootballClubFieldValue.name(value)) => acc.copy(name = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: FootballClubRow): ZIO[ZConnection, Throwable, UpdateResult[FootballClubRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala new file mode 100644 index 0000000000..9466b904d5 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubRow.scala @@ -0,0 +1,50 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class FootballClubRow( + id: FootballClubId, + name: /* max 100 chars */ String +) + +object FootballClubRow { + implicit lazy val jdbcDecoder: JdbcDecoder[FootballClubRow] = new JdbcDecoder[FootballClubRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, FootballClubRow) = + columIndex + 1 -> + FootballClubRow( + id = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[FootballClubRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + if (id.isRight && name.isRight) + Right(FootballClubRow(id = id.toOption.get, name = name.toOption.get)) + else Left(List[Either[String, Any]](id, name).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[FootballClubRow] = new JsonEncoder[FootballClubRow] { + override def unsafeEncode(a: FootballClubRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala new file mode 100644 index 0000000000..0a1540fc26 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/football_club/FootballClubStructure.scala @@ -0,0 +1,28 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package football_club + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class FootballClubStructure[Row](val prefix: Option[String], val extract: Row => FootballClubRow, val merge: (Row, FootballClubRow) => Row) + extends Relation[FootballClubFields, FootballClubRow, Row] + with FootballClubFields[Row] { outer => + + override val id = new IdField[FootballClubId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, name) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => FootballClubRow, merge: (NewRow, FootballClubRow) => NewRow): FootballClubStructure[NewRow] = + new FootballClubStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala new file mode 100644 index 0000000000..35c6ebae67 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFieldValue.scala @@ -0,0 +1,18 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + + + +sealed abstract class MaritalStatusFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class MaritalStatusFieldValue[T](name: String, value: T) extends MaritalStatusFieldOrIdValue(name, value) + +object MaritalStatusFieldValue { + case class id(override val value: MaritalStatusId) extends MaritalStatusFieldOrIdValue("id", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala new file mode 100644 index 0000000000..614cb66ff6 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusFields.scala @@ -0,0 +1,17 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.IdField + +trait MaritalStatusFields[Row] { + val id: IdField[MaritalStatusId, Row] +} +object MaritalStatusFields extends MaritalStatusStructure[MaritalStatusRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala new file mode 100644 index 0000000000..7495cac342 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +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 `myschema.marital_status` */ +case class MaritalStatusId(value: Long) extends AnyVal +object MaritalStatusId { + implicit lazy val arraySetter: Setter[Array[MaritalStatusId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[MaritalStatusId, Long] = Bijection[MaritalStatusId, Long](_.value)(MaritalStatusId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusId] = JdbcDecoder.longDecoder.map(MaritalStatusId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[MaritalStatusId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusId] = JsonDecoder.long.map(MaritalStatusId.apply) + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[MaritalStatusId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[MaritalStatusId] = ParameterMetaData.instance[MaritalStatusId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[MaritalStatusId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala new file mode 100644 index 0000000000..b559a3fd93 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepo.scala @@ -0,0 +1,30 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait MaritalStatusRepo { + def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] + def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] + def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] + def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] + def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] + def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] + def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala new file mode 100644 index 0000000000..518d1399b1 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoImpl.scala @@ -0,0 +1,72 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object MaritalStatusRepoImpl extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilder("myschema.marital_status", MaritalStatusFields) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + sql"""insert into myschema.marital_status("id") + values (${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8) + returning "id" + """.insertReturning(MaritalStatusRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderSql("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + sql"""select "id" from myschema.marital_status where "id" = ${Segment.paramSegment(id)(Setter[MaritalStatusId])}""".query(MaritalStatusRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + sql"""select "id" from myschema.marital_status where "id" = ANY(${Segment.paramSegment(ids)(MaritalStatusId.arraySetter)})""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case MaritalStatusFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + } + ) + sql"""select "id" from myschema.marital_status where $wheres""".query(MaritalStatusRow.jdbcDecoder).selectStream + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilder("myschema.marital_status", MaritalStatusFields, MaritalStatusRow.jdbcDecoder) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + sql"""insert into myschema.marital_status("id") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[MaritalStatusId])}::int8 + ) + on conflict ("id") + returning "id"""".insertReturning(MaritalStatusRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala new file mode 100644 index 0000000000..529a6f848b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class MaritalStatusRepoMock(map: scala.collection.mutable.Map[MaritalStatusId, MaritalStatusRow] = scala.collection.mutable.Map.empty) extends MaritalStatusRepo { + override def delete(id: MaritalStatusId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[MaritalStatusFields, MaritalStatusRow] = { + DeleteBuilderMock(DeleteParams.empty, MaritalStatusFields, map) + } + override def insert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, MaritalStatusRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def select: SelectBuilder[MaritalStatusFields, MaritalStatusRow] = { + SelectBuilderMock(MaritalStatusFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: MaritalStatusId): ZIO[ZConnection, Throwable, Option[MaritalStatusRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[MaritalStatusId]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[MaritalStatusFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, MaritalStatusRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, MaritalStatusFieldValue.id(value)) => acc.filter(_.id == value) + } + } + } + override def update: UpdateBuilder[MaritalStatusFields, MaritalStatusRow] = { + UpdateBuilderMock(UpdateParams.empty, MaritalStatusFields, map) + } + override def upsert(unsaved: MaritalStatusRow): ZIO[ZConnection, Throwable, UpdateResult[MaritalStatusRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala new file mode 100644 index 0000000000..1859f9c436 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusRow.scala @@ -0,0 +1,37 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class MaritalStatusRow( + id: MaritalStatusId +) + +object MaritalStatusRow { + implicit lazy val jdbcDecoder: JdbcDecoder[MaritalStatusRow] = MaritalStatusId.jdbcDecoder.map(v => MaritalStatusRow(id = v)) + implicit lazy val jsonDecoder: JsonDecoder[MaritalStatusRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + if (id.isRight) + Right(MaritalStatusRow(id = id.toOption.get)) + else Left(List[Either[String, Any]](id).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[MaritalStatusRow] = new JsonEncoder[MaritalStatusRow] { + override def unsafeEncode(a: MaritalStatusRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala new file mode 100644 index 0000000000..eeca5f848e --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/marital_status/MaritalStatusStructure.scala @@ -0,0 +1,26 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package marital_status + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class MaritalStatusStructure[Row](val prefix: Option[String], val extract: Row => MaritalStatusRow, val merge: (Row, MaritalStatusRow) => Row) + extends Relation[MaritalStatusFields, MaritalStatusRow, Row] + with MaritalStatusFields[Row] { outer => + + override val id = new IdField[MaritalStatusId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => MaritalStatusRow, merge: (NewRow, MaritalStatusRow) => NewRow): MaritalStatusStructure[NewRow] = + new MaritalStatusStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala new file mode 100644 index 0000000000..9b131a996b --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFieldValue.scala @@ -0,0 +1,32 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId + +sealed abstract class PersonFieldOrIdValue[T](val name: String, val value: T) +sealed abstract class PersonFieldValue[T](name: String, value: T) extends PersonFieldOrIdValue(name, value) + +object PersonFieldValue { + case class id(override val value: PersonId) extends PersonFieldOrIdValue("id", value) + case class favouriteFootballClubId(override val value: FootballClubId) extends PersonFieldValue("favourite_football_club_id", value) + case class name(override val value: /* max 100 chars */ String) extends PersonFieldValue("name", value) + case class nickName(override val value: Option[/* max 30 chars */ String]) extends PersonFieldValue("nick_name", value) + case class blogUrl(override val value: Option[/* max 100 chars */ String]) extends PersonFieldValue("blog_url", value) + case class email(override val value: /* max 254 chars */ String) extends PersonFieldValue("email", value) + case class phone(override val value: /* max 8 chars */ String) extends PersonFieldValue("phone", value) + case class likesPizza(override val value: Boolean) extends PersonFieldValue("likes_pizza", value) + case class maritalStatusId(override val value: MaritalStatusId) extends PersonFieldValue("marital_status_id", value) + case class workEmail(override val value: Option[/* max 254 chars */ String]) extends PersonFieldValue("work_email", value) + case class sector(override val value: Sector) extends PersonFieldValue("sector", value) + case class favoriteNumber(override val value: Number) extends PersonFieldValue("favorite_number", value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala new file mode 100644 index 0000000000..29b9ae44ab --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonFields.scala @@ -0,0 +1,34 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val id: IdField[PersonId, Row] + val favouriteFootballClubId: Field[FootballClubId, Row] + val name: Field[/* max 100 chars */ String, Row] + val nickName: OptField[/* max 30 chars */ String, Row] + val blogUrl: OptField[/* max 100 chars */ String, Row] + val email: Field[/* max 254 chars */ String, Row] + val phone: Field[/* max 8 chars */ String, Row] + val likesPizza: Field[Boolean, Row] + val maritalStatusId: Field[MaritalStatusId, Row] + val workEmail: OptField[/* max 254 chars */ String, Row] + val sector: Field[Sector, Row] + val favoriteNumber: Field[Number, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala new file mode 100644 index 0000000000..1f701b7740 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonId.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +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 `myschema.person` */ +case class PersonId(value: Long) extends AnyVal +object PersonId { + implicit lazy val arraySetter: Setter[Array[PersonId]] = testdb.hardcoded.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PersonId, Long] = Bijection[PersonId, Long](_.value)(PersonId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PersonId] = JdbcDecoder.longDecoder.map(PersonId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PersonId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PersonId] = JsonDecoder.long.map(PersonId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PersonId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PersonId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PersonId] = ParameterMetaData.instance[PersonId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PersonId] = Setter.longSetter.contramap(_.value) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala new file mode 100644 index 0000000000..a7317acdde --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepo.scala @@ -0,0 +1,33 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] + def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..ad588b5827 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoImpl.scala @@ -0,0 +1,189 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.NonEmptyChunk +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("myschema.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values (${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number) + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""favourite_football_club_id"""", sql"${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}")), + Some((sql""""nick_name"""", sql"${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""blog_url"""", sql"${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""email"""", sql"${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}")), + Some((sql""""phone"""", sql"${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}")), + Some((sql""""likes_pizza"""", sql"${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}")), + Some((sql""""work_email"""", sql"${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.id match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""id"""", sql"${Segment.paramSegment(value: PersonId)(Setter[PersonId])}::int8")) + }, + unsaved.maritalStatusId match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""marital_status_id"""", sql"${Segment.paramSegment(value: MaritalStatusId)(Setter[MaritalStatusId])}")) + }, + unsaved.sector match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""sector"""", sql"${Segment.paramSegment(value: Sector)(Setter[Sector])}::myschema.sector")) + }, + unsaved.favoriteNumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""favorite_number"""", sql"${Segment.paramSegment(value: Number)(Setter[Number])}::myschema.number")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into myschema.person default values + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into myschema.person($names) values ($values) returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where "id" = ANY(${Segment.paramSegment(ids)(PersonId.arraySetter)})""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + fieldValues match { + case Nil => selectAll + case nonEmpty => + val wheres = SqlFragment.empty.and( + nonEmpty.map { + case PersonFieldValue.id(value) => sql""""id" = ${Segment.paramSegment(value)(Setter[PersonId])}""" + case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}""" + } + ) + sql"""select "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number" from myschema.person where $wheres""".query(PersonRow.jdbcDecoder).selectStream + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val id = row.id + sql"""update myschema.person + set "favourite_football_club_id" = ${Segment.paramSegment(row.favouriteFootballClubId)(Setter[FootballClubId])}, + "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)}, + "nick_name" = ${Segment.paramSegment(row.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + "blog_url" = ${Segment.paramSegment(row.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + "email" = ${Segment.paramSegment(row.email)(Setter.stringSetter)}, + "phone" = ${Segment.paramSegment(row.phone)(Setter.stringSetter)}, + "likes_pizza" = ${Segment.paramSegment(row.likesPizza)(Setter.booleanSetter)}, + "marital_status_id" = ${Segment.paramSegment(row.maritalStatusId)(Setter[MaritalStatusId])}, + "work_email" = ${Segment.paramSegment(row.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + "sector" = ${Segment.paramSegment(row.sector)(Setter[Sector])}::myschema.sector, + "favorite_number" = ${Segment.paramSegment(row.favoriteNumber)(Setter[Number])}::myschema.number + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("myschema.person", PersonFields, PersonRow.jdbcDecoder) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + NonEmptyChunk.fromIterableOption(fieldValues) match { + case None => ZIO.succeed(false) + case Some(nonEmpty) => + val updates = nonEmpty.map { case PersonFieldValue.favouriteFootballClubId(value) => sql""""favourite_football_club_id" = ${Segment.paramSegment(value)(Setter[FootballClubId])}""" + case PersonFieldValue.name(value) => sql""""name" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.nickName(value) => sql""""nick_name" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.blogUrl(value) => sql""""blog_url" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.email(value) => sql""""email" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.phone(value) => sql""""phone" = ${Segment.paramSegment(value)(Setter.stringSetter)}""" + case PersonFieldValue.likesPizza(value) => sql""""likes_pizza" = ${Segment.paramSegment(value)(Setter.booleanSetter)}""" + case PersonFieldValue.maritalStatusId(value) => sql""""marital_status_id" = ${Segment.paramSegment(value)(Setter[MaritalStatusId])}""" + case PersonFieldValue.workEmail(value) => sql""""work_email" = ${Segment.paramSegment(value)(Setter.optionParamSetter(Setter.stringSetter))}""" + case PersonFieldValue.sector(value) => sql""""sector" = ${Segment.paramSegment(value)(Setter[Sector])}::myschema.sector""" + case PersonFieldValue.favoriteNumber(value) => sql""""favorite_number" = ${Segment.paramSegment(value)(Setter[Number])}::myschema.number""" }.mkFragment(SqlFragment(", ")) + sql"""update myschema.person + set $updates + where "id" = ${Segment.paramSegment(id)(Setter[PersonId])} + """.update.map(_ > 0) + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into myschema.person("id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number") + values ( + ${Segment.paramSegment(unsaved.id)(Setter[PersonId])}::int8, + ${Segment.paramSegment(unsaved.favouriteFootballClubId)(Setter[FootballClubId])}, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.nickName)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.blogUrl)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.email)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.phone)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.likesPizza)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.maritalStatusId)(Setter[MaritalStatusId])}, + ${Segment.paramSegment(unsaved.workEmail)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.sector)(Setter[Sector])}::myschema.sector, + ${Segment.paramSegment(unsaved.favoriteNumber)(Setter[Number])}::myschema.number + ) + on conflict ("id") + do update set + "favourite_football_club_id" = EXCLUDED."favourite_football_club_id", + "name" = EXCLUDED."name", + "nick_name" = EXCLUDED."nick_name", + "blog_url" = EXCLUDED."blog_url", + "email" = EXCLUDED."email", + "phone" = EXCLUDED."phone", + "likes_pizza" = EXCLUDED."likes_pizza", + "marital_status_id" = EXCLUDED."marital_status_id", + "work_email" = EXCLUDED."work_email", + "sector" = EXCLUDED."sector", + "favorite_number" = EXCLUDED."favorite_number" + returning "id", "favourite_football_club_id", "name", "nick_name", "blog_url", "email", "phone", "likes_pizza", "marital_status_id", "work_email", "sector", "favorite_number"""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala new file mode 100644 index 0000000000..e11c0937ff --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRepoMock.scala @@ -0,0 +1,126 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[PersonId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(id: PersonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(id).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.id)) + sys.error(s"id ${unsaved.id} already exists") + else + map.put(unsaved.id, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(id: PersonId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(id)) + } + override def selectByIds(ids: Array[PersonId]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(ids.flatMap(map.get)) + } + override def selectByFieldValues(fieldValues: List[PersonFieldOrIdValue[?]]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable { + fieldValues.foldLeft(map.values) { + case (acc, PersonFieldValue.id(value)) => acc.filter(_.id == value) + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.filter(_.favouriteFootballClubId == value) + case (acc, PersonFieldValue.name(value)) => acc.filter(_.name == value) + case (acc, PersonFieldValue.nickName(value)) => acc.filter(_.nickName == value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.filter(_.blogUrl == value) + case (acc, PersonFieldValue.email(value)) => acc.filter(_.email == value) + case (acc, PersonFieldValue.phone(value)) => acc.filter(_.phone == value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.filter(_.likesPizza == value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.filter(_.maritalStatusId == value) + case (acc, PersonFieldValue.workEmail(value)) => acc.filter(_.workEmail == value) + case (acc, PersonFieldValue.sector(value)) => acc.filter(_.sector == value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.filter(_.favoriteNumber == value) + } + } + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.id) match { + case Some(`row`) => false + case Some(_) => + map.put(row.id, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def updateFieldValues(id: PersonId, fieldValues: List[PersonFieldValue[?]]): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(id) match { + case Some(oldRow) => + val updatedRow = fieldValues.foldLeft(oldRow) { + case (acc, PersonFieldValue.favouriteFootballClubId(value)) => acc.copy(favouriteFootballClubId = value) + case (acc, PersonFieldValue.name(value)) => acc.copy(name = value) + case (acc, PersonFieldValue.nickName(value)) => acc.copy(nickName = value) + case (acc, PersonFieldValue.blogUrl(value)) => acc.copy(blogUrl = value) + case (acc, PersonFieldValue.email(value)) => acc.copy(email = value) + case (acc, PersonFieldValue.phone(value)) => acc.copy(phone = value) + case (acc, PersonFieldValue.likesPizza(value)) => acc.copy(likesPizza = value) + case (acc, PersonFieldValue.maritalStatusId(value)) => acc.copy(maritalStatusId = value) + case (acc, PersonFieldValue.workEmail(value)) => acc.copy(workEmail = value) + case (acc, PersonFieldValue.sector(value)) => acc.copy(sector = value) + case (acc, PersonFieldValue.favoriteNumber(value)) => acc.copy(favoriteNumber = value) + } + if (updatedRow != oldRow) { + map.put(id, updatedRow): @nowarn + true + } else { + false + } + case None => false + } + } + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.id, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala new file mode 100644 index 0000000000..4321795ca7 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRow.scala @@ -0,0 +1,116 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import java.sql.ResultSet +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + id: PersonId, + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + /** Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: MaritalStatusId, + workEmail: Option[/* max 254 chars */ String], + sector: Sector, + favoriteNumber: Number +) + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 11 -> + PersonRow( + id = PersonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + favouriteFootballClubId = FootballClubId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + nickName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + blogUrl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + email = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + phone = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + likesPizza = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + maritalStatusId = MaritalStatusId.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + workEmail = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + sector = Sector.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + favoriteNumber = Number.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(PersonId.jsonDecoder)) + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(MaritalStatusId.jsonDecoder)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Sector.jsonDecoder)) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Number.jsonDecoder)) + if (id.isRight && favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && maritalStatusId.isRight && workEmail.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRow(id = id.toOption.get, favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, maritalStatusId = maritalStatusId.toOption.get, workEmail = workEmail.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + PersonId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + MaritalStatusId.jsonEncoder.unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""sector":""") + Sector.jsonEncoder.unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Number.jsonEncoder.unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..47897e8d14 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonRowUnsaved.scala @@ -0,0 +1,129 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `myschema.person` which has not been persisted yet */ +case class PersonRowUnsaved( + /** Points to [[football_club.FootballClubRow.id]] */ + favouriteFootballClubId: FootballClubId, + name: /* max 100 chars */ String, + nickName: Option[/* max 30 chars */ String], + blogUrl: Option[/* max 100 chars */ String], + email: /* max 254 chars */ String, + phone: /* max 8 chars */ String, + likesPizza: Boolean, + workEmail: Option[/* max 254 chars */ String], + /** Default: auto-increment */ + id: Defaulted[PersonId] = Defaulted.UseDefault, + /** Default: some-value + Points to [[marital_status.MaritalStatusRow.id]] */ + maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, + /** Default: PUBLIC */ + sector: Defaulted[Sector] = Defaulted.UseDefault, + /** Default: one */ + favoriteNumber: Defaulted[Number] = Defaulted.UseDefault +) { + def toRow(idDefault: => PersonId, maritalStatusIdDefault: => MaritalStatusId, sectorDefault: => Sector, favoriteNumberDefault: => Number): PersonRow = + PersonRow( + favouriteFootballClubId = favouriteFootballClubId, + name = name, + nickName = nickName, + blogUrl = blogUrl, + email = email, + phone = phone, + likesPizza = likesPizza, + workEmail = workEmail, + id = id match { + case Defaulted.UseDefault => idDefault + case Defaulted.Provided(value) => value + }, + maritalStatusId = maritalStatusId match { + case Defaulted.UseDefault => maritalStatusIdDefault + case Defaulted.Provided(value) => value + }, + sector = sector match { + case Defaulted.UseDefault => sectorDefault + case Defaulted.Provided(value) => value + }, + favoriteNumber = favoriteNumber match { + case Defaulted.UseDefault => favoriteNumberDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val favouriteFootballClubId = jsonObj.get("favourite_football_club_id").toRight("Missing field 'favourite_football_club_id'").flatMap(_.as(FootballClubId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val nickName = jsonObj.get("nick_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blogUrl = jsonObj.get("blog_url").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(JsonDecoder.string)) + val phone = jsonObj.get("phone").toRight("Missing field 'phone'").flatMap(_.as(JsonDecoder.string)) + val likesPizza = jsonObj.get("likes_pizza").toRight("Missing field 'likes_pizza'").flatMap(_.as(JsonDecoder.boolean)) + val workEmail = jsonObj.get("work_email").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(Defaulted.jsonDecoder(PersonId.jsonDecoder))) + val maritalStatusId = jsonObj.get("marital_status_id").toRight("Missing field 'marital_status_id'").flatMap(_.as(Defaulted.jsonDecoder(MaritalStatusId.jsonDecoder))) + val sector = jsonObj.get("sector").toRight("Missing field 'sector'").flatMap(_.as(Defaulted.jsonDecoder(Sector.jsonDecoder))) + val favoriteNumber = jsonObj.get("favorite_number").toRight("Missing field 'favorite_number'").flatMap(_.as(Defaulted.jsonDecoder(Number.jsonDecoder))) + if (favouriteFootballClubId.isRight && name.isRight && nickName.isRight && blogUrl.isRight && email.isRight && phone.isRight && likesPizza.isRight && workEmail.isRight && id.isRight && maritalStatusId.isRight && sector.isRight && favoriteNumber.isRight) + Right(PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId.toOption.get, name = name.toOption.get, nickName = nickName.toOption.get, blogUrl = blogUrl.toOption.get, email = email.toOption.get, phone = phone.toOption.get, likesPizza = likesPizza.toOption.get, workEmail = workEmail.toOption.get, id = id.toOption.get, maritalStatusId = maritalStatusId.toOption.get, sector = sector.toOption.get, favoriteNumber = favoriteNumber.toOption.get)) + else Left(List[Either[String, Any]](favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, workEmail, id, maritalStatusId, sector, favoriteNumber).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""favourite_football_club_id":""") + FootballClubId.jsonEncoder.unsafeEncode(a.favouriteFootballClubId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""nick_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.nickName, indent, out) + out.write(",") + out.write(""""blog_url":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.blogUrl, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.string.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""phone":""") + JsonEncoder.string.unsafeEncode(a.phone, indent, out) + out.write(",") + out.write(""""likes_pizza":""") + JsonEncoder.boolean.unsafeEncode(a.likesPizza, indent, out) + out.write(",") + out.write(""""work_email":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.workEmail, indent, out) + out.write(",") + out.write(""""id":""") + Defaulted.jsonEncoder(PersonId.jsonEncoder).unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""marital_status_id":""") + Defaulted.jsonEncoder(MaritalStatusId.jsonEncoder).unsafeEncode(a.maritalStatusId, indent, out) + out.write(",") + out.write(""""sector":""") + Defaulted.jsonEncoder(Sector.jsonEncoder).unsafeEncode(a.sector, indent, out) + out.write(",") + out.write(""""favorite_number":""") + Defaulted.jsonEncoder(Number.jsonEncoder).unsafeEncode(a.favoriteNumber, indent, out) + out.write("}") + } + } +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala new file mode 100644 index 0000000000..1886c54182 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/myschema/person/PersonStructure.scala @@ -0,0 +1,43 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded +package myschema +package person + +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val id = new IdField[PersonId, Row](prefix, "id", None, Some("int8"))(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val favouriteFootballClubId = new Field[FootballClubId, Row](prefix, "favourite_football_club_id", None, None)(x => extract(x).favouriteFootballClubId, (row, value) => merge(row, extract(row).copy(favouriteFootballClubId = value))) + override val name = new Field[/* max 100 chars */ String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val nickName = new OptField[/* max 30 chars */ String, Row](prefix, "nick_name", None, None)(x => extract(x).nickName, (row, value) => merge(row, extract(row).copy(nickName = value))) + override val blogUrl = new OptField[/* max 100 chars */ String, Row](prefix, "blog_url", None, None)(x => extract(x).blogUrl, (row, value) => merge(row, extract(row).copy(blogUrl = value))) + override val email = new Field[/* max 254 chars */ String, Row](prefix, "email", None, None)(x => extract(x).email, (row, value) => merge(row, extract(row).copy(email = value))) + override val phone = new Field[/* max 8 chars */ String, Row](prefix, "phone", None, None)(x => extract(x).phone, (row, value) => merge(row, extract(row).copy(phone = value))) + override val likesPizza = new Field[Boolean, Row](prefix, "likes_pizza", None, None)(x => extract(x).likesPizza, (row, value) => merge(row, extract(row).copy(likesPizza = value))) + override val maritalStatusId = new Field[MaritalStatusId, Row](prefix, "marital_status_id", None, None)(x => extract(x).maritalStatusId, (row, value) => merge(row, extract(row).copy(maritalStatusId = value))) + override val workEmail = new OptField[/* max 254 chars */ String, Row](prefix, "work_email", None, None)(x => extract(x).workEmail, (row, value) => merge(row, extract(row).copy(workEmail = value))) + override val sector = new Field[Sector, Row](prefix, "sector", None, Some("myschema.sector"))(x => extract(x).sector, (row, value) => merge(row, extract(row).copy(sector = value))) + override val favoriteNumber = new Field[Number, Row](prefix, "favorite_number", None, Some("myschema.number"))(x => extract(x).favoriteNumber, (row, value) => merge(row, extract(row).copy(favoriteNumber = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, favouriteFootballClubId, name, nickName, blogUrl, email, phone, likesPizza, maritalStatusId, workEmail, sector, favoriteNumber) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala new file mode 100644 index 0000000000..c8ffbefab4 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/package.scala @@ -0,0 +1,243 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb + +package object hardcoded { + implicit lazy val BigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] = new zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.math.BigDecimal]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.math.BigDecimal]) { + case (b, x: java.math.BigDecimal) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.math.BigDecimal] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.math.BigDecimal) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.math.BigDecimal). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.math.BigDecimal]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BigDecimalArraySetter) + implicit lazy val BigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.math.BigDecimal]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.math.BigDecimal]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("numeric", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val BooleanArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Boolean]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Boolean]) { + case (b, x: scala.Boolean) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Boolean] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Boolean) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Boolean). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BooleanArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Boolean]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BooleanArraySetter) + implicit lazy val BooleanArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Boolean]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Boolean]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("bool", v.map(x => boolean2Boolean(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val DoubleArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Double]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Double]) { + case (b, x: scala.Double) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Double] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Double) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Double). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val DoubleArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Double]] = zio.jdbc.JdbcEncoder.singleParamEncoder(DoubleArraySetter) + implicit lazy val DoubleArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Double]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Double]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float8", v.map(x => double2Double(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val FloatArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Float]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Float]) { + case (b, x: scala.Float) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Float] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Float) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Float). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val FloatArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Float]] = zio.jdbc.JdbcEncoder.singleParamEncoder(FloatArraySetter) + implicit lazy val FloatArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Float]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Float]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float4", v.map(x => float2Float(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val IntArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Int]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Int]) { + case (b, x: scala.Int) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Int] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Int) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Int). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val IntArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Int]] = zio.jdbc.JdbcEncoder.singleParamEncoder(IntArraySetter) + implicit lazy val IntArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Int]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Int]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int4", v.map(x => int2Integer(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val LongArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Long]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Long]) { + case (b, x: scala.Long) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Long] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Long) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Long). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val LongArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Long]] = zio.jdbc.JdbcEncoder.singleParamEncoder(LongArraySetter) + implicit lazy val LongArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Long]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Long]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int8", v.map(x => long2Long(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val ScalaBigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayDecoder.map(v => if (v eq null) null else v.map(scala.math.BigDecimal.apply)) + implicit lazy val ScalaBigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayEncoder.contramap(_.map(_.bigDecimal)) + implicit lazy val ScalaBigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.math.BigDecimal]] = BigDecimalArraySetter.contramap(_.map(_.bigDecimal)) + implicit lazy val StringArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] = new zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.lang.String]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.lang.String]) { + case (b, x: java.lang.String) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.lang.String] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.lang.String) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.lang.String). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val StringArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.lang.String]] = zio.jdbc.JdbcEncoder.singleParamEncoder(StringArraySetter) + implicit lazy val StringArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.lang.String]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.lang.String]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("varchar", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) +} diff --git a/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala new file mode 100644 index 0000000000..de77901c73 --- /dev/null +++ b/.bleep/generated-sources/typo-tester-zio-jdbc@jvm3/scripts.GenHardcodedFiles/testdb/hardcoded/testInsert.scala @@ -0,0 +1,31 @@ +/** + * File automatically generated by `typo` for its own test suite. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN + */ +package testdb +package hardcoded + +import scala.util.Random +import testdb.hardcoded.compositepk.person.PersonRepoImpl +import testdb.hardcoded.compositepk.person.PersonRow +import testdb.hardcoded.compositepk.person.PersonRowUnsaved +import testdb.hardcoded.customtypes.Defaulted +import testdb.hardcoded.myschema.Number +import testdb.hardcoded.myschema.Sector +import testdb.hardcoded.myschema.football_club.FootballClubId +import testdb.hardcoded.myschema.football_club.FootballClubRepoImpl +import testdb.hardcoded.myschema.football_club.FootballClubRow +import testdb.hardcoded.myschema.marital_status.MaritalStatusId +import testdb.hardcoded.myschema.marital_status.MaritalStatusRepoImpl +import testdb.hardcoded.myschema.marital_status.MaritalStatusRow +import testdb.hardcoded.myschema.person.PersonId +import zio.ZIO +import zio.jdbc.ZConnection + +class testInsert(random: Random) { + def compositepkPerson(name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), one: Defaulted[Long] = Defaulted.UseDefault, two: Defaulted[Option[String]] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersonRow] = PersonRepoImpl.insert(new PersonRowUnsaved(name = name, one = one, two = two)) + def myschemaFootballClub(id: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, FootballClubRow] = FootballClubRepoImpl.insert(new FootballClubRow(id = id, name = name)) + def myschemaMaritalStatus(id: MaritalStatusId): ZIO[ZConnection, Throwable, MaritalStatusRow] = MaritalStatusRepoImpl.insert(new MaritalStatusRow(id = id)) + def myschemaPerson(favouriteFootballClubId: FootballClubId, name: /* max 100 chars */ String = random.alphanumeric.take(20).mkString, nickName: Option[/* max 30 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), blogUrl: Option[/* max 100 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), email: /* max 254 chars */ String = random.alphanumeric.take(20).mkString, phone: /* max 8 chars */ String = random.alphanumeric.take(8).mkString, likesPizza: Boolean = random.nextBoolean(), workEmail: Option[/* max 254 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), id: Defaulted[PersonId] = Defaulted.UseDefault, maritalStatusId: Defaulted[MaritalStatusId] = Defaulted.UseDefault, sector: Defaulted[Sector] = Defaulted.UseDefault, favoriteNumber: Defaulted[Number] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, testdb.hardcoded.myschema.person.PersonRow] = testdb.hardcoded.myschema.person.PersonRepoImpl.insert(new testdb.hardcoded.myschema.person.PersonRowUnsaved(favouriteFootballClubId = favouriteFootballClubId, name = name, nickName = nickName, blogUrl = blogUrl, email = email, phone = phone, likesPizza = likesPizza, workEmail = workEmail, id = id, maritalStatusId = maritalStatusId, sector = sector, favoriteNumber = favoriteNumber)) +} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 48ede7793b..5063bdc4ea 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ target /.bloop .vscode site/docs -myproject/ \ No newline at end of file +myproject/ diff --git a/bleep.yaml b/bleep.yaml index 9523f03b44..e9a7954081 100644 --- a/bleep.yaml +++ b/bleep.yaml @@ -2,6 +2,13 @@ $schema: https://raw.githubusercontent.com/oyvindberg/bleep/master/schema.json $version: 0.0.3 jvm: name: graalvm-java17:22.3.1 +resolvers: + - type: maven + uri: https://oss.sonatype.org/content/repositories/snapshots + name: sonatype-snapshots + - type: maven + uri: https://s01.oss.sonatype.org/content/repositories/snapshots + name: sonatype-s01-snapshots projects: # these tests do not depend on running codegen, just unit tests and so on tests: @@ -37,6 +44,15 @@ projects: dependencies: org.tpolecat::doobie-postgres:1.0.0-RC4 extends: template-cross sources: ../typo-dsl-shared + typo-dsl-zio-jdbc: + cross: + jvm212: + extends: template-kind-projector + jvm213: + extends: template-kind-projector + dependencies: dev.zio::zio-jdbc:0.1.1 + extends: template-cross + sources: ../typo-dsl-shared # scripts for generating docs typo-scripts-doc: dependencies: @@ -77,6 +93,18 @@ projects: main: scripts.GenHardcodedFiles project: typo-scripts sources: ./generated-and-checked-in + typo-tester-zio-jdbc: + dependencies: + - dev.zio::zio-json:0.6.2 + - org.postgresql:postgresql:42.6.0 + - org.scalatest::scalatest:3.3.0-SNAP4 + dependsOn: typo-dsl-zio-jdbc + extends: template-cross + isTestProject: true + sourcegen: + main: scripts.GenHardcodedFiles + project: typo-scripts + sources: ./generated-and-checked-in scripts: generate-adventureworks: main: scripts.GeneratedAdventureWorks diff --git a/site-in/customization/overview.md b/site-in/customization/overview.md index ebb85ef339..bb41b54bbf 100644 --- a/site-in/customization/overview.md +++ b/site-in/customization/overview.md @@ -21,7 +21,7 @@ val options = Options( | Field Name | Effect | |-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `pkg` | Specifies the package name for the generated code. | -| `dbLib` | Defines the database library to use for code generation (anorm, doobie or none). | +| `dbLib` | Defines the database library to use for code generation (anorm, doobie, zio-jdbc or `None`). | | `jsonLibs` | JSON libraries to generate codecs for (default is empty). | | `silentBanner` | Controls whether to suppress the Typo banner while running Typo (default is `false`). | | `fileHeader` | Sets the header text that appears at the top of generated files. | diff --git a/site-in/other-features/flexible.md b/site-in/other-features/flexible.md index 4e052f950e..8372df58fc 100644 --- a/site-in/other-features/flexible.md +++ b/site-in/other-features/flexible.md @@ -15,7 +15,7 @@ Everything works on 2.12, 2.13, and 3.3. Not wanting to invent all the wheels, Typo expects you to already use a Scala database library. -For now you have the option of `doobie` or `anorm`, with `skunk` to follow. Maybe also plain `jdbc` mode later. +For now you have the option of `doobie`, `anorm` or `zio-jdbc`, with `skunk` to follow. Maybe also plain `jdbc` mode later. ## Bring your own JSON library diff --git a/site-in/other-features/json.md b/site-in/other-features/json.md index bab5228d17..a3009d5336 100644 --- a/site-in/other-features/json.md +++ b/site-in/other-features/json.md @@ -9,7 +9,7 @@ PostgreSQL or write some generic code across tables, it's very convenient to be You add the wanted JSON libraries to `typo.Options` when running typo to get the codecs. -Currently, you can choose between `play-json` and `circe`. +Currently, you can choose between `play-json`, `circe` and `zio-json`. It's likely quite easy to add another one if you want to contribute! For instance: @@ -19,7 +19,7 @@ import typo.* val options = Options( pkg = "org.foo", - jsonLibs = List(JsonLibName.PlayJson), // or List() if you don't want json + jsonLibs = List(JsonLibName.PlayJson), // or `Nil` if you don't want json dbLib = Some(DbLibName.Anorm) ) ``` diff --git a/site-in/setup.md b/site-in/setup.md index 105eca0dfa..d9fce7bb91 100644 --- a/site-in/setup.md +++ b/site-in/setup.md @@ -3,7 +3,7 @@ title: Getting started --- ## Database library -Note that you're supposed to [bring your own database library](other-features/flexible.md). You choose either anorm or doobie in `Options` (see below), +Note that you're supposed to [bring your own database library](other-features/flexible.md). You choose either anorm, doobie or zio-jdbc in `Options` (see below), and you need to have that added to your build as well. ## Getting started with DSL @@ -22,6 +22,7 @@ Options( You also need to add a dependency to your build in that case, which varies by database library: - for doobie: https://mvnrepository.com/artifact/com.olvind.typo/typo-dsl-doobie - for anorm: https://mvnrepository.com/artifact/com.olvind.typo/typo-dsl-anorm +- for zio-jdbc: https://mvnrepository.com/artifact/com.olvind.typo/typo-dsl-zio-jdbc ## example script diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/DeleteBuilder.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/DeleteBuilder.scala new file mode 100644 index 0000000000..785fbcee0f --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/DeleteBuilder.scala @@ -0,0 +1,73 @@ +package typo.dsl + +import zio.ZIO +import zio.jdbc.* + +import java.util.concurrent.atomic.AtomicInteger +import scala.annotation.nowarn + +trait DeleteBuilder[Fields[_], Row] { + protected def params: DeleteParams[Fields, Row] + protected def withParams(sqlParams: DeleteParams[Fields, Row]): DeleteBuilder[Fields, Row] + + final def where[N[_]: Nullability](v: Fields[Row] => SqlExpr[Boolean, N, Row]): DeleteBuilder[Fields, Row] = + whereStrict(f => v(f).?.coalesce(false)) + + final def whereStrict(v: Fields[Row] => SqlExpr[Boolean, Required, Row]): DeleteBuilder[Fields, Row] = + withParams(params.where(v)) + + def sql: Option[SqlFragment] + def execute: ZIO[ZConnection, Throwable, Long] +} + +object DeleteBuilder { + def apply[Fields[_], Row](name: String, structure: Structure.Relation[Fields, ?, Row]): DeleteBuilderSql[Fields, Row] = + DeleteBuilderSql(name, structure, DeleteParams.empty) + + final case class DeleteBuilderSql[Fields[_], Row]( + name: String, + structure: Structure.Relation[Fields, ?, Row], + params: DeleteParams[Fields, Row] + ) extends DeleteBuilder[Fields, Row] { + override def withParams(params: DeleteParams[Fields, Row]): DeleteBuilder[Fields, Row] = + copy(params = params) + + def mkSql(counter: AtomicInteger): SqlFragment = { + List[Iterable[SqlFragment]]( + Some(SqlFragment.deleteFrom(name)), + params.where + .map(w => w(structure.fields)) + .reduceLeftOption(_ and _) + .map { where => sql" where " ++ where.render(counter) } + ).flatten.reduce(_ ++ _) + } + + override def sql: Option[SqlFragment] = + Some(mkSql(new AtomicInteger(1))) + + override def execute: ZIO[ZConnection, Throwable, Long] = + mkSql(new AtomicInteger(0)).update + } + + final case class DeleteBuilderMock[Id, Fields[_], Row]( + params: DeleteParams[Fields, Row], + fields: Fields[Row], + map: scala.collection.mutable.Map[Id, Row] + ) extends DeleteBuilder[Fields, Row] { + override def withParams(params: DeleteParams[Fields, Row]): DeleteBuilder[Fields, Row] = + copy(params = params) + + override def sql: Option[SqlFragment] = None + + override def execute: ZIO[ZConnection, Throwable, Long] = ZIO.succeed { + var changed: Long = 0L + map.foreach { case (id, row) => + if (params.where.forall(w => w(fields).eval(row))) { + map.remove(id): @nowarn + changed += 1 + } + } + changed + } + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/ParameterMetaData.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/ParameterMetaData.scala new file mode 100644 index 0000000000..bb5608f76c --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/ParameterMetaData.scala @@ -0,0 +1,248 @@ +package typo.dsl + +import java.lang.{Boolean as JBool, Byte as JByte, Double as JDouble, Float as JFloat, Long as JLong, Short as JShort} +import java.math.{BigInteger, BigDecimal as JBigDec} +import java.net.{URI, URL} +import java.sql.{Timestamp, Types} +import java.time.OffsetDateTime +import java.util.{Date, UUID as JUUID} + +/** ** Copied from anorm** + * + * Parameter meta data for type `T` + */ +@annotation.implicitNotFound( + "Meta data not found for parameter of type ${T}: `typo.dsl.ParameterMetaData[${T}]` required; See https://github.com/playframework/anorm/blob/main/docs/manual/working/scalaGuide/main/sql/ScalaAnorm.md#parameters" +) +trait ParameterMetaData[T] { + + /** Name of SQL type (see `java.sql.Types`) + */ + def sqlType: String + + /** JDBC type (see `java.sql.Types`) + */ + def jdbcType: Int +} + +/** ParameterMetaData companion, providing defaults based on SQL92. + */ +object ParameterMetaData extends JavaTimeParameterMetaData { + def instance[T](_sqlType: String, _jdbcType: Int): ParameterMetaData[T] = new ParameterMetaData[T] { + val sqlType = _sqlType + val jdbcType = _jdbcType + } + + /** Binary meta data */ + implicit object BlobParameterMetaData extends ParameterMetaData[java.sql.Blob] { + val sqlType = "BLOB" + val jdbcType = Types.BLOB + } + + /** Array of byte meta data */ + implicit object ByteArrayParameterMetaData extends ParameterMetaData[Array[Byte]] { + val sqlType = "LONGVARBINARY" + val jdbcType = Types.LONGVARBINARY + } + + implicit object InputStreamParameterMetaData extends ParameterMetaData[java.io.InputStream] { + val sqlType = ByteArrayParameterMetaData.sqlType + val jdbcType = ByteArrayParameterMetaData.jdbcType + } + + /** Boolean parameter meta data */ + implicit object BooleanParameterMetaData extends ParameterMetaData[Boolean] { + val sqlType = "BOOLEAN" + val jdbcType = Types.BOOLEAN + } + + implicit object JBooleanParameterMetaData extends ParameterMetaData[JBool] { + val sqlType = BooleanParameterMetaData.sqlType + val jdbcType = BooleanParameterMetaData.jdbcType + } + + /** Clob meta data */ + implicit object ClobParameterMetaData extends ParameterMetaData[java.sql.Clob] { + val sqlType = "CLOB" + val jdbcType = Types.CLOB + } + + /** Double parameter meta data */ + implicit object DoubleParameterMetaData extends ParameterMetaData[Double] { + val sqlType = "DOUBLE PRECISION" + val jdbcType = Types.DOUBLE + } + + implicit object JDoubleParameterMetaData extends ParameterMetaData[JDouble] { + val sqlType = DoubleParameterMetaData.sqlType + val jdbcType = DoubleParameterMetaData.jdbcType + } + + /** Float parameter meta data */ + implicit object FloatParameterMetaData extends ParameterMetaData[Float] { + val sqlType = "FLOAT" + val jdbcType = Types.FLOAT + } + + implicit object JFloatParameterMetaData extends ParameterMetaData[JFloat] { + val sqlType = FloatParameterMetaData.sqlType + val jdbcType = FloatParameterMetaData.jdbcType + } + + /** Integer parameter meta data */ + implicit object IntParameterMetaData extends ParameterMetaData[Int] { + val sqlType = "INTEGER" + val jdbcType = Types.INTEGER + } + + implicit object ByteParameterMetaData extends ParameterMetaData[Byte] { + val sqlType = IntParameterMetaData.sqlType + val jdbcType = Types.TINYINT + } + + implicit object JByteParameterMetaData extends ParameterMetaData[JByte] { + val sqlType = IntParameterMetaData.sqlType + val jdbcType = ByteParameterMetaData.jdbcType + } + + implicit object IntegerParameterMetaData extends ParameterMetaData[Integer] { + val sqlType = IntParameterMetaData.sqlType + val jdbcType = IntParameterMetaData.jdbcType + } + + implicit object ShortParameterMetaData extends ParameterMetaData[Short] { + val sqlType = IntParameterMetaData.sqlType + val jdbcType = Types.SMALLINT + } + + implicit object JShortParameterMetaData extends ParameterMetaData[JShort] { + val sqlType = IntParameterMetaData.sqlType + val jdbcType = ShortParameterMetaData.jdbcType + } + + /** Numeric (big integer) parameter meta data */ + implicit object BigIntParameterMetaData extends ParameterMetaData[BigInt] { + val sqlType = "NUMERIC" + val jdbcType = Types.BIGINT + } + + implicit object BigIntegerParameterMetaData extends ParameterMetaData[BigInteger] { + val sqlType = BigIntParameterMetaData.sqlType + val jdbcType = BigIntParameterMetaData.jdbcType + } + + implicit object LongParameterMetaData extends ParameterMetaData[Long] { + val sqlType = BigIntParameterMetaData.sqlType + val jdbcType = BigIntParameterMetaData.jdbcType + } + + implicit object JLongParameterMetaData extends ParameterMetaData[JLong] { + val sqlType = BigIntParameterMetaData.sqlType + val jdbcType = BigIntParameterMetaData.jdbcType + } + + /** Decimal (big decimal) parameter meta data */ + implicit object BigDecimalParameterMetaData extends ParameterMetaData[BigDecimal] { + val sqlType = "DECIMAL" + val jdbcType = Types.DECIMAL + } + + implicit object JBigDecParameterMetaData extends ParameterMetaData[JBigDec] { + val sqlType = BigDecimalParameterMetaData.sqlType + val jdbcType = BigDecimalParameterMetaData.jdbcType + } + + /** Timestamp parameter meta data */ + implicit object TimestampParameterMetaData extends ParameterMetaData[Timestamp] { + val sqlType = "TIMESTAMP" + val jdbcType = Types.TIMESTAMP + } + + implicit object DateParameterMetaData extends ParameterMetaData[Date] { + val sqlType = TimestampParameterMetaData.sqlType + val jdbcType = TimestampParameterMetaData.jdbcType + } + + @SuppressWarnings(Array("MethodNames")) + implicit def TimestampWrapper1MetaData[T <: { def getTimestamp: java.sql.Timestamp }]: ParameterMetaData[T] = new ParameterMetaData[T] { + val sqlType = TimestampParameterMetaData.sqlType + val jdbcType = TimestampParameterMetaData.jdbcType + } + + /** String/VARCHAR parameter meta data */ + implicit object StringParameterMetaData extends ParameterMetaData[String] { + val sqlType = "VARCHAR" + val jdbcType = Types.VARCHAR + } + + implicit object UUIDParameterMetaData extends ParameterMetaData[JUUID] { + val sqlType = StringParameterMetaData.sqlType + val jdbcType = StringParameterMetaData.jdbcType + } + + implicit object URIParameterMetaData extends ParameterMetaData[URI] { + val sqlType = StringParameterMetaData.sqlType + val jdbcType = StringParameterMetaData.jdbcType + } + + implicit object URLParameterMetaData extends ParameterMetaData[URL] { + val sqlType = StringParameterMetaData.sqlType + val jdbcType = StringParameterMetaData.jdbcType + } + + implicit object CharacterStreamMetaData extends ParameterMetaData[java.io.Reader] { + val sqlType = StringParameterMetaData.sqlType + val jdbcType = StringParameterMetaData.jdbcType + } + + /** Character parameter meta data */ + implicit object CharParameterMetaData extends ParameterMetaData[Char] { + val sqlType = "CHAR" + val jdbcType = Types.CHAR + } + + implicit object CharacterParameterMetaData extends ParameterMetaData[Character] { + val sqlType = CharParameterMetaData.sqlType + val jdbcType = CharParameterMetaData.jdbcType + } +} + +sealed trait JavaTimeParameterMetaData { + import java.time.{Instant, LocalDate, LocalDateTime, ZonedDateTime} + + /** Parameter metadata for Java8 instant */ + implicit object InstantParameterMetaData extends ParameterMetaData[Instant] { + val sqlType = "TIMESTAMPZ" + val jdbcType = Types.TIMESTAMP_WITH_TIMEZONE + } + + /** Parameter metadata for Java8 local date/time */ + implicit object LocalDateTimeParameterMetaData extends ParameterMetaData[LocalDateTime] { + val sqlType = "TIMESTAMP" + val jdbcType = Types.TIMESTAMP + } + + /** Parameter metadata for Java8 local date */ + implicit object LocalDateParameterMetaData extends ParameterMetaData[LocalDate] { + val sqlType = "TIMESTAMP" + val jdbcType = Types.TIMESTAMP + } + + /** Parameter metadata for Java8 zoned date/time */ + implicit object ZonedDateTimeParameterMetaData extends ParameterMetaData[ZonedDateTime] { + val sqlType = "TIMESTAMPZ" + val jdbcType = Types.TIMESTAMP_WITH_TIMEZONE + } + + /** Parameter metadata for Java8 offset date/time */ + implicit object OffsetDateTimeParameterMetaData extends ParameterMetaData[OffsetDateTime] { + val sqlType = "TIMESTAMPZ" + val jdbcType = Types.TIMESTAMP_WITH_TIMEZONE + } + + // added in typo. this is postgres-specific + implicit def arrayParameterMetaData[T](implicit T: ParameterMetaData[T]): ParameterMetaData[Array[T]] = new ParameterMetaData[Array[T]] { + override def sqlType: java.lang.String = "_" + T.sqlType + override def jdbcType: scala.Int = java.sql.Types.ARRAY + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilder.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilder.scala new file mode 100644 index 0000000000..3de105524e --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilder.scala @@ -0,0 +1,99 @@ +package typo.dsl + +import zio.{Chunk, ZIO} +import zio.jdbc.* + +trait SelectBuilder[Fields[_], Row] { + + /** Add a where clause to the query. + * + * Consecutive calls to where will be combined with `AND` + * + * {{{ + * productRepo.select + * .where(_.`class` === "H") + * .where(x => x.daystomanufacture > 25 or x.daystomanufacture <= 0) + * .where(x => x.productline === "foo") + * }}} + */ + final def where[N[_]: Nullability](v: Fields[Hidden] => SqlExpr[Boolean, N, Hidden]): SelectBuilder[Fields, Row] = + withParams(params.where(fields => v(fields.asInstanceOf[Fields[Hidden]]).asInstanceOf[SqlExpr[Boolean, N, Row]].?)) + + /** Same as [[where]], but requires the expression to not be nullable */ + final def whereStrict(v: Fields[Hidden] => SqlExpr[Boolean, Required, Hidden]): SelectBuilder[Fields, Row] = + withParams(params.where(fields => v(fields.asInstanceOf[Fields[Hidden]]).asInstanceOf[SqlExpr[Boolean, Required, Row]].?)) + + /** Add an order by clause to the query. + * + * Consecutive calls to orderBy will be combined and order kept + * + * {{{ + * productRepo.select + * .join(unitmeasureRepo.select.where(_.name.like("name%"))) + * .on { case (p, um) => p.sizeunitmeasurecode === um.unitmeasurecode } + * .join(projectModelRepo.select) + * .leftOn { case ((product, _), productModel) => product.productmodelid === productModel.productmodelid } + * .orderBy { case ((product, _), _) => product.productmodelid.asc } + * .orderBy { case ((_, _), productModel) => productModel(_.name).desc.withNullsFirst } + * }}} + */ + final def orderBy(v: Fields[Hidden] => SortOrder[?, Hidden]): SelectBuilder[Fields, Row] = + withParams(params.orderBy(v.asInstanceOf[Fields[Row] => SortOrder[?, Row]])) + final def offset(v: Int): SelectBuilder[Fields, Row] = + withParams(params.offset(v)) + final def limit(v: Int): SelectBuilder[Fields, Row] = + withParams(params.limit(v)) + + /** Execute the query and return the results as a list */ + def toChunk: ZIO[ZConnection, Throwable, Chunk[Row]] + + /** Return sql for debugging. [[None]] if backed by a mock repository */ + def sql: Option[SqlFragment] + + /** start constructing a join */ + final def join[F2[_], Row2](other: SelectBuilder[F2, Row2]): PartialJoin[F2, Row2] = + new PartialJoin[F2, Row2](other) + + final class PartialJoin[Fields2[_], Row2](other: SelectBuilder[Fields2, Row2]) { + + /** inner join with the given predicate + * {{{ + * val query = productRepo.select + * .join(unitmeasureRepo.select.where(_.name.like("name%"))) + * .on { case (p, um) => p.sizeunitmeasurecode === um.unitmeasurecode } + * }}} + */ + def on[N[_]: Nullability](pred: Joined[Fields, Fields2, Hidden] => SqlExpr[Boolean, N, Hidden]): SelectBuilder[Joined[Fields, Fields2, *], (Row, Row2)] = + joinOn(other)(pred.asInstanceOf[Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)]]) + + /** Variant of `on` that requires the join predicate to not be nullable */ + def onStrict(pred: Joined[Fields, Fields2, Hidden] => SqlExpr[Boolean, Required, Hidden]): SelectBuilder[Joined[Fields, Fields2, *], (Row, Row2)] = + joinOn(other)(pred.asInstanceOf[Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, Required, (Row, Row2)]]) + + /** left join with the given predicate + * {{{ + * val leftJoined = productRepo.select + * .join(projectModelRepo.select) + * .leftOn { case (p, pm) => p.productmodelid === pm.productmodelid } + * }}} + */ + def leftOn[N[_]: Nullability](pred: Joined[Fields, Fields2, Hidden] => SqlExpr[Boolean, N, Hidden]): SelectBuilder[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])] = + leftJoinOn(other)(pred.asInstanceOf[Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)]]) + + /** Variant of `leftOn` that requires the join predicate to not be nullable */ + def leftOnStrict(pred: Joined[Fields, Fields2, Hidden] => SqlExpr[Boolean, Required, Hidden]): SelectBuilder[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])] = + leftJoinOn(other)(pred.asInstanceOf[Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, Required, (Row, Row2)]]) + } + + protected def params: SelectParams[Fields, Row] + + protected def withParams(sqlParams: SelectParams[Fields, Row]): SelectBuilder[Fields, Row] + + protected def joinOn[Fields2[_], N[_]: Nullability, Row2](other: SelectBuilder[Fields2, Row2])( + pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)] + ): SelectBuilder[Joined[Fields, Fields2, *], (Row, Row2)] + + protected def leftJoinOn[Fields2[_], N[_]: Nullability, Row2](other: SelectBuilder[Fields2, Row2])( + pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)] + ): SelectBuilder[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])] +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderMock.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderMock.scala new file mode 100644 index 0000000000..f47ba64df1 --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderMock.scala @@ -0,0 +1,65 @@ +package typo.dsl + +import zio.{Chunk, ZIO} +import zio.jdbc.* + +final case class SelectBuilderMock[Fields[_], Row]( + structure: Structure[Fields, Row], + all: ZIO[ZConnection, Throwable, Chunk[Row]], + params: SelectParams[Fields, Row] +) extends SelectBuilder[Fields, Row] { + override def withParams(sqlParams: SelectParams[Fields, Row]): SelectBuilder[Fields, Row] = + copy(params = params) + + override def toChunk: ZIO[ZConnection, Throwable, Chunk[Row]] = + all.map(all => SelectParams.applyParams(structure.fields, all, params)) + + override def joinOn[Fields2[_], N[_]: Nullability, Row2]( + other: SelectBuilder[Fields2, Row2] + )(pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)]): SelectBuilder[Joined[Fields, Fields2, *], (Row, Row2)] = { + def otherMock: SelectBuilderMock[Fields2, Row2] = other match { + case x: SelectBuilderMock[Fields2, Row2] => x + case _ => sys.error("you cannot mix mock and sql repos") + } + + val newStructure = structure.join(otherMock.structure) + + val newRows: ZIO[ZConnection, Throwable, Chunk[(Row, Row2)]] = + for { + lefts <- this.toChunk + rights <- otherMock.toChunk + } yield for { + left <- lefts + right <- rights + newRow = (left, right) + if Nullability[N].toOpt(pred(newStructure.fields).eval(newRow)).getOrElse(false) + } yield newRow + + SelectBuilderMock[Joined[Fields, Fields2, *], (Row, Row2)](newStructure, newRows, SelectParams.empty) + } + override def leftJoinOn[Fields2[_], N[_]: Nullability, Row2](other: SelectBuilder[Fields2, Row2])( + pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)] + ): SelectBuilder[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])] = { + def otherMock: SelectBuilderMock[Fields2, Row2] = other match { + case x: SelectBuilderMock[Fields2, Row2] => x + case _ => sys.error("you cannot mix mock and sql repos") + } + + val newRows: ZIO[ZConnection, Throwable, Chunk[(Row, Option[Row2])]] = { + for { + lefts <- this.toChunk + rights <- otherMock.toChunk + } yield { + lefts.map { left => + val maybeRight = rights.find { right => + Nullability[N].toOpt(pred(structure.join(otherMock.structure).fields).eval((left, right))).getOrElse(false) + } + (left, maybeRight) + } + } + } + SelectBuilderMock[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])](structure.leftJoin(otherMock.structure), newRows, SelectParams.empty) + } + + override def sql: Option[SqlFragment] = None +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderSql.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderSql.scala new file mode 100644 index 0000000000..c29f254e8e --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectBuilderSql.scala @@ -0,0 +1,212 @@ +package typo.dsl + +import zio.jdbc.* +import extensions.* +import zio.{Chunk, NonEmptyChunk, ZIO} + +import java.util.concurrent.atomic.AtomicInteger + +sealed trait SelectBuilderSql[Fields[_], Row] extends SelectBuilder[Fields, Row] { + def instantiate(counter: AtomicInteger): SelectBuilderSql.Instantiated[Fields, Row] + def sqlFor(counter: AtomicInteger): Query[Row] + + override def sql: Option[SqlFragment] = Some(sqlFor(new AtomicInteger(0)).sql) + + final override def joinOn[Fields2[_], N[_]: Nullability, Row2](other: SelectBuilder[Fields2, Row2])( + pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)] + ): SelectBuilder[Joined[Fields, Fields2, *], (Row, Row2)] = + other match { + case otherSql: SelectBuilderSql[Fields2, Row2] => + new SelectBuilderSql.TableJoin[Fields, Fields2, N, Row, Row2](this, otherSql, pred, SelectParams.empty) + case _ => + sys.error("you cannot mix mock and sql repos") + } + + final override def leftJoinOn[Fields2[_], N[_]: Nullability, Row2](other: SelectBuilder[Fields2, Row2])( + pred: Joined[Fields, Fields2, (Row, Row2)] => SqlExpr[Boolean, N, (Row, Row2)] + ): SelectBuilder[LeftJoined[Fields, Fields2, *], (Row, Option[Row2])] = + other match { + case otherSql: SelectBuilderSql[Fields2, Row2] => + SelectBuilderSql.TableLeftJoin(this, otherSql, pred, SelectParams.empty) + case _ => + sys.error("you cannot mix mock and sql repos") + } + + final override def toChunk: ZIO[ZConnection, Throwable, Chunk[Row]] = + sqlFor(new AtomicInteger(0)).selectAll +} + +object SelectBuilderSql { + def apply[Fields[_], OriginalRow, Row]( + name: String, + structure: Structure.Relation[Fields, OriginalRow, Row], + read: JdbcDecoder[Row] + ): SelectBuilderSql[Fields, Row] = + Relation(name, structure, read, SelectParams.empty) + + private final case class Relation[Fields[_], OriginalRow, Row]( + name: String, + structure: Structure.Relation[Fields, OriginalRow, Row], + read: JdbcDecoder[Row], + params: SelectParams[Fields, Row] + ) extends SelectBuilderSql[Fields, Row] { + override def withParams(sqlParams: SelectParams[Fields, Row]): SelectBuilder[Fields, Row] = + copy(params = sqlParams) + + private def sql(counter: AtomicInteger): SqlFragment = { + val cols = structure.columns + .map(x => SqlFragment(x.sqlReadCast.foldLeft("\"" + x.value + "\"") { case (acc, cast) => s"$acc::$cast" })) + .mkFragment(", ") + + val baseSql = sql"select $cols from ${SqlFragment(name)}" + SelectParams.render(structure.fields, baseSql, counter, params) + } + + override def sqlFor(counter: AtomicInteger): Query[Row] = + sql(counter).query[Row](read) + + override def instantiate(counter: AtomicInteger): SelectBuilderSql.Instantiated[Fields, Row] = { + val completeSql = sql(counter) + val alias = s"${name.split("\\.").last}${counter.incrementAndGet()}" + val prefixed = structure.withPrefix(alias) + val subquery = SelectBuilderSql.InstantiatedPart(alias, NonEmptyChunk.fromIterableOption(prefixed.columns).get, completeSql, joinFrag = SqlFragment.empty) + SelectBuilderSql.Instantiated(prefixed, NonEmptyChunk.single(subquery), read) + } + } + + private final case class TableJoin[Fields1[_], Fields2[_], N[_]: Nullability, Row1, Row2]( + left: SelectBuilderSql[Fields1, Row1], + right: SelectBuilderSql[Fields2, Row2], + pred: Joined[Fields1, Fields2, (Row1, Row2)] => SqlExpr[Boolean, N, (Row1, Row2)], + params: SelectParams[Joined[Fields1, Fields2, *], (Row1, Row2)] + ) extends SelectBuilderSql[Joined[Fields1, Fields2, *], (Row1, Row2)] { + + override def withParams(sqlParams: SelectParams[Joined[Fields1, Fields2, *], (Row1, Row2)]): SelectBuilder[Joined[Fields1, Fields2, *], (Row1, Row2)] = + copy(params = sqlParams) + + override def instantiate(counter: AtomicInteger): Instantiated[Joined[Fields1, Fields2, *], (Row1, Row2)] = { + val leftInstantiated = left.instantiate(counter) + val rightInstantiated = right.instantiate(counter) + val newStructure = leftInstantiated.structure.join(rightInstantiated.structure) + val newRightInstantiatedParts = rightInstantiated.parts + .mapLast(_.copy(joinFrag = pred(newStructure.fields).render(counter))) + + SelectBuilderSql.Instantiated( + structure = newStructure, + parts = leftInstantiated.parts ++ newRightInstantiatedParts, + decoder = JdbcDecoder.tuple2Decoder(leftInstantiated.decoder, rightInstantiated.decoder) + ) + } + override def sqlFor(paramCounter: AtomicInteger): Query[(Row1, Row2)] = { + val instance = instantiate(paramCounter) + val combinedFrag = { + val size = instance.parts.size + if (size == 1) instance.parts.head.sqlFrag + else { + val first = instance.parts.head + val rest = instance.parts.tail + + val prelude = + sql"""select ${instance.columns.map(c => SqlFragment(c.value)).mkFragment(", ")} + from ( + ${first.sqlFrag} + ) ${SqlFragment(first.alias)} + """ + + val joins = rest.map { case SelectBuilderSql.InstantiatedPart(alias, _, sqlFrag, joinFrag) => + sql"""join ( + $sqlFrag + ) ${SqlFragment(alias)} on $joinFrag + """ + } + + prelude ++ joins.reduce(_ ++ _) + } + } + val newCombinedFrag = SelectParams.render[(Row1, Row2), Joined[Fields1, Fields2, *]](instance.structure.fields, combinedFrag, paramCounter, params) + + newCombinedFrag.query(instance.decoder) + } + } + + private final case class TableLeftJoin[Fields1[_], Fields2[_], N[_]: Nullability, Row1, Row2]( + left: SelectBuilderSql[Fields1, Row1], + right: SelectBuilderSql[Fields2, Row2], + pred: Joined[Fields1, Fields2, (Row1, Row2)] => SqlExpr[Boolean, N, (Row1, Row2)], + params: SelectParams[LeftJoined[Fields1, Fields2, *], (Row1, Option[Row2])] + ) extends SelectBuilderSql[LeftJoined[Fields1, Fields2, *], (Row1, Option[Row2])] { + + override def withParams( + sqlParams: SelectParams[LeftJoined[Fields1, Fields2, *], (Row1, Option[Row2])] + ): SelectBuilder[LeftJoined[Fields1, Fields2, *], (Row1, Option[Row2])] = + copy(params = sqlParams) + + override def instantiate(counter: AtomicInteger): Instantiated[LeftJoined[Fields1, Fields2, *], (Row1, Option[Row2])] = { + val leftInstantiated = left.instantiate(counter) + val rightInstantiated = right.instantiate(counter) + val newStructure = leftInstantiated.structure.leftJoin(rightInstantiated.structure) + val newRightInstantiatedParts = rightInstantiated.parts + .mapLast(_.copy(joinFrag = pred(leftInstantiated.structure.join(rightInstantiated.structure).fields).render(counter))) + + SelectBuilderSql.Instantiated( + structure = newStructure, + parts = leftInstantiated.parts ++ newRightInstantiatedParts, + decoder = JdbcDecoder.tuple2Decoder(leftInstantiated.decoder, JdbcDecoder.optionDecoder(rightInstantiated.decoder)) + ) + } + + override def sqlFor(paramCounter: AtomicInteger): Query[(Row1, Option[Row2])] = { + val instance = instantiate(paramCounter) + val combinedFrag = { + val size = instance.parts.size + if (size == 1) instance.parts.head.sqlFrag + else { + val first = instance.parts.head + val rest = instance.parts.tail + + val prelude = + sql"""select ${instance.columns.map(c => SqlFragment(c.value)).mkFragment(", ")} + from ( + ${first.sqlFrag} + ) ${SqlFragment(first.alias)} + """ + + val joins = rest.map { case SelectBuilderSql.InstantiatedPart(alias, _, sqlFrag, joinFrag) => + sql"""left join ( + ${sqlFrag} + ) ${SqlFragment(alias)} on $joinFrag + """ + } + prelude ++ joins.reduce(_ ++ _) + } + } + val newCombinedFrag = + SelectParams.render[(Row1, Option[Row2]), LeftJoined[Fields1, Fields2, *]](instance.structure.fields, combinedFrag, paramCounter, params) + + newCombinedFrag.query(instance.decoder) + } + } + + implicit class ListMapLastOps[T](private val ts: NonEmptyChunk[T]) extends AnyVal { + def mapLast(f: T => T): NonEmptyChunk[T] = NonEmptyChunk.fromChunk(ts.updated(ts.length - 1, f(ts.last))).get // unsafe + } + + /** Need this intermediate data structure to generate aliases for tables (and prefixes for column selections) when we have a tree of joined tables. Need to start from the root after the user has + * constructed the tree + */ + final case class Instantiated[Fields[_], Row]( + structure: Structure[Fields, Row], + parts: NonEmptyChunk[SelectBuilderSql.InstantiatedPart], + decoder: JdbcDecoder[Row] + ) { + val columns: NonEmptyChunk[SqlExpr.FieldLikeNoHkt[?, ?]] = parts.flatMap(_.columns) + } + + /** This is needlessly awkward because the we start with a tree, but we need to make it linear to render it */ + final case class InstantiatedPart( + alias: String, + columns: NonEmptyChunk[SqlExpr.FieldLikeNoHkt[?, ?]], + sqlFrag: SqlFragment, + joinFrag: SqlFragment + ) +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectParams.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectParams.scala new file mode 100644 index 0000000000..e4acbd45fd --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SelectParams.scala @@ -0,0 +1,57 @@ +package typo.dsl + +import typo.dsl.extensions.NonEmptyChunkOps +import zio.jdbc.* +import zio.{Chunk, NonEmptyChunk} + +import java.util.concurrent.atomic.AtomicInteger + +final case class SelectParams[Fields[_], Row]( + where: List[Fields[Row] => SqlExpr[Boolean, Option, Row]], + orderBy: List[Fields[Row] => SortOrder[?, Row]], + offset: Option[Int], + limit: Option[Int] +) { + def where(v: Fields[Row] => SqlExpr[Boolean, Option, Row]): SelectParams[Fields, Row] = copy(where = where :+ v) + def orderBy(v: Fields[Row] => SortOrder[?, Row]): SelectParams[Fields, Row] = copy(orderBy = orderBy :+ v) + def offset(v: Int): SelectParams[Fields, Row] = copy(offset = Some(v)) + def limit(v: Int): SelectParams[Fields, Row] = copy(limit = Some(v)) +} + +object SelectParams { + def empty[Fields[_], Row]: SelectParams[Fields, Row] = + SelectParams[Fields, Row](List.empty, List.empty, None, None) + + def render[Row, Fields[_]](fields: Fields[Row], baseSql: SqlFragment, counter: AtomicInteger, params: SelectParams[Fields, Row]): SqlFragment = { + List[Option[SqlFragment]]( + Some(baseSql), + NonEmptyChunk.fromIterableOption(params.where.map(f => f(fields).render(counter))).map(fs => fs.mkFragment(" WHERE ", " AND ", "")), + NonEmptyChunk.fromIterableOption(params.orderBy.map(f => f(fields).render(counter))).map(fs => fs.mkFragment(" ORDER BY ", ", ", "")), + params.offset.map(value => sql" offset $value"), + params.limit.map(value => sql" limit $value") + ).flatten.reduce(_ ++ _) + } + + def applyParams[Fields[_], Row](fields: Fields[Row], rows: Chunk[Row], params: SelectParams[Fields, Row]): Chunk[Row] = { + // precompute filters and order bys for this row structure + val filters: List[SqlExpr[Boolean, Option, Row]] = + params.where.map(f => f(fields)) + val orderBys: List[SortOrder[?, Row]] = + params.orderBy.map(f => f(fields)) + + rows + .filter(row => filters.forall(_.eval(row).getOrElse(false))) + .sorted((row1: Row, row2: Row) => + orderBys.foldLeft(0) { + case (acc, so: SortOrder[t, Row]) if acc == 0 => + val t1: t = so.expr.eval(row1) + val t2: t = so.expr.eval(row2) + val ordering: Ordering[t] = if (so.ascending) so.ordering else so.ordering.reverse + ordering.compare(t1, t2) + case (acc, _) => acc + } + ) + .drop(params.offset.getOrElse(0)) + .take(params.limit.getOrElse(Int.MaxValue)) + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SortOrder.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SortOrder.scala new file mode 100644 index 0000000000..4138e4dac2 --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SortOrder.scala @@ -0,0 +1,18 @@ +package typo.dsl + +import zio.Chunk +import zio.jdbc.* +import extensions.FragmentOps +import java.util.concurrent.atomic.AtomicInteger + +// sort by a field +final case class SortOrder[NT, R](expr: SqlExpr.SqlExprNoHkt[NT, R], ascending: Boolean, nullsFirst: Boolean)(implicit val ordering: Ordering[NT]) { + def withNullsFirst: SortOrder[NT, R] = copy(nullsFirst = true)(ordering) + def render(counter: AtomicInteger): SqlFragment = { + Chunk( + expr.render(counter), + if (ascending) sql"ASC" else sql"DESC", + if (nullsFirst) sql"NULLS FIRST" else SqlFragment.empty + ).mkFragment(" ") + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/SqlExpr.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SqlExpr.scala new file mode 100644 index 0000000000..659e40cf1f --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/SqlExpr.scala @@ -0,0 +1,269 @@ +package typo.dsl + +import zio.jdbc.* + +import java.util.concurrent.atomic.AtomicInteger +import scala.reflect.ClassTag + +trait SqlExpr[T, N[_], R] extends SqlExpr.SqlExprNoHkt[N[T], R] { + final def isEqual[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + this === t + + final def isNotEqual[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + this !== t + + final def ===[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.eq, t, N) + + final def !==[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.neq, t, N) + + final def >[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.gt, t, N) + + final def >=[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.gte, t, N) + + final def <[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.lt, t, N) + + final def <=[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit O: Ordering[T], N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(this, SqlOperator.lte, t, N) + + final def or[N2[_], NC[_]](other: SqlExpr[T, N2, R])(implicit B: Bijection[T, Boolean], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.or[T], other, N) + + final def and[N2[_], NC[_]](other: SqlExpr[T, N2, R])(implicit B: Bijection[T, Boolean], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.and[T], other, N) + + def unary_!(implicit B: Bijection[T, Boolean], N: Nullability[N]): SqlExpr[T, N, R] = + SqlExpr.Not(this, B, N) + + final def +[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + plus(t) + final def plus[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.plus, t, N) + + final def -[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + sub(t) + final def sub[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.minus, t, N) + + final def *[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + mul(t) + final def mul[N2[_], NC[_]](t: SqlExpr[T, N2, R])(implicit Num: Numeric[T], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.mul, t, N) + + final def underlying[TT](implicit B: Bijection[T, TT], N: Nullability[N]): SqlExpr[TT, N, R] = + SqlExpr.Underlying(this, B, N) + + final def like(str: String)(implicit B: Bijection[T, String], N: Nullability[N]): SqlExpr[Boolean, N, R] = + SqlExpr.Binary(this, SqlOperator.like, SqlExpr.asConstRequired(str), N.withRequired) + + final def ||[N2[_], NC[_]](other: SqlExpr[T, N2, R])(implicit B: Bijection[T, String], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + stringAppend(other) + final def stringAppend[N2[_], NC[_]](other: SqlExpr[T, N2, R])(implicit B: Bijection[T, String], N: Nullability2[N, N2, NC]): SqlExpr[T, NC, R] = + SqlExpr.Binary(this, SqlOperator.strAdd, other, N) + + final def lower(implicit B: Bijection[T, String], N: Nullability[N]): SqlExpr[T, N, R] = + SqlExpr.Apply1(SqlFunction1.lower, this, N) + + final def reverse(implicit B: Bijection[T, String], N: Nullability[N]): SqlExpr[T, N, R] = + SqlExpr.Apply1(SqlFunction1.reverse, this, N) + + final def upper(implicit B: Bijection[T, String], N: Nullability[N]): SqlExpr[T, N, R] = + SqlExpr.Apply1(SqlFunction1.upper, this, N) + + final def strpos[N2[_], NC[_]](substring: SqlExpr[String, N2, R])(implicit B: Bijection[T, String], N: Nullability2[N, N2, NC]): SqlExpr[Int, NC, R] = + SqlExpr.Apply2(SqlFunction2.strpos, this, substring, N) + + final def strLength(implicit B: Bijection[T, String], N: Nullability[N]): SqlExpr[Int, N, R] = + SqlExpr.Apply1(SqlFunction1.length, this, N) + + final def substring[N2[_], N3[_], NC[_]](from: SqlExpr[Int, N2, R], count: SqlExpr[Int, N3, R])(implicit + B: Bijection[T, String], + N: Nullability3[N, N2, N3, NC] + ): SqlExpr[T, NC, R] = + SqlExpr.Apply3(SqlFunction3.substring[T](), this, from, count, N) + + final def in(ts: Array[T])(implicit ev: JdbcEncoder[Array[T]], N: Nullability[N]): SqlExpr[Boolean, N, R] = + SqlExpr.In(this, ts, ev, N) + + final def ?(implicit N: Nullability[N]): SqlExpr[T, Option, R] = opt + final def opt(implicit N: Nullability[N]): SqlExpr[T, Option, R] = SqlExpr.ToNullable(this, N) +} + +object SqlExpr { + trait SqlExprNoHkt[NT, R] { + def eval(row: R): NT + + def render(counter: AtomicInteger): SqlFragment + } + + sealed trait FieldLikeNoHkt[NT, Row] extends SqlExprNoHkt[NT, Row] { + private[typo] val prefix: Option[String] + private[typo] val name: String + private[typo] val get: Row => NT + private[typo] val set: (Row, NT) => Row + private[typo] val sqlReadCast: Option[String] + private[typo] val sqlWriteCast: Option[String] + + final def value: String = prefix.fold("")(_ + ".") + name + } + + sealed trait FieldLikeNotIdNoHkt[NT, R] extends FieldLikeNoHkt[NT, R] + + sealed abstract class FieldLike[T, N[_], R](val prefix: Option[String], val name: String, val sqlReadCast: Option[String], val sqlWriteCast: Option[String])( + val get: R => N[T], + val set: (R, N[T]) => R + ) extends SqlExpr[T, N, R] + with FieldLikeNoHkt[N[T], R] { + override def eval(row: R): N[T] = get(row) + override def render(counter: AtomicInteger): SqlFragment = SqlFragment(value) + } + + sealed trait FieldLikeNotId[T, N[_], R] extends FieldLike[T, N, R] with FieldLikeNotIdNoHkt[N[T], R] + + // connect a field `name` to a type `T` for a relation `R` + class Field[T, R](prefix: Option[String], name: String, sqlReadCast: Option[String] = None, sqlWriteCast: Option[String] = None)(get: R => T, set: (R, T) => R) + extends FieldLike[T, Required, R](prefix, name, sqlReadCast, sqlWriteCast)(get, set) + with FieldLikeNotId[T, Required, R] + + class IdField[T, R](prefix: Option[String], name: String, sqlReadCast: Option[String] = None, sqlWriteCast: Option[String] = None)(get: R => T, set: (R, T) => R) + extends FieldLike[T, Required, R](prefix, name, sqlReadCast, sqlWriteCast)(get, set) + + class OptField[T, R](prefix: Option[String], name: String, sqlReadCast: Option[String] = None, sqlWriteCast: Option[String] = None)(get: R => Option[T], set: (R, Option[T]) => R) + extends FieldLike[T, Option, R](prefix, name, sqlReadCast, sqlWriteCast)(get, set) + with FieldLikeNotId[T, Option, R] + + final case class Const[T, N[_], R](value: N[T], E: JdbcEncoder[N[T]], P: ParameterMetaData[T]) extends SqlExpr[T, N, R] { + override def eval(row: R): N[T] = value + + override def render(counter: AtomicInteger): SqlFragment = sql"${E.encode(value)}" ++ s"::${P.sqlType}" + } + + final case class ArrayIndex[T, N1[_], N2[_], R](arr: SqlExpr[Array[T], N1, R], idx: SqlExpr[Int, N2, R], N: Nullability2[N1, N2, Option]) extends SqlExpr[T, Option, R] { + override def eval(row: R): Option[T] = { + N.mapN(arr.eval(row), idx.eval(row)) { (arr, idx) => + if (idx < 0 || idx >= arr.length) None + else Some(arr(idx)) + }.flatten + } + + override def render(counter: AtomicInteger): SqlFragment = + sql"${arr.render(counter)}[${idx.render(counter)}]" + } + + final case class Apply1[T1, O, N[_], R](f: SqlFunction1[T1, O], arg1: SqlExpr[T1, N, R], N: Nullability[N]) extends SqlExpr[O, N, R] { + override def eval(row: R): N[O] = + N.mapN(arg1.eval(row))(f.eval) + override def render(counter: AtomicInteger): SqlFragment = + sql"${SqlFragment(f.name)}(${arg1.render(counter)})" + } + + final case class Apply2[T1, T2, O, N1[_], N2[_], N[_], R](f: SqlFunction2[T1, T2, O], arg1: SqlExpr[T1, N1, R], arg2: SqlExpr[T2, N2, R], N: Nullability2[N1, N2, N]) extends SqlExpr[O, N, R] { + override def eval(row: R): N[O] = + N.mapN(arg1.eval(row), arg2.eval(row))(f.eval) + override def render(counter: AtomicInteger): SqlFragment = + sql"${SqlFragment(f.name)}(${arg1.render(counter)}, ${arg2.render(counter)})" + } + + final case class Apply3[T1, T2, T3, N1[_], N2[_], N3[_], N[_], O, R]( + f: SqlFunction3[T1, T2, T3, O], + arg1: SqlExpr[T1, N1, R], + arg2: SqlExpr[T2, N2, R], + arg3: SqlExpr[T3, N3, R], + N: Nullability3[N1, N2, N3, N] + ) extends SqlExpr[O, N, R] { + override def eval(row: R): N[O] = + N.mapN(arg1.eval(row), arg2.eval(row), arg3.eval(row))(f.eval) + override def render(counter: AtomicInteger): SqlFragment = + sql"${SqlFragment(f.name)}(${arg1.render(counter)}, ${arg2.render(counter)}, ${arg3.render(counter)})" + } + + final case class Binary[T1, T2, O, N1[_], N2[_], N[_], R](left: SqlExpr[T1, N1, R], op: SqlOperator[T1, T2, O], right: SqlExpr[T2, N2, R], N: Nullability2[N1, N2, N]) extends SqlExpr[O, N, R] { + override def eval(row: R): N[O] = + N.mapN(left.eval(row), right.eval(row))(op.eval) + override def render(counter: AtomicInteger): SqlFragment = + sql"${left.render(counter)} ${SqlFragment(op.name)} ${right.render(counter)}" + } + + final case class Underlying[T, TT, N[_], R](expr: SqlExpr[T, N, R], bijection: Bijection[T, TT], N: Nullability[N]) extends SqlExpr[TT, N, R] { + override def eval(row: R): N[TT] = + N.mapN(expr.eval(row))(bijection.underlying) + override def render(counter: AtomicInteger): SqlFragment = + expr.render(counter) + } + + final case class Coalesce[T, R](expr: SqlExpr[T, Option, R], getOrElse: SqlExpr[T, Required, R]) extends SqlExpr[T, Required, R] { + override def eval(row: R): T = + expr.eval(row).getOrElse(getOrElse.eval(row)) + override def render(counter: AtomicInteger): SqlFragment = + sql"coalesce(${expr.render(counter)}, ${getOrElse.render(counter)})" + } + + final case class In[T, N[_], R](expr: SqlExpr[T, N, R], values: Array[T], ev: JdbcEncoder[Array[T]], N: Nullability[N]) extends SqlExpr[Boolean, N, R] { + override def eval(row: R): N[Boolean] = + N.mapN(expr.eval(row))(values.contains) + + override def render(counter: AtomicInteger): SqlFragment = + sql"${expr.render(counter)} = ANY(${ev.encode(values)})" + } + + final case class IsNull[T, R](expr: SqlExpr[T, Option, R]) extends SqlExpr[Boolean, Required, R] { + override def eval(row: R): Boolean = + expr.eval(row).isEmpty + override def render(counter: AtomicInteger): SqlFragment = + sql"${expr.render(counter)} IS NULL" + } + + final case class Not[T, N[_], R](expr: SqlExpr[T, N, R], B: Bijection[T, Boolean], N: Nullability[N]) extends SqlExpr[T, N, R] { + override def eval(row: R): N[T] = + N.mapN(expr.eval(row))(t => B.map(t)(b => !b)) + + override def render(counter: AtomicInteger): SqlFragment = + sql"NOT ${expr.render(counter)}" + } + + final case class ToNullable[T, R, N1[_]](expr: SqlExpr[T, N1, R], N: Nullability[N1]) extends SqlExpr[T, Option, R] { + override def eval(row: R): Option[T] = + N.toOpt(expr.eval(row)) + override def render(counter: AtomicInteger): SqlFragment = + expr.render(counter) + } + + // automatically put values in a constant expression + implicit def asConstOpt[T, R](t: Option[T])(implicit E: JdbcEncoder[Option[T]], P: ParameterMetaData[T]): SqlExpr[T, Option, R] = + Const(t, E, P) + + implicit def asConstRequired[T: JdbcEncoder: ParameterMetaData, R](t: T): SqlExpr[T, Required, R] = + Const[T, Required, R](t, implicitly, implicitly) + + // some syntax to construct field sort order + implicit class SqlExprSortSyntax[NT, R](private val expr: SqlExprNoHkt[NT, R]) extends AnyVal { + def asc(implicit O: Ordering[NT]): SortOrder[NT, R] = SortOrder(expr, ascending = true, nullsFirst = false) + def desc(implicit O: Ordering[NT]): SortOrder[NT, R] = SortOrder(expr, ascending = false, nullsFirst = false) + } + + implicit class SqlExprArraySyntax[T, N[_], R](private val expr: SqlExpr[Array[T], N, R]) extends AnyVal { + + /** look up an element in an array at index `idx` */ + def arrayIndex[N2[_]](idx: SqlExpr[Int, N2, R])(implicit N: Nullability2[N, N2, Option]): SqlExpr[T, Option, R] = + SqlExpr.ArrayIndex[T, N, N2, R](expr, idx, N) + + /** concatenate two arrays */ + def arrayConcat[N2[_], NC[_]](other: SqlExpr[Array[T], N2, R])(implicit C: ClassTag[T], N: Nullability2[N, N2, NC]): SqlExpr[Array[T], NC, R] = + SqlExpr.Binary(expr, SqlOperator.arrayConcat, other, N) + + /** does arrays have elements in common */ + def arrayOverlaps[N2[_], NC[_]](other: SqlExpr[Array[T], N2, R])(implicit N: Nullability2[N, N2, NC]): SqlExpr[Boolean, NC, R] = + SqlExpr.Binary(expr, SqlOperator.arrayOverlaps[Array[T], T], other, N) + } + + implicit class SqlExprOptionalSyntax[T, R](private val expr: SqlExpr[T, Option, R]) extends AnyVal { + def isNull: SqlExpr[Boolean, Required, R] = + SqlExpr.IsNull(expr) + def coalesce(orElse: SqlExpr[T, Required, R]): SqlExpr[T, Required, R] = + SqlExpr.Coalesce(expr, orElse) + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/UpdateBuilder.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/UpdateBuilder.scala new file mode 100644 index 0000000000..81d87d8fa0 --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/UpdateBuilder.scala @@ -0,0 +1,112 @@ +package typo.dsl + +import typo.dsl.extensions.* +import zio.jdbc.* +import zio.{Chunk, NonEmptyChunk, ZIO} + +import java.util.concurrent.atomic.AtomicInteger + +trait UpdateBuilder[Fields[_], Row] { + protected def params: UpdateParams[Fields, Row] + protected def withParams(sqlParams: UpdateParams[Fields, Row]): UpdateBuilder[Fields, Row] + + final def whereStrict(v: Fields[Row] => SqlExpr[Boolean, Required, Row]): UpdateBuilder[Fields, Row] = + withParams(params.where(v)) + + final def where[N[_]: Nullability](v: Fields[Row] => SqlExpr[Boolean, N, Row]): UpdateBuilder[Fields, Row] = + withParams(params.where(f => v(f).?.coalesce(false))) + + final def setValue[N[_], T](col: Fields[Row] => SqlExpr.FieldLikeNotId[T, N, Row])(value: N[T])(implicit E: JdbcEncoder[N[T]], P: ParameterMetaData[T]): UpdateBuilder[Fields, Row] = + withParams(params.set(col, _ => SqlExpr.Const[T, N, Row](value, E, P))) + + final def setComputedValue[T, N[_]](col: Fields[Row] => SqlExpr.FieldLikeNotId[T, N, Row])(value: SqlExpr.FieldLikeNotId[T, N, Row] => SqlExpr[T, N, Row]): UpdateBuilder[Fields, Row] = + withParams(params.set(col, fields => value(col(fields)))) + + final def setComputedValueFromRow[T, N[_]](col: Fields[Row] => SqlExpr.FieldLikeNotId[T, N, Row])(value: Fields[Row] => SqlExpr[T, N, Row]): UpdateBuilder[Fields, Row] = + withParams(params.set(col, value)) + + def sql(returning: Boolean): Option[SqlFragment] + def execute: ZIO[ZConnection, Throwable, Long] + def executeReturnChanged: ZIO[ZConnection, Throwable, Chunk[Row]] +} + +object UpdateBuilder { + def apply[Fields[_], Row](name: String, structure: Structure.Relation[Fields, ?, Row], rowParser: JdbcDecoder[Row]): UpdateBuilderSql[Fields, Row] = + UpdateBuilderSql(name, structure, rowParser, UpdateParams.empty) + + final case class UpdateBuilderSql[Fields[_], Row]( + name: String, + structure: Structure.Relation[Fields, ?, Row], + decoder: JdbcDecoder[Row], + params: UpdateParams[Fields, Row] + ) extends UpdateBuilder[Fields, Row] { + override def withParams(params: UpdateParams[Fields, Row]): UpdateBuilder[Fields, Row] = + copy(params = params) + + def mkSql(counter: AtomicInteger, returning: Boolean): SqlFragment = { + Chunk[Option[SqlFragment]]( + Some(SqlFragment.update(name)), + NonEmptyChunk.fromIterableOption(params.setters) match { + case None => + sys.error("you must specify a columns to set. use `set` method") + case Some(setters) => + val setFragments = setters + .map { setter => + val fieldExpr = setter.col(structure.fields) + val valueExpr = setter.value(structure.fields) + sql"${fieldExpr.render(counter)} = ${valueExpr.render(counter)}${fieldExpr.sqlWriteCast.fold(SqlFragment.empty)(cast => SqlFragment(s"::$cast"))}" + } + .mkFragment(", ") + Some(sql"SET $setFragments") + }, + NonEmptyChunk.fromIterableOption(params.where).map { wheres => + sql"WHERE ${wheres.toChunk.map { where => where(structure.fields).render(counter) }.mkFragment(" AND ")} " + }, + if (returning) { + val colFragments = + structure.columns + .map { col => SqlFragment(col.sqlReadCast.foldLeft("\"" + col.value + "\"") { case (acc, cast) => s"$acc::$cast" }) } + .mkFragment(", ") + + Some(sql"returning $colFragments") + } else None + ).flatten.mkFragment(sql" ") + } + + override def sql(returning: Boolean): Option[SqlFragment] = { + Some(mkSql(new AtomicInteger(1), returning)) + } + + override def execute: ZIO[ZConnection, Throwable, Long] = + mkSql(new AtomicInteger(0), returning = false).update + + override def executeReturnChanged: ZIO[ZConnection, Throwable, Chunk[Row]] = { + mkSql(new AtomicInteger(0), returning = true).query[Row](decoder).selectAll + } + } + final case class UpdateBuilderMock[Id, Fields[_], Row]( + params: UpdateParams[Fields, Row], + fields: Fields[Row], + map: scala.collection.mutable.Map[Id, Row] + ) extends UpdateBuilder[Fields, Row] { + override def withParams(params: UpdateParams[Fields, Row]): UpdateBuilder[Fields, Row] = + copy(params = params) + + override def sql(returning: Boolean): Option[SqlFragment] = None + + override def execute: ZIO[ZConnection, Throwable, Long] = + executeReturnChanged.map(_.size.toLong) + + override def executeReturnChanged: ZIO[ZConnection, Throwable, Chunk[Row]] = ZIO.succeed { + val changed = Chunk.newBuilder[Row] + map.foreach { case (id, row) => + if (params.where.forall(w => w(fields).eval(row))) { + val newRow = params.setters.foldLeft(row) { case (row, set) => set.transform(fields, row) } + map.update(id, newRow) + changed += newRow + } + } + changed.result() + } + } +} diff --git a/typo-dsl-zio-jdbc/src/scala/typo/dsl/extensions.scala b/typo-dsl-zio-jdbc/src/scala/typo/dsl/extensions.scala new file mode 100644 index 0000000000..6ab0e9b793 --- /dev/null +++ b/typo-dsl-zio-jdbc/src/scala/typo/dsl/extensions.scala @@ -0,0 +1,21 @@ +package typo.dsl + +import zio.NonEmptyChunk +import zio.jdbc.SqlFragment + +object extensions { + implicit final class FragmentOps[I[t] <: Iterable[t]](private val fragments: I[SqlFragment]) extends AnyVal { + def mkFragment(sep: SqlFragment): SqlFragment = + SqlFragment.intersperse(sep, fragments) + + def mkFragment(start: SqlFragment, sep: SqlFragment, end: SqlFragment): SqlFragment = + start ++ SqlFragment.intersperse(sep, fragments) ++ end + } + + implicit final class NonEmptyChunkOps(private val fragments: NonEmptyChunk[SqlFragment]) extends AnyVal { + def mkFragment(sep: SqlFragment): SqlFragment = + fragments.toChunk.mkFragment(sep) + def mkFragment(start: SqlFragment, sep: SqlFragment, end: SqlFragment): SqlFragment = + fragments.toChunk.mkFragment(start, sep, end) + } +} diff --git a/typo-scripts/src/scala/scripts/CompileBenchmark.scala b/typo-scripts/src/scala/scripts/CompileBenchmark.scala index 6fb8479f18..f39585da4b 100644 --- a/typo-scripts/src/scala/scripts/CompileBenchmark.scala +++ b/typo-scripts/src/scala/scripts/CompileBenchmark.scala @@ -22,8 +22,10 @@ object CompileBenchmark extends BleepScript("CompileBenchmark") { val crossIds = List("jvm212", "jvm213", "jvm3").map(str => model.CrossId(str)) val variants = List( + (Some(DbLibName.ZioJdbc), Nil, "typo-tester-zio-jdbc"), (Some(DbLibName.Doobie), Nil, "typo-tester-doobie"), (Some(DbLibName.Anorm), Nil, "typo-tester-anorm"), + (None, List(JsonLibName.ZioJson), "typo-tester-zio-jdbc"), (None, List(JsonLibName.Circe), "typo-tester-doobie"), (None, List(JsonLibName.PlayJson), "typo-tester-anorm") ) diff --git a/typo-scripts/src/scala/scripts/GenHardcodedFiles.scala b/typo-scripts/src/scala/scripts/GenHardcodedFiles.scala index ad91d34d4b..93fb47fb35 100644 --- a/typo-scripts/src/scala/scripts/GenHardcodedFiles.scala +++ b/typo-scripts/src/scala/scripts/GenHardcodedFiles.scala @@ -131,6 +131,8 @@ object GenHardcodedFiles extends BleepCodegenScript("GenHardcodedFiles") { val (dbLib, jsonLib) = if (target.project.value.contains("doobie")) (DbLibName.Doobie, JsonLibName.Circe) + else if (target.project.value.contains("zio-jdbc")) + (DbLibName.ZioJdbc, JsonLibName.ZioJson) else (DbLibName.Anorm, JsonLibName.PlayJson) val domains = Nil diff --git a/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala b/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala index d8b8d6bcb7..fdd8627c54 100644 --- a/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala +++ b/typo-scripts/src/scala/scripts/GeneratedAdventureWorks.scala @@ -2,9 +2,9 @@ package scripts import bleep.logging.{Formatter, LogLevel, Loggers} import bleep.{FileWatching, LogPatterns, cli} +import typo.* import typo.internal.sqlfiles.readSqlFileDirectories import typo.internal.{FileSync, generate} -import typo.* import java.nio.file.Path import java.sql.{Connection, DriverManager} @@ -30,7 +30,8 @@ object GeneratedAdventureWorks { val variants = List( (DbLibName.Anorm, JsonLibName.PlayJson, "typo-tester-anorm", new AtomicReference(Map.empty[RelPath, sc.Code])), - (DbLibName.Doobie, JsonLibName.Circe, "typo-tester-doobie", new AtomicReference(Map.empty[RelPath, sc.Code])) + (DbLibName.Doobie, JsonLibName.Circe, "typo-tester-doobie", new AtomicReference(Map.empty[RelPath, sc.Code])), + (DbLibName.ZioJdbc, JsonLibName.ZioJson, "typo-tester-zio-jdbc", new AtomicReference(Map.empty[RelPath, sc.Code])) ) def go(): Unit = { diff --git a/typo-scripts/src/scala/scripts/projectsToPublish.scala b/typo-scripts/src/scala/scripts/projectsToPublish.scala index 553a4f7019..d956e01720 100644 --- a/typo-scripts/src/scala/scripts/projectsToPublish.scala +++ b/typo-scripts/src/scala/scripts/projectsToPublish.scala @@ -6,9 +6,10 @@ object projectsToPublish { // will publish these with dependencies def include(crossName: model.CrossProjectName): Boolean = crossName.name.value match { - case "typo" => true - case "typo-dsl-anorm" => true - case "typo-dsl-doobie" => true - case _ => false + case "typo" => true + case "typo-dsl-anorm" => true + case "typo-dsl-doobie" => true + case "typo-dsl-zio-jdbc" => true + case _ => false } } diff --git a/typo-tester-doobie/src/scala/adventureworks/production/product/ProductTest.scala b/typo-tester-doobie/src/scala/adventureworks/production/product/ProductTest.scala index 90561f1f94..a93494bb88 100644 --- a/typo-tester-doobie/src/scala/adventureworks/production/product/ProductTest.scala +++ b/typo-tester-doobie/src/scala/adventureworks/production/product/ProductTest.scala @@ -124,7 +124,7 @@ class ProductTest extends AnyFunSuite with TypeCheckedTripleEquals { _ <- delay(assert(updated.name === Name("MANf"))) _ <- delay(assert(updated.listprice === BigDecimal(2))) _ <- delay(assert(updated.reorderpoint === TypoShort(40))) - _ <- delay { + _ <- { val q = productRepo.select .where(p => !p.name.like("foo%")) .where(p => !(p.name.underlying || p.color).like("foo%")) @@ -136,7 +136,6 @@ class ProductTest extends AnyFunSuite with TypeCheckedTripleEquals { q.sql.foreach(f => println(f)) q.toList.map(list => list.foreach(println)) - } _ <- { val q = productRepo.select diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/Defaulted.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/Defaulted.scala new file mode 100644 index 0000000000..88cd9af6f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/Defaulted.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import scala.util.Success +import scala.util.Try +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.JsonError +import zio.json.internal.RetractReader +import zio.json.internal.Write + + +/** + * This signals a value where if you don't provide it, postgres will generate it for you + */ +sealed trait Defaulted[+T] + +object Defaulted { + case class Provided[T](value: T) extends Defaulted[T] + case object UseDefault extends Defaulted[Nothing] + implicit def jsonDecoder[T](implicit T: JsonDecoder[T]): JsonDecoder[Defaulted[T]] = new JsonDecoder[Defaulted[T]] { + override def unsafeDecode(trace: List[JsonError], in: RetractReader): Defaulted[T] = + Try(JsonDecoder.string.unsafeDecode(trace, in)) match { + case Success("defaulted") => UseDefault + case _ => Provided(T.unsafeDecode(trace, in)) + } + } + implicit def jsonEncoder[T](implicit T: JsonEncoder[T]): JsonEncoder[Defaulted[T]] = new JsonEncoder[Defaulted[T]] { + override def unsafeEncode(a: Defaulted[T], indent: Option[Int], out: Write): Unit = + a match { + case Provided(value) => + out.write("{") + out.write("\"provided\":") + T.unsafeEncode(value, None, out) + out.write("}") + case UseDefault => out.write("\"defaulted\"") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAclItem.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAclItem.scala new file mode 100644 index 0000000000..a317d0097c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAclItem.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** aclitem (via PGObject) */ +case class TypoAclItem(value: String) + +object TypoAclItem { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoAclItem]] = JdbcDecoder[Array[TypoAclItem]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoAclItem(x.asInstanceOf[PGobject].getValue)) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoAclItem]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoAclItem]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "aclitem", + v.map { vv => + { + val obj = new PGobject + obj.setType("aclitem") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoAclItem, String] = Bijection[TypoAclItem, String](_.value)(TypoAclItem.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoAclItem] = JdbcDecoder[TypoAclItem]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoAclItem(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoAclItem] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoAclItem] = JsonDecoder.string.map(TypoAclItem.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoAclItem] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoAclItem] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoAclItem] = ParameterMetaData.instance[TypoAclItem]("aclitem", Types.OTHER) + implicit lazy val setter: Setter[TypoAclItem] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("aclitem") + obj.setValue(v.value) + obj + } + ) + }, + "aclitem" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAnyArray.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAnyArray.scala new file mode 100644 index 0000000000..c0e9ec3eb2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoAnyArray.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** anyarray (via PGObject) */ +case class TypoAnyArray(value: String) + +object TypoAnyArray { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoAnyArray]] = JdbcDecoder[Array[TypoAnyArray]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoAnyArray(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoAnyArray]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoAnyArray]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "anyarray", + v.map { vv => + { + val obj = new PGobject + obj.setType("anyarray") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoAnyArray, String] = Bijection[TypoAnyArray, String](_.value)(TypoAnyArray.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoAnyArray] = JdbcDecoder[TypoAnyArray]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoAnyArray(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoAnyArray] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoAnyArray] = JsonDecoder.string.map(TypoAnyArray.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoAnyArray] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoAnyArray] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoAnyArray] = ParameterMetaData.instance[TypoAnyArray]("anyarray", Types.OTHER) + implicit lazy val setter: Setter[TypoAnyArray] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("anyarray") + obj.setValue(v.value) + obj + } + ) + }, + "anyarray" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBox.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBox.scala new file mode 100644 index 0000000000..9be5dbdd10 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBox.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGbox +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** This represents the box datatype in PostgreSQL */ +case class TypoBox(x1: Double, y1: Double, x2: Double, y2: Double) + +object TypoBox { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoBox]] = JdbcDecoder[Array[TypoBox]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoBox(x.asInstanceOf[PGbox].point(0).x, x.asInstanceOf[PGbox].point(0).y, x.asInstanceOf[PGbox].point(1).x, x.asInstanceOf[PGbox].point(1).y)) + }, + "scala.Array[org.postgresql.geometric.PGbox]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoBox]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoBox]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "box", + v.map { vv => + new PGbox(vv.x1, vv.y1, vv.x2, vv.y2) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoBox] = JdbcDecoder[TypoBox]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoBox(v.asInstanceOf[PGbox].point(0).x, v.asInstanceOf[PGbox].point(0).y, v.asInstanceOf[PGbox].point(1).x, v.asInstanceOf[PGbox].point(1).y) + }, + "org.postgresql.geometric.PGbox" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoBox] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoBox] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val x1 = jsonObj.get("x1").toRight("Missing field 'x1'").flatMap(_.as(JsonDecoder.double)) + val y1 = jsonObj.get("y1").toRight("Missing field 'y1'").flatMap(_.as(JsonDecoder.double)) + val x2 = jsonObj.get("x2").toRight("Missing field 'x2'").flatMap(_.as(JsonDecoder.double)) + val y2 = jsonObj.get("y2").toRight("Missing field 'y2'").flatMap(_.as(JsonDecoder.double)) + if (x1.isRight && y1.isRight && x2.isRight && y2.isRight) + Right(TypoBox(x1 = x1.toOption.get, y1 = y1.toOption.get, x2 = x2.toOption.get, y2 = y2.toOption.get)) + else Left(List[Either[String, Any]](x1, y1, x2, y2).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoBox] = new JsonEncoder[TypoBox] { + override def unsafeEncode(a: TypoBox, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""x1":""") + JsonEncoder.double.unsafeEncode(a.x1, indent, out) + out.write(",") + out.write(""""y1":""") + JsonEncoder.double.unsafeEncode(a.y1, indent, out) + out.write(",") + out.write(""""x2":""") + JsonEncoder.double.unsafeEncode(a.x2, indent, out) + out.write(",") + out.write(""""y2":""") + JsonEncoder.double.unsafeEncode(a.y2, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[TypoBox] = Ordering.by(x => (x.x1, x.y1, x.x2, x.y2)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoBox] = ParameterMetaData.instance[TypoBox]("box", Types.OTHER) + implicit lazy val setter: Setter[TypoBox] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGbox(v.x1, v.y1, v.x2, v.y2) + ) + }, + "box" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBytea.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBytea.scala new file mode 100644 index 0000000000..64bae9e17c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoBytea.scala @@ -0,0 +1,45 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This represents the bytea datatype in PostgreSQL */ +case class TypoBytea(value: Array[Byte]) + +object TypoBytea { + implicit lazy val bijection: Bijection[TypoBytea, Array[Byte]] = Bijection[TypoBytea, Array[Byte]](_.value)(TypoBytea.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoBytea] = JdbcDecoder[TypoBytea]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoBytea(v.asInstanceOf[Array[Byte]]) + }, + "scala.Array[scala.Byte]" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoBytea] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoBytea] = JsonDecoder.array[Byte](JsonDecoder.byte, implicitly).map(TypoBytea.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoBytea] = JsonEncoder.array[Byte](JsonEncoder.byte, implicitly).contramap(_.value) + implicit def ordering(implicit O0: Ordering[Array[Byte]]): Ordering[TypoBytea] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoBytea] = ParameterMetaData.instance[TypoBytea]("bytea", Types.OTHER) + implicit lazy val setter: Setter[TypoBytea] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "bytea" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoCircle.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoCircle.scala new file mode 100644 index 0000000000..72800dc626 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoCircle.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGcircle +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** This represents circle datatype in PostgreSQL, consisting of a point and a radius */ +case class TypoCircle(center: TypoPoint, radius: Double) + +object TypoCircle { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoCircle]] = JdbcDecoder[Array[TypoCircle]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoCircle(TypoPoint(x.asInstanceOf[PGcircle].center.x, x.asInstanceOf[PGcircle].center.y), x.asInstanceOf[PGcircle].radius)) + }, + "scala.Array[org.postgresql.geometric.PGcircle]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoCircle]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoCircle]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "circle", + v.map { vv => + new PGcircle(vv.center.x, vv.center.y, vv.radius) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoCircle] = JdbcDecoder[TypoCircle]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoCircle(TypoPoint(v.asInstanceOf[PGcircle].center.x, v.asInstanceOf[PGcircle].center.y), v.asInstanceOf[PGcircle].radius) + }, + "org.postgresql.geometric.PGcircle" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoCircle] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoCircle] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val center = jsonObj.get("center").toRight("Missing field 'center'").flatMap(_.as(TypoPoint.jsonDecoder)) + val radius = jsonObj.get("radius").toRight("Missing field 'radius'").flatMap(_.as(JsonDecoder.double)) + if (center.isRight && radius.isRight) + Right(TypoCircle(center = center.toOption.get, radius = radius.toOption.get)) + else Left(List[Either[String, Any]](center, radius).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoCircle] = new JsonEncoder[TypoCircle] { + override def unsafeEncode(a: TypoCircle, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""center":""") + TypoPoint.jsonEncoder.unsafeEncode(a.center, indent, out) + out.write(",") + out.write(""""radius":""") + JsonEncoder.double.unsafeEncode(a.radius, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoPoint]): Ordering[TypoCircle] = Ordering.by(x => (x.center, x.radius)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoCircle] = ParameterMetaData.instance[TypoCircle]("circle", Types.OTHER) + implicit lazy val setter: Setter[TypoCircle] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGcircle(v.center.x, v.center.y, v.radius) + ) + }, + "circle" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoHStore.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoHStore.scala new file mode 100644 index 0000000000..96608cad5a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoHStore.scala @@ -0,0 +1,54 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.util.HashMap +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 + +/** The text representation of an hstore, used for input and output, includes zero or more key => value pairs separated by commas */ +case class TypoHStore(value: Map[String, String]) + +object TypoHStore { + implicit lazy val bijection: Bijection[TypoHStore, Map[String, String]] = Bijection[TypoHStore, Map[String, String]](_.value)(TypoHStore.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoHStore] = JdbcDecoder[TypoHStore]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else { + val b = Map.newBuilder[String, String] + v.asInstanceOf[java.util.Map[?, ?]].forEach { case (k, v) => b += k.asInstanceOf[String] -> v.asInstanceOf[String]} + TypoHStore(b.result()) + } + }, + "java.util.Map[java.lang.String, java.lang.String]" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoHStore] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoHStore] = JsonDecoder[Map[String, String]].map(TypoHStore.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoHStore] = JsonEncoder[Map[String, String]].contramap(_.value) + implicit def ordering(implicit O0: Ordering[Map[String, String]]): Ordering[TypoHStore] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoHStore] = ParameterMetaData.instance[TypoHStore]("hstore", Types.OTHER) + implicit lazy val setter: Setter[TypoHStore] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val b = new HashMap[String, String] + v.value.foreach { case (k, v) => b.put(k, v)} + b + } + ) + }, + "hstore" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInet.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInet.scala new file mode 100644 index 0000000000..d907dc85f3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInet.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** inet (via PGObject) */ +case class TypoInet(value: String) + +object TypoInet { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoInet]] = JdbcDecoder[Array[TypoInet]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoInet(x.asInstanceOf[PGobject].getValue)) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoInet]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoInet]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "inet", + v.map { vv => + { + val obj = new PGobject + obj.setType("inet") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoInet, String] = Bijection[TypoInet, String](_.value)(TypoInet.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoInet] = JdbcDecoder[TypoInet]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoInet(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoInet] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoInet] = JsonDecoder.string.map(TypoInet.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoInet] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoInet] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoInet] = ParameterMetaData.instance[TypoInet]("inet", Types.OTHER) + implicit lazy val setter: Setter[TypoInet] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("inet") + obj.setValue(v.value) + obj + } + ) + }, + "inet" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInstant.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInstant.scala new file mode 100644 index 0000000000..9559d8cf0f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInstant.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.time.Instant +import java.time.OffsetDateTime +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatterBuilder +import java.time.temporal.ChronoField +import java.time.temporal.ChronoUnit +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 + +/** This is `java.time.TypoInstant`, but with microsecond precision and transferred to and from postgres as strings. The reason is that postgres driver and db libs are broken */ +case class TypoInstant(value: Instant) + +object TypoInstant { + val parser: DateTimeFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).appendPattern("X").toFormatter + def apply(value: Instant): TypoInstant = new TypoInstant(value.truncatedTo(ChronoUnit.MICROS)) + def apply(str: String): TypoInstant = apply(OffsetDateTime.parse(str, parser).toInstant) + def now = TypoInstant(Instant.now) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoInstant]] = JdbcDecoder[Array[TypoInstant]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoInstant(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoInstant]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoInstant]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "timestamptz", + v.map { vv => + vv.value.toString + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoInstant, Instant] = Bijection[TypoInstant, Instant](_.value)(TypoInstant.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoInstant] = JdbcDecoder[TypoInstant]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoInstant(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoInstant] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoInstant] = JsonDecoder.instant.map(TypoInstant.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoInstant] = JsonEncoder.instant.contramap(_.value) + implicit def ordering(implicit O0: Ordering[Instant]): Ordering[TypoInstant] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoInstant] = ParameterMetaData.instance[TypoInstant]("timestamptz", Types.OTHER) + implicit lazy val setter: Setter[TypoInstant] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toString + ) + }, + "timestamptz" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInt2Vector.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInt2Vector.scala new file mode 100644 index 0000000000..5a140fbd09 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInt2Vector.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** int2vector (via PGObject). Valid syntax: `TypoInt2Vector("1 2 3") */ +case class TypoInt2Vector(value: String) + +object TypoInt2Vector { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoInt2Vector]] = JdbcDecoder[Array[TypoInt2Vector]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoInt2Vector(x.asInstanceOf[PGobject].getValue)) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoInt2Vector]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoInt2Vector]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "int2vector", + v.map { vv => + { + val obj = new PGobject + obj.setType("int2vector") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoInt2Vector, String] = Bijection[TypoInt2Vector, String](_.value)(TypoInt2Vector.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoInt2Vector] = JdbcDecoder[TypoInt2Vector]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoInt2Vector(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoInt2Vector] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoInt2Vector] = JsonDecoder.string.map(TypoInt2Vector.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoInt2Vector] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoInt2Vector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoInt2Vector] = ParameterMetaData.instance[TypoInt2Vector]("int2vector", Types.OTHER) + implicit lazy val setter: Setter[TypoInt2Vector] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("int2vector") + obj.setValue(v.value) + obj + } + ) + }, + "int2vector" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInterval.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInterval.scala new file mode 100644 index 0000000000..3bea173ed3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoInterval.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGInterval +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** Interval type in PostgreSQL */ +case class TypoInterval(years: Int, months: Int, days: Int, hours: Int, minutes: Int, seconds: Double) + +object TypoInterval { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoInterval]] = JdbcDecoder[Array[TypoInterval]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoInterval(x.asInstanceOf[PGInterval].getYears, x.asInstanceOf[PGInterval].getMonths, x.asInstanceOf[PGInterval].getDays, x.asInstanceOf[PGInterval].getHours, x.asInstanceOf[PGInterval].getMinutes, x.asInstanceOf[PGInterval].getSeconds)) + }, + "scala.Array[org.postgresql.util.PGInterval]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoInterval]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoInterval]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "interval", + v.map { vv => + new PGInterval(vv.years, vv.months, vv.days, vv.hours, vv.minutes, vv.seconds) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoInterval] = JdbcDecoder[TypoInterval]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoInterval(v.asInstanceOf[PGInterval].getYears, v.asInstanceOf[PGInterval].getMonths, v.asInstanceOf[PGInterval].getDays, v.asInstanceOf[PGInterval].getHours, v.asInstanceOf[PGInterval].getMinutes, v.asInstanceOf[PGInterval].getSeconds) + }, + "org.postgresql.util.PGInterval" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoInterval] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoInterval] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val years = jsonObj.get("years").toRight("Missing field 'years'").flatMap(_.as(JsonDecoder.int)) + val months = jsonObj.get("months").toRight("Missing field 'months'").flatMap(_.as(JsonDecoder.int)) + val days = jsonObj.get("days").toRight("Missing field 'days'").flatMap(_.as(JsonDecoder.int)) + val hours = jsonObj.get("hours").toRight("Missing field 'hours'").flatMap(_.as(JsonDecoder.int)) + val minutes = jsonObj.get("minutes").toRight("Missing field 'minutes'").flatMap(_.as(JsonDecoder.int)) + val seconds = jsonObj.get("seconds").toRight("Missing field 'seconds'").flatMap(_.as(JsonDecoder.double)) + if (years.isRight && months.isRight && days.isRight && hours.isRight && minutes.isRight && seconds.isRight) + Right(TypoInterval(years = years.toOption.get, months = months.toOption.get, days = days.toOption.get, hours = hours.toOption.get, minutes = minutes.toOption.get, seconds = seconds.toOption.get)) + else Left(List[Either[String, Any]](years, months, days, hours, minutes, seconds).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoInterval] = new JsonEncoder[TypoInterval] { + override def unsafeEncode(a: TypoInterval, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""years":""") + JsonEncoder.int.unsafeEncode(a.years, indent, out) + out.write(",") + out.write(""""months":""") + JsonEncoder.int.unsafeEncode(a.months, indent, out) + out.write(",") + out.write(""""days":""") + JsonEncoder.int.unsafeEncode(a.days, indent, out) + out.write(",") + out.write(""""hours":""") + JsonEncoder.int.unsafeEncode(a.hours, indent, out) + out.write(",") + out.write(""""minutes":""") + JsonEncoder.int.unsafeEncode(a.minutes, indent, out) + out.write(",") + out.write(""""seconds":""") + JsonEncoder.double.unsafeEncode(a.seconds, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[TypoInterval] = Ordering.by(x => (x.years, x.months, x.days, x.hours, x.minutes, x.seconds)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoInterval] = ParameterMetaData.instance[TypoInterval]("interval", Types.OTHER) + implicit lazy val setter: Setter[TypoInterval] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGInterval(v.years, v.months, v.days, v.hours, v.minutes, v.seconds) + ) + }, + "interval" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJson.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJson.scala new file mode 100644 index 0000000000..6f9342243d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJson.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** json (via PGObject) */ +case class TypoJson(value: String) + +object TypoJson { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoJson]] = JdbcDecoder[Array[TypoJson]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoJson(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoJson]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoJson]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "json", + v.map { vv => + { + val obj = new PGobject + obj.setType("json") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoJson, String] = Bijection[TypoJson, String](_.value)(TypoJson.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoJson] = JdbcDecoder[TypoJson]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoJson(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoJson] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoJson] = JsonDecoder.string.map(TypoJson.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoJson] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoJson] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoJson] = ParameterMetaData.instance[TypoJson]("json", Types.OTHER) + implicit lazy val setter: Setter[TypoJson] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("json") + obj.setValue(v.value) + obj + } + ) + }, + "json" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJsonb.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJsonb.scala new file mode 100644 index 0000000000..2a0a73eb9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoJsonb.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** jsonb (via PGObject) */ +case class TypoJsonb(value: String) + +object TypoJsonb { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoJsonb]] = JdbcDecoder[Array[TypoJsonb]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoJsonb(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoJsonb]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoJsonb]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "jsonb", + v.map { vv => + { + val obj = new PGobject + obj.setType("jsonb") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoJsonb, String] = Bijection[TypoJsonb, String](_.value)(TypoJsonb.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoJsonb] = JdbcDecoder[TypoJsonb]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoJsonb(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoJsonb] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoJsonb] = JsonDecoder.string.map(TypoJsonb.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoJsonb] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoJsonb] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoJsonb] = ParameterMetaData.instance[TypoJsonb]("jsonb", Types.OTHER) + implicit lazy val setter: Setter[TypoJsonb] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("jsonb") + obj.setValue(v.value) + obj + } + ) + }, + "jsonb" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLine.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLine.scala new file mode 100644 index 0000000000..238d244bed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLine.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGline +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** This implements a line represented by the linear equation Ax + By + C = 0 */ +case class TypoLine(a: Double, b: Double, c: Double) + +object TypoLine { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoLine]] = JdbcDecoder[Array[TypoLine]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoLine(x.asInstanceOf[PGline].a, x.asInstanceOf[PGline].b, x.asInstanceOf[PGline].c)) + }, + "scala.Array[org.postgresql.geometric.PGline]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoLine]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoLine]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "line", + v.map { vv => + new PGline(vv.a, vv.b, vv.c) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoLine] = JdbcDecoder[TypoLine]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoLine(v.asInstanceOf[PGline].a, v.asInstanceOf[PGline].b, v.asInstanceOf[PGline].c) + }, + "org.postgresql.geometric.PGline" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoLine] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoLine] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val a = jsonObj.get("a").toRight("Missing field 'a'").flatMap(_.as(JsonDecoder.double)) + val b = jsonObj.get("b").toRight("Missing field 'b'").flatMap(_.as(JsonDecoder.double)) + val c = jsonObj.get("c").toRight("Missing field 'c'").flatMap(_.as(JsonDecoder.double)) + if (a.isRight && b.isRight && c.isRight) + Right(TypoLine(a = a.toOption.get, b = b.toOption.get, c = c.toOption.get)) + else Left(List[Either[String, Any]](a, b, c).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoLine] = new JsonEncoder[TypoLine] { + override def unsafeEncode(a: TypoLine, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""a":""") + JsonEncoder.double.unsafeEncode(a.a, indent, out) + out.write(",") + out.write(""""b":""") + JsonEncoder.double.unsafeEncode(a.b, indent, out) + out.write(",") + out.write(""""c":""") + JsonEncoder.double.unsafeEncode(a.c, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[TypoLine] = Ordering.by(x => (x.a, x.b, x.c)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoLine] = ParameterMetaData.instance[TypoLine]("line", Types.OTHER) + implicit lazy val setter: Setter[TypoLine] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGline(v.a, v.b, v.c) + ) + }, + "line" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLineSegment.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLineSegment.scala new file mode 100644 index 0000000000..cfb0131da7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLineSegment.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGlseg +import org.postgresql.geometric.PGpoint +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** This implements a line represented by the linear equation Ax + By + C = 0 */ +case class TypoLineSegment(p1: TypoPoint, p2: TypoPoint) + +object TypoLineSegment { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoLineSegment]] = JdbcDecoder[Array[TypoLineSegment]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoLineSegment(TypoPoint(x.asInstanceOf[PGlseg].point(0).x, x.asInstanceOf[PGlseg].point(0).y), TypoPoint(x.asInstanceOf[PGlseg].point(1).x, x.asInstanceOf[PGlseg].point(1).y))) + }, + "scala.Array[org.postgresql.geometric.PGlseg]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoLineSegment]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoLineSegment]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "lseg", + v.map { vv => + new PGlseg(new PGpoint(vv.p1.x, vv.p1.y), new PGpoint(vv.p2.x, vv.p2.y)) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoLineSegment] = JdbcDecoder[TypoLineSegment]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoLineSegment(TypoPoint(v.asInstanceOf[PGlseg].point(0).x, v.asInstanceOf[PGlseg].point(0).y), TypoPoint(v.asInstanceOf[PGlseg].point(1).x, v.asInstanceOf[PGlseg].point(1).y)) + }, + "org.postgresql.geometric.PGlseg" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoLineSegment] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoLineSegment] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val p1 = jsonObj.get("p1").toRight("Missing field 'p1'").flatMap(_.as(TypoPoint.jsonDecoder)) + val p2 = jsonObj.get("p2").toRight("Missing field 'p2'").flatMap(_.as(TypoPoint.jsonDecoder)) + if (p1.isRight && p2.isRight) + Right(TypoLineSegment(p1 = p1.toOption.get, p2 = p2.toOption.get)) + else Left(List[Either[String, Any]](p1, p2).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoLineSegment] = new JsonEncoder[TypoLineSegment] { + override def unsafeEncode(a: TypoLineSegment, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""p1":""") + TypoPoint.jsonEncoder.unsafeEncode(a.p1, indent, out) + out.write(",") + out.write(""""p2":""") + TypoPoint.jsonEncoder.unsafeEncode(a.p2, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoPoint]): Ordering[TypoLineSegment] = Ordering.by(x => (x.p1, x.p2)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoLineSegment] = ParameterMetaData.instance[TypoLineSegment]("lseg", Types.OTHER) + implicit lazy val setter: Setter[TypoLineSegment] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGlseg(new PGpoint(v.p1.x, v.p1.y), new PGpoint(v.p2.x, v.p2.y)) + ) + }, + "lseg" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDate.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDate.scala new file mode 100644 index 0000000000..ec2fbd8eb4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDate.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.time.LocalDate +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 + +/** This is `java.time.LocalDate`, but transferred to and from postgres as strings. The reason is that postgres driver and db libs are broken */ +case class TypoLocalDate(value: LocalDate) + +object TypoLocalDate { + def now = TypoLocalDate(LocalDate.now) + def apply(str: String): TypoLocalDate = TypoLocalDate(LocalDate.parse(str)) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoLocalDate]] = JdbcDecoder[Array[TypoLocalDate]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoLocalDate(LocalDate.parse(x.asInstanceOf[String]))) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoLocalDate]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoLocalDate]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "date", + v.map { vv => + vv.value.toString + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoLocalDate, LocalDate] = Bijection[TypoLocalDate, LocalDate](_.value)(TypoLocalDate.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoLocalDate] = JdbcDecoder[TypoLocalDate]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoLocalDate(LocalDate.parse(v.asInstanceOf[String])) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoLocalDate] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoLocalDate] = JsonDecoder.localDate.map(TypoLocalDate.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoLocalDate] = JsonEncoder.localDate.contramap(_.value) + implicit def ordering(implicit O0: Ordering[LocalDate]): Ordering[TypoLocalDate] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoLocalDate] = ParameterMetaData.instance[TypoLocalDate]("date", Types.OTHER) + implicit lazy val setter: Setter[TypoLocalDate] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toString + ) + }, + "date" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDateTime.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDateTime.scala new file mode 100644 index 0000000000..8d96670d9e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalDateTime.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatterBuilder +import java.time.temporal.ChronoField +import java.time.temporal.ChronoUnit +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 + +/** This is `java.time.LocalDateTime`, but with microsecond precision and transferred to and from postgres as strings. The reason is that postgres driver and db libs are broken */ +case class TypoLocalDateTime(value: LocalDateTime) + +object TypoLocalDateTime { + val parser: DateTimeFormatter = new DateTimeFormatterBuilder().appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).toFormatter + def apply(value: LocalDateTime): TypoLocalDateTime = new TypoLocalDateTime(value.truncatedTo(ChronoUnit.MICROS)) + def apply(str: String): TypoLocalDateTime = apply(LocalDateTime.parse(str, parser)) + def now = TypoLocalDateTime(LocalDateTime.now) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoLocalDateTime]] = JdbcDecoder[Array[TypoLocalDateTime]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoLocalDateTime(LocalDateTime.parse(x.asInstanceOf[String], parser))) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoLocalDateTime]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoLocalDateTime]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "timestamp", + v.map { vv => + vv.value.toString + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoLocalDateTime, LocalDateTime] = Bijection[TypoLocalDateTime, LocalDateTime](_.value)(TypoLocalDateTime.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoLocalDateTime] = JdbcDecoder[TypoLocalDateTime]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoLocalDateTime(LocalDateTime.parse(v.asInstanceOf[String], parser)) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoLocalDateTime] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoLocalDateTime] = JsonDecoder.localDateTime.map(TypoLocalDateTime.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoLocalDateTime] = JsonEncoder.localDateTime.contramap(_.value) + implicit def ordering(implicit O0: Ordering[LocalDateTime]): Ordering[TypoLocalDateTime] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoLocalDateTime] = ParameterMetaData.instance[TypoLocalDateTime]("timestamp", Types.OTHER) + implicit lazy val setter: Setter[TypoLocalDateTime] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toString + ) + }, + "timestamp" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalTime.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalTime.scala new file mode 100644 index 0000000000..0c3a1ffb8a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoLocalTime.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.time.LocalTime +import java.time.temporal.ChronoUnit +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 + +/** This is `java.time.LocalTime`, but with microsecond precision and transferred to and from postgres as strings. The reason is that postgres driver and db libs are broken */ +case class TypoLocalTime(value: LocalTime) + +object TypoLocalTime { + def apply(value: LocalTime): TypoLocalTime = new TypoLocalTime(value.truncatedTo(ChronoUnit.MICROS)) + def apply(str: String): TypoLocalTime = apply(LocalTime.parse(str)) + def now: TypoLocalTime = TypoLocalTime(LocalTime.now) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoLocalTime]] = JdbcDecoder[Array[TypoLocalTime]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoLocalTime(LocalTime.parse(x.asInstanceOf[String]))) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoLocalTime]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoLocalTime]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "time", + v.map { vv => + vv.value.toString + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoLocalTime, LocalTime] = Bijection[TypoLocalTime, LocalTime](_.value)(TypoLocalTime.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoLocalTime] = JdbcDecoder[TypoLocalTime]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoLocalTime(LocalTime.parse(v.asInstanceOf[String])) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoLocalTime] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoLocalTime] = JsonDecoder.localTime.map(TypoLocalTime.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoLocalTime] = JsonEncoder.localTime.contramap(_.value) + implicit def ordering(implicit O0: Ordering[LocalTime]): Ordering[TypoLocalTime] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoLocalTime] = ParameterMetaData.instance[TypoLocalTime]("time", Types.OTHER) + implicit lazy val setter: Setter[TypoLocalTime] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toString + ) + }, + "time" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoMoney.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoMoney.scala new file mode 100644 index 0000000000..f37df33760 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoMoney.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** Money and cash types in PostgreSQL */ +case class TypoMoney(value: BigDecimal) + +object TypoMoney { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoMoney]] = JdbcDecoder[Array[TypoMoney]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoMoney(BigDecimal(x.asInstanceOf[java.math.BigDecimal]))) + }, + "scala.Array[java.math.BigDecimal]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoMoney]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoMoney]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "money", + v.map { vv => + vv.value.bigDecimal + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoMoney, BigDecimal] = Bijection[TypoMoney, BigDecimal](_.value)(TypoMoney.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoMoney] = JdbcDecoder[TypoMoney]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoMoney(BigDecimal(v.asInstanceOf[java.math.BigDecimal])) + }, + "java.math.BigDecimal" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoMoney] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoMoney] = JsonDecoder.scalaBigDecimal.map(TypoMoney.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoMoney] = JsonEncoder.scalaBigDecimal.contramap(_.value) + implicit lazy val ordering: Ordering[TypoMoney] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoMoney] = ParameterMetaData.instance[TypoMoney]("money", Types.OTHER) + implicit lazy val setter: Setter[TypoMoney] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.bigDecimal + ) + }, + "money" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOffsetTime.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOffsetTime.scala new file mode 100644 index 0000000000..8723ec9fd7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOffsetTime.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.time.OffsetTime +import java.time.format.DateTimeFormatter +import java.time.format.DateTimeFormatterBuilder +import java.time.temporal.ChronoField +import java.time.temporal.ChronoUnit +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 + +/** This is `java.time.OffsetTime`, but with microsecond precision and transferred to and from postgres as strings. The reason is that postgres driver and db libs are broken */ +case class TypoOffsetTime(value: OffsetTime) + +object TypoOffsetTime { + val parser: DateTimeFormatter = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss").appendFraction(ChronoField.MICRO_OF_SECOND, 0, 6, true).appendPattern("X").toFormatter + def apply(value: OffsetTime): TypoOffsetTime = new TypoOffsetTime(value.truncatedTo(ChronoUnit.MICROS)) + def apply(str: String): TypoOffsetTime = apply(OffsetTime.parse(str, parser)) + def now = TypoOffsetTime(OffsetTime.now) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoOffsetTime]] = JdbcDecoder[Array[TypoOffsetTime]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoOffsetTime(OffsetTime.parse(x.asInstanceOf[String], parser))) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoOffsetTime]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoOffsetTime]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "timetz", + v.map { vv => + vv.value.toString + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoOffsetTime, OffsetTime] = Bijection[TypoOffsetTime, OffsetTime](_.value)(TypoOffsetTime.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoOffsetTime] = JdbcDecoder[TypoOffsetTime]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoOffsetTime(OffsetTime.parse(v.asInstanceOf[String], parser)) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoOffsetTime] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoOffsetTime] = JsonDecoder.offsetTime.map(TypoOffsetTime.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoOffsetTime] = JsonEncoder.offsetTime.contramap(_.value) + implicit def ordering(implicit O0: Ordering[OffsetTime]): Ordering[TypoOffsetTime] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoOffsetTime] = ParameterMetaData.instance[TypoOffsetTime]("timetz", Types.OTHER) + implicit lazy val setter: Setter[TypoOffsetTime] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toString + ) + }, + "timetz" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOidVector.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOidVector.scala new file mode 100644 index 0000000000..410b4608c6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoOidVector.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** oidvector (via PGObject) */ +case class TypoOidVector(value: String) + +object TypoOidVector { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoOidVector]] = JdbcDecoder[Array[TypoOidVector]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoOidVector(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoOidVector]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoOidVector]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "oidvector", + v.map { vv => + { + val obj = new PGobject + obj.setType("oidvector") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoOidVector, String] = Bijection[TypoOidVector, String](_.value)(TypoOidVector.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoOidVector] = JdbcDecoder[TypoOidVector]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoOidVector(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoOidVector] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoOidVector] = JsonDecoder.string.map(TypoOidVector.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoOidVector] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoOidVector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoOidVector] = ParameterMetaData.instance[TypoOidVector]("oidvector", Types.OTHER) + implicit lazy val setter: Setter[TypoOidVector] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("oidvector") + obj.setValue(v.value) + obj + } + ) + }, + "oidvector" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPath.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPath.scala new file mode 100644 index 0000000000..5d1a745183 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPath.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGpath +import org.postgresql.geometric.PGpoint +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** This implements a path (a multiple segmented line, which may be closed) */ +case class TypoPath(open: Boolean, points: List[TypoPoint]) + +object TypoPath { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoPath]] = JdbcDecoder[Array[TypoPath]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoPath(x.asInstanceOf[PGpath].isOpen, x.asInstanceOf[PGpath].points.map(p => TypoPoint(p.x, p.y)).toList)) + }, + "scala.Array[org.postgresql.geometric.PGpath]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoPath]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoPath]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "path", + v.map { vv => + new PGpath(vv.points.map(p => new PGpoint(p.x, p.y)).toArray, vv.open) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoPath] = JdbcDecoder[TypoPath]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoPath(v.asInstanceOf[PGpath].isOpen, v.asInstanceOf[PGpath].points.map(p => TypoPoint(p.x, p.y)).toList) + }, + "org.postgresql.geometric.PGpath" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoPath] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoPath] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val open = jsonObj.get("open").toRight("Missing field 'open'").flatMap(_.as(JsonDecoder.boolean)) + val points = jsonObj.get("points").toRight("Missing field 'points'").flatMap(_.as(JsonDecoder[List[TypoPoint]])) + if (open.isRight && points.isRight) + Right(TypoPath(open = open.toOption.get, points = points.toOption.get)) + else Left(List[Either[String, Any]](open, points).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoPath] = new JsonEncoder[TypoPath] { + override def unsafeEncode(a: TypoPath, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""open":""") + JsonEncoder.boolean.unsafeEncode(a.open, indent, out) + out.write(",") + out.write(""""points":""") + JsonEncoder[List[TypoPoint]].unsafeEncode(a.points, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[List[TypoPoint]]): Ordering[TypoPath] = Ordering.by(x => (x.open, x.points)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoPath] = ParameterMetaData.instance[TypoPath]("path", Types.OTHER) + implicit lazy val setter: Setter[TypoPath] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGpath(v.points.map(p => new PGpoint(p.x, p.y)).toArray, v.open) + ) + }, + "path" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPgNodeTree.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPgNodeTree.scala new file mode 100644 index 0000000000..10444d870b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPgNodeTree.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** pg_node_tree (via PGObject) */ +case class TypoPgNodeTree(value: String) + +object TypoPgNodeTree { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoPgNodeTree]] = JdbcDecoder[Array[TypoPgNodeTree]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoPgNodeTree(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoPgNodeTree]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoPgNodeTree]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "pg_node_tree", + v.map { vv => + { + val obj = new PGobject + obj.setType("pg_node_tree") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoPgNodeTree, String] = Bijection[TypoPgNodeTree, String](_.value)(TypoPgNodeTree.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoPgNodeTree] = JdbcDecoder[TypoPgNodeTree]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoPgNodeTree(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoPgNodeTree] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoPgNodeTree] = JsonDecoder.string.map(TypoPgNodeTree.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoPgNodeTree] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoPgNodeTree] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoPgNodeTree] = ParameterMetaData.instance[TypoPgNodeTree]("pg_node_tree", Types.OTHER) + implicit lazy val setter: Setter[TypoPgNodeTree] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("pg_node_tree") + obj.setValue(v.value) + obj + } + ) + }, + "pg_node_tree" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPoint.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPoint.scala new file mode 100644 index 0000000000..296c929f25 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPoint.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGpoint +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 +import zio.json.ast.Json +import zio.json.internal.Write + +/** Point datatype in PostgreSQL */ +case class TypoPoint(x: Double, y: Double) + +object TypoPoint { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoPoint]] = JdbcDecoder[Array[TypoPoint]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoPoint(x.asInstanceOf[PGpoint].x, x.asInstanceOf[PGpoint].y)) + }, + "scala.Array[org.postgresql.geometric.PGpoint]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoPoint]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoPoint]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "point", + v.map { vv => + new PGpoint(vv.x, vv.y) + } + ) + ), + Types.ARRAY + ) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoPoint] = JdbcDecoder[TypoPoint]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoPoint(v.asInstanceOf[PGpoint].x, v.asInstanceOf[PGpoint].y) + }, + "org.postgresql.geometric.PGpoint" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoPoint] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoPoint] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val x = jsonObj.get("x").toRight("Missing field 'x'").flatMap(_.as(JsonDecoder.double)) + val y = jsonObj.get("y").toRight("Missing field 'y'").flatMap(_.as(JsonDecoder.double)) + if (x.isRight && y.isRight) + Right(TypoPoint(x = x.toOption.get, y = y.toOption.get)) + else Left(List[Either[String, Any]](x, y).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TypoPoint] = new JsonEncoder[TypoPoint] { + override def unsafeEncode(a: TypoPoint, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""x":""") + JsonEncoder.double.unsafeEncode(a.x, indent, out) + out.write(",") + out.write(""""y":""") + JsonEncoder.double.unsafeEncode(a.y, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[TypoPoint] = Ordering.by(x => (x.x, x.y)) + implicit lazy val parameterMetadata: ParameterMetaData[TypoPoint] = ParameterMetaData.instance[TypoPoint]("point", Types.OTHER) + implicit lazy val setter: Setter[TypoPoint] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGpoint(v.x, v.y) + ) + }, + "point" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPolygon.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPolygon.scala new file mode 100644 index 0000000000..439ec18158 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoPolygon.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.geometric.PGpoint +import org.postgresql.geometric.PGpolygon +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 + +/** Polygon datatype in PostgreSQL */ +case class TypoPolygon(points: List[TypoPoint]) + +object TypoPolygon { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoPolygon]] = JdbcDecoder[Array[TypoPolygon]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoPolygon(x.asInstanceOf[PGpolygon].points.map(p => TypoPoint(p.x, p.y)).toList)) + }, + "scala.Array[org.postgresql.geometric.PGpolygon]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoPolygon]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoPolygon]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "polygon", + v.map { vv => + new PGpolygon(vv.points.map(p => new PGpoint(p.x, p.y)).toArray) + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoPolygon, List[TypoPoint]] = Bijection[TypoPolygon, List[TypoPoint]](_.points)(TypoPolygon.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoPolygon] = JdbcDecoder[TypoPolygon]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoPolygon(v.asInstanceOf[PGpolygon].points.map(p => TypoPoint(p.x, p.y)).toList) + }, + "org.postgresql.geometric.PGpolygon" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoPolygon] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoPolygon] = JsonDecoder[List[TypoPoint]].map(TypoPolygon.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoPolygon] = JsonEncoder[List[TypoPoint]].contramap(_.points) + implicit def ordering(implicit O0: Ordering[List[TypoPoint]]): Ordering[TypoPolygon] = Ordering.by(_.points) + implicit lazy val parameterMetadata: ParameterMetaData[TypoPolygon] = ParameterMetaData.instance[TypoPolygon]("polygon", Types.OTHER) + implicit lazy val setter: Setter[TypoPolygon] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + new PGpolygon(v.points.map(p => new PGpoint(p.x, p.y)).toArray) + ) + }, + "polygon" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRecord.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRecord.scala new file mode 100644 index 0000000000..54b2da9880 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRecord.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** record (via PGObject) */ +case class TypoRecord(value: String) + +object TypoRecord { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoRecord]] = JdbcDecoder[Array[TypoRecord]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoRecord(x.asInstanceOf[PGobject].getValue)) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoRecord]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoRecord]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "record", + v.map { vv => + { + val obj = new PGobject + obj.setType("record") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoRecord, String] = Bijection[TypoRecord, String](_.value)(TypoRecord.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoRecord] = JdbcDecoder[TypoRecord]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoRecord(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoRecord] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoRecord] = JsonDecoder.string.map(TypoRecord.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoRecord] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoRecord] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoRecord] = ParameterMetaData.instance[TypoRecord]("record", Types.OTHER) + implicit lazy val setter: Setter[TypoRecord] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("record") + obj.setValue(v.value) + obj + } + ) + }, + "record" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegproc.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegproc.scala new file mode 100644 index 0000000000..860ac21644 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegproc.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** regproc (via PGObject) */ +case class TypoRegproc(value: String) + +object TypoRegproc { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoRegproc]] = JdbcDecoder[Array[TypoRegproc]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoRegproc(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoRegproc]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoRegproc]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "regproc", + v.map { vv => + { + val obj = new PGobject + obj.setType("regproc") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoRegproc, String] = Bijection[TypoRegproc, String](_.value)(TypoRegproc.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoRegproc] = JdbcDecoder[TypoRegproc]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoRegproc(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoRegproc] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoRegproc] = JsonDecoder.string.map(TypoRegproc.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoRegproc] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoRegproc] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoRegproc] = ParameterMetaData.instance[TypoRegproc]("regproc", Types.OTHER) + implicit lazy val setter: Setter[TypoRegproc] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("regproc") + obj.setValue(v.value) + obj + } + ) + }, + "regproc" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegtype.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegtype.scala new file mode 100644 index 0000000000..3c107465b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoRegtype.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** regtype (via PGObject) */ +case class TypoRegtype(value: String) + +object TypoRegtype { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoRegtype]] = JdbcDecoder[Array[TypoRegtype]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoRegtype(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoRegtype]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoRegtype]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "regtype", + v.map { vv => + { + val obj = new PGobject + obj.setType("regtype") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoRegtype, String] = Bijection[TypoRegtype, String](_.value)(TypoRegtype.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoRegtype] = JdbcDecoder[TypoRegtype]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoRegtype(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoRegtype] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoRegtype] = JsonDecoder.string.map(TypoRegtype.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoRegtype] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoRegtype] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoRegtype] = ParameterMetaData.instance[TypoRegtype]("regtype", Types.OTHER) + implicit lazy val setter: Setter[TypoRegtype] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("regtype") + obj.setValue(v.value) + obj + } + ) + }, + "regtype" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoShort.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoShort.scala new file mode 100644 index 0000000000..62661f8d02 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoShort.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import scala.math.Numeric +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 + +/** Short primitive */ +case class TypoShort(value: Short) + +object TypoShort { + implicit object numeric extends Numeric[TypoShort] { + override def compare(x: TypoShort, y: TypoShort): Int = java.lang.Short.compare(x.value, y.value) + override def plus(x: TypoShort, y: TypoShort): TypoShort = TypoShort((x.value + y.value).toShort) + override def minus(x: TypoShort, y: TypoShort): TypoShort = TypoShort((x.value - y.value).toShort) + override def times(x: TypoShort, y: TypoShort): TypoShort = TypoShort((x.value * y.value).toShort) + override def negate(x: TypoShort): TypoShort = TypoShort((-x.value).toShort) + override def fromInt(x: Int): TypoShort = TypoShort(x.toShort) + override def toInt(x: TypoShort): Int = x.toInt + override def toLong(x: TypoShort): Long = x.toLong + override def toFloat(x: TypoShort): Float = x.toFloat + override def toDouble(x: TypoShort): Double = x.toDouble + def parseString(str: String): Option[TypoShort] = (str, Option.empty[TypoShort])._2 // sorry mac, this was too much trouble to implement for 2.12 + } + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoShort]] = JdbcDecoder[Array[TypoShort]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoShort(x.asInstanceOf[java.lang.Short])) + }, + "scala.Array[java.lang.Integer]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoShort]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoShort]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "int2", + v.map { vv => + vv.value: java.lang.Short + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoShort, Short] = Bijection[TypoShort, Short](_.value)(TypoShort.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoShort] = JdbcDecoder[TypoShort]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoShort(v.asInstanceOf[Integer].toShort) + }, + "java.lang.Integer" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoShort] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoShort] = JsonDecoder[Short].map(TypoShort.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoShort] = JsonEncoder[Short].contramap(_.value) + implicit lazy val ordering: Ordering[TypoShort] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoShort] = ParameterMetaData.instance[TypoShort]("int2", Types.OTHER) + implicit lazy val setter: Setter[TypoShort] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.toInt + ) + }, + "int2" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUUID.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUUID.scala new file mode 100644 index 0000000000..7564c9cb59 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUUID.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import java.util.UUID +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 + +/** UUID */ +case class TypoUUID(value: UUID) + +object TypoUUID { + def apply(str: String): TypoUUID = TypoUUID(UUID.fromString(str)) + def randomUUID: TypoUUID = TypoUUID(UUID.randomUUID()) + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUUID]] = JdbcDecoder[Array[TypoUUID]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUUID(x.asInstanceOf[UUID])) + }, + "scala.Array[java.util.UUID]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUUID]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUUID]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "uuid", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUUID, UUID] = Bijection[TypoUUID, UUID](_.value)(TypoUUID.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUUID] = JdbcDecoder[TypoUUID]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUUID(v.asInstanceOf[UUID]) + }, + "java.util.UUID" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUUID] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUUID] = JsonDecoder.uuid.map(TypoUUID.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUUID] = JsonEncoder.uuid.contramap(_.value) + implicit def ordering(implicit O0: Ordering[UUID]): Ordering[TypoUUID] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUUID] = ParameterMetaData.instance[TypoUUID]("uuid", Types.OTHER) + implicit lazy val setter: Setter[TypoUUID] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "uuid" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownCitext.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownCitext.scala new file mode 100644 index 0000000000..dd7a68f0de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownCitext.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This is a type typo does not know how to handle yet. This falls back to casting to string and crossing fingers. Time to file an issue! :] */ +case class TypoUnknownCitext(value: String) + +object TypoUnknownCitext { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUnknownCitext]] = JdbcDecoder[Array[TypoUnknownCitext]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUnknownCitext(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUnknownCitext]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUnknownCitext]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "citext", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUnknownCitext, String] = Bijection[TypoUnknownCitext, String](_.value)(TypoUnknownCitext.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUnknownCitext] = JdbcDecoder[TypoUnknownCitext]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUnknownCitext(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUnknownCitext] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUnknownCitext] = JsonDecoder.string.map(TypoUnknownCitext.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUnknownCitext] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoUnknownCitext] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUnknownCitext] = ParameterMetaData.instance[TypoUnknownCitext]("citext", Types.OTHER) + implicit lazy val setter: Setter[TypoUnknownCitext] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "citext" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgDependencies.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgDependencies.scala new file mode 100644 index 0000000000..9ee8fb9ad0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgDependencies.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This is a type typo does not know how to handle yet. This falls back to casting to string and crossing fingers. Time to file an issue! :] */ +case class TypoUnknownPgDependencies(value: String) + +object TypoUnknownPgDependencies { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUnknownPgDependencies]] = JdbcDecoder[Array[TypoUnknownPgDependencies]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUnknownPgDependencies(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUnknownPgDependencies]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUnknownPgDependencies]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "pg_dependencies", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUnknownPgDependencies, String] = Bijection[TypoUnknownPgDependencies, String](_.value)(TypoUnknownPgDependencies.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUnknownPgDependencies] = JdbcDecoder[TypoUnknownPgDependencies]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUnknownPgDependencies(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUnknownPgDependencies] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUnknownPgDependencies] = JsonDecoder.string.map(TypoUnknownPgDependencies.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUnknownPgDependencies] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoUnknownPgDependencies] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUnknownPgDependencies] = ParameterMetaData.instance[TypoUnknownPgDependencies]("pg_dependencies", Types.OTHER) + implicit lazy val setter: Setter[TypoUnknownPgDependencies] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "pg_dependencies" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgMcvList.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgMcvList.scala new file mode 100644 index 0000000000..b442dbbf86 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgMcvList.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This is a type typo does not know how to handle yet. This falls back to casting to string and crossing fingers. Time to file an issue! :] */ +case class TypoUnknownPgMcvList(value: String) + +object TypoUnknownPgMcvList { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUnknownPgMcvList]] = JdbcDecoder[Array[TypoUnknownPgMcvList]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUnknownPgMcvList(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUnknownPgMcvList]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUnknownPgMcvList]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "pg_mcv_list", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUnknownPgMcvList, String] = Bijection[TypoUnknownPgMcvList, String](_.value)(TypoUnknownPgMcvList.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUnknownPgMcvList] = JdbcDecoder[TypoUnknownPgMcvList]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUnknownPgMcvList(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUnknownPgMcvList] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUnknownPgMcvList] = JsonDecoder.string.map(TypoUnknownPgMcvList.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUnknownPgMcvList] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoUnknownPgMcvList] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUnknownPgMcvList] = ParameterMetaData.instance[TypoUnknownPgMcvList]("pg_mcv_list", Types.OTHER) + implicit lazy val setter: Setter[TypoUnknownPgMcvList] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "pg_mcv_list" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgNdistinct.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgNdistinct.scala new file mode 100644 index 0000000000..7657f4be27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgNdistinct.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This is a type typo does not know how to handle yet. This falls back to casting to string and crossing fingers. Time to file an issue! :] */ +case class TypoUnknownPgNdistinct(value: String) + +object TypoUnknownPgNdistinct { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUnknownPgNdistinct]] = JdbcDecoder[Array[TypoUnknownPgNdistinct]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUnknownPgNdistinct(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUnknownPgNdistinct]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUnknownPgNdistinct]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "pg_ndistinct", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUnknownPgNdistinct, String] = Bijection[TypoUnknownPgNdistinct, String](_.value)(TypoUnknownPgNdistinct.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUnknownPgNdistinct] = JdbcDecoder[TypoUnknownPgNdistinct]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUnknownPgNdistinct(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUnknownPgNdistinct] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUnknownPgNdistinct] = JsonDecoder.string.map(TypoUnknownPgNdistinct.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUnknownPgNdistinct] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoUnknownPgNdistinct] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUnknownPgNdistinct] = ParameterMetaData.instance[TypoUnknownPgNdistinct]("pg_ndistinct", Types.OTHER) + implicit lazy val setter: Setter[TypoUnknownPgNdistinct] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "pg_ndistinct" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgStatistic.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgStatistic.scala new file mode 100644 index 0000000000..d526a467c6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoUnknownPgStatistic.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +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 + +/** This is a type typo does not know how to handle yet. This falls back to casting to string and crossing fingers. Time to file an issue! :] */ +case class TypoUnknownPgStatistic(value: String) + +object TypoUnknownPgStatistic { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoUnknownPgStatistic]] = JdbcDecoder[Array[TypoUnknownPgStatistic]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoUnknownPgStatistic(x.asInstanceOf[String])) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoUnknownPgStatistic]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoUnknownPgStatistic]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "pg_statistic", + v.map { vv => + vv.value + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoUnknownPgStatistic, String] = Bijection[TypoUnknownPgStatistic, String](_.value)(TypoUnknownPgStatistic.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoUnknownPgStatistic] = JdbcDecoder[TypoUnknownPgStatistic]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoUnknownPgStatistic(v.asInstanceOf[String]) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoUnknownPgStatistic] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoUnknownPgStatistic] = JsonDecoder.string.map(TypoUnknownPgStatistic.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoUnknownPgStatistic] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoUnknownPgStatistic] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoUnknownPgStatistic] = ParameterMetaData.instance[TypoUnknownPgStatistic]("pg_statistic", Types.OTHER) + implicit lazy val setter: Setter[TypoUnknownPgStatistic] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "pg_statistic" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoVector.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoVector.scala new file mode 100644 index 0000000000..a025e6245d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoVector.scala @@ -0,0 +1,46 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.jdbc.PgArray +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 + +/** extension: https://github.com/pgvector/pgvector */ +case class TypoVector(value: Array[Float]) + +object TypoVector { + implicit lazy val bijection: Bijection[TypoVector, Array[Float]] = Bijection[TypoVector, Array[Float]](_.value)(TypoVector.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoVector] = JdbcDecoder[TypoVector]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoVector(v.asInstanceOf[PgArray].getArray.asInstanceOf[Array[java.lang.Float]].map(Float2float)) + }, + "scala.Array[java.lang.Float]" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoVector] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoVector] = JsonDecoder.array[Float](JsonDecoder.float, implicitly).map(TypoVector.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoVector] = JsonEncoder.array[Float](JsonEncoder.float, implicitly).contramap(_.value) + implicit def ordering(implicit O0: Ordering[Array[Float]]): Ordering[TypoVector] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoVector] = ParameterMetaData.instance[TypoVector]("vector", Types.OTHER) + implicit lazy val setter: Setter[TypoVector] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value.map(x => x: java.lang.Float) + ) + }, + "vector" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXid.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXid.scala new file mode 100644 index 0000000000..44cf5d3b69 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXid.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.util.PGobject +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 + +/** xid (via PGObject) */ +case class TypoXid(value: String) + +object TypoXid { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoXid]] = JdbcDecoder[Array[TypoXid]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoXid(x.asInstanceOf[String])) + }, + "scala.Array[org.postgresql.util.PGobject]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoXid]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoXid]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "xid", + v.map { vv => + { + val obj = new PGobject + obj.setType("xid") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoXid, String] = Bijection[TypoXid, String](_.value)(TypoXid.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoXid] = JdbcDecoder[TypoXid]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoXid(v.asInstanceOf[PGobject].getValue) + }, + "org.postgresql.util.PGobject" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoXid] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoXid] = JsonDecoder.string.map(TypoXid.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoXid] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoXid] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoXid] = ParameterMetaData.instance[TypoXid]("xid", Types.OTHER) + implicit lazy val setter: Setter[TypoXid] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + { + val obj = new PGobject + obj.setType("xid") + obj.setValue(v.value) + obj + } + ) + }, + "xid" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXml.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXml.scala new file mode 100644 index 0000000000..3c3b36ee45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/customtypes/TypoXml.scala @@ -0,0 +1,72 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package customtypes + +import java.sql.ResultSet +import java.sql.Types +import org.postgresql.jdbc.PgSQLXML +import org.postgresql.util.PGobject +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 + +/** XML */ +case class TypoXml(value: String) + +object TypoXml { + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[TypoXml]] = JdbcDecoder[Array[TypoXml]]((rs: ResultSet) => (i: Int) => + rs.getArray(i) match { + case null => null + case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => TypoXml(x.asInstanceOf[PGobject].getValue)) + }, + "scala.Array[java.lang.String]" + ) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[TypoXml]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[TypoXml]] = Setter.forSqlType((ps, i, v) => + ps.setArray( + i, + ps.getConnection.createArrayOf( + "xml", + v.map { vv => + { + val obj = new PGobject + obj.setType("xml") + obj.setValue(vv.value) + obj + } + } + ) + ), + Types.ARRAY + ) + implicit lazy val bijection: Bijection[TypoXml, String] = Bijection[TypoXml, String](_.value)(TypoXml.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TypoXml] = JdbcDecoder[TypoXml]( + (rs: ResultSet) => (i: Int) => { + val v = rs.getObject(i) + if (v eq null) null else TypoXml(v.asInstanceOf[PgSQLXML].getString) + }, + "java.lang.String" + ) + implicit lazy val jdbcEncoder: JdbcEncoder[TypoXml] = JdbcEncoder.singleParamEncoder(setter) + implicit lazy val jsonDecoder: JsonDecoder[TypoXml] = JsonDecoder.string.map(TypoXml.apply) + implicit lazy val jsonEncoder: JsonEncoder[TypoXml] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[TypoXml] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TypoXml] = ParameterMetaData.instance[TypoXml]("xml", Types.OTHER) + implicit lazy val setter: Setter[TypoXml] = Setter.other( + (ps, i, v) => { + ps.setObject( + i, + v.value + ) + }, + "xml" + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewFields.scala new file mode 100644 index 0000000000..720ed330a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package d + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait DViewFields[Row] { + val id: Field[DepartmentId, Row] + val departmentid: Field[DepartmentId, Row] + val name: Field[Name, Row] + val groupname: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object DViewFields extends DViewStructure[DViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepo.scala new file mode 100644 index 0000000000..be21c803b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package d + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DViewRepo { + def select: SelectBuilder[DViewFields, DViewRow] + def selectAll: ZStream[ZConnection, Throwable, DViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepoImpl.scala new file mode 100644 index 0000000000..6cf3df6d0a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package d + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DViewRepoImpl extends DViewRepo { + override def select: SelectBuilder[DViewFields, DViewRow] = { + SelectBuilderSql("hr.d", DViewFields, DViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DViewRow] = { + sql"""select "id", "departmentid", "name", "groupname", "modifieddate"::text from hr.d""".query(DViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRow.scala new file mode 100644 index 0000000000..03f35af952 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package d + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DViewRow( + /** Points to [[humanresources.department.DepartmentRow.departmentid]] */ + id: DepartmentId, + /** Points to [[humanresources.department.DepartmentRow.departmentid]] */ + departmentid: DepartmentId, + /** Points to [[humanresources.department.DepartmentRow.name]] */ + name: Name, + /** Points to [[humanresources.department.DepartmentRow.groupname]] */ + groupname: Name, + /** Points to [[humanresources.department.DepartmentRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object DViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DViewRow] = new JdbcDecoder[DViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DViewRow) = + columIndex + 4 -> + DViewRow( + id = DepartmentId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + departmentid = DepartmentId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + groupname = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(DepartmentId.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val groupname = jsonObj.get("groupname").toRight("Missing field 'groupname'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && departmentid.isRight && name.isRight && groupname.isRight && modifieddate.isRight) + Right(DViewRow(id = id.toOption.get, departmentid = departmentid.toOption.get, name = name.toOption.get, groupname = groupname.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, departmentid, name, groupname, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DViewRow] = new JsonEncoder[DViewRow] { + override def unsafeEncode(a: DViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + DepartmentId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""groupname":""") + Name.jsonEncoder.unsafeEncode(a.groupname, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewStructure.scala new file mode 100644 index 0000000000..ab458605c8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/d/DViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package d + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class DViewStructure[Row](val prefix: Option[String], val extract: Row => DViewRow, val merge: (Row, DViewRow) => Row) + extends Relation[DViewFields, DViewRow, Row] + with DViewFields[Row] { outer => + + override val id = new Field[DepartmentId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val departmentid = new Field[DepartmentId, Row](prefix, "departmentid", None, None)(x => extract(x).departmentid, (row, value) => merge(row, extract(row).copy(departmentid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val groupname = new Field[Name, Row](prefix, "groupname", None, None)(x => extract(x).groupname, (row, value) => merge(row, extract(row).copy(groupname = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, departmentid, name, groupname, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DViewRow, merge: (NewRow, DViewRow) => NewRow): DViewStructure[NewRow] = + new DViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewFields.scala new file mode 100644 index 0000000000..9557d3f03a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewFields.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package e + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait EViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val nationalidnumber: Field[/* max 15 chars */ String, Row] + val loginid: Field[/* max 256 chars */ String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val birthdate: Field[TypoLocalDate, Row] + val maritalstatus: Field[/* bpchar, max 1 chars */ String, Row] + val gender: Field[/* bpchar, max 1 chars */ String, Row] + val hiredate: Field[TypoLocalDate, Row] + val salariedflag: Field[Flag, Row] + val vacationhours: Field[TypoShort, Row] + val sickleavehours: Field[TypoShort, Row] + val currentflag: Field[Flag, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val organizationnode: OptField[String, Row] +} +object EViewFields extends EViewStructure[EViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepo.scala new file mode 100644 index 0000000000..848cba8daa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package e + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EViewRepo { + def select: SelectBuilder[EViewFields, EViewRow] + def selectAll: ZStream[ZConnection, Throwable, EViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepoImpl.scala new file mode 100644 index 0000000000..64c208e314 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package e + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EViewRepoImpl extends EViewRepo { + override def select: SelectBuilder[EViewFields, EViewRow] = { + SelectBuilderSql("hr.e", EViewFields, EViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EViewRow] = { + sql"""select "id", "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" from hr.e""".query(EViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRow.scala new file mode 100644 index 0000000000..632d089b29 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewRow.scala @@ -0,0 +1,155 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package e + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EViewRow( + /** Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[humanresources.employee.EmployeeRow.nationalidnumber]] */ + nationalidnumber: /* max 15 chars */ String, + /** Points to [[humanresources.employee.EmployeeRow.loginid]] */ + loginid: /* max 256 chars */ String, + /** Points to [[humanresources.employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[humanresources.employee.EmployeeRow.birthdate]] */ + birthdate: TypoLocalDate, + /** Points to [[humanresources.employee.EmployeeRow.maritalstatus]] */ + maritalstatus: /* bpchar, max 1 chars */ String, + /** Points to [[humanresources.employee.EmployeeRow.gender]] */ + gender: /* bpchar, max 1 chars */ String, + /** Points to [[humanresources.employee.EmployeeRow.hiredate]] */ + hiredate: TypoLocalDate, + /** Points to [[humanresources.employee.EmployeeRow.salariedflag]] */ + salariedflag: Flag, + /** Points to [[humanresources.employee.EmployeeRow.vacationhours]] */ + vacationhours: TypoShort, + /** Points to [[humanresources.employee.EmployeeRow.sickleavehours]] */ + sickleavehours: TypoShort, + /** Points to [[humanresources.employee.EmployeeRow.currentflag]] */ + currentflag: Flag, + /** Points to [[humanresources.employee.EmployeeRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[humanresources.employee.EmployeeRow.modifieddate]] */ + modifieddate: TypoLocalDateTime, + /** Points to [[humanresources.employee.EmployeeRow.organizationnode]] */ + organizationnode: Option[String] +) + +object EViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EViewRow] = new JdbcDecoder[EViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EViewRow) = + columIndex + 15 -> + EViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + nationalidnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + loginid = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + birthdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + maritalstatus = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + gender = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + hiredate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + salariedflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + vacationhours = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + sickleavehours = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + currentflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + organizationnode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val nationalidnumber = jsonObj.get("nationalidnumber").toRight("Missing field 'nationalidnumber'").flatMap(_.as(JsonDecoder.string)) + val loginid = jsonObj.get("loginid").toRight("Missing field 'loginid'").flatMap(_.as(JsonDecoder.string)) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val birthdate = jsonObj.get("birthdate").toRight("Missing field 'birthdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val maritalstatus = jsonObj.get("maritalstatus").toRight("Missing field 'maritalstatus'").flatMap(_.as(JsonDecoder.string)) + val gender = jsonObj.get("gender").toRight("Missing field 'gender'").flatMap(_.as(JsonDecoder.string)) + val hiredate = jsonObj.get("hiredate").toRight("Missing field 'hiredate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val salariedflag = jsonObj.get("salariedflag").toRight("Missing field 'salariedflag'").flatMap(_.as(Flag.jsonDecoder)) + val vacationhours = jsonObj.get("vacationhours").toRight("Missing field 'vacationhours'").flatMap(_.as(TypoShort.jsonDecoder)) + val sickleavehours = jsonObj.get("sickleavehours").toRight("Missing field 'sickleavehours'").flatMap(_.as(TypoShort.jsonDecoder)) + val currentflag = jsonObj.get("currentflag").toRight("Missing field 'currentflag'").flatMap(_.as(Flag.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val organizationnode = jsonObj.get("organizationnode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (id.isRight && businessentityid.isRight && nationalidnumber.isRight && loginid.isRight && jobtitle.isRight && birthdate.isRight && maritalstatus.isRight && gender.isRight && hiredate.isRight && salariedflag.isRight && vacationhours.isRight && sickleavehours.isRight && currentflag.isRight && rowguid.isRight && modifieddate.isRight && organizationnode.isRight) + Right(EViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, nationalidnumber = nationalidnumber.toOption.get, loginid = loginid.toOption.get, jobtitle = jobtitle.toOption.get, birthdate = birthdate.toOption.get, maritalstatus = maritalstatus.toOption.get, gender = gender.toOption.get, hiredate = hiredate.toOption.get, salariedflag = salariedflag.toOption.get, vacationhours = vacationhours.toOption.get, sickleavehours = sickleavehours.toOption.get, currentflag = currentflag.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, organizationnode = organizationnode.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, nationalidnumber, loginid, jobtitle, birthdate, maritalstatus, gender, hiredate, salariedflag, vacationhours, sickleavehours, currentflag, rowguid, modifieddate, organizationnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EViewRow] = new JsonEncoder[EViewRow] { + override def unsafeEncode(a: EViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""nationalidnumber":""") + JsonEncoder.string.unsafeEncode(a.nationalidnumber, indent, out) + out.write(",") + out.write(""""loginid":""") + JsonEncoder.string.unsafeEncode(a.loginid, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""birthdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.birthdate, indent, out) + out.write(",") + out.write(""""maritalstatus":""") + JsonEncoder.string.unsafeEncode(a.maritalstatus, indent, out) + out.write(",") + out.write(""""gender":""") + JsonEncoder.string.unsafeEncode(a.gender, indent, out) + out.write(",") + out.write(""""hiredate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.hiredate, indent, out) + out.write(",") + out.write(""""salariedflag":""") + Flag.jsonEncoder.unsafeEncode(a.salariedflag, indent, out) + out.write(",") + out.write(""""vacationhours":""") + TypoShort.jsonEncoder.unsafeEncode(a.vacationhours, indent, out) + out.write(",") + out.write(""""sickleavehours":""") + TypoShort.jsonEncoder.unsafeEncode(a.sickleavehours, indent, out) + out.write(",") + out.write(""""currentflag":""") + Flag.jsonEncoder.unsafeEncode(a.currentflag, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""organizationnode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.organizationnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewStructure.scala new file mode 100644 index 0000000000..2a50379009 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/e/EViewStructure.scala @@ -0,0 +1,47 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package e + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EViewStructure[Row](val prefix: Option[String], val extract: Row => EViewRow, val merge: (Row, EViewRow) => Row) + extends Relation[EViewFields, EViewRow, Row] + with EViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val nationalidnumber = new Field[/* max 15 chars */ String, Row](prefix, "nationalidnumber", None, None)(x => extract(x).nationalidnumber, (row, value) => merge(row, extract(row).copy(nationalidnumber = value))) + override val loginid = new Field[/* max 256 chars */ String, Row](prefix, "loginid", None, None)(x => extract(x).loginid, (row, value) => merge(row, extract(row).copy(loginid = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val birthdate = new Field[TypoLocalDate, Row](prefix, "birthdate", Some("text"), None)(x => extract(x).birthdate, (row, value) => merge(row, extract(row).copy(birthdate = value))) + override val maritalstatus = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "maritalstatus", None, None)(x => extract(x).maritalstatus, (row, value) => merge(row, extract(row).copy(maritalstatus = value))) + override val gender = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "gender", None, None)(x => extract(x).gender, (row, value) => merge(row, extract(row).copy(gender = value))) + override val hiredate = new Field[TypoLocalDate, Row](prefix, "hiredate", Some("text"), None)(x => extract(x).hiredate, (row, value) => merge(row, extract(row).copy(hiredate = value))) + override val salariedflag = new Field[Flag, Row](prefix, "salariedflag", None, None)(x => extract(x).salariedflag, (row, value) => merge(row, extract(row).copy(salariedflag = value))) + override val vacationhours = new Field[TypoShort, Row](prefix, "vacationhours", None, None)(x => extract(x).vacationhours, (row, value) => merge(row, extract(row).copy(vacationhours = value))) + override val sickleavehours = new Field[TypoShort, Row](prefix, "sickleavehours", None, None)(x => extract(x).sickleavehours, (row, value) => merge(row, extract(row).copy(sickleavehours = value))) + override val currentflag = new Field[Flag, Row](prefix, "currentflag", None, None)(x => extract(x).currentflag, (row, value) => merge(row, extract(row).copy(currentflag = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val organizationnode = new OptField[String, Row](prefix, "organizationnode", None, None)(x => extract(x).organizationnode, (row, value) => merge(row, extract(row).copy(organizationnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, nationalidnumber, loginid, jobtitle, birthdate, maritalstatus, gender, hiredate, salariedflag, vacationhours, sickleavehours, currentflag, rowguid, modifieddate, organizationnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EViewRow, merge: (NewRow, EViewRow) => NewRow): EViewStructure[NewRow] = + new EViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewFields.scala new file mode 100644 index 0000000000..057cb8089a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package edh + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait EdhViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val departmentid: Field[DepartmentId, Row] + val shiftid: Field[ShiftId, Row] + val startdate: Field[TypoLocalDate, Row] + val enddate: OptField[TypoLocalDate, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EdhViewFields extends EdhViewStructure[EdhViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepo.scala new file mode 100644 index 0000000000..7c6ad0c175 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package edh + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EdhViewRepo { + def select: SelectBuilder[EdhViewFields, EdhViewRow] + def selectAll: ZStream[ZConnection, Throwable, EdhViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepoImpl.scala new file mode 100644 index 0000000000..bd391ef4e4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package edh + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EdhViewRepoImpl extends EdhViewRepo { + override def select: SelectBuilder[EdhViewFields, EdhViewRow] = { + SelectBuilderSql("hr.edh", EdhViewFields, EdhViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EdhViewRow] = { + sql"""select "id", "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text from hr.edh""".query(EdhViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRow.scala new file mode 100644 index 0000000000..0d0dfd4931 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package edh + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EdhViewRow( + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.departmentid]] */ + departmentid: DepartmentId, + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.shiftid]] */ + shiftid: ShiftId, + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.startdate]] */ + startdate: TypoLocalDate, + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.enddate]] */ + enddate: Option[TypoLocalDate], + /** Points to [[humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object EdhViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EdhViewRow] = new JdbcDecoder[EdhViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EdhViewRow) = + columIndex + 6 -> + EdhViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + departmentid = DepartmentId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + shiftid = ShiftId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + startdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EdhViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && departmentid.isRight && shiftid.isRight && startdate.isRight && enddate.isRight && modifieddate.isRight) + Right(EdhViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, departmentid = departmentid.toOption.get, shiftid = shiftid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, departmentid, shiftid, startdate, enddate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EdhViewRow] = new JsonEncoder[EdhViewRow] { + override def unsafeEncode(a: EdhViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewStructure.scala new file mode 100644 index 0000000000..4ea9c21a49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/edh/EdhViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package edh + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EdhViewStructure[Row](val prefix: Option[String], val extract: Row => EdhViewRow, val merge: (Row, EdhViewRow) => Row) + extends Relation[EdhViewFields, EdhViewRow, Row] + with EdhViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val departmentid = new Field[DepartmentId, Row](prefix, "departmentid", None, None)(x => extract(x).departmentid, (row, value) => merge(row, extract(row).copy(departmentid = value))) + override val shiftid = new Field[ShiftId, Row](prefix, "shiftid", None, None)(x => extract(x).shiftid, (row, value) => merge(row, extract(row).copy(shiftid = value))) + override val startdate = new Field[TypoLocalDate, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDate, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, departmentid, shiftid, startdate, enddate, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EdhViewRow, merge: (NewRow, EdhViewRow) => NewRow): EdhViewStructure[NewRow] = + new EdhViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewFields.scala new file mode 100644 index 0000000000..048512420d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package eph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field + +trait EphViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val ratechangedate: Field[TypoLocalDateTime, Row] + val rate: Field[BigDecimal, Row] + val payfrequency: Field[TypoShort, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EphViewFields extends EphViewStructure[EphViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepo.scala new file mode 100644 index 0000000000..39eb681325 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package eph + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EphViewRepo { + def select: SelectBuilder[EphViewFields, EphViewRow] + def selectAll: ZStream[ZConnection, Throwable, EphViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepoImpl.scala new file mode 100644 index 0000000000..a58b19c380 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package eph + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EphViewRepoImpl extends EphViewRepo { + override def select: SelectBuilder[EphViewFields, EphViewRow] = { + SelectBuilderSql("hr.eph", EphViewFields, EphViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EphViewRow] = { + sql"""select "id", "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text from hr.eph""".query(EphViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRow.scala new file mode 100644 index 0000000000..d4230e7d56 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package eph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EphViewRow( + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.ratechangedate]] */ + ratechangedate: TypoLocalDateTime, + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.rate]] */ + rate: BigDecimal, + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.payfrequency]] */ + payfrequency: TypoShort, + /** Points to [[humanresources.employeepayhistory.EmployeepayhistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object EphViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EphViewRow] = new JdbcDecoder[EphViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EphViewRow) = + columIndex + 5 -> + EphViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + ratechangedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + payfrequency = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EphViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val ratechangedate = jsonObj.get("ratechangedate").toRight("Missing field 'ratechangedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val rate = jsonObj.get("rate").toRight("Missing field 'rate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val payfrequency = jsonObj.get("payfrequency").toRight("Missing field 'payfrequency'").flatMap(_.as(TypoShort.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && ratechangedate.isRight && rate.isRight && payfrequency.isRight && modifieddate.isRight) + Right(EphViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, ratechangedate = ratechangedate.toOption.get, rate = rate.toOption.get, payfrequency = payfrequency.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, ratechangedate, rate, payfrequency, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EphViewRow] = new JsonEncoder[EphViewRow] { + override def unsafeEncode(a: EphViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""ratechangedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.ratechangedate, indent, out) + out.write(",") + out.write(""""rate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rate, indent, out) + out.write(",") + out.write(""""payfrequency":""") + TypoShort.jsonEncoder.unsafeEncode(a.payfrequency, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewStructure.scala new file mode 100644 index 0000000000..729f28f6bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/eph/EphViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package eph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class EphViewStructure[Row](val prefix: Option[String], val extract: Row => EphViewRow, val merge: (Row, EphViewRow) => Row) + extends Relation[EphViewFields, EphViewRow, Row] + with EphViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val ratechangedate = new Field[TypoLocalDateTime, Row](prefix, "ratechangedate", Some("text"), None)(x => extract(x).ratechangedate, (row, value) => merge(row, extract(row).copy(ratechangedate = value))) + override val rate = new Field[BigDecimal, Row](prefix, "rate", None, None)(x => extract(x).rate, (row, value) => merge(row, extract(row).copy(rate = value))) + override val payfrequency = new Field[TypoShort, Row](prefix, "payfrequency", None, None)(x => extract(x).payfrequency, (row, value) => merge(row, extract(row).copy(payfrequency = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, ratechangedate, rate, payfrequency, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EphViewRow, merge: (NewRow, EphViewRow) => NewRow): EphViewStructure[NewRow] = + new EphViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewFields.scala new file mode 100644 index 0000000000..1403c7be19 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package jc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait JcViewFields[Row] { + val id: Field[JobcandidateId, Row] + val jobcandidateid: Field[JobcandidateId, Row] + val businessentityid: OptField[BusinessentityId, Row] + val resume: OptField[TypoXml, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object JcViewFields extends JcViewStructure[JcViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepo.scala new file mode 100644 index 0000000000..81f8c0db1c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package jc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait JcViewRepo { + def select: SelectBuilder[JcViewFields, JcViewRow] + def selectAll: ZStream[ZConnection, Throwable, JcViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepoImpl.scala new file mode 100644 index 0000000000..520f7c91ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package jc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object JcViewRepoImpl extends JcViewRepo { + override def select: SelectBuilder[JcViewFields, JcViewRow] = { + SelectBuilderSql("hr.jc", JcViewFields, JcViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, JcViewRow] = { + sql"""select "id", "jobcandidateid", "businessentityid", "resume", "modifieddate"::text from hr.jc""".query(JcViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRow.scala new file mode 100644 index 0000000000..4d0214b1e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package jc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class JcViewRow( + /** Points to [[humanresources.jobcandidate.JobcandidateRow.jobcandidateid]] */ + id: JobcandidateId, + /** Points to [[humanresources.jobcandidate.JobcandidateRow.jobcandidateid]] */ + jobcandidateid: JobcandidateId, + /** Points to [[humanresources.jobcandidate.JobcandidateRow.businessentityid]] */ + businessentityid: Option[BusinessentityId], + /** Points to [[humanresources.jobcandidate.JobcandidateRow.resume]] */ + resume: Option[TypoXml], + /** Points to [[humanresources.jobcandidate.JobcandidateRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object JcViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[JcViewRow] = new JdbcDecoder[JcViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, JcViewRow) = + columIndex + 4 -> + JcViewRow( + id = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + jobcandidateid = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + businessentityid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + resume = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[JcViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val resume = jsonObj.get("resume").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && jobcandidateid.isRight && businessentityid.isRight && resume.isRight && modifieddate.isRight) + Right(JcViewRow(id = id.toOption.get, jobcandidateid = jobcandidateid.toOption.get, businessentityid = businessentityid.toOption.get, resume = resume.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, jobcandidateid, businessentityid, resume, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[JcViewRow] = new JsonEncoder[JcViewRow] { + override def unsafeEncode(a: JcViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""jobcandidateid":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""resume":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.resume, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewStructure.scala new file mode 100644 index 0000000000..fa1d098dfb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/jc/JcViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package jc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class JcViewStructure[Row](val prefix: Option[String], val extract: Row => JcViewRow, val merge: (Row, JcViewRow) => Row) + extends Relation[JcViewFields, JcViewRow, Row] + with JcViewFields[Row] { outer => + + override val id = new Field[JobcandidateId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val jobcandidateid = new Field[JobcandidateId, Row](prefix, "jobcandidateid", None, None)(x => extract(x).jobcandidateid, (row, value) => merge(row, extract(row).copy(jobcandidateid = value))) + override val businessentityid = new OptField[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val resume = new OptField[TypoXml, Row](prefix, "resume", None, None)(x => extract(x).resume, (row, value) => merge(row, extract(row).copy(resume = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, jobcandidateid, businessentityid, resume, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => JcViewRow, merge: (NewRow, JcViewRow) => NewRow): JcViewStructure[NewRow] = + new JcViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewFields.scala new file mode 100644 index 0000000000..e163d56da1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.humanresources.shift.ShiftId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait SViewFields[Row] { + val id: Field[ShiftId, Row] + val shiftid: Field[ShiftId, Row] + val name: Field[Name, Row] + val starttime: Field[TypoLocalTime, Row] + val endtime: Field[TypoLocalTime, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SViewFields extends SViewStructure[SViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepo.scala new file mode 100644 index 0000000000..4cbabc8ef7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package s + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SViewRepo { + def select: SelectBuilder[SViewFields, SViewRow] + def selectAll: ZStream[ZConnection, Throwable, SViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepoImpl.scala new file mode 100644 index 0000000000..7c6b16daf8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package s + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SViewRepoImpl extends SViewRepo { + override def select: SelectBuilder[SViewFields, SViewRow] = { + SelectBuilderSql("hr.s", SViewFields, SViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SViewRow] = { + sql"""select "id", "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text from hr.s""".query(SViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRow.scala new file mode 100644 index 0000000000..0e9bcd0c4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewRow.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.humanresources.shift.ShiftId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SViewRow( + /** Points to [[humanresources.shift.ShiftRow.shiftid]] */ + id: ShiftId, + /** Points to [[humanresources.shift.ShiftRow.shiftid]] */ + shiftid: ShiftId, + /** Points to [[humanresources.shift.ShiftRow.name]] */ + name: Name, + /** Points to [[humanresources.shift.ShiftRow.starttime]] */ + starttime: TypoLocalTime, + /** Points to [[humanresources.shift.ShiftRow.endtime]] */ + endtime: TypoLocalTime, + /** Points to [[humanresources.shift.ShiftRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SViewRow] = new JdbcDecoder[SViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SViewRow) = + columIndex + 5 -> + SViewRow( + id = ShiftId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + shiftid = ShiftId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + starttime = TypoLocalTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + endtime = TypoLocalTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ShiftId.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val starttime = jsonObj.get("starttime").toRight("Missing field 'starttime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val endtime = jsonObj.get("endtime").toRight("Missing field 'endtime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && shiftid.isRight && name.isRight && starttime.isRight && endtime.isRight && modifieddate.isRight) + Right(SViewRow(id = id.toOption.get, shiftid = shiftid.toOption.get, name = name.toOption.get, starttime = starttime.toOption.get, endtime = endtime.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, shiftid, name, starttime, endtime, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SViewRow] = new JsonEncoder[SViewRow] { + override def unsafeEncode(a: SViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ShiftId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""starttime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.starttime, indent, out) + out.write(",") + out.write(""""endtime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.endtime, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewStructure.scala new file mode 100644 index 0000000000..e3a4cd57a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/hr/s/SViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package hr +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.humanresources.shift.ShiftId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SViewStructure[Row](val prefix: Option[String], val extract: Row => SViewRow, val merge: (Row, SViewRow) => Row) + extends Relation[SViewFields, SViewRow, Row] + with SViewFields[Row] { outer => + + override val id = new Field[ShiftId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val shiftid = new Field[ShiftId, Row](prefix, "shiftid", None, None)(x => extract(x).shiftid, (row, value) => merge(row, extract(row).copy(shiftid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val starttime = new Field[TypoLocalTime, Row](prefix, "starttime", Some("text"), None)(x => extract(x).starttime, (row, value) => merge(row, extract(row).copy(starttime = value))) + override val endtime = new Field[TypoLocalTime, Row](prefix, "endtime", Some("text"), None)(x => extract(x).endtime, (row, value) => merge(row, extract(row).copy(endtime = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, shiftid, name, starttime, endtime, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SViewRow, merge: (NewRow, SViewRow) => NewRow): SViewStructure[NewRow] = + new SViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentFields.scala new file mode 100644 index 0000000000..d5c56ff6f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait DepartmentFields[Row] { + val departmentid: IdField[DepartmentId, Row] + val name: Field[Name, Row] + val groupname: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object DepartmentFields extends DepartmentStructure[DepartmentRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentId.scala new file mode 100644 index 0000000000..95f1b49ff0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +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 `humanresources.department` */ +case class DepartmentId(value: Int) extends AnyVal +object DepartmentId { + implicit lazy val arraySetter: Setter[Array[DepartmentId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[DepartmentId, Int] = Bijection[DepartmentId, Int](_.value)(DepartmentId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[DepartmentId] = JdbcDecoder.intDecoder.map(DepartmentId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[DepartmentId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[DepartmentId] = JsonDecoder.int.map(DepartmentId.apply) + implicit lazy val jsonEncoder: JsonEncoder[DepartmentId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[DepartmentId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[DepartmentId] = ParameterMetaData.instance[DepartmentId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[DepartmentId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepo.scala new file mode 100644 index 0000000000..1654f0e7ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DepartmentRepo { + def delete(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[DepartmentFields, DepartmentRow] + def insert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, DepartmentRow] + def insert(unsaved: DepartmentRowUnsaved): ZIO[ZConnection, Throwable, DepartmentRow] + def select: SelectBuilder[DepartmentFields, DepartmentRow] + def selectAll: ZStream[ZConnection, Throwable, DepartmentRow] + def selectById(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Option[DepartmentRow]] + def selectByIds(departmentids: Array[DepartmentId]): ZStream[ZConnection, Throwable, DepartmentRow] + def update(row: DepartmentRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[DepartmentFields, DepartmentRow] + def upsert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, UpdateResult[DepartmentRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoImpl.scala new file mode 100644 index 0000000000..e14714d86d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoImpl.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DepartmentRepoImpl extends DepartmentRepo { + override def delete(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.department where "departmentid" = ${Segment.paramSegment(departmentid)(DepartmentId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[DepartmentFields, DepartmentRow] = { + DeleteBuilder("humanresources.department", DepartmentFields) + } + override def insert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, DepartmentRow] = { + sql"""insert into humanresources.department("departmentid", "name", "groupname", "modifieddate") + values (${Segment.paramSegment(unsaved.departmentid)(DepartmentId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.groupname)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "departmentid", "name", "groupname", "modifieddate"::text + """.insertReturning(DepartmentRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: DepartmentRowUnsaved): ZIO[ZConnection, Throwable, DepartmentRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""groupname"""", sql"${Segment.paramSegment(unsaved.groupname)(Name.setter)}::varchar")), + unsaved.departmentid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""departmentid"""", sql"${Segment.paramSegment(value: DepartmentId)(DepartmentId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.department default values + returning "departmentid", "name", "groupname", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.department($names) values ($values) returning "departmentid", "name", "groupname", "modifieddate"::text""" + } + q.insertReturning(DepartmentRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[DepartmentFields, DepartmentRow] = { + SelectBuilderSql("humanresources.department", DepartmentFields, DepartmentRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DepartmentRow] = { + sql"""select "departmentid", "name", "groupname", "modifieddate"::text from humanresources.department""".query(DepartmentRow.jdbcDecoder).selectStream + } + override def selectById(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Option[DepartmentRow]] = { + sql"""select "departmentid", "name", "groupname", "modifieddate"::text from humanresources.department where "departmentid" = ${Segment.paramSegment(departmentid)(DepartmentId.setter)}""".query(DepartmentRow.jdbcDecoder).selectOne + } + override def selectByIds(departmentids: Array[DepartmentId]): ZStream[ZConnection, Throwable, DepartmentRow] = { + sql"""select "departmentid", "name", "groupname", "modifieddate"::text from humanresources.department where "departmentid" = ANY(${Segment.paramSegment(departmentids)(DepartmentId.arraySetter)})""".query(DepartmentRow.jdbcDecoder).selectStream + } + override def update(row: DepartmentRow): ZIO[ZConnection, Throwable, Boolean] = { + val departmentid = row.departmentid + sql"""update humanresources.department + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "groupname" = ${Segment.paramSegment(row.groupname)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "departmentid" = ${Segment.paramSegment(departmentid)(DepartmentId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[DepartmentFields, DepartmentRow] = { + UpdateBuilder("humanresources.department", DepartmentFields, DepartmentRow.jdbcDecoder) + } + override def upsert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, UpdateResult[DepartmentRow]] = { + sql"""insert into humanresources.department("departmentid", "name", "groupname", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.departmentid)(DepartmentId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.groupname)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("departmentid") + do update set + "name" = EXCLUDED."name", + "groupname" = EXCLUDED."groupname", + "modifieddate" = EXCLUDED."modifieddate" + returning "departmentid", "name", "groupname", "modifieddate"::text""".insertReturning(DepartmentRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoMock.scala new file mode 100644 index 0000000000..fa71326aa0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class DepartmentRepoMock(toRow: Function1[DepartmentRowUnsaved, DepartmentRow], + map: scala.collection.mutable.Map[DepartmentId, DepartmentRow] = scala.collection.mutable.Map.empty) extends DepartmentRepo { + override def delete(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(departmentid).isDefined) + } + override def delete: DeleteBuilder[DepartmentFields, DepartmentRow] = { + DeleteBuilderMock(DeleteParams.empty, DepartmentFields, map) + } + override def insert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, DepartmentRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.departmentid)) + sys.error(s"id ${unsaved.departmentid} already exists") + else + map.put(unsaved.departmentid, unsaved) + + unsaved + } + } + override def insert(unsaved: DepartmentRowUnsaved): ZIO[ZConnection, Throwable, DepartmentRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[DepartmentFields, DepartmentRow] = { + SelectBuilderMock(DepartmentFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, DepartmentRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(departmentid: DepartmentId): ZIO[ZConnection, Throwable, Option[DepartmentRow]] = { + ZIO.succeed(map.get(departmentid)) + } + override def selectByIds(departmentids: Array[DepartmentId]): ZStream[ZConnection, Throwable, DepartmentRow] = { + ZStream.fromIterable(departmentids.flatMap(map.get)) + } + override def update(row: DepartmentRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.departmentid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.departmentid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[DepartmentFields, DepartmentRow] = { + UpdateBuilderMock(UpdateParams.empty, DepartmentFields, map) + } + override def upsert(unsaved: DepartmentRow): ZIO[ZConnection, Throwable, UpdateResult[DepartmentRow]] = { + ZIO.succeed { + map.put(unsaved.departmentid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRow.scala new file mode 100644 index 0000000000..785d0cd968 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRow.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DepartmentRow( + /** Primary key for Department records. */ + departmentid: DepartmentId, + /** Name of the department. */ + name: Name, + /** Name of the group to which the department belongs. */ + groupname: Name, + modifieddate: TypoLocalDateTime +) + +object DepartmentRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DepartmentRow] = new JdbcDecoder[DepartmentRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DepartmentRow) = + columIndex + 3 -> + DepartmentRow( + departmentid = DepartmentId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + groupname = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DepartmentRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val groupname = jsonObj.get("groupname").toRight("Missing field 'groupname'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (departmentid.isRight && name.isRight && groupname.isRight && modifieddate.isRight) + Right(DepartmentRow(departmentid = departmentid.toOption.get, name = name.toOption.get, groupname = groupname.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](departmentid, name, groupname, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DepartmentRow] = new JsonEncoder[DepartmentRow] { + override def unsafeEncode(a: DepartmentRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""groupname":""") + Name.jsonEncoder.unsafeEncode(a.groupname, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRowUnsaved.scala new file mode 100644 index 0000000000..572d8d8479 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentRowUnsaved.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.department` which has not been persisted yet */ +case class DepartmentRowUnsaved( + /** Name of the department. */ + name: Name, + /** Name of the group to which the department belongs. */ + groupname: Name, + /** Default: nextval('humanresources.department_departmentid_seq'::regclass) + Primary key for Department records. */ + departmentid: Defaulted[DepartmentId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(departmentidDefault: => DepartmentId, modifieddateDefault: => TypoLocalDateTime): DepartmentRow = + DepartmentRow( + name = name, + groupname = groupname, + departmentid = departmentid match { + case Defaulted.UseDefault => departmentidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object DepartmentRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[DepartmentRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val groupname = jsonObj.get("groupname").toRight("Missing field 'groupname'").flatMap(_.as(Name.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(Defaulted.jsonDecoder(DepartmentId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && groupname.isRight && departmentid.isRight && modifieddate.isRight) + Right(DepartmentRowUnsaved(name = name.toOption.get, groupname = groupname.toOption.get, departmentid = departmentid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, groupname, departmentid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DepartmentRowUnsaved] = new JsonEncoder[DepartmentRowUnsaved] { + override def unsafeEncode(a: DepartmentRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""groupname":""") + Name.jsonEncoder.unsafeEncode(a.groupname, indent, out) + out.write(",") + out.write(""""departmentid":""") + Defaulted.jsonEncoder(DepartmentId.jsonEncoder).unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentStructure.scala new file mode 100644 index 0000000000..50ec794eff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/department/DepartmentStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package department + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class DepartmentStructure[Row](val prefix: Option[String], val extract: Row => DepartmentRow, val merge: (Row, DepartmentRow) => Row) + extends Relation[DepartmentFields, DepartmentRow, Row] + with DepartmentFields[Row] { outer => + + override val departmentid = new IdField[DepartmentId, Row](prefix, "departmentid", None, Some("int4"))(x => extract(x).departmentid, (row, value) => merge(row, extract(row).copy(departmentid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val groupname = new Field[Name, Row](prefix, "groupname", None, Some("varchar"))(x => extract(x).groupname, (row, value) => merge(row, extract(row).copy(groupname = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](departmentid, name, groupname, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DepartmentRow, merge: (NewRow, DepartmentRow) => NewRow): DepartmentStructure[NewRow] = + new DepartmentStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeFields.scala new file mode 100644 index 0000000000..95087474b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeFields.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait EmployeeFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val nationalidnumber: Field[/* max 15 chars */ String, Row] + val loginid: Field[/* max 256 chars */ String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val birthdate: Field[TypoLocalDate, Row] + val maritalstatus: Field[/* bpchar, max 1 chars */ String, Row] + val gender: Field[/* bpchar, max 1 chars */ String, Row] + val hiredate: Field[TypoLocalDate, Row] + val salariedflag: Field[Flag, Row] + val vacationhours: Field[TypoShort, Row] + val sickleavehours: Field[TypoShort, Row] + val currentflag: Field[Flag, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val organizationnode: OptField[String, Row] +} +object EmployeeFields extends EmployeeStructure[EmployeeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepo.scala new file mode 100644 index 0000000000..ddc2986f53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EmployeeRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[EmployeeFields, EmployeeRow] + def insert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, EmployeeRow] + def insert(unsaved: EmployeeRowUnsaved): ZIO[ZConnection, Throwable, EmployeeRow] + def select: SelectBuilder[EmployeeFields, EmployeeRow] + def selectAll: ZStream[ZConnection, Throwable, EmployeeRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[EmployeeRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, EmployeeRow] + def update(row: EmployeeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[EmployeeFields, EmployeeRow] + def upsert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoImpl.scala new file mode 100644 index 0000000000..1cad6bdd65 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoImpl.scala @@ -0,0 +1,166 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EmployeeRepoImpl extends EmployeeRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.employee where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[EmployeeFields, EmployeeRow] = { + DeleteBuilder("humanresources.employee", EmployeeFields) + } + override def insert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, EmployeeRow] = { + sql"""insert into humanresources.employee("businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate", "maritalstatus", "gender", "hiredate", "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate", "organizationnode") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.nationalidnumber)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.loginid)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.jobtitle)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.birthdate)(TypoLocalDate.setter)}::date, ${Segment.paramSegment(unsaved.maritalstatus)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.gender)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.hiredate)(TypoLocalDate.setter)}::date, ${Segment.paramSegment(unsaved.salariedflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.vacationhours)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.sickleavehours)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.currentflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.organizationnode)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" + """.insertReturning(EmployeeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: EmployeeRowUnsaved): ZIO[ZConnection, Throwable, EmployeeRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""nationalidnumber"""", sql"${Segment.paramSegment(unsaved.nationalidnumber)(Setter.stringSetter)}")), + Some((sql""""loginid"""", sql"${Segment.paramSegment(unsaved.loginid)(Setter.stringSetter)}")), + Some((sql""""jobtitle"""", sql"${Segment.paramSegment(unsaved.jobtitle)(Setter.stringSetter)}")), + Some((sql""""birthdate"""", sql"${Segment.paramSegment(unsaved.birthdate)(TypoLocalDate.setter)}::date")), + Some((sql""""maritalstatus"""", sql"${Segment.paramSegment(unsaved.maritalstatus)(Setter.stringSetter)}::bpchar")), + Some((sql""""gender"""", sql"${Segment.paramSegment(unsaved.gender)(Setter.stringSetter)}::bpchar")), + Some((sql""""hiredate"""", sql"${Segment.paramSegment(unsaved.hiredate)(TypoLocalDate.setter)}::date")), + unsaved.salariedflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salariedflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.vacationhours match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""vacationhours"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.sickleavehours match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""sickleavehours"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.currentflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""currentflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.organizationnode match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""organizationnode"""", sql"${Segment.paramSegment(value: Option[String])(Setter.optionParamSetter(Setter.stringSetter))}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.employee default values + returning "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.employee($names) values ($values) returning "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode"""" + } + q.insertReturning(EmployeeRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[EmployeeFields, EmployeeRow] = { + SelectBuilderSql("humanresources.employee", EmployeeFields, EmployeeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeeRow] = { + sql"""select "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" from humanresources.employee""".query(EmployeeRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[EmployeeRow]] = { + sql"""select "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" from humanresources.employee where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(EmployeeRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, EmployeeRow] = { + sql"""select "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode" from humanresources.employee where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(EmployeeRow.jdbcDecoder).selectStream + } + override def update(row: EmployeeRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update humanresources.employee + set "nationalidnumber" = ${Segment.paramSegment(row.nationalidnumber)(Setter.stringSetter)}, + "loginid" = ${Segment.paramSegment(row.loginid)(Setter.stringSetter)}, + "jobtitle" = ${Segment.paramSegment(row.jobtitle)(Setter.stringSetter)}, + "birthdate" = ${Segment.paramSegment(row.birthdate)(TypoLocalDate.setter)}::date, + "maritalstatus" = ${Segment.paramSegment(row.maritalstatus)(Setter.stringSetter)}::bpchar, + "gender" = ${Segment.paramSegment(row.gender)(Setter.stringSetter)}::bpchar, + "hiredate" = ${Segment.paramSegment(row.hiredate)(TypoLocalDate.setter)}::date, + "salariedflag" = ${Segment.paramSegment(row.salariedflag)(Flag.setter)}::bool, + "vacationhours" = ${Segment.paramSegment(row.vacationhours)(TypoShort.setter)}::int2, + "sickleavehours" = ${Segment.paramSegment(row.sickleavehours)(TypoShort.setter)}::int2, + "currentflag" = ${Segment.paramSegment(row.currentflag)(Flag.setter)}::bool, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp, + "organizationnode" = ${Segment.paramSegment(row.organizationnode)(Setter.optionParamSetter(Setter.stringSetter))} + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[EmployeeFields, EmployeeRow] = { + UpdateBuilder("humanresources.employee", EmployeeFields, EmployeeRow.jdbcDecoder) + } + override def upsert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeeRow]] = { + sql"""insert into humanresources.employee("businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate", "maritalstatus", "gender", "hiredate", "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate", "organizationnode") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.nationalidnumber)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.loginid)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.jobtitle)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.birthdate)(TypoLocalDate.setter)}::date, + ${Segment.paramSegment(unsaved.maritalstatus)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.gender)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.hiredate)(TypoLocalDate.setter)}::date, + ${Segment.paramSegment(unsaved.salariedflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.vacationhours)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.sickleavehours)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.currentflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.organizationnode)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("businessentityid") + do update set + "nationalidnumber" = EXCLUDED."nationalidnumber", + "loginid" = EXCLUDED."loginid", + "jobtitle" = EXCLUDED."jobtitle", + "birthdate" = EXCLUDED."birthdate", + "maritalstatus" = EXCLUDED."maritalstatus", + "gender" = EXCLUDED."gender", + "hiredate" = EXCLUDED."hiredate", + "salariedflag" = EXCLUDED."salariedflag", + "vacationhours" = EXCLUDED."vacationhours", + "sickleavehours" = EXCLUDED."sickleavehours", + "currentflag" = EXCLUDED."currentflag", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate", + "organizationnode" = EXCLUDED."organizationnode" + returning "businessentityid", "nationalidnumber", "loginid", "jobtitle", "birthdate"::text, "maritalstatus", "gender", "hiredate"::text, "salariedflag", "vacationhours", "sickleavehours", "currentflag", "rowguid", "modifieddate"::text, "organizationnode"""".insertReturning(EmployeeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoMock.scala new file mode 100644 index 0000000000..0bc9d0dd85 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class EmployeeRepoMock(toRow: Function1[EmployeeRowUnsaved, EmployeeRow], + map: scala.collection.mutable.Map[BusinessentityId, EmployeeRow] = scala.collection.mutable.Map.empty) extends EmployeeRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[EmployeeFields, EmployeeRow] = { + DeleteBuilderMock(DeleteParams.empty, EmployeeFields, map) + } + override def insert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, EmployeeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: EmployeeRowUnsaved): ZIO[ZConnection, Throwable, EmployeeRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[EmployeeFields, EmployeeRow] = { + SelectBuilderMock(EmployeeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[EmployeeRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, EmployeeRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: EmployeeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[EmployeeFields, EmployeeRow] = { + UpdateBuilderMock(UpdateParams.empty, EmployeeFields, map) + } + override def upsert(unsaved: EmployeeRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeeRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRow.scala new file mode 100644 index 0000000000..93a18d8c32 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRow.scala @@ -0,0 +1,153 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EmployeeRow( + /** Primary key for Employee records. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Unique national identification number such as a social security number. */ + nationalidnumber: /* max 15 chars */ String, + /** Network login. */ + loginid: /* max 256 chars */ String, + /** Work title such as Buyer or Sales Representative. */ + jobtitle: /* max 50 chars */ String, + /** Date of birth. + Constraint CK_Employee_BirthDate affecting columns "birthdate": (((birthdate >= '1930-01-01'::date) AND (birthdate <= (now() - '18 years'::interval)))) */ + birthdate: TypoLocalDate, + /** M = Married, S = Single + Constraint CK_Employee_MaritalStatus affecting columns "maritalstatus": ((upper((maritalstatus)::text) = ANY (ARRAY['M'::text, 'S'::text]))) */ + maritalstatus: /* bpchar, max 1 chars */ String, + /** M = Male, F = Female + Constraint CK_Employee_Gender affecting columns "gender": ((upper((gender)::text) = ANY (ARRAY['M'::text, 'F'::text]))) */ + gender: /* bpchar, max 1 chars */ String, + /** Employee hired on this date. + Constraint CK_Employee_HireDate affecting columns "hiredate": (((hiredate >= '1996-07-01'::date) AND (hiredate <= (now() + '1 day'::interval)))) */ + hiredate: TypoLocalDate, + /** Job classification. 0 = Hourly, not exempt from collective bargaining. 1 = Salaried, exempt from collective bargaining. */ + salariedflag: Flag, + /** Number of available vacation hours. + Constraint CK_Employee_VacationHours affecting columns "vacationhours": (((vacationhours >= '-40'::integer) AND (vacationhours <= 240))) */ + vacationhours: TypoShort, + /** Number of available sick leave hours. + Constraint CK_Employee_SickLeaveHours affecting columns "sickleavehours": (((sickleavehours >= 0) AND (sickleavehours <= 120))) */ + sickleavehours: TypoShort, + /** 0 = Inactive, 1 = Active */ + currentflag: Flag, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime, + /** Where the employee is located in corporate hierarchy. */ + organizationnode: Option[String] +) + +object EmployeeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EmployeeRow] = new JdbcDecoder[EmployeeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EmployeeRow) = + columIndex + 14 -> + EmployeeRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + nationalidnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + loginid = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + birthdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + maritalstatus = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + gender = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + hiredate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + salariedflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + vacationhours = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + sickleavehours = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + currentflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + organizationnode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EmployeeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val nationalidnumber = jsonObj.get("nationalidnumber").toRight("Missing field 'nationalidnumber'").flatMap(_.as(JsonDecoder.string)) + val loginid = jsonObj.get("loginid").toRight("Missing field 'loginid'").flatMap(_.as(JsonDecoder.string)) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val birthdate = jsonObj.get("birthdate").toRight("Missing field 'birthdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val maritalstatus = jsonObj.get("maritalstatus").toRight("Missing field 'maritalstatus'").flatMap(_.as(JsonDecoder.string)) + val gender = jsonObj.get("gender").toRight("Missing field 'gender'").flatMap(_.as(JsonDecoder.string)) + val hiredate = jsonObj.get("hiredate").toRight("Missing field 'hiredate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val salariedflag = jsonObj.get("salariedflag").toRight("Missing field 'salariedflag'").flatMap(_.as(Flag.jsonDecoder)) + val vacationhours = jsonObj.get("vacationhours").toRight("Missing field 'vacationhours'").flatMap(_.as(TypoShort.jsonDecoder)) + val sickleavehours = jsonObj.get("sickleavehours").toRight("Missing field 'sickleavehours'").flatMap(_.as(TypoShort.jsonDecoder)) + val currentflag = jsonObj.get("currentflag").toRight("Missing field 'currentflag'").flatMap(_.as(Flag.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val organizationnode = jsonObj.get("organizationnode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (businessentityid.isRight && nationalidnumber.isRight && loginid.isRight && jobtitle.isRight && birthdate.isRight && maritalstatus.isRight && gender.isRight && hiredate.isRight && salariedflag.isRight && vacationhours.isRight && sickleavehours.isRight && currentflag.isRight && rowguid.isRight && modifieddate.isRight && organizationnode.isRight) + Right(EmployeeRow(businessentityid = businessentityid.toOption.get, nationalidnumber = nationalidnumber.toOption.get, loginid = loginid.toOption.get, jobtitle = jobtitle.toOption.get, birthdate = birthdate.toOption.get, maritalstatus = maritalstatus.toOption.get, gender = gender.toOption.get, hiredate = hiredate.toOption.get, salariedflag = salariedflag.toOption.get, vacationhours = vacationhours.toOption.get, sickleavehours = sickleavehours.toOption.get, currentflag = currentflag.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, organizationnode = organizationnode.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, nationalidnumber, loginid, jobtitle, birthdate, maritalstatus, gender, hiredate, salariedflag, vacationhours, sickleavehours, currentflag, rowguid, modifieddate, organizationnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeeRow] = new JsonEncoder[EmployeeRow] { + override def unsafeEncode(a: EmployeeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""nationalidnumber":""") + JsonEncoder.string.unsafeEncode(a.nationalidnumber, indent, out) + out.write(",") + out.write(""""loginid":""") + JsonEncoder.string.unsafeEncode(a.loginid, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""birthdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.birthdate, indent, out) + out.write(",") + out.write(""""maritalstatus":""") + JsonEncoder.string.unsafeEncode(a.maritalstatus, indent, out) + out.write(",") + out.write(""""gender":""") + JsonEncoder.string.unsafeEncode(a.gender, indent, out) + out.write(",") + out.write(""""hiredate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.hiredate, indent, out) + out.write(",") + out.write(""""salariedflag":""") + Flag.jsonEncoder.unsafeEncode(a.salariedflag, indent, out) + out.write(",") + out.write(""""vacationhours":""") + TypoShort.jsonEncoder.unsafeEncode(a.vacationhours, indent, out) + out.write(",") + out.write(""""sickleavehours":""") + TypoShort.jsonEncoder.unsafeEncode(a.sickleavehours, indent, out) + out.write(",") + out.write(""""currentflag":""") + Flag.jsonEncoder.unsafeEncode(a.currentflag, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""organizationnode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.organizationnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRowUnsaved.scala new file mode 100644 index 0000000000..d41cb48165 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeRowUnsaved.scala @@ -0,0 +1,178 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.employee` which has not been persisted yet */ +case class EmployeeRowUnsaved( + /** Primary key for Employee records. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Unique national identification number such as a social security number. */ + nationalidnumber: /* max 15 chars */ String, + /** Network login. */ + loginid: /* max 256 chars */ String, + /** Work title such as Buyer or Sales Representative. */ + jobtitle: /* max 50 chars */ String, + /** Date of birth. + Constraint CK_Employee_BirthDate affecting columns "birthdate": (((birthdate >= '1930-01-01'::date) AND (birthdate <= (now() - '18 years'::interval)))) */ + birthdate: TypoLocalDate, + /** M = Married, S = Single + Constraint CK_Employee_MaritalStatus affecting columns "maritalstatus": ((upper((maritalstatus)::text) = ANY (ARRAY['M'::text, 'S'::text]))) */ + maritalstatus: /* bpchar, max 1 chars */ String, + /** M = Male, F = Female + Constraint CK_Employee_Gender affecting columns "gender": ((upper((gender)::text) = ANY (ARRAY['M'::text, 'F'::text]))) */ + gender: /* bpchar, max 1 chars */ String, + /** Employee hired on this date. + Constraint CK_Employee_HireDate affecting columns "hiredate": (((hiredate >= '1996-07-01'::date) AND (hiredate <= (now() + '1 day'::interval)))) */ + hiredate: TypoLocalDate, + /** Default: true + Job classification. 0 = Hourly, not exempt from collective bargaining. 1 = Salaried, exempt from collective bargaining. */ + salariedflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: 0 + Number of available vacation hours. + Constraint CK_Employee_VacationHours affecting columns "vacationhours": (((vacationhours >= '-40'::integer) AND (vacationhours <= 240))) */ + vacationhours: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: 0 + Number of available sick leave hours. + Constraint CK_Employee_SickLeaveHours affecting columns "sickleavehours": (((sickleavehours >= 0) AND (sickleavehours <= 120))) */ + sickleavehours: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: true + 0 = Inactive, 1 = Active */ + currentflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: '/'::character varying + Where the employee is located in corporate hierarchy. */ + organizationnode: Defaulted[Option[String]] = Defaulted.UseDefault +) { + def toRow(salariedflagDefault: => Flag, vacationhoursDefault: => TypoShort, sickleavehoursDefault: => TypoShort, currentflagDefault: => Flag, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime, organizationnodeDefault: => Option[String]): EmployeeRow = + EmployeeRow( + businessentityid = businessentityid, + nationalidnumber = nationalidnumber, + loginid = loginid, + jobtitle = jobtitle, + birthdate = birthdate, + maritalstatus = maritalstatus, + gender = gender, + hiredate = hiredate, + salariedflag = salariedflag match { + case Defaulted.UseDefault => salariedflagDefault + case Defaulted.Provided(value) => value + }, + vacationhours = vacationhours match { + case Defaulted.UseDefault => vacationhoursDefault + case Defaulted.Provided(value) => value + }, + sickleavehours = sickleavehours match { + case Defaulted.UseDefault => sickleavehoursDefault + case Defaulted.Provided(value) => value + }, + currentflag = currentflag match { + case Defaulted.UseDefault => currentflagDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + }, + organizationnode = organizationnode match { + case Defaulted.UseDefault => organizationnodeDefault + case Defaulted.Provided(value) => value + } + ) +} +object EmployeeRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[EmployeeRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val nationalidnumber = jsonObj.get("nationalidnumber").toRight("Missing field 'nationalidnumber'").flatMap(_.as(JsonDecoder.string)) + val loginid = jsonObj.get("loginid").toRight("Missing field 'loginid'").flatMap(_.as(JsonDecoder.string)) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val birthdate = jsonObj.get("birthdate").toRight("Missing field 'birthdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val maritalstatus = jsonObj.get("maritalstatus").toRight("Missing field 'maritalstatus'").flatMap(_.as(JsonDecoder.string)) + val gender = jsonObj.get("gender").toRight("Missing field 'gender'").flatMap(_.as(JsonDecoder.string)) + val hiredate = jsonObj.get("hiredate").toRight("Missing field 'hiredate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val salariedflag = jsonObj.get("salariedflag").toRight("Missing field 'salariedflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val vacationhours = jsonObj.get("vacationhours").toRight("Missing field 'vacationhours'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val sickleavehours = jsonObj.get("sickleavehours").toRight("Missing field 'sickleavehours'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val currentflag = jsonObj.get("currentflag").toRight("Missing field 'currentflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val organizationnode = jsonObj.get("organizationnode").toRight("Missing field 'organizationnode'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.option(JsonDecoder.string)))) + if (businessentityid.isRight && nationalidnumber.isRight && loginid.isRight && jobtitle.isRight && birthdate.isRight && maritalstatus.isRight && gender.isRight && hiredate.isRight && salariedflag.isRight && vacationhours.isRight && sickleavehours.isRight && currentflag.isRight && rowguid.isRight && modifieddate.isRight && organizationnode.isRight) + Right(EmployeeRowUnsaved(businessentityid = businessentityid.toOption.get, nationalidnumber = nationalidnumber.toOption.get, loginid = loginid.toOption.get, jobtitle = jobtitle.toOption.get, birthdate = birthdate.toOption.get, maritalstatus = maritalstatus.toOption.get, gender = gender.toOption.get, hiredate = hiredate.toOption.get, salariedflag = salariedflag.toOption.get, vacationhours = vacationhours.toOption.get, sickleavehours = sickleavehours.toOption.get, currentflag = currentflag.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, organizationnode = organizationnode.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, nationalidnumber, loginid, jobtitle, birthdate, maritalstatus, gender, hiredate, salariedflag, vacationhours, sickleavehours, currentflag, rowguid, modifieddate, organizationnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeeRowUnsaved] = new JsonEncoder[EmployeeRowUnsaved] { + override def unsafeEncode(a: EmployeeRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""nationalidnumber":""") + JsonEncoder.string.unsafeEncode(a.nationalidnumber, indent, out) + out.write(",") + out.write(""""loginid":""") + JsonEncoder.string.unsafeEncode(a.loginid, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""birthdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.birthdate, indent, out) + out.write(",") + out.write(""""maritalstatus":""") + JsonEncoder.string.unsafeEncode(a.maritalstatus, indent, out) + out.write(",") + out.write(""""gender":""") + JsonEncoder.string.unsafeEncode(a.gender, indent, out) + out.write(",") + out.write(""""hiredate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.hiredate, indent, out) + out.write(",") + out.write(""""salariedflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.salariedflag, indent, out) + out.write(",") + out.write(""""vacationhours":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.vacationhours, indent, out) + out.write(",") + out.write(""""sickleavehours":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.sickleavehours, indent, out) + out.write(",") + out.write(""""currentflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.currentflag, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""organizationnode":""") + Defaulted.jsonEncoder(JsonEncoder.option(JsonEncoder.string)).unsafeEncode(a.organizationnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeStructure.scala new file mode 100644 index 0000000000..2193c5da6e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employee/EmployeeStructure.scala @@ -0,0 +1,47 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EmployeeStructure[Row](val prefix: Option[String], val extract: Row => EmployeeRow, val merge: (Row, EmployeeRow) => Row) + extends Relation[EmployeeFields, EmployeeRow, Row] + with EmployeeFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val nationalidnumber = new Field[/* max 15 chars */ String, Row](prefix, "nationalidnumber", None, None)(x => extract(x).nationalidnumber, (row, value) => merge(row, extract(row).copy(nationalidnumber = value))) + override val loginid = new Field[/* max 256 chars */ String, Row](prefix, "loginid", None, None)(x => extract(x).loginid, (row, value) => merge(row, extract(row).copy(loginid = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val birthdate = new Field[TypoLocalDate, Row](prefix, "birthdate", Some("text"), Some("date"))(x => extract(x).birthdate, (row, value) => merge(row, extract(row).copy(birthdate = value))) + override val maritalstatus = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "maritalstatus", None, Some("bpchar"))(x => extract(x).maritalstatus, (row, value) => merge(row, extract(row).copy(maritalstatus = value))) + override val gender = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "gender", None, Some("bpchar"))(x => extract(x).gender, (row, value) => merge(row, extract(row).copy(gender = value))) + override val hiredate = new Field[TypoLocalDate, Row](prefix, "hiredate", Some("text"), Some("date"))(x => extract(x).hiredate, (row, value) => merge(row, extract(row).copy(hiredate = value))) + override val salariedflag = new Field[Flag, Row](prefix, "salariedflag", None, Some("bool"))(x => extract(x).salariedflag, (row, value) => merge(row, extract(row).copy(salariedflag = value))) + override val vacationhours = new Field[TypoShort, Row](prefix, "vacationhours", None, Some("int2"))(x => extract(x).vacationhours, (row, value) => merge(row, extract(row).copy(vacationhours = value))) + override val sickleavehours = new Field[TypoShort, Row](prefix, "sickleavehours", None, Some("int2"))(x => extract(x).sickleavehours, (row, value) => merge(row, extract(row).copy(sickleavehours = value))) + override val currentflag = new Field[Flag, Row](prefix, "currentflag", None, Some("bool"))(x => extract(x).currentflag, (row, value) => merge(row, extract(row).copy(currentflag = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val organizationnode = new OptField[String, Row](prefix, "organizationnode", None, None)(x => extract(x).organizationnode, (row, value) => merge(row, extract(row).copy(organizationnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, nationalidnumber, loginid, jobtitle, birthdate, maritalstatus, gender, hiredate, salariedflag, vacationhours, sickleavehours, currentflag, rowguid, modifieddate, organizationnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EmployeeRow, merge: (NewRow, EmployeeRow) => NewRow): EmployeeStructure[NewRow] = + new EmployeeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryFields.scala new file mode 100644 index 0000000000..e3dd76934a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait EmployeedepartmenthistoryFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val departmentid: IdField[DepartmentId, Row] + val shiftid: IdField[ShiftId, Row] + val startdate: IdField[TypoLocalDate, Row] + val enddate: OptField[TypoLocalDate, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EmployeedepartmenthistoryFields extends EmployeedepartmenthistoryStructure[EmployeedepartmenthistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryId.scala new file mode 100644 index 0000000000..5d41dacb1e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryId.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `humanresources.employeedepartmenthistory` */ +case class EmployeedepartmenthistoryId(businessentityid: BusinessentityId, startdate: TypoLocalDate, departmentid: DepartmentId, shiftid: ShiftId) +object EmployeedepartmenthistoryId { + implicit lazy val jsonDecoder: JsonDecoder[EmployeedepartmenthistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + if (businessentityid.isRight && startdate.isRight && departmentid.isRight && shiftid.isRight) + Right(EmployeedepartmenthistoryId(businessentityid = businessentityid.toOption.get, startdate = startdate.toOption.get, departmentid = departmentid.toOption.get, shiftid = shiftid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, startdate, departmentid, shiftid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeedepartmenthistoryId] = new JsonEncoder[EmployeedepartmenthistoryId] { + override def unsafeEncode(a: EmployeedepartmenthistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDate]): Ordering[EmployeedepartmenthistoryId] = Ordering.by(x => (x.businessentityid, x.startdate, x.departmentid, x.shiftid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepo.scala new file mode 100644 index 0000000000..9069a6a3f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EmployeedepartmenthistoryRepo { + def delete(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] + def insert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] + def insert(unsaved: EmployeedepartmenthistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] + def select: SelectBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] + def selectAll: ZStream[ZConnection, Throwable, EmployeedepartmenthistoryRow] + def selectById(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Option[EmployeedepartmenthistoryRow]] + def update(row: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] + def upsert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeedepartmenthistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoImpl.scala new file mode 100644 index 0000000000..99608de42e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoImpl.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EmployeedepartmenthistoryRepoImpl extends EmployeedepartmenthistoryRepo { + override def delete(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.employeedepartmenthistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDate.setter)} AND "departmentid" = ${Segment.paramSegment(compositeId.departmentid)(DepartmentId.setter)} AND "shiftid" = ${Segment.paramSegment(compositeId.shiftid)(ShiftId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + DeleteBuilder("humanresources.employeedepartmenthistory", EmployeedepartmenthistoryFields) + } + override def insert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + sql"""insert into humanresources.employeedepartmenthistory("businessentityid", "departmentid", "shiftid", "startdate", "enddate", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.departmentid)(DepartmentId.setter)}::int2, ${Segment.paramSegment(unsaved.shiftid)(ShiftId.setter)}::int2, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDate.setter)}::date, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDate.setter))}::date, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text + """.insertReturning(EmployeedepartmenthistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: EmployeedepartmenthistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""departmentid"""", sql"${Segment.paramSegment(unsaved.departmentid)(DepartmentId.setter)}::int2")), + Some((sql""""shiftid"""", sql"${Segment.paramSegment(unsaved.shiftid)(ShiftId.setter)}::int2")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDate.setter)}::date")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDate.setter))}::date")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.employeedepartmenthistory default values + returning "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.employeedepartmenthistory($names) values ($values) returning "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text""" + } + q.insertReturning(EmployeedepartmenthistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + SelectBuilderSql("humanresources.employeedepartmenthistory", EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + sql"""select "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text from humanresources.employeedepartmenthistory""".query(EmployeedepartmenthistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Option[EmployeedepartmenthistoryRow]] = { + sql"""select "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text from humanresources.employeedepartmenthistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDate.setter)} AND "departmentid" = ${Segment.paramSegment(compositeId.departmentid)(DepartmentId.setter)} AND "shiftid" = ${Segment.paramSegment(compositeId.shiftid)(ShiftId.setter)}""".query(EmployeedepartmenthistoryRow.jdbcDecoder).selectOne + } + override def update(row: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update humanresources.employeedepartmenthistory + set "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDate.setter))}::date, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDate.setter)} AND "departmentid" = ${Segment.paramSegment(compositeId.departmentid)(DepartmentId.setter)} AND "shiftid" = ${Segment.paramSegment(compositeId.shiftid)(ShiftId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + UpdateBuilder("humanresources.employeedepartmenthistory", EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow.jdbcDecoder) + } + override def upsert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeedepartmenthistoryRow]] = { + sql"""insert into humanresources.employeedepartmenthistory("businessentityid", "departmentid", "shiftid", "startdate", "enddate", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.departmentid)(DepartmentId.setter)}::int2, + ${Segment.paramSegment(unsaved.shiftid)(ShiftId.setter)}::int2, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDate.setter)}::date, + ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDate.setter))}::date, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "startdate", "departmentid", "shiftid") + do update set + "enddate" = EXCLUDED."enddate", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "departmentid", "shiftid", "startdate"::text, "enddate"::text, "modifieddate"::text""".insertReturning(EmployeedepartmenthistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoMock.scala new file mode 100644 index 0000000000..fba6185d95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class EmployeedepartmenthistoryRepoMock(toRow: Function1[EmployeedepartmenthistoryRowUnsaved, EmployeedepartmenthistoryRow], + map: scala.collection.mutable.Map[EmployeedepartmenthistoryId, EmployeedepartmenthistoryRow] = scala.collection.mutable.Map.empty) extends EmployeedepartmenthistoryRepo { + override def delete(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, EmployeedepartmenthistoryFields, map) + } + override def insert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: EmployeedepartmenthistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + SelectBuilderMock(EmployeedepartmenthistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeedepartmenthistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: EmployeedepartmenthistoryId): ZIO[ZConnection, Throwable, Option[EmployeedepartmenthistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, EmployeedepartmenthistoryFields, map) + } + override def upsert(unsaved: EmployeedepartmenthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeedepartmenthistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRow.scala new file mode 100644 index 0000000000..aee14e38de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRow.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EmployeedepartmenthistoryRow( + /** Employee identification number. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Department in which the employee worked including currently. Foreign key to Department.DepartmentID. + Points to [[department.DepartmentRow.departmentid]] */ + departmentid: DepartmentId, + /** Identifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID. + Points to [[shift.ShiftRow.shiftid]] */ + shiftid: ShiftId, + /** Date the employee started work in the department. + Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDate, + /** Date the employee left the department. NULL = Current department. + Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDate], + modifieddate: TypoLocalDateTime +){ + val compositeId: EmployeedepartmenthistoryId = EmployeedepartmenthistoryId(businessentityid, startdate, departmentid, shiftid) + } + +object EmployeedepartmenthistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EmployeedepartmenthistoryRow] = new JdbcDecoder[EmployeedepartmenthistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EmployeedepartmenthistoryRow) = + columIndex + 5 -> + EmployeedepartmenthistoryRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + departmentid = DepartmentId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + shiftid = ShiftId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + startdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EmployeedepartmenthistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && departmentid.isRight && shiftid.isRight && startdate.isRight && enddate.isRight && modifieddate.isRight) + Right(EmployeedepartmenthistoryRow(businessentityid = businessentityid.toOption.get, departmentid = departmentid.toOption.get, shiftid = shiftid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, departmentid, shiftid, startdate, enddate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeedepartmenthistoryRow] = new JsonEncoder[EmployeedepartmenthistoryRow] { + override def unsafeEncode(a: EmployeedepartmenthistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRowUnsaved.scala new file mode 100644 index 0000000000..abc0e843ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryRowUnsaved.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.employeedepartmenthistory` which has not been persisted yet */ +case class EmployeedepartmenthistoryRowUnsaved( + /** Employee identification number. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Department in which the employee worked including currently. Foreign key to Department.DepartmentID. + Points to [[department.DepartmentRow.departmentid]] */ + departmentid: DepartmentId, + /** Identifies which 8-hour shift the employee works. Foreign key to Shift.Shift.ID. + Points to [[shift.ShiftRow.shiftid]] */ + shiftid: ShiftId, + /** Date the employee started work in the department. + Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDate, + /** Date the employee left the department. NULL = Current department. + Constraint CK_EmployeeDepartmentHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDate], + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): EmployeedepartmenthistoryRow = + EmployeedepartmenthistoryRow( + businessentityid = businessentityid, + departmentid = departmentid, + shiftid = shiftid, + startdate = startdate, + enddate = enddate, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object EmployeedepartmenthistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[EmployeedepartmenthistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val departmentid = jsonObj.get("departmentid").toRight("Missing field 'departmentid'").flatMap(_.as(DepartmentId.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && departmentid.isRight && shiftid.isRight && startdate.isRight && enddate.isRight && modifieddate.isRight) + Right(EmployeedepartmenthistoryRowUnsaved(businessentityid = businessentityid.toOption.get, departmentid = departmentid.toOption.get, shiftid = shiftid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, departmentid, shiftid, startdate, enddate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeedepartmenthistoryRowUnsaved] = new JsonEncoder[EmployeedepartmenthistoryRowUnsaved] { + override def unsafeEncode(a: EmployeedepartmenthistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""departmentid":""") + DepartmentId.jsonEncoder.unsafeEncode(a.departmentid, indent, out) + out.write(",") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryStructure.scala new file mode 100644 index 0000000000..7c99ac336d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeedepartmenthistory/EmployeedepartmenthistoryStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.shift.ShiftId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EmployeedepartmenthistoryStructure[Row](val prefix: Option[String], val extract: Row => EmployeedepartmenthistoryRow, val merge: (Row, EmployeedepartmenthistoryRow) => Row) + extends Relation[EmployeedepartmenthistoryFields, EmployeedepartmenthistoryRow, Row] + with EmployeedepartmenthistoryFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val departmentid = new IdField[DepartmentId, Row](prefix, "departmentid", None, Some("int2"))(x => extract(x).departmentid, (row, value) => merge(row, extract(row).copy(departmentid = value))) + override val shiftid = new IdField[ShiftId, Row](prefix, "shiftid", None, Some("int2"))(x => extract(x).shiftid, (row, value) => merge(row, extract(row).copy(shiftid = value))) + override val startdate = new IdField[TypoLocalDate, Row](prefix, "startdate", Some("text"), Some("date"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDate, Row](prefix, "enddate", Some("text"), Some("date"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, departmentid, shiftid, startdate, enddate, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EmployeedepartmenthistoryRow, merge: (NewRow, EmployeedepartmenthistoryRow) => NewRow): EmployeedepartmenthistoryStructure[NewRow] = + new EmployeedepartmenthistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryFields.scala new file mode 100644 index 0000000000..c06bb4aaff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait EmployeepayhistoryFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val ratechangedate: IdField[TypoLocalDateTime, Row] + val rate: Field[BigDecimal, Row] + val payfrequency: Field[TypoShort, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EmployeepayhistoryFields extends EmployeepayhistoryStructure[EmployeepayhistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryId.scala new file mode 100644 index 0000000000..01e3caa7c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `humanresources.employeepayhistory` */ +case class EmployeepayhistoryId(businessentityid: BusinessentityId, ratechangedate: TypoLocalDateTime) +object EmployeepayhistoryId { + implicit lazy val jsonDecoder: JsonDecoder[EmployeepayhistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val ratechangedate = jsonObj.get("ratechangedate").toRight("Missing field 'ratechangedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && ratechangedate.isRight) + Right(EmployeepayhistoryId(businessentityid = businessentityid.toOption.get, ratechangedate = ratechangedate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, ratechangedate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeepayhistoryId] = new JsonEncoder[EmployeepayhistoryId] { + override def unsafeEncode(a: EmployeepayhistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""ratechangedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.ratechangedate, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDateTime]): Ordering[EmployeepayhistoryId] = Ordering.by(x => (x.businessentityid, x.ratechangedate)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepo.scala new file mode 100644 index 0000000000..b9fc2fdf40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EmployeepayhistoryRepo { + def delete(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] + def insert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] + def insert(unsaved: EmployeepayhistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] + def select: SelectBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] + def selectAll: ZStream[ZConnection, Throwable, EmployeepayhistoryRow] + def selectById(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Option[EmployeepayhistoryRow]] + def update(row: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] + def upsert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeepayhistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoImpl.scala new file mode 100644 index 0000000000..1f4ae093cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoImpl.scala @@ -0,0 +1,100 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EmployeepayhistoryRepoImpl extends EmployeepayhistoryRepo { + override def delete(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.employeepayhistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "ratechangedate" = ${Segment.paramSegment(compositeId.ratechangedate)(TypoLocalDateTime.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + DeleteBuilder("humanresources.employeepayhistory", EmployeepayhistoryFields) + } + override def insert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] = { + sql"""insert into humanresources.employeepayhistory("businessentityid", "ratechangedate", "rate", "payfrequency", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.ratechangedate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.rate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.payfrequency)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text + """.insertReturning(EmployeepayhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: EmployeepayhistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""ratechangedate"""", sql"${Segment.paramSegment(unsaved.ratechangedate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""rate"""", sql"${Segment.paramSegment(unsaved.rate)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""payfrequency"""", sql"${Segment.paramSegment(unsaved.payfrequency)(TypoShort.setter)}::int2")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.employeepayhistory default values + returning "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.employeepayhistory($names) values ($values) returning "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text""" + } + q.insertReturning(EmployeepayhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + SelectBuilderSql("humanresources.employeepayhistory", EmployeepayhistoryFields, EmployeepayhistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeepayhistoryRow] = { + sql"""select "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text from humanresources.employeepayhistory""".query(EmployeepayhistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Option[EmployeepayhistoryRow]] = { + sql"""select "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text from humanresources.employeepayhistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "ratechangedate" = ${Segment.paramSegment(compositeId.ratechangedate)(TypoLocalDateTime.setter)}""".query(EmployeepayhistoryRow.jdbcDecoder).selectOne + } + override def update(row: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update humanresources.employeepayhistory + set "rate" = ${Segment.paramSegment(row.rate)(Setter.bigDecimalScalaSetter)}::numeric, + "payfrequency" = ${Segment.paramSegment(row.payfrequency)(TypoShort.setter)}::int2, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "ratechangedate" = ${Segment.paramSegment(compositeId.ratechangedate)(TypoLocalDateTime.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + UpdateBuilder("humanresources.employeepayhistory", EmployeepayhistoryFields, EmployeepayhistoryRow.jdbcDecoder) + } + override def upsert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeepayhistoryRow]] = { + sql"""insert into humanresources.employeepayhistory("businessentityid", "ratechangedate", "rate", "payfrequency", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.ratechangedate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.rate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.payfrequency)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "ratechangedate") + do update set + "rate" = EXCLUDED."rate", + "payfrequency" = EXCLUDED."payfrequency", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "ratechangedate"::text, "rate", "payfrequency", "modifieddate"::text""".insertReturning(EmployeepayhistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoMock.scala new file mode 100644 index 0000000000..1ec4954985 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class EmployeepayhistoryRepoMock(toRow: Function1[EmployeepayhistoryRowUnsaved, EmployeepayhistoryRow], + map: scala.collection.mutable.Map[EmployeepayhistoryId, EmployeepayhistoryRow] = scala.collection.mutable.Map.empty) extends EmployeepayhistoryRepo { + override def delete(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, EmployeepayhistoryFields, map) + } + override def insert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: EmployeepayhistoryRowUnsaved): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + SelectBuilderMock(EmployeepayhistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, EmployeepayhistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: EmployeepayhistoryId): ZIO[ZConnection, Throwable, Option[EmployeepayhistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[EmployeepayhistoryFields, EmployeepayhistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, EmployeepayhistoryFields, map) + } + override def upsert(unsaved: EmployeepayhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[EmployeepayhistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRow.scala new file mode 100644 index 0000000000..4ef7bac5c9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EmployeepayhistoryRow( + /** Employee identification number. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Date the change in pay is effective */ + ratechangedate: TypoLocalDateTime, + /** Salary hourly rate. + Constraint CK_EmployeePayHistory_Rate affecting columns "rate": (((rate >= 6.50) AND (rate <= 200.00))) */ + rate: BigDecimal, + /** 1 = Salary received monthly, 2 = Salary received biweekly + Constraint CK_EmployeePayHistory_PayFrequency affecting columns "payfrequency": ((payfrequency = ANY (ARRAY[1, 2]))) */ + payfrequency: TypoShort, + modifieddate: TypoLocalDateTime +){ + val compositeId: EmployeepayhistoryId = EmployeepayhistoryId(businessentityid, ratechangedate) + } + +object EmployeepayhistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EmployeepayhistoryRow] = new JdbcDecoder[EmployeepayhistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EmployeepayhistoryRow) = + columIndex + 4 -> + EmployeepayhistoryRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + ratechangedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + rate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 2, rs)._2, + payfrequency = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EmployeepayhistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val ratechangedate = jsonObj.get("ratechangedate").toRight("Missing field 'ratechangedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val rate = jsonObj.get("rate").toRight("Missing field 'rate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val payfrequency = jsonObj.get("payfrequency").toRight("Missing field 'payfrequency'").flatMap(_.as(TypoShort.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && ratechangedate.isRight && rate.isRight && payfrequency.isRight && modifieddate.isRight) + Right(EmployeepayhistoryRow(businessentityid = businessentityid.toOption.get, ratechangedate = ratechangedate.toOption.get, rate = rate.toOption.get, payfrequency = payfrequency.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, ratechangedate, rate, payfrequency, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeepayhistoryRow] = new JsonEncoder[EmployeepayhistoryRow] { + override def unsafeEncode(a: EmployeepayhistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""ratechangedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.ratechangedate, indent, out) + out.write(",") + out.write(""""rate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rate, indent, out) + out.write(",") + out.write(""""payfrequency":""") + TypoShort.jsonEncoder.unsafeEncode(a.payfrequency, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRowUnsaved.scala new file mode 100644 index 0000000000..87a60a5e59 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryRowUnsaved.scala @@ -0,0 +1,78 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.employeepayhistory` which has not been persisted yet */ +case class EmployeepayhistoryRowUnsaved( + /** Employee identification number. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Date the change in pay is effective */ + ratechangedate: TypoLocalDateTime, + /** Salary hourly rate. + Constraint CK_EmployeePayHistory_Rate affecting columns "rate": (((rate >= 6.50) AND (rate <= 200.00))) */ + rate: BigDecimal, + /** 1 = Salary received monthly, 2 = Salary received biweekly + Constraint CK_EmployeePayHistory_PayFrequency affecting columns "payfrequency": ((payfrequency = ANY (ARRAY[1, 2]))) */ + payfrequency: TypoShort, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): EmployeepayhistoryRow = + EmployeepayhistoryRow( + businessentityid = businessentityid, + ratechangedate = ratechangedate, + rate = rate, + payfrequency = payfrequency, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object EmployeepayhistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[EmployeepayhistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val ratechangedate = jsonObj.get("ratechangedate").toRight("Missing field 'ratechangedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val rate = jsonObj.get("rate").toRight("Missing field 'rate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val payfrequency = jsonObj.get("payfrequency").toRight("Missing field 'payfrequency'").flatMap(_.as(TypoShort.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && ratechangedate.isRight && rate.isRight && payfrequency.isRight && modifieddate.isRight) + Right(EmployeepayhistoryRowUnsaved(businessentityid = businessentityid.toOption.get, ratechangedate = ratechangedate.toOption.get, rate = rate.toOption.get, payfrequency = payfrequency.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, ratechangedate, rate, payfrequency, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmployeepayhistoryRowUnsaved] = new JsonEncoder[EmployeepayhistoryRowUnsaved] { + override def unsafeEncode(a: EmployeepayhistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""ratechangedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.ratechangedate, indent, out) + out.write(",") + out.write(""""rate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rate, indent, out) + out.write(",") + out.write(""""payfrequency":""") + TypoShort.jsonEncoder.unsafeEncode(a.payfrequency, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryStructure.scala new file mode 100644 index 0000000000..6956bed217 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/employeepayhistory/EmployeepayhistoryStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package employeepayhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class EmployeepayhistoryStructure[Row](val prefix: Option[String], val extract: Row => EmployeepayhistoryRow, val merge: (Row, EmployeepayhistoryRow) => Row) + extends Relation[EmployeepayhistoryFields, EmployeepayhistoryRow, Row] + with EmployeepayhistoryFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val ratechangedate = new IdField[TypoLocalDateTime, Row](prefix, "ratechangedate", Some("text"), Some("timestamp"))(x => extract(x).ratechangedate, (row, value) => merge(row, extract(row).copy(ratechangedate = value))) + override val rate = new Field[BigDecimal, Row](prefix, "rate", None, Some("numeric"))(x => extract(x).rate, (row, value) => merge(row, extract(row).copy(rate = value))) + override val payfrequency = new Field[TypoShort, Row](prefix, "payfrequency", None, Some("int2"))(x => extract(x).payfrequency, (row, value) => merge(row, extract(row).copy(payfrequency = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, ratechangedate, rate, payfrequency, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EmployeepayhistoryRow, merge: (NewRow, EmployeepayhistoryRow) => NewRow): EmployeepayhistoryStructure[NewRow] = + new EmployeepayhistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateFields.scala new file mode 100644 index 0000000000..f77da744f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait JobcandidateFields[Row] { + val jobcandidateid: IdField[JobcandidateId, Row] + val businessentityid: OptField[BusinessentityId, Row] + val resume: OptField[TypoXml, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object JobcandidateFields extends JobcandidateStructure[JobcandidateRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateId.scala new file mode 100644 index 0000000000..a714a4ad19 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +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 `humanresources.jobcandidate` */ +case class JobcandidateId(value: Int) extends AnyVal +object JobcandidateId { + implicit lazy val arraySetter: Setter[Array[JobcandidateId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[JobcandidateId, Int] = Bijection[JobcandidateId, Int](_.value)(JobcandidateId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[JobcandidateId] = JdbcDecoder.intDecoder.map(JobcandidateId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[JobcandidateId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[JobcandidateId] = JsonDecoder.int.map(JobcandidateId.apply) + implicit lazy val jsonEncoder: JsonEncoder[JobcandidateId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[JobcandidateId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[JobcandidateId] = ParameterMetaData.instance[JobcandidateId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[JobcandidateId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepo.scala new file mode 100644 index 0000000000..31c343ed56 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait JobcandidateRepo { + def delete(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[JobcandidateFields, JobcandidateRow] + def insert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, JobcandidateRow] + def insert(unsaved: JobcandidateRowUnsaved): ZIO[ZConnection, Throwable, JobcandidateRow] + def select: SelectBuilder[JobcandidateFields, JobcandidateRow] + def selectAll: ZStream[ZConnection, Throwable, JobcandidateRow] + def selectById(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Option[JobcandidateRow]] + def selectByIds(jobcandidateids: Array[JobcandidateId]): ZStream[ZConnection, Throwable, JobcandidateRow] + def update(row: JobcandidateRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[JobcandidateFields, JobcandidateRow] + def upsert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, UpdateResult[JobcandidateRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoImpl.scala new file mode 100644 index 0000000000..d3df5e4653 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoImpl.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object JobcandidateRepoImpl extends JobcandidateRepo { + override def delete(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.jobcandidate where "jobcandidateid" = ${Segment.paramSegment(jobcandidateid)(JobcandidateId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[JobcandidateFields, JobcandidateRow] = { + DeleteBuilder("humanresources.jobcandidate", JobcandidateFields) + } + override def insert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, JobcandidateRow] = { + sql"""insert into humanresources.jobcandidate("jobcandidateid", "businessentityid", "resume", "modifieddate") + values (${Segment.paramSegment(unsaved.jobcandidateid)(JobcandidateId.setter)}::int4, ${Segment.paramSegment(unsaved.businessentityid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, ${Segment.paramSegment(unsaved.resume)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "jobcandidateid", "businessentityid", "resume", "modifieddate"::text + """.insertReturning(JobcandidateRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: JobcandidateRowUnsaved): ZIO[ZConnection, Throwable, JobcandidateRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4")), + Some((sql""""resume"""", sql"${Segment.paramSegment(unsaved.resume)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + unsaved.jobcandidateid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""jobcandidateid"""", sql"${Segment.paramSegment(value: JobcandidateId)(JobcandidateId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.jobcandidate default values + returning "jobcandidateid", "businessentityid", "resume", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.jobcandidate($names) values ($values) returning "jobcandidateid", "businessentityid", "resume", "modifieddate"::text""" + } + q.insertReturning(JobcandidateRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[JobcandidateFields, JobcandidateRow] = { + SelectBuilderSql("humanresources.jobcandidate", JobcandidateFields, JobcandidateRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, JobcandidateRow] = { + sql"""select "jobcandidateid", "businessentityid", "resume", "modifieddate"::text from humanresources.jobcandidate""".query(JobcandidateRow.jdbcDecoder).selectStream + } + override def selectById(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Option[JobcandidateRow]] = { + sql"""select "jobcandidateid", "businessentityid", "resume", "modifieddate"::text from humanresources.jobcandidate where "jobcandidateid" = ${Segment.paramSegment(jobcandidateid)(JobcandidateId.setter)}""".query(JobcandidateRow.jdbcDecoder).selectOne + } + override def selectByIds(jobcandidateids: Array[JobcandidateId]): ZStream[ZConnection, Throwable, JobcandidateRow] = { + sql"""select "jobcandidateid", "businessentityid", "resume", "modifieddate"::text from humanresources.jobcandidate where "jobcandidateid" = ANY(${Segment.paramSegment(jobcandidateids)(JobcandidateId.arraySetter)})""".query(JobcandidateRow.jdbcDecoder).selectStream + } + override def update(row: JobcandidateRow): ZIO[ZConnection, Throwable, Boolean] = { + val jobcandidateid = row.jobcandidateid + sql"""update humanresources.jobcandidate + set "businessentityid" = ${Segment.paramSegment(row.businessentityid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + "resume" = ${Segment.paramSegment(row.resume)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "jobcandidateid" = ${Segment.paramSegment(jobcandidateid)(JobcandidateId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[JobcandidateFields, JobcandidateRow] = { + UpdateBuilder("humanresources.jobcandidate", JobcandidateFields, JobcandidateRow.jdbcDecoder) + } + override def upsert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, UpdateResult[JobcandidateRow]] = { + sql"""insert into humanresources.jobcandidate("jobcandidateid", "businessentityid", "resume", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.jobcandidateid)(JobcandidateId.setter)}::int4, + ${Segment.paramSegment(unsaved.businessentityid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + ${Segment.paramSegment(unsaved.resume)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("jobcandidateid") + do update set + "businessentityid" = EXCLUDED."businessentityid", + "resume" = EXCLUDED."resume", + "modifieddate" = EXCLUDED."modifieddate" + returning "jobcandidateid", "businessentityid", "resume", "modifieddate"::text""".insertReturning(JobcandidateRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoMock.scala new file mode 100644 index 0000000000..be5c93964f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class JobcandidateRepoMock(toRow: Function1[JobcandidateRowUnsaved, JobcandidateRow], + map: scala.collection.mutable.Map[JobcandidateId, JobcandidateRow] = scala.collection.mutable.Map.empty) extends JobcandidateRepo { + override def delete(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(jobcandidateid).isDefined) + } + override def delete: DeleteBuilder[JobcandidateFields, JobcandidateRow] = { + DeleteBuilderMock(DeleteParams.empty, JobcandidateFields, map) + } + override def insert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, JobcandidateRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.jobcandidateid)) + sys.error(s"id ${unsaved.jobcandidateid} already exists") + else + map.put(unsaved.jobcandidateid, unsaved) + + unsaved + } + } + override def insert(unsaved: JobcandidateRowUnsaved): ZIO[ZConnection, Throwable, JobcandidateRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[JobcandidateFields, JobcandidateRow] = { + SelectBuilderMock(JobcandidateFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, JobcandidateRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(jobcandidateid: JobcandidateId): ZIO[ZConnection, Throwable, Option[JobcandidateRow]] = { + ZIO.succeed(map.get(jobcandidateid)) + } + override def selectByIds(jobcandidateids: Array[JobcandidateId]): ZStream[ZConnection, Throwable, JobcandidateRow] = { + ZStream.fromIterable(jobcandidateids.flatMap(map.get)) + } + override def update(row: JobcandidateRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.jobcandidateid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.jobcandidateid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[JobcandidateFields, JobcandidateRow] = { + UpdateBuilderMock(UpdateParams.empty, JobcandidateFields, map) + } + override def upsert(unsaved: JobcandidateRow): ZIO[ZConnection, Throwable, UpdateResult[JobcandidateRow]] = { + ZIO.succeed { + map.put(unsaved.jobcandidateid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRow.scala new file mode 100644 index 0000000000..955825deaf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class JobcandidateRow( + /** Primary key for JobCandidate records. */ + jobcandidateid: JobcandidateId, + /** Employee identification number if applicant was hired. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: Option[BusinessentityId], + /** Résumé in XML format. */ + resume: Option[TypoXml], + modifieddate: TypoLocalDateTime +) + +object JobcandidateRow { + implicit lazy val jdbcDecoder: JdbcDecoder[JobcandidateRow] = new JdbcDecoder[JobcandidateRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, JobcandidateRow) = + columIndex + 3 -> + JobcandidateRow( + jobcandidateid = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + resume = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[JobcandidateRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val resume = jsonObj.get("resume").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (jobcandidateid.isRight && businessentityid.isRight && resume.isRight && modifieddate.isRight) + Right(JobcandidateRow(jobcandidateid = jobcandidateid.toOption.get, businessentityid = businessentityid.toOption.get, resume = resume.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](jobcandidateid, businessentityid, resume, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[JobcandidateRow] = new JsonEncoder[JobcandidateRow] { + override def unsafeEncode(a: JobcandidateRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""jobcandidateid":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""resume":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.resume, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRowUnsaved.scala new file mode 100644 index 0000000000..8ef808abc2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateRowUnsaved.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.jobcandidate` which has not been persisted yet */ +case class JobcandidateRowUnsaved( + /** Employee identification number if applicant was hired. Foreign key to Employee.BusinessEntityID. + Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: Option[BusinessentityId], + /** Résumé in XML format. */ + resume: Option[TypoXml], + /** Default: nextval('humanresources.jobcandidate_jobcandidateid_seq'::regclass) + Primary key for JobCandidate records. */ + jobcandidateid: Defaulted[JobcandidateId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(jobcandidateidDefault: => JobcandidateId, modifieddateDefault: => TypoLocalDateTime): JobcandidateRow = + JobcandidateRow( + businessentityid = businessentityid, + resume = resume, + jobcandidateid = jobcandidateid match { + case Defaulted.UseDefault => jobcandidateidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object JobcandidateRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[JobcandidateRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val resume = jsonObj.get("resume").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(Defaulted.jsonDecoder(JobcandidateId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && resume.isRight && jobcandidateid.isRight && modifieddate.isRight) + Right(JobcandidateRowUnsaved(businessentityid = businessentityid.toOption.get, resume = resume.toOption.get, jobcandidateid = jobcandidateid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, resume, jobcandidateid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[JobcandidateRowUnsaved] = new JsonEncoder[JobcandidateRowUnsaved] { + override def unsafeEncode(a: JobcandidateRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""resume":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.resume, indent, out) + out.write(",") + out.write(""""jobcandidateid":""") + Defaulted.jsonEncoder(JobcandidateId.jsonEncoder).unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateStructure.scala new file mode 100644 index 0000000000..067bb2b939 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/jobcandidate/JobcandidateStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package jobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class JobcandidateStructure[Row](val prefix: Option[String], val extract: Row => JobcandidateRow, val merge: (Row, JobcandidateRow) => Row) + extends Relation[JobcandidateFields, JobcandidateRow, Row] + with JobcandidateFields[Row] { outer => + + override val jobcandidateid = new IdField[JobcandidateId, Row](prefix, "jobcandidateid", None, Some("int4"))(x => extract(x).jobcandidateid, (row, value) => merge(row, extract(row).copy(jobcandidateid = value))) + override val businessentityid = new OptField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val resume = new OptField[TypoXml, Row](prefix, "resume", None, Some("xml"))(x => extract(x).resume, (row, value) => merge(row, extract(row).copy(resume = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](jobcandidateid, businessentityid, resume, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => JobcandidateRow, merge: (NewRow, JobcandidateRow) => NewRow): JobcandidateStructure[NewRow] = + new JobcandidateStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftFields.scala new file mode 100644 index 0000000000..a2fdea72e1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ShiftFields[Row] { + val shiftid: IdField[ShiftId, Row] + val name: Field[Name, Row] + val starttime: Field[TypoLocalTime, Row] + val endtime: Field[TypoLocalTime, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ShiftFields extends ShiftStructure[ShiftRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftId.scala new file mode 100644 index 0000000000..117e670732 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +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 `humanresources.shift` */ +case class ShiftId(value: Int) extends AnyVal +object ShiftId { + implicit lazy val arraySetter: Setter[Array[ShiftId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ShiftId, Int] = Bijection[ShiftId, Int](_.value)(ShiftId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ShiftId] = JdbcDecoder.intDecoder.map(ShiftId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ShiftId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ShiftId] = JsonDecoder.int.map(ShiftId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ShiftId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ShiftId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ShiftId] = ParameterMetaData.instance[ShiftId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ShiftId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepo.scala new file mode 100644 index 0000000000..6b28e607ba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ShiftRepo { + def delete(shiftid: ShiftId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ShiftFields, ShiftRow] + def insert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, ShiftRow] + def insert(unsaved: ShiftRowUnsaved): ZIO[ZConnection, Throwable, ShiftRow] + def select: SelectBuilder[ShiftFields, ShiftRow] + def selectAll: ZStream[ZConnection, Throwable, ShiftRow] + def selectById(shiftid: ShiftId): ZIO[ZConnection, Throwable, Option[ShiftRow]] + def selectByIds(shiftids: Array[ShiftId]): ZStream[ZConnection, Throwable, ShiftRow] + def update(row: ShiftRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ShiftFields, ShiftRow] + def upsert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, UpdateResult[ShiftRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoImpl.scala new file mode 100644 index 0000000000..b7de936eab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoImpl.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ShiftRepoImpl extends ShiftRepo { + override def delete(shiftid: ShiftId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from humanresources.shift where "shiftid" = ${Segment.paramSegment(shiftid)(ShiftId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ShiftFields, ShiftRow] = { + DeleteBuilder("humanresources.shift", ShiftFields) + } + override def insert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, ShiftRow] = { + sql"""insert into humanresources.shift("shiftid", "name", "starttime", "endtime", "modifieddate") + values (${Segment.paramSegment(unsaved.shiftid)(ShiftId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.starttime)(TypoLocalTime.setter)}::time, ${Segment.paramSegment(unsaved.endtime)(TypoLocalTime.setter)}::time, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text + """.insertReturning(ShiftRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ShiftRowUnsaved): ZIO[ZConnection, Throwable, ShiftRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""starttime"""", sql"${Segment.paramSegment(unsaved.starttime)(TypoLocalTime.setter)}::time")), + Some((sql""""endtime"""", sql"${Segment.paramSegment(unsaved.endtime)(TypoLocalTime.setter)}::time")), + unsaved.shiftid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""shiftid"""", sql"${Segment.paramSegment(value: ShiftId)(ShiftId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into humanresources.shift default values + returning "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into humanresources.shift($names) values ($values) returning "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text""" + } + q.insertReturning(ShiftRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ShiftFields, ShiftRow] = { + SelectBuilderSql("humanresources.shift", ShiftFields, ShiftRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ShiftRow] = { + sql"""select "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text from humanresources.shift""".query(ShiftRow.jdbcDecoder).selectStream + } + override def selectById(shiftid: ShiftId): ZIO[ZConnection, Throwable, Option[ShiftRow]] = { + sql"""select "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text from humanresources.shift where "shiftid" = ${Segment.paramSegment(shiftid)(ShiftId.setter)}""".query(ShiftRow.jdbcDecoder).selectOne + } + override def selectByIds(shiftids: Array[ShiftId]): ZStream[ZConnection, Throwable, ShiftRow] = { + sql"""select "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text from humanresources.shift where "shiftid" = ANY(${Segment.paramSegment(shiftids)(ShiftId.arraySetter)})""".query(ShiftRow.jdbcDecoder).selectStream + } + override def update(row: ShiftRow): ZIO[ZConnection, Throwable, Boolean] = { + val shiftid = row.shiftid + sql"""update humanresources.shift + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "starttime" = ${Segment.paramSegment(row.starttime)(TypoLocalTime.setter)}::time, + "endtime" = ${Segment.paramSegment(row.endtime)(TypoLocalTime.setter)}::time, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "shiftid" = ${Segment.paramSegment(shiftid)(ShiftId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ShiftFields, ShiftRow] = { + UpdateBuilder("humanresources.shift", ShiftFields, ShiftRow.jdbcDecoder) + } + override def upsert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, UpdateResult[ShiftRow]] = { + sql"""insert into humanresources.shift("shiftid", "name", "starttime", "endtime", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.shiftid)(ShiftId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.starttime)(TypoLocalTime.setter)}::time, + ${Segment.paramSegment(unsaved.endtime)(TypoLocalTime.setter)}::time, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("shiftid") + do update set + "name" = EXCLUDED."name", + "starttime" = EXCLUDED."starttime", + "endtime" = EXCLUDED."endtime", + "modifieddate" = EXCLUDED."modifieddate" + returning "shiftid", "name", "starttime"::text, "endtime"::text, "modifieddate"::text""".insertReturning(ShiftRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoMock.scala new file mode 100644 index 0000000000..4e0de59361 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ShiftRepoMock(toRow: Function1[ShiftRowUnsaved, ShiftRow], + map: scala.collection.mutable.Map[ShiftId, ShiftRow] = scala.collection.mutable.Map.empty) extends ShiftRepo { + override def delete(shiftid: ShiftId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(shiftid).isDefined) + } + override def delete: DeleteBuilder[ShiftFields, ShiftRow] = { + DeleteBuilderMock(DeleteParams.empty, ShiftFields, map) + } + override def insert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, ShiftRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.shiftid)) + sys.error(s"id ${unsaved.shiftid} already exists") + else + map.put(unsaved.shiftid, unsaved) + + unsaved + } + } + override def insert(unsaved: ShiftRowUnsaved): ZIO[ZConnection, Throwable, ShiftRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ShiftFields, ShiftRow] = { + SelectBuilderMock(ShiftFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ShiftRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(shiftid: ShiftId): ZIO[ZConnection, Throwable, Option[ShiftRow]] = { + ZIO.succeed(map.get(shiftid)) + } + override def selectByIds(shiftids: Array[ShiftId]): ZStream[ZConnection, Throwable, ShiftRow] = { + ZStream.fromIterable(shiftids.flatMap(map.get)) + } + override def update(row: ShiftRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.shiftid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.shiftid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ShiftFields, ShiftRow] = { + UpdateBuilderMock(UpdateParams.empty, ShiftFields, map) + } + override def upsert(unsaved: ShiftRow): ZIO[ZConnection, Throwable, UpdateResult[ShiftRow]] = { + ZIO.succeed { + map.put(unsaved.shiftid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRow.scala new file mode 100644 index 0000000000..938d4f934c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRow.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ShiftRow( + /** Primary key for Shift records. */ + shiftid: ShiftId, + /** Shift description. */ + name: Name, + /** Shift start time. */ + starttime: TypoLocalTime, + /** Shift end time. */ + endtime: TypoLocalTime, + modifieddate: TypoLocalDateTime +) + +object ShiftRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ShiftRow] = new JdbcDecoder[ShiftRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ShiftRow) = + columIndex + 4 -> + ShiftRow( + shiftid = ShiftId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + starttime = TypoLocalTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + endtime = TypoLocalTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ShiftRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(ShiftId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val starttime = jsonObj.get("starttime").toRight("Missing field 'starttime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val endtime = jsonObj.get("endtime").toRight("Missing field 'endtime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (shiftid.isRight && name.isRight && starttime.isRight && endtime.isRight && modifieddate.isRight) + Right(ShiftRow(shiftid = shiftid.toOption.get, name = name.toOption.get, starttime = starttime.toOption.get, endtime = endtime.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](shiftid, name, starttime, endtime, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShiftRow] = new JsonEncoder[ShiftRow] { + override def unsafeEncode(a: ShiftRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""shiftid":""") + ShiftId.jsonEncoder.unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""starttime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.starttime, indent, out) + out.write(",") + out.write(""""endtime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.endtime, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRowUnsaved.scala new file mode 100644 index 0000000000..434707e5d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftRowUnsaved.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `humanresources.shift` which has not been persisted yet */ +case class ShiftRowUnsaved( + /** Shift description. */ + name: Name, + /** Shift start time. */ + starttime: TypoLocalTime, + /** Shift end time. */ + endtime: TypoLocalTime, + /** Default: nextval('humanresources.shift_shiftid_seq'::regclass) + Primary key for Shift records. */ + shiftid: Defaulted[ShiftId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(shiftidDefault: => ShiftId, modifieddateDefault: => TypoLocalDateTime): ShiftRow = + ShiftRow( + name = name, + starttime = starttime, + endtime = endtime, + shiftid = shiftid match { + case Defaulted.UseDefault => shiftidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ShiftRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ShiftRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val starttime = jsonObj.get("starttime").toRight("Missing field 'starttime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val endtime = jsonObj.get("endtime").toRight("Missing field 'endtime'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val shiftid = jsonObj.get("shiftid").toRight("Missing field 'shiftid'").flatMap(_.as(Defaulted.jsonDecoder(ShiftId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && starttime.isRight && endtime.isRight && shiftid.isRight && modifieddate.isRight) + Right(ShiftRowUnsaved(name = name.toOption.get, starttime = starttime.toOption.get, endtime = endtime.toOption.get, shiftid = shiftid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, starttime, endtime, shiftid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShiftRowUnsaved] = new JsonEncoder[ShiftRowUnsaved] { + override def unsafeEncode(a: ShiftRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""starttime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.starttime, indent, out) + out.write(",") + out.write(""""endtime":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.endtime, indent, out) + out.write(",") + out.write(""""shiftid":""") + Defaulted.jsonEncoder(ShiftId.jsonEncoder).unsafeEncode(a.shiftid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftStructure.scala new file mode 100644 index 0000000000..b26d189a1a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/shift/ShiftStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package shift + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ShiftStructure[Row](val prefix: Option[String], val extract: Row => ShiftRow, val merge: (Row, ShiftRow) => Row) + extends Relation[ShiftFields, ShiftRow, Row] + with ShiftFields[Row] { outer => + + override val shiftid = new IdField[ShiftId, Row](prefix, "shiftid", None, Some("int4"))(x => extract(x).shiftid, (row, value) => merge(row, extract(row).copy(shiftid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val starttime = new Field[TypoLocalTime, Row](prefix, "starttime", Some("text"), Some("time"))(x => extract(x).starttime, (row, value) => merge(row, extract(row).copy(starttime = value))) + override val endtime = new Field[TypoLocalTime, Row](prefix, "endtime", Some("text"), Some("time"))(x => extract(x).endtime, (row, value) => merge(row, extract(row).copy(endtime = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](shiftid, name, starttime, endtime, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ShiftRow, merge: (NewRow, ShiftRow) => NewRow): ShiftStructure[NewRow] = + new ShiftStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewFields.scala new file mode 100644 index 0000000000..1d61296667 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewFields.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployee + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VemployeeViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val phonenumber: OptField[Phone, Row] + val phonenumbertype: OptField[Name, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val emailpromotion: Field[Int, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovincename: Field[Name, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val countryregionname: Field[Name, Row] + val additionalcontactinfo: OptField[TypoXml, Row] +} +object VemployeeViewFields extends VemployeeViewStructure[VemployeeViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepo.scala new file mode 100644 index 0000000000..783577820e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployee + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VemployeeViewRepo { + def select: SelectBuilder[VemployeeViewFields, VemployeeViewRow] + def selectAll: ZStream[ZConnection, Throwable, VemployeeViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepoImpl.scala new file mode 100644 index 0000000000..f0f4ec09ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployee + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VemployeeViewRepoImpl extends VemployeeViewRepo { + override def select: SelectBuilder[VemployeeViewFields, VemployeeViewRow] = { + SelectBuilderSql("humanresources.vemployee", VemployeeViewFields, VemployeeViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VemployeeViewRow] = { + sql"""select "businessentityid", "title", "firstname", "middlename", "lastname", "suffix", "jobtitle", "phonenumber", "phonenumbertype", "emailaddress", "emailpromotion", "addressline1", "addressline2", "city", "stateprovincename", "postalcode", "countryregionname", "additionalcontactinfo" from humanresources.vemployee""".query(VemployeeViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRow.scala new file mode 100644 index 0000000000..8c99b5ed89 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewRow.scala @@ -0,0 +1,168 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployee + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VemployeeViewRow( + /** Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Option[Phone], + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + phonenumbertype: Option[Name], + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + countryregionname: Name, + /** Points to [[person.person.PersonRow.additionalcontactinfo]] */ + additionalcontactinfo: Option[TypoXml] +) + +object VemployeeViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VemployeeViewRow] = new JdbcDecoder[VemployeeViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VemployeeViewRow) = + columIndex + 17 -> + VemployeeViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + phonenumber = JdbcDecoder.optionDecoder(Phone.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + phonenumbertype = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 10, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 11, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 13, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 15, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + additionalcontactinfo = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VemployeeViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val phonenumber = jsonObj.get("phonenumber").fold[Either[String, Option[Phone]]](Right(None))(_.as(JsonDecoder.option(Phone.jsonDecoder))) + val phonenumbertype = jsonObj.get("phonenumbertype").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + val additionalcontactinfo = jsonObj.get("additionalcontactinfo").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && jobtitle.isRight && phonenumber.isRight && phonenumbertype.isRight && emailaddress.isRight && emailpromotion.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovincename.isRight && postalcode.isRight && countryregionname.isRight && additionalcontactinfo.isRight) + Right(VemployeeViewRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, jobtitle = jobtitle.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertype = phonenumbertype.toOption.get, emailaddress = emailaddress.toOption.get, emailpromotion = emailpromotion.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovincename = stateprovincename.toOption.get, postalcode = postalcode.toOption.get, countryregionname = countryregionname.toOption.get, additionalcontactinfo = additionalcontactinfo.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, phonenumber, phonenumbertype, emailaddress, emailpromotion, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, additionalcontactinfo).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VemployeeViewRow] = new JsonEncoder[VemployeeViewRow] { + override def unsafeEncode(a: VemployeeViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""phonenumber":""") + JsonEncoder.option(Phone.jsonEncoder).unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertype":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.phonenumbertype, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write(",") + out.write(""""additionalcontactinfo":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.additionalcontactinfo, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewStructure.scala new file mode 100644 index 0000000000..62e865c75f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployee/VemployeeViewStructure.scala @@ -0,0 +1,48 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployee + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VemployeeViewStructure[Row](val prefix: Option[String], val extract: Row => VemployeeViewRow, val merge: (Row, VemployeeViewRow) => Row) + extends Relation[VemployeeViewFields, VemployeeViewRow, Row] + with VemployeeViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val phonenumber = new OptField[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertype = new OptField[Name, Row](prefix, "phonenumbertype", None, None)(x => extract(x).phonenumbertype, (row, value) => merge(row, extract(row).copy(phonenumbertype = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + override val additionalcontactinfo = new OptField[TypoXml, Row](prefix, "additionalcontactinfo", None, None)(x => extract(x).additionalcontactinfo, (row, value) => merge(row, extract(row).copy(additionalcontactinfo = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, phonenumber, phonenumbertype, emailaddress, emailpromotion, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, additionalcontactinfo) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VemployeeViewRow, merge: (NewRow, VemployeeViewRow) => NewRow): VemployeeViewStructure[NewRow] = + new VemployeeViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewFields.scala new file mode 100644 index 0000000000..1ecb4d0b1c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VemployeedepartmentViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val department: Field[Name, Row] + val groupname: Field[Name, Row] + val startdate: Field[TypoLocalDate, Row] +} +object VemployeedepartmentViewFields extends VemployeedepartmentViewStructure[VemployeedepartmentViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepo.scala new file mode 100644 index 0000000000..76998a8a03 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartment + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VemployeedepartmentViewRepo { + def select: SelectBuilder[VemployeedepartmentViewFields, VemployeedepartmentViewRow] + def selectAll: ZStream[ZConnection, Throwable, VemployeedepartmentViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepoImpl.scala new file mode 100644 index 0000000000..dc6acbbfc7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartment + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VemployeedepartmentViewRepoImpl extends VemployeedepartmentViewRepo { + override def select: SelectBuilder[VemployeedepartmentViewFields, VemployeedepartmentViewRow] = { + SelectBuilderSql("humanresources.vemployeedepartment", VemployeedepartmentViewFields, VemployeedepartmentViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VemployeedepartmentViewRow] = { + sql"""select "businessentityid", "title", "firstname", "middlename", "lastname", "suffix", "jobtitle", "department", "groupname", "startdate"::text from humanresources.vemployeedepartment""".query(VemployeedepartmentViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRow.scala new file mode 100644 index 0000000000..6f3212bb75 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewRow.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VemployeedepartmentViewRow( + /** Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[department.DepartmentRow.name]] */ + department: Name, + /** Points to [[department.DepartmentRow.groupname]] */ + groupname: Name, + /** Points to [[employeedepartmenthistory.EmployeedepartmenthistoryRow.startdate]] */ + startdate: TypoLocalDate +) + +object VemployeedepartmentViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VemployeedepartmentViewRow] = new JdbcDecoder[VemployeedepartmentViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VemployeedepartmentViewRow) = + columIndex + 9 -> + VemployeedepartmentViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + department = Name.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + groupname = Name.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + startdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VemployeedepartmentViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val department = jsonObj.get("department").toRight("Missing field 'department'").flatMap(_.as(Name.jsonDecoder)) + val groupname = jsonObj.get("groupname").toRight("Missing field 'groupname'").flatMap(_.as(Name.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && jobtitle.isRight && department.isRight && groupname.isRight && startdate.isRight) + Right(VemployeedepartmentViewRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, jobtitle = jobtitle.toOption.get, department = department.toOption.get, groupname = groupname.toOption.get, startdate = startdate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, department, groupname, startdate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VemployeedepartmentViewRow] = new JsonEncoder[VemployeedepartmentViewRow] { + override def unsafeEncode(a: VemployeedepartmentViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""department":""") + Name.jsonEncoder.unsafeEncode(a.department, indent, out) + out.write(",") + out.write(""""groupname":""") + Name.jsonEncoder.unsafeEncode(a.groupname, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewStructure.scala new file mode 100644 index 0000000000..2d36b7de0c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartment/VemployeedepartmentViewStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VemployeedepartmentViewStructure[Row](val prefix: Option[String], val extract: Row => VemployeedepartmentViewRow, val merge: (Row, VemployeedepartmentViewRow) => Row) + extends Relation[VemployeedepartmentViewFields, VemployeedepartmentViewRow, Row] + with VemployeedepartmentViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val department = new Field[Name, Row](prefix, "department", None, None)(x => extract(x).department, (row, value) => merge(row, extract(row).copy(department = value))) + override val groupname = new Field[Name, Row](prefix, "groupname", None, None)(x => extract(x).groupname, (row, value) => merge(row, extract(row).copy(groupname = value))) + override val startdate = new Field[TypoLocalDate, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, department, groupname, startdate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VemployeedepartmentViewRow, merge: (NewRow, VemployeedepartmentViewRow) => NewRow): VemployeedepartmentViewStructure[NewRow] = + new VemployeedepartmentViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewFields.scala new file mode 100644 index 0000000000..0b8e99af1e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VemployeedepartmenthistoryViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val shift: Field[Name, Row] + val department: Field[Name, Row] + val groupname: Field[Name, Row] + val startdate: Field[TypoLocalDate, Row] + val enddate: OptField[TypoLocalDate, Row] +} +object VemployeedepartmenthistoryViewFields extends VemployeedepartmenthistoryViewStructure[VemployeedepartmenthistoryViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepo.scala new file mode 100644 index 0000000000..bfb3d39a5d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartmenthistory + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VemployeedepartmenthistoryViewRepo { + def select: SelectBuilder[VemployeedepartmenthistoryViewFields, VemployeedepartmenthistoryViewRow] + def selectAll: ZStream[ZConnection, Throwable, VemployeedepartmenthistoryViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepoImpl.scala new file mode 100644 index 0000000000..17f07d5f15 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartmenthistory + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VemployeedepartmenthistoryViewRepoImpl extends VemployeedepartmenthistoryViewRepo { + override def select: SelectBuilder[VemployeedepartmenthistoryViewFields, VemployeedepartmenthistoryViewRow] = { + SelectBuilderSql("humanresources.vemployeedepartmenthistory", VemployeedepartmenthistoryViewFields, VemployeedepartmenthistoryViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VemployeedepartmenthistoryViewRow] = { + sql"""select "businessentityid", "title", "firstname", "middlename", "lastname", "suffix", "shift", "department", "groupname", "startdate"::text, "enddate"::text from humanresources.vemployeedepartmenthistory""".query(VemployeedepartmenthistoryViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRow.scala new file mode 100644 index 0000000000..67d3a65fdc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewRow.scala @@ -0,0 +1,118 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VemployeedepartmenthistoryViewRow( + /** Points to [[employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[shift.ShiftRow.name]] */ + shift: Name, + /** Points to [[department.DepartmentRow.name]] */ + department: Name, + /** Points to [[department.DepartmentRow.groupname]] */ + groupname: Name, + /** Points to [[employeedepartmenthistory.EmployeedepartmenthistoryRow.startdate]] */ + startdate: TypoLocalDate, + /** Points to [[employeedepartmenthistory.EmployeedepartmenthistoryRow.enddate]] */ + enddate: Option[TypoLocalDate] +) + +object VemployeedepartmenthistoryViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VemployeedepartmenthistoryViewRow] = new JdbcDecoder[VemployeedepartmenthistoryViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VemployeedepartmenthistoryViewRow) = + columIndex + 10 -> + VemployeedepartmenthistoryViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + shift = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + department = Name.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + groupname = Name.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + startdate = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VemployeedepartmenthistoryViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val shift = jsonObj.get("shift").toRight("Missing field 'shift'").flatMap(_.as(Name.jsonDecoder)) + val department = jsonObj.get("department").toRight("Missing field 'department'").flatMap(_.as(Name.jsonDecoder)) + val groupname = jsonObj.get("groupname").toRight("Missing field 'groupname'").flatMap(_.as(Name.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && shift.isRight && department.isRight && groupname.isRight && startdate.isRight && enddate.isRight) + Right(VemployeedepartmenthistoryViewRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, shift = shift.toOption.get, department = department.toOption.get, groupname = groupname.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, suffix, shift, department, groupname, startdate, enddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VemployeedepartmenthistoryViewRow] = new JsonEncoder[VemployeedepartmenthistoryViewRow] { + override def unsafeEncode(a: VemployeedepartmenthistoryViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""shift":""") + Name.jsonEncoder.unsafeEncode(a.shift, indent, out) + out.write(",") + out.write(""""department":""") + Name.jsonEncoder.unsafeEncode(a.department, indent, out) + out.write(",") + out.write(""""groupname":""") + Name.jsonEncoder.unsafeEncode(a.groupname, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewStructure.scala new file mode 100644 index 0000000000..a4d7298c70 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vemployeedepartmenthistory/VemployeedepartmenthistoryViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vemployeedepartmenthistory + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VemployeedepartmenthistoryViewStructure[Row](val prefix: Option[String], val extract: Row => VemployeedepartmenthistoryViewRow, val merge: (Row, VemployeedepartmenthistoryViewRow) => Row) + extends Relation[VemployeedepartmenthistoryViewFields, VemployeedepartmenthistoryViewRow, Row] + with VemployeedepartmenthistoryViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val shift = new Field[Name, Row](prefix, "shift", None, None)(x => extract(x).shift, (row, value) => merge(row, extract(row).copy(shift = value))) + override val department = new Field[Name, Row](prefix, "department", None, None)(x => extract(x).department, (row, value) => merge(row, extract(row).copy(department = value))) + override val groupname = new Field[Name, Row](prefix, "groupname", None, None)(x => extract(x).groupname, (row, value) => merge(row, extract(row).copy(groupname = value))) + override val startdate = new Field[TypoLocalDate, Row](prefix, "startdate", Some("text"), None)(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDate, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, title, firstname, middlename, lastname, suffix, shift, department, groupname, startdate, enddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VemployeedepartmenthistoryViewRow, merge: (NewRow, VemployeedepartmenthistoryViewRow) => NewRow): VemployeedepartmenthistoryViewStructure[NewRow] = + new VemployeedepartmenthistoryViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewFields.scala new file mode 100644 index 0000000000..93938baac3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewFields.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VjobcandidateViewFields[Row] { + val jobcandidateid: Field[JobcandidateId, Row] + val businessentityid: OptField[BusinessentityId, Row] + val `Name.Prefix`: OptField[/* max 30 chars */ String, Row] + val `Name.First`: OptField[/* max 30 chars */ String, Row] + val `Name.Middle`: OptField[/* max 30 chars */ String, Row] + val `Name.Last`: OptField[/* max 30 chars */ String, Row] + val `Name.Suffix`: OptField[/* max 30 chars */ String, Row] + val Skills: OptField[String, Row] + val `Addr.Type`: OptField[/* max 30 chars */ String, Row] + val `Addr.Loc.CountryRegion`: OptField[/* max 100 chars */ String, Row] + val `Addr.Loc.State`: OptField[/* max 100 chars */ String, Row] + val `Addr.Loc.City`: OptField[/* max 100 chars */ String, Row] + val `Addr.PostalCode`: OptField[/* max 20 chars */ String, Row] + val EMail: OptField[String, Row] + val WebSite: OptField[String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VjobcandidateViewFields extends VjobcandidateViewStructure[VjobcandidateViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepo.scala new file mode 100644 index 0000000000..18cca79b18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidate + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VjobcandidateViewRepo { + def select: SelectBuilder[VjobcandidateViewFields, VjobcandidateViewRow] + def selectAll: ZStream[ZConnection, Throwable, VjobcandidateViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepoImpl.scala new file mode 100644 index 0000000000..b34702dec8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidate + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VjobcandidateViewRepoImpl extends VjobcandidateViewRepo { + override def select: SelectBuilder[VjobcandidateViewFields, VjobcandidateViewRow] = { + SelectBuilderSql("humanresources.vjobcandidate", VjobcandidateViewFields, VjobcandidateViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VjobcandidateViewRow] = { + sql"""select "jobcandidateid", "businessentityid", "Name.Prefix", "Name.First", "Name.Middle", "Name.Last", "Name.Suffix", "Skills", "Addr.Type", "Addr.Loc.CountryRegion", "Addr.Loc.State", "Addr.Loc.City", "Addr.PostalCode", "EMail", "WebSite", "modifieddate"::text from humanresources.vjobcandidate""".query(VjobcandidateViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRow.scala new file mode 100644 index 0000000000..4185b946fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewRow.scala @@ -0,0 +1,139 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VjobcandidateViewRow( + /** Points to [[jobcandidate.JobcandidateRow.jobcandidateid]] */ + jobcandidateid: JobcandidateId, + /** Points to [[jobcandidate.JobcandidateRow.businessentityid]] */ + businessentityid: Option[BusinessentityId], + `Name.Prefix`: /* nullability unknown */ Option[/* max 30 chars */ String], + `Name.First`: /* nullability unknown */ Option[/* max 30 chars */ String], + `Name.Middle`: /* nullability unknown */ Option[/* max 30 chars */ String], + `Name.Last`: /* nullability unknown */ Option[/* max 30 chars */ String], + `Name.Suffix`: /* nullability unknown */ Option[/* max 30 chars */ String], + Skills: /* nullability unknown */ Option[String], + `Addr.Type`: /* nullability unknown */ Option[/* max 30 chars */ String], + `Addr.Loc.CountryRegion`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Addr.Loc.State`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Addr.Loc.City`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Addr.PostalCode`: /* nullability unknown */ Option[/* max 20 chars */ String], + EMail: /* nullability unknown */ Option[String], + WebSite: /* nullability unknown */ Option[String], + /** Points to [[jobcandidate.JobcandidateRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object VjobcandidateViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VjobcandidateViewRow] = new JdbcDecoder[VjobcandidateViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VjobcandidateViewRow) = + columIndex + 15 -> + VjobcandidateViewRow( + jobcandidateid = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + `Name.Prefix` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + `Name.First` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + `Name.Middle` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + `Name.Last` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + `Name.Suffix` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + Skills = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + `Addr.Type` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + `Addr.Loc.CountryRegion` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + `Addr.Loc.State` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + `Addr.Loc.City` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + `Addr.PostalCode` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + EMail = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + WebSite = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VjobcandidateViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val `Name.Prefix` = jsonObj.get("Name.Prefix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Name.First` = jsonObj.get("Name.First").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Name.Middle` = jsonObj.get("Name.Middle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Name.Last` = jsonObj.get("Name.Last").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Name.Suffix` = jsonObj.get("Name.Suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val Skills = jsonObj.get("Skills").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Addr.Type` = jsonObj.get("Addr.Type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Addr.Loc.CountryRegion` = jsonObj.get("Addr.Loc.CountryRegion").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Addr.Loc.State` = jsonObj.get("Addr.Loc.State").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Addr.Loc.City` = jsonObj.get("Addr.Loc.City").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Addr.PostalCode` = jsonObj.get("Addr.PostalCode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val EMail = jsonObj.get("EMail").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val WebSite = jsonObj.get("WebSite").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (jobcandidateid.isRight && businessentityid.isRight && `Name.Prefix`.isRight && `Name.First`.isRight && `Name.Middle`.isRight && `Name.Last`.isRight && `Name.Suffix`.isRight && Skills.isRight && `Addr.Type`.isRight && `Addr.Loc.CountryRegion`.isRight && `Addr.Loc.State`.isRight && `Addr.Loc.City`.isRight && `Addr.PostalCode`.isRight && EMail.isRight && WebSite.isRight && modifieddate.isRight) + Right(VjobcandidateViewRow(jobcandidateid = jobcandidateid.toOption.get, businessentityid = businessentityid.toOption.get, `Name.Prefix` = `Name.Prefix`.toOption.get, `Name.First` = `Name.First`.toOption.get, `Name.Middle` = `Name.Middle`.toOption.get, `Name.Last` = `Name.Last`.toOption.get, `Name.Suffix` = `Name.Suffix`.toOption.get, Skills = Skills.toOption.get, `Addr.Type` = `Addr.Type`.toOption.get, `Addr.Loc.CountryRegion` = `Addr.Loc.CountryRegion`.toOption.get, `Addr.Loc.State` = `Addr.Loc.State`.toOption.get, `Addr.Loc.City` = `Addr.Loc.City`.toOption.get, `Addr.PostalCode` = `Addr.PostalCode`.toOption.get, EMail = EMail.toOption.get, WebSite = WebSite.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](jobcandidateid, businessentityid, `Name.Prefix`, `Name.First`, `Name.Middle`, `Name.Last`, `Name.Suffix`, Skills, `Addr.Type`, `Addr.Loc.CountryRegion`, `Addr.Loc.State`, `Addr.Loc.City`, `Addr.PostalCode`, EMail, WebSite, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VjobcandidateViewRow] = new JsonEncoder[VjobcandidateViewRow] { + override def unsafeEncode(a: VjobcandidateViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""jobcandidateid":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""Name.Prefix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Name.Prefix`, indent, out) + out.write(",") + out.write(""""Name.First":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Name.First`, indent, out) + out.write(",") + out.write(""""Name.Middle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Name.Middle`, indent, out) + out.write(",") + out.write(""""Name.Last":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Name.Last`, indent, out) + out.write(",") + out.write(""""Name.Suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Name.Suffix`, indent, out) + out.write(",") + out.write(""""Skills":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Skills, indent, out) + out.write(",") + out.write(""""Addr.Type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Addr.Type`, indent, out) + out.write(",") + out.write(""""Addr.Loc.CountryRegion":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Addr.Loc.CountryRegion`, indent, out) + out.write(",") + out.write(""""Addr.Loc.State":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Addr.Loc.State`, indent, out) + out.write(",") + out.write(""""Addr.Loc.City":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Addr.Loc.City`, indent, out) + out.write(",") + out.write(""""Addr.PostalCode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Addr.PostalCode`, indent, out) + out.write(",") + out.write(""""EMail":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.EMail, indent, out) + out.write(",") + out.write(""""WebSite":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.WebSite, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewStructure.scala new file mode 100644 index 0000000000..bf1d0efa6a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidate/VjobcandidateViewStructure.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VjobcandidateViewStructure[Row](val prefix: Option[String], val extract: Row => VjobcandidateViewRow, val merge: (Row, VjobcandidateViewRow) => Row) + extends Relation[VjobcandidateViewFields, VjobcandidateViewRow, Row] + with VjobcandidateViewFields[Row] { outer => + + override val jobcandidateid = new Field[JobcandidateId, Row](prefix, "jobcandidateid", None, None)(x => extract(x).jobcandidateid, (row, value) => merge(row, extract(row).copy(jobcandidateid = value))) + override val businessentityid = new OptField[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val `Name.Prefix` = new OptField[/* max 30 chars */ String, Row](prefix, "Name.Prefix", None, None)(x => extract(x).`Name.Prefix`, (row, value) => merge(row, extract(row).copy(`Name.Prefix` = value))) + override val `Name.First` = new OptField[/* max 30 chars */ String, Row](prefix, "Name.First", None, None)(x => extract(x).`Name.First`, (row, value) => merge(row, extract(row).copy(`Name.First` = value))) + override val `Name.Middle` = new OptField[/* max 30 chars */ String, Row](prefix, "Name.Middle", None, None)(x => extract(x).`Name.Middle`, (row, value) => merge(row, extract(row).copy(`Name.Middle` = value))) + override val `Name.Last` = new OptField[/* max 30 chars */ String, Row](prefix, "Name.Last", None, None)(x => extract(x).`Name.Last`, (row, value) => merge(row, extract(row).copy(`Name.Last` = value))) + override val `Name.Suffix` = new OptField[/* max 30 chars */ String, Row](prefix, "Name.Suffix", None, None)(x => extract(x).`Name.Suffix`, (row, value) => merge(row, extract(row).copy(`Name.Suffix` = value))) + override val Skills = new OptField[String, Row](prefix, "Skills", None, None)(x => extract(x).Skills, (row, value) => merge(row, extract(row).copy(Skills = value))) + override val `Addr.Type` = new OptField[/* max 30 chars */ String, Row](prefix, "Addr.Type", None, None)(x => extract(x).`Addr.Type`, (row, value) => merge(row, extract(row).copy(`Addr.Type` = value))) + override val `Addr.Loc.CountryRegion` = new OptField[/* max 100 chars */ String, Row](prefix, "Addr.Loc.CountryRegion", None, None)(x => extract(x).`Addr.Loc.CountryRegion`, (row, value) => merge(row, extract(row).copy(`Addr.Loc.CountryRegion` = value))) + override val `Addr.Loc.State` = new OptField[/* max 100 chars */ String, Row](prefix, "Addr.Loc.State", None, None)(x => extract(x).`Addr.Loc.State`, (row, value) => merge(row, extract(row).copy(`Addr.Loc.State` = value))) + override val `Addr.Loc.City` = new OptField[/* max 100 chars */ String, Row](prefix, "Addr.Loc.City", None, None)(x => extract(x).`Addr.Loc.City`, (row, value) => merge(row, extract(row).copy(`Addr.Loc.City` = value))) + override val `Addr.PostalCode` = new OptField[/* max 20 chars */ String, Row](prefix, "Addr.PostalCode", None, None)(x => extract(x).`Addr.PostalCode`, (row, value) => merge(row, extract(row).copy(`Addr.PostalCode` = value))) + override val EMail = new OptField[String, Row](prefix, "EMail", None, None)(x => extract(x).EMail, (row, value) => merge(row, extract(row).copy(EMail = value))) + override val WebSite = new OptField[String, Row](prefix, "WebSite", None, None)(x => extract(x).WebSite, (row, value) => merge(row, extract(row).copy(WebSite = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](jobcandidateid, businessentityid, `Name.Prefix`, `Name.First`, `Name.Middle`, `Name.Last`, `Name.Suffix`, Skills, `Addr.Type`, `Addr.Loc.CountryRegion`, `Addr.Loc.State`, `Addr.Loc.City`, `Addr.PostalCode`, EMail, WebSite, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VjobcandidateViewRow, merge: (NewRow, VjobcandidateViewRow) => NewRow): VjobcandidateViewStructure[NewRow] = + new VjobcandidateViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewFields.scala new file mode 100644 index 0000000000..773ebbdbb7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateeducation + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VjobcandidateeducationViewFields[Row] { + val jobcandidateid: Field[JobcandidateId, Row] + val `Edu.Level`: OptField[/* max 50 chars */ String, Row] + val `Edu.StartDate`: OptField[TypoLocalDate, Row] + val `Edu.EndDate`: OptField[TypoLocalDate, Row] + val `Edu.Degree`: OptField[/* max 50 chars */ String, Row] + val `Edu.Major`: OptField[/* max 50 chars */ String, Row] + val `Edu.Minor`: OptField[/* max 50 chars */ String, Row] + val `Edu.GPA`: OptField[/* max 5 chars */ String, Row] + val `Edu.GPAScale`: OptField[/* max 5 chars */ String, Row] + val `Edu.School`: OptField[/* max 100 chars */ String, Row] + val `Edu.Loc.CountryRegion`: OptField[/* max 100 chars */ String, Row] + val `Edu.Loc.State`: OptField[/* max 100 chars */ String, Row] + val `Edu.Loc.City`: OptField[/* max 100 chars */ String, Row] +} +object VjobcandidateeducationViewFields extends VjobcandidateeducationViewStructure[VjobcandidateeducationViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepo.scala new file mode 100644 index 0000000000..392933d588 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateeducation + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VjobcandidateeducationViewRepo { + def select: SelectBuilder[VjobcandidateeducationViewFields, VjobcandidateeducationViewRow] + def selectAll: ZStream[ZConnection, Throwable, VjobcandidateeducationViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepoImpl.scala new file mode 100644 index 0000000000..cf84e3ef9f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateeducation + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VjobcandidateeducationViewRepoImpl extends VjobcandidateeducationViewRepo { + override def select: SelectBuilder[VjobcandidateeducationViewFields, VjobcandidateeducationViewRow] = { + SelectBuilderSql("humanresources.vjobcandidateeducation", VjobcandidateeducationViewFields, VjobcandidateeducationViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VjobcandidateeducationViewRow] = { + sql"""select "jobcandidateid", "Edu.Level", "Edu.StartDate"::text, "Edu.EndDate"::text, "Edu.Degree", "Edu.Major", "Edu.Minor", "Edu.GPA", "Edu.GPAScale", "Edu.School", "Edu.Loc.CountryRegion", "Edu.Loc.State", "Edu.Loc.City" from humanresources.vjobcandidateeducation""".query(VjobcandidateeducationViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRow.scala new file mode 100644 index 0000000000..da935cf52e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewRow.scala @@ -0,0 +1,118 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateeducation + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VjobcandidateeducationViewRow( + /** Points to [[jobcandidate.JobcandidateRow.jobcandidateid]] */ + jobcandidateid: JobcandidateId, + `Edu.Level`: /* nullability unknown */ Option[/* max 50 chars */ String], + `Edu.StartDate`: /* nullability unknown */ Option[TypoLocalDate], + `Edu.EndDate`: /* nullability unknown */ Option[TypoLocalDate], + `Edu.Degree`: /* nullability unknown */ Option[/* max 50 chars */ String], + `Edu.Major`: /* nullability unknown */ Option[/* max 50 chars */ String], + `Edu.Minor`: /* nullability unknown */ Option[/* max 50 chars */ String], + `Edu.GPA`: /* nullability unknown */ Option[/* max 5 chars */ String], + `Edu.GPAScale`: /* nullability unknown */ Option[/* max 5 chars */ String], + `Edu.School`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Edu.Loc.CountryRegion`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Edu.Loc.State`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Edu.Loc.City`: /* nullability unknown */ Option[/* max 100 chars */ String] +) + +object VjobcandidateeducationViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VjobcandidateeducationViewRow] = new JdbcDecoder[VjobcandidateeducationViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VjobcandidateeducationViewRow) = + columIndex + 12 -> + VjobcandidateeducationViewRow( + jobcandidateid = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + `Edu.Level` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + `Edu.StartDate` = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + `Edu.EndDate` = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + `Edu.Degree` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + `Edu.Major` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + `Edu.Minor` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + `Edu.GPA` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + `Edu.GPAScale` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + `Edu.School` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + `Edu.Loc.CountryRegion` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + `Edu.Loc.State` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + `Edu.Loc.City` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VjobcandidateeducationViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val `Edu.Level` = jsonObj.get("Edu.Level").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.StartDate` = jsonObj.get("Edu.StartDate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val `Edu.EndDate` = jsonObj.get("Edu.EndDate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val `Edu.Degree` = jsonObj.get("Edu.Degree").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.Major` = jsonObj.get("Edu.Major").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.Minor` = jsonObj.get("Edu.Minor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.GPA` = jsonObj.get("Edu.GPA").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.GPAScale` = jsonObj.get("Edu.GPAScale").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.School` = jsonObj.get("Edu.School").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.Loc.CountryRegion` = jsonObj.get("Edu.Loc.CountryRegion").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.Loc.State` = jsonObj.get("Edu.Loc.State").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Edu.Loc.City` = jsonObj.get("Edu.Loc.City").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (jobcandidateid.isRight && `Edu.Level`.isRight && `Edu.StartDate`.isRight && `Edu.EndDate`.isRight && `Edu.Degree`.isRight && `Edu.Major`.isRight && `Edu.Minor`.isRight && `Edu.GPA`.isRight && `Edu.GPAScale`.isRight && `Edu.School`.isRight && `Edu.Loc.CountryRegion`.isRight && `Edu.Loc.State`.isRight && `Edu.Loc.City`.isRight) + Right(VjobcandidateeducationViewRow(jobcandidateid = jobcandidateid.toOption.get, `Edu.Level` = `Edu.Level`.toOption.get, `Edu.StartDate` = `Edu.StartDate`.toOption.get, `Edu.EndDate` = `Edu.EndDate`.toOption.get, `Edu.Degree` = `Edu.Degree`.toOption.get, `Edu.Major` = `Edu.Major`.toOption.get, `Edu.Minor` = `Edu.Minor`.toOption.get, `Edu.GPA` = `Edu.GPA`.toOption.get, `Edu.GPAScale` = `Edu.GPAScale`.toOption.get, `Edu.School` = `Edu.School`.toOption.get, `Edu.Loc.CountryRegion` = `Edu.Loc.CountryRegion`.toOption.get, `Edu.Loc.State` = `Edu.Loc.State`.toOption.get, `Edu.Loc.City` = `Edu.Loc.City`.toOption.get)) + else Left(List[Either[String, Any]](jobcandidateid, `Edu.Level`, `Edu.StartDate`, `Edu.EndDate`, `Edu.Degree`, `Edu.Major`, `Edu.Minor`, `Edu.GPA`, `Edu.GPAScale`, `Edu.School`, `Edu.Loc.CountryRegion`, `Edu.Loc.State`, `Edu.Loc.City`).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VjobcandidateeducationViewRow] = new JsonEncoder[VjobcandidateeducationViewRow] { + override def unsafeEncode(a: VjobcandidateeducationViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""jobcandidateid":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""Edu.Level":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Level`, indent, out) + out.write(",") + out.write(""""Edu.StartDate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.`Edu.StartDate`, indent, out) + out.write(",") + out.write(""""Edu.EndDate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.`Edu.EndDate`, indent, out) + out.write(",") + out.write(""""Edu.Degree":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Degree`, indent, out) + out.write(",") + out.write(""""Edu.Major":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Major`, indent, out) + out.write(",") + out.write(""""Edu.Minor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Minor`, indent, out) + out.write(",") + out.write(""""Edu.GPA":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.GPA`, indent, out) + out.write(",") + out.write(""""Edu.GPAScale":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.GPAScale`, indent, out) + out.write(",") + out.write(""""Edu.School":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.School`, indent, out) + out.write(",") + out.write(""""Edu.Loc.CountryRegion":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Loc.CountryRegion`, indent, out) + out.write(",") + out.write(""""Edu.Loc.State":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Loc.State`, indent, out) + out.write(",") + out.write(""""Edu.Loc.City":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Edu.Loc.City`, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewStructure.scala new file mode 100644 index 0000000000..e8fbf52207 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateeducation/VjobcandidateeducationViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateeducation + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VjobcandidateeducationViewStructure[Row](val prefix: Option[String], val extract: Row => VjobcandidateeducationViewRow, val merge: (Row, VjobcandidateeducationViewRow) => Row) + extends Relation[VjobcandidateeducationViewFields, VjobcandidateeducationViewRow, Row] + with VjobcandidateeducationViewFields[Row] { outer => + + override val jobcandidateid = new Field[JobcandidateId, Row](prefix, "jobcandidateid", None, None)(x => extract(x).jobcandidateid, (row, value) => merge(row, extract(row).copy(jobcandidateid = value))) + override val `Edu.Level` = new OptField[/* max 50 chars */ String, Row](prefix, "Edu.Level", None, None)(x => extract(x).`Edu.Level`, (row, value) => merge(row, extract(row).copy(`Edu.Level` = value))) + override val `Edu.StartDate` = new OptField[TypoLocalDate, Row](prefix, "Edu.StartDate", Some("text"), None)(x => extract(x).`Edu.StartDate`, (row, value) => merge(row, extract(row).copy(`Edu.StartDate` = value))) + override val `Edu.EndDate` = new OptField[TypoLocalDate, Row](prefix, "Edu.EndDate", Some("text"), None)(x => extract(x).`Edu.EndDate`, (row, value) => merge(row, extract(row).copy(`Edu.EndDate` = value))) + override val `Edu.Degree` = new OptField[/* max 50 chars */ String, Row](prefix, "Edu.Degree", None, None)(x => extract(x).`Edu.Degree`, (row, value) => merge(row, extract(row).copy(`Edu.Degree` = value))) + override val `Edu.Major` = new OptField[/* max 50 chars */ String, Row](prefix, "Edu.Major", None, None)(x => extract(x).`Edu.Major`, (row, value) => merge(row, extract(row).copy(`Edu.Major` = value))) + override val `Edu.Minor` = new OptField[/* max 50 chars */ String, Row](prefix, "Edu.Minor", None, None)(x => extract(x).`Edu.Minor`, (row, value) => merge(row, extract(row).copy(`Edu.Minor` = value))) + override val `Edu.GPA` = new OptField[/* max 5 chars */ String, Row](prefix, "Edu.GPA", None, None)(x => extract(x).`Edu.GPA`, (row, value) => merge(row, extract(row).copy(`Edu.GPA` = value))) + override val `Edu.GPAScale` = new OptField[/* max 5 chars */ String, Row](prefix, "Edu.GPAScale", None, None)(x => extract(x).`Edu.GPAScale`, (row, value) => merge(row, extract(row).copy(`Edu.GPAScale` = value))) + override val `Edu.School` = new OptField[/* max 100 chars */ String, Row](prefix, "Edu.School", None, None)(x => extract(x).`Edu.School`, (row, value) => merge(row, extract(row).copy(`Edu.School` = value))) + override val `Edu.Loc.CountryRegion` = new OptField[/* max 100 chars */ String, Row](prefix, "Edu.Loc.CountryRegion", None, None)(x => extract(x).`Edu.Loc.CountryRegion`, (row, value) => merge(row, extract(row).copy(`Edu.Loc.CountryRegion` = value))) + override val `Edu.Loc.State` = new OptField[/* max 100 chars */ String, Row](prefix, "Edu.Loc.State", None, None)(x => extract(x).`Edu.Loc.State`, (row, value) => merge(row, extract(row).copy(`Edu.Loc.State` = value))) + override val `Edu.Loc.City` = new OptField[/* max 100 chars */ String, Row](prefix, "Edu.Loc.City", None, None)(x => extract(x).`Edu.Loc.City`, (row, value) => merge(row, extract(row).copy(`Edu.Loc.City` = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](jobcandidateid, `Edu.Level`, `Edu.StartDate`, `Edu.EndDate`, `Edu.Degree`, `Edu.Major`, `Edu.Minor`, `Edu.GPA`, `Edu.GPAScale`, `Edu.School`, `Edu.Loc.CountryRegion`, `Edu.Loc.State`, `Edu.Loc.City`) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VjobcandidateeducationViewRow, merge: (NewRow, VjobcandidateeducationViewRow) => NewRow): VjobcandidateeducationViewStructure[NewRow] = + new VjobcandidateeducationViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewFields.scala new file mode 100644 index 0000000000..91792438f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateemployment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VjobcandidateemploymentViewFields[Row] { + val jobcandidateid: Field[JobcandidateId, Row] + val `Emp.StartDate`: OptField[TypoLocalDate, Row] + val `Emp.EndDate`: OptField[TypoLocalDate, Row] + val `Emp.OrgName`: OptField[/* max 100 chars */ String, Row] + val `Emp.JobTitle`: OptField[/* max 100 chars */ String, Row] + val `Emp.Responsibility`: OptField[String, Row] + val `Emp.FunctionCategory`: OptField[String, Row] + val `Emp.IndustryCategory`: OptField[String, Row] + val `Emp.Loc.CountryRegion`: OptField[String, Row] + val `Emp.Loc.State`: OptField[String, Row] + val `Emp.Loc.City`: OptField[String, Row] +} +object VjobcandidateemploymentViewFields extends VjobcandidateemploymentViewStructure[VjobcandidateemploymentViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepo.scala new file mode 100644 index 0000000000..24229ad0ce --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateemployment + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VjobcandidateemploymentViewRepo { + def select: SelectBuilder[VjobcandidateemploymentViewFields, VjobcandidateemploymentViewRow] + def selectAll: ZStream[ZConnection, Throwable, VjobcandidateemploymentViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepoImpl.scala new file mode 100644 index 0000000000..8becd64334 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateemployment + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VjobcandidateemploymentViewRepoImpl extends VjobcandidateemploymentViewRepo { + override def select: SelectBuilder[VjobcandidateemploymentViewFields, VjobcandidateemploymentViewRow] = { + SelectBuilderSql("humanresources.vjobcandidateemployment", VjobcandidateemploymentViewFields, VjobcandidateemploymentViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VjobcandidateemploymentViewRow] = { + sql"""select "jobcandidateid", "Emp.StartDate"::text, "Emp.EndDate"::text, "Emp.OrgName", "Emp.JobTitle", "Emp.Responsibility", "Emp.FunctionCategory", "Emp.IndustryCategory", "Emp.Loc.CountryRegion", "Emp.Loc.State", "Emp.Loc.City" from humanresources.vjobcandidateemployment""".query(VjobcandidateemploymentViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRow.scala new file mode 100644 index 0000000000..e241b31977 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewRow.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateemployment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VjobcandidateemploymentViewRow( + /** Points to [[jobcandidate.JobcandidateRow.jobcandidateid]] */ + jobcandidateid: JobcandidateId, + `Emp.StartDate`: /* nullability unknown */ Option[TypoLocalDate], + `Emp.EndDate`: /* nullability unknown */ Option[TypoLocalDate], + `Emp.OrgName`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Emp.JobTitle`: /* nullability unknown */ Option[/* max 100 chars */ String], + `Emp.Responsibility`: /* nullability unknown */ Option[String], + `Emp.FunctionCategory`: /* nullability unknown */ Option[String], + `Emp.IndustryCategory`: /* nullability unknown */ Option[String], + `Emp.Loc.CountryRegion`: /* nullability unknown */ Option[String], + `Emp.Loc.State`: /* nullability unknown */ Option[String], + `Emp.Loc.City`: /* nullability unknown */ Option[String] +) + +object VjobcandidateemploymentViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VjobcandidateemploymentViewRow] = new JdbcDecoder[VjobcandidateemploymentViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VjobcandidateemploymentViewRow) = + columIndex + 10 -> + VjobcandidateemploymentViewRow( + jobcandidateid = JobcandidateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + `Emp.StartDate` = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + `Emp.EndDate` = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + `Emp.OrgName` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + `Emp.JobTitle` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + `Emp.Responsibility` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + `Emp.FunctionCategory` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + `Emp.IndustryCategory` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + `Emp.Loc.CountryRegion` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + `Emp.Loc.State` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + `Emp.Loc.City` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VjobcandidateemploymentViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val jobcandidateid = jsonObj.get("jobcandidateid").toRight("Missing field 'jobcandidateid'").flatMap(_.as(JobcandidateId.jsonDecoder)) + val `Emp.StartDate` = jsonObj.get("Emp.StartDate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val `Emp.EndDate` = jsonObj.get("Emp.EndDate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val `Emp.OrgName` = jsonObj.get("Emp.OrgName").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.JobTitle` = jsonObj.get("Emp.JobTitle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.Responsibility` = jsonObj.get("Emp.Responsibility").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.FunctionCategory` = jsonObj.get("Emp.FunctionCategory").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.IndustryCategory` = jsonObj.get("Emp.IndustryCategory").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.Loc.CountryRegion` = jsonObj.get("Emp.Loc.CountryRegion").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.Loc.State` = jsonObj.get("Emp.Loc.State").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `Emp.Loc.City` = jsonObj.get("Emp.Loc.City").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (jobcandidateid.isRight && `Emp.StartDate`.isRight && `Emp.EndDate`.isRight && `Emp.OrgName`.isRight && `Emp.JobTitle`.isRight && `Emp.Responsibility`.isRight && `Emp.FunctionCategory`.isRight && `Emp.IndustryCategory`.isRight && `Emp.Loc.CountryRegion`.isRight && `Emp.Loc.State`.isRight && `Emp.Loc.City`.isRight) + Right(VjobcandidateemploymentViewRow(jobcandidateid = jobcandidateid.toOption.get, `Emp.StartDate` = `Emp.StartDate`.toOption.get, `Emp.EndDate` = `Emp.EndDate`.toOption.get, `Emp.OrgName` = `Emp.OrgName`.toOption.get, `Emp.JobTitle` = `Emp.JobTitle`.toOption.get, `Emp.Responsibility` = `Emp.Responsibility`.toOption.get, `Emp.FunctionCategory` = `Emp.FunctionCategory`.toOption.get, `Emp.IndustryCategory` = `Emp.IndustryCategory`.toOption.get, `Emp.Loc.CountryRegion` = `Emp.Loc.CountryRegion`.toOption.get, `Emp.Loc.State` = `Emp.Loc.State`.toOption.get, `Emp.Loc.City` = `Emp.Loc.City`.toOption.get)) + else Left(List[Either[String, Any]](jobcandidateid, `Emp.StartDate`, `Emp.EndDate`, `Emp.OrgName`, `Emp.JobTitle`, `Emp.Responsibility`, `Emp.FunctionCategory`, `Emp.IndustryCategory`, `Emp.Loc.CountryRegion`, `Emp.Loc.State`, `Emp.Loc.City`).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VjobcandidateemploymentViewRow] = new JsonEncoder[VjobcandidateemploymentViewRow] { + override def unsafeEncode(a: VjobcandidateemploymentViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""jobcandidateid":""") + JobcandidateId.jsonEncoder.unsafeEncode(a.jobcandidateid, indent, out) + out.write(",") + out.write(""""Emp.StartDate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.`Emp.StartDate`, indent, out) + out.write(",") + out.write(""""Emp.EndDate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.`Emp.EndDate`, indent, out) + out.write(",") + out.write(""""Emp.OrgName":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.OrgName`, indent, out) + out.write(",") + out.write(""""Emp.JobTitle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.JobTitle`, indent, out) + out.write(",") + out.write(""""Emp.Responsibility":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.Responsibility`, indent, out) + out.write(",") + out.write(""""Emp.FunctionCategory":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.FunctionCategory`, indent, out) + out.write(",") + out.write(""""Emp.IndustryCategory":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.IndustryCategory`, indent, out) + out.write(",") + out.write(""""Emp.Loc.CountryRegion":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.Loc.CountryRegion`, indent, out) + out.write(",") + out.write(""""Emp.Loc.State":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.Loc.State`, indent, out) + out.write(",") + out.write(""""Emp.Loc.City":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`Emp.Loc.City`, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewStructure.scala new file mode 100644 index 0000000000..21af2c6559 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/humanresources/vjobcandidateemployment/VjobcandidateemploymentViewStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package humanresources +package vjobcandidateemployment + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.humanresources.jobcandidate.JobcandidateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VjobcandidateemploymentViewStructure[Row](val prefix: Option[String], val extract: Row => VjobcandidateemploymentViewRow, val merge: (Row, VjobcandidateemploymentViewRow) => Row) + extends Relation[VjobcandidateemploymentViewFields, VjobcandidateemploymentViewRow, Row] + with VjobcandidateemploymentViewFields[Row] { outer => + + override val jobcandidateid = new Field[JobcandidateId, Row](prefix, "jobcandidateid", None, None)(x => extract(x).jobcandidateid, (row, value) => merge(row, extract(row).copy(jobcandidateid = value))) + override val `Emp.StartDate` = new OptField[TypoLocalDate, Row](prefix, "Emp.StartDate", Some("text"), None)(x => extract(x).`Emp.StartDate`, (row, value) => merge(row, extract(row).copy(`Emp.StartDate` = value))) + override val `Emp.EndDate` = new OptField[TypoLocalDate, Row](prefix, "Emp.EndDate", Some("text"), None)(x => extract(x).`Emp.EndDate`, (row, value) => merge(row, extract(row).copy(`Emp.EndDate` = value))) + override val `Emp.OrgName` = new OptField[/* max 100 chars */ String, Row](prefix, "Emp.OrgName", None, None)(x => extract(x).`Emp.OrgName`, (row, value) => merge(row, extract(row).copy(`Emp.OrgName` = value))) + override val `Emp.JobTitle` = new OptField[/* max 100 chars */ String, Row](prefix, "Emp.JobTitle", None, None)(x => extract(x).`Emp.JobTitle`, (row, value) => merge(row, extract(row).copy(`Emp.JobTitle` = value))) + override val `Emp.Responsibility` = new OptField[String, Row](prefix, "Emp.Responsibility", None, None)(x => extract(x).`Emp.Responsibility`, (row, value) => merge(row, extract(row).copy(`Emp.Responsibility` = value))) + override val `Emp.FunctionCategory` = new OptField[String, Row](prefix, "Emp.FunctionCategory", None, None)(x => extract(x).`Emp.FunctionCategory`, (row, value) => merge(row, extract(row).copy(`Emp.FunctionCategory` = value))) + override val `Emp.IndustryCategory` = new OptField[String, Row](prefix, "Emp.IndustryCategory", None, None)(x => extract(x).`Emp.IndustryCategory`, (row, value) => merge(row, extract(row).copy(`Emp.IndustryCategory` = value))) + override val `Emp.Loc.CountryRegion` = new OptField[String, Row](prefix, "Emp.Loc.CountryRegion", None, None)(x => extract(x).`Emp.Loc.CountryRegion`, (row, value) => merge(row, extract(row).copy(`Emp.Loc.CountryRegion` = value))) + override val `Emp.Loc.State` = new OptField[String, Row](prefix, "Emp.Loc.State", None, None)(x => extract(x).`Emp.Loc.State`, (row, value) => merge(row, extract(row).copy(`Emp.Loc.State` = value))) + override val `Emp.Loc.City` = new OptField[String, Row](prefix, "Emp.Loc.City", None, None)(x => extract(x).`Emp.Loc.City`, (row, value) => merge(row, extract(row).copy(`Emp.Loc.City` = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](jobcandidateid, `Emp.StartDate`, `Emp.EndDate`, `Emp.OrgName`, `Emp.JobTitle`, `Emp.Responsibility`, `Emp.FunctionCategory`, `Emp.IndustryCategory`, `Emp.Loc.CountryRegion`, `Emp.Loc.State`, `Emp.Loc.City`) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VjobcandidateemploymentViewRow, merge: (NewRow, VjobcandidateemploymentViewRow) => NewRow): VjobcandidateemploymentViewStructure[NewRow] = + new VjobcandidateemploymentViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CardinalNumber.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CardinalNumber.scala new file mode 100644 index 0000000000..336fa03ce7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CardinalNumber.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema + +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 + +/** Domain `information_schema.cardinal_number` + * Constraint: CHECK ((VALUE >= 0)) + */ +case class CardinalNumber(value: Int) extends AnyVal +object CardinalNumber { + implicit lazy val arraySetter: Setter[Array[CardinalNumber]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CardinalNumber, Int] = Bijection[CardinalNumber, Int](_.value)(CardinalNumber.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CardinalNumber] = JdbcDecoder.intDecoder.map(CardinalNumber.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CardinalNumber] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CardinalNumber] = JsonDecoder.int.map(CardinalNumber.apply) + implicit lazy val jsonEncoder: JsonEncoder[CardinalNumber] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[CardinalNumber] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CardinalNumber] = ParameterMetaData.instance[CardinalNumber](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CardinalNumber] = Setter.intSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CharacterData.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CharacterData.scala new file mode 100644 index 0000000000..00eeb66490 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/CharacterData.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema + +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 + +/** Domain `information_schema.character_data` + * No constraint + */ +case class CharacterData(value: String) extends AnyVal +object CharacterData { + implicit lazy val arraySetter: Setter[Array[CharacterData]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CharacterData, String] = Bijection[CharacterData, String](_.value)(CharacterData.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CharacterData] = JdbcDecoder.stringDecoder.map(CharacterData.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CharacterData] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CharacterData] = JsonDecoder.string.map(CharacterData.apply) + implicit lazy val jsonEncoder: JsonEncoder[CharacterData] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[CharacterData] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CharacterData] = ParameterMetaData.instance[CharacterData](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CharacterData] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/YesOrNo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/YesOrNo.scala new file mode 100644 index 0000000000..6170250156 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/YesOrNo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema + +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 + +/** Domain `information_schema.yes_or_no` + * Constraint: CHECK (((VALUE)::text = ANY ((ARRAY['YES'::character varying, 'NO'::character varying])::text[]))) + */ +case class YesOrNo(value: String) extends AnyVal +object YesOrNo { + implicit lazy val arraySetter: Setter[Array[YesOrNo]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[YesOrNo, String] = Bijection[YesOrNo, String](_.value)(YesOrNo.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[YesOrNo] = JdbcDecoder.stringDecoder.map(YesOrNo.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[YesOrNo] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[YesOrNo] = JsonDecoder.string.map(YesOrNo.apply) + implicit lazy val jsonEncoder: JsonEncoder[YesOrNo] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[YesOrNo] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[YesOrNo] = ParameterMetaData.instance[YesOrNo](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[YesOrNo] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewFields.scala new file mode 100644 index 0000000000..afdcd52e80 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_data_wrappers` + +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgForeignDataWrappersViewFields[Row] { + val oid: Field[PgForeignDataWrapperId, Row] + val fdwowner: Field[/* oid */ Long, Row] + val fdwoptions: OptField[Array[String], Row] + val foreignDataWrapperCatalog: OptField[String, Row] + val foreignDataWrapperName: OptField[String, Row] + val authorizationIdentifier: OptField[String, Row] + val foreignDataWrapperLanguage: OptField[String, Row] +} +object PgForeignDataWrappersViewFields extends PgForeignDataWrappersViewStructure[PgForeignDataWrappersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepo.scala new file mode 100644 index 0000000000..8b1cb07149 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_data_wrappers` + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignDataWrappersViewRepo { + def select: SelectBuilder[PgForeignDataWrappersViewFields, PgForeignDataWrappersViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignDataWrappersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepoImpl.scala new file mode 100644 index 0000000000..b8d490ccde --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_data_wrappers` + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignDataWrappersViewRepoImpl extends PgForeignDataWrappersViewRepo { + override def select: SelectBuilder[PgForeignDataWrappersViewFields, PgForeignDataWrappersViewRow] = { + SelectBuilderSql("information_schema._pg_foreign_data_wrappers", PgForeignDataWrappersViewFields, PgForeignDataWrappersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignDataWrappersViewRow] = { + sql"""select "oid", "fdwowner", "fdwoptions", "foreign_data_wrapper_catalog", "foreign_data_wrapper_name", "authorization_identifier", "foreign_data_wrapper_language" from information_schema._pg_foreign_data_wrappers""".query(PgForeignDataWrappersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRow.scala new file mode 100644 index 0000000000..fce8b4374a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewRow.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_data_wrappers` + +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignDataWrappersViewRow( + /** Points to [[pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRow.oid]] */ + oid: PgForeignDataWrapperId, + /** Points to [[pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRow.fdwowner]] */ + fdwowner: /* oid */ Long, + /** Points to [[pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRow.fdwoptions]] */ + fdwoptions: Option[Array[String]], + foreignDataWrapperCatalog: /* nullability unknown */ Option[String], + foreignDataWrapperName: /* nullability unknown */ Option[String], + authorizationIdentifier: /* nullability unknown */ Option[String], + foreignDataWrapperLanguage: /* nullability unknown */ Option[String] +) + +object PgForeignDataWrappersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignDataWrappersViewRow] = new JdbcDecoder[PgForeignDataWrappersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignDataWrappersViewRow) = + columIndex + 6 -> + PgForeignDataWrappersViewRow( + oid = PgForeignDataWrapperId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + fdwowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + fdwoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 2, rs)._2, + foreignDataWrapperCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignDataWrapperName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + foreignDataWrapperLanguage = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignDataWrappersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgForeignDataWrapperId.jsonDecoder)) + val fdwowner = jsonObj.get("fdwowner").toRight("Missing field 'fdwowner'").flatMap(_.as(JsonDecoder.long)) + val fdwoptions = jsonObj.get("fdwoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val foreignDataWrapperCatalog = jsonObj.get("foreign_data_wrapper_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperName = jsonObj.get("foreign_data_wrapper_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperLanguage = jsonObj.get("foreign_data_wrapper_language").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && fdwowner.isRight && fdwoptions.isRight && foreignDataWrapperCatalog.isRight && foreignDataWrapperName.isRight && authorizationIdentifier.isRight && foreignDataWrapperLanguage.isRight) + Right(PgForeignDataWrappersViewRow(oid = oid.toOption.get, fdwowner = fdwowner.toOption.get, fdwoptions = fdwoptions.toOption.get, foreignDataWrapperCatalog = foreignDataWrapperCatalog.toOption.get, foreignDataWrapperName = foreignDataWrapperName.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get, foreignDataWrapperLanguage = foreignDataWrapperLanguage.toOption.get)) + else Left(List[Either[String, Any]](oid, fdwowner, fdwoptions, foreignDataWrapperCatalog, foreignDataWrapperName, authorizationIdentifier, foreignDataWrapperLanguage).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignDataWrappersViewRow] = new JsonEncoder[PgForeignDataWrappersViewRow] { + override def unsafeEncode(a: PgForeignDataWrappersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgForeignDataWrapperId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""fdwowner":""") + JsonEncoder.long.unsafeEncode(a.fdwowner, indent, out) + out.write(",") + out.write(""""fdwoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.fdwoptions, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperCatalog, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperName, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_language":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperLanguage, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewStructure.scala new file mode 100644 index 0000000000..621d244b6f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_data_wrappers/PgForeignDataWrappersViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_data_wrappers` + +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignDataWrappersViewStructure[Row](val prefix: Option[String], val extract: Row => PgForeignDataWrappersViewRow, val merge: (Row, PgForeignDataWrappersViewRow) => Row) + extends Relation[PgForeignDataWrappersViewFields, PgForeignDataWrappersViewRow, Row] + with PgForeignDataWrappersViewFields[Row] { outer => + + override val oid = new Field[PgForeignDataWrapperId, Row](prefix, "oid", None, None)(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val fdwowner = new Field[/* oid */ Long, Row](prefix, "fdwowner", None, None)(x => extract(x).fdwowner, (row, value) => merge(row, extract(row).copy(fdwowner = value))) + override val fdwoptions = new OptField[Array[String], Row](prefix, "fdwoptions", None, None)(x => extract(x).fdwoptions, (row, value) => merge(row, extract(row).copy(fdwoptions = value))) + override val foreignDataWrapperCatalog = new OptField[String, Row](prefix, "foreign_data_wrapper_catalog", None, None)(x => extract(x).foreignDataWrapperCatalog, (row, value) => merge(row, extract(row).copy(foreignDataWrapperCatalog = value))) + override val foreignDataWrapperName = new OptField[String, Row](prefix, "foreign_data_wrapper_name", None, None)(x => extract(x).foreignDataWrapperName, (row, value) => merge(row, extract(row).copy(foreignDataWrapperName = value))) + override val authorizationIdentifier = new OptField[String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + override val foreignDataWrapperLanguage = new OptField[String, Row](prefix, "foreign_data_wrapper_language", None, None)(x => extract(x).foreignDataWrapperLanguage, (row, value) => merge(row, extract(row).copy(foreignDataWrapperLanguage = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, fdwowner, fdwoptions, foreignDataWrapperCatalog, foreignDataWrapperName, authorizationIdentifier, foreignDataWrapperLanguage) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignDataWrappersViewRow, merge: (NewRow, PgForeignDataWrappersViewRow) => NewRow): PgForeignDataWrappersViewStructure[NewRow] = + new PgForeignDataWrappersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewFields.scala new file mode 100644 index 0000000000..30f2caec65 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_servers` + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgForeignServersViewFields[Row] { + val oid: Field[PgForeignServerId, Row] + val srvoptions: OptField[Array[String], Row] + val foreignServerCatalog: OptField[String, Row] + val foreignServerName: OptField[String, Row] + val foreignDataWrapperCatalog: OptField[String, Row] + val foreignDataWrapperName: OptField[String, Row] + val foreignServerType: OptField[String, Row] + val foreignServerVersion: OptField[String, Row] + val authorizationIdentifier: OptField[String, Row] +} +object PgForeignServersViewFields extends PgForeignServersViewStructure[PgForeignServersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepo.scala new file mode 100644 index 0000000000..fe371231db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_servers` + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignServersViewRepo { + def select: SelectBuilder[PgForeignServersViewFields, PgForeignServersViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignServersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepoImpl.scala new file mode 100644 index 0000000000..efe06102d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_servers` + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignServersViewRepoImpl extends PgForeignServersViewRepo { + override def select: SelectBuilder[PgForeignServersViewFields, PgForeignServersViewRow] = { + SelectBuilderSql("information_schema._pg_foreign_servers", PgForeignServersViewFields, PgForeignServersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignServersViewRow] = { + sql"""select "oid", "srvoptions", "foreign_server_catalog", "foreign_server_name", "foreign_data_wrapper_catalog", "foreign_data_wrapper_name", "foreign_server_type", "foreign_server_version", "authorization_identifier" from information_schema._pg_foreign_servers""".query(PgForeignServersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRow.scala new file mode 100644 index 0000000000..a14c5d15ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewRow.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_servers` + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignServersViewRow( + /** Points to [[pg_catalog.pg_foreign_server.PgForeignServerRow.oid]] */ + oid: PgForeignServerId, + /** Points to [[pg_catalog.pg_foreign_server.PgForeignServerRow.srvoptions]] */ + srvoptions: Option[Array[String]], + foreignServerCatalog: /* nullability unknown */ Option[String], + foreignServerName: /* nullability unknown */ Option[String], + foreignDataWrapperCatalog: /* nullability unknown */ Option[String], + foreignDataWrapperName: /* nullability unknown */ Option[String], + foreignServerType: /* nullability unknown */ Option[String], + foreignServerVersion: /* nullability unknown */ Option[String], + authorizationIdentifier: /* nullability unknown */ Option[String] +) + +object PgForeignServersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignServersViewRow] = new JdbcDecoder[PgForeignServersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignServersViewRow) = + columIndex + 8 -> + PgForeignServersViewRow( + oid = PgForeignServerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + srvoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignDataWrapperCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + foreignDataWrapperName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + foreignServerType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + foreignServerVersion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignServersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgForeignServerId.jsonDecoder)) + val srvoptions = jsonObj.get("srvoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperCatalog = jsonObj.get("foreign_data_wrapper_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperName = jsonObj.get("foreign_data_wrapper_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerType = jsonObj.get("foreign_server_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerVersion = jsonObj.get("foreign_server_version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && srvoptions.isRight && foreignServerCatalog.isRight && foreignServerName.isRight && foreignDataWrapperCatalog.isRight && foreignDataWrapperName.isRight && foreignServerType.isRight && foreignServerVersion.isRight && authorizationIdentifier.isRight) + Right(PgForeignServersViewRow(oid = oid.toOption.get, srvoptions = srvoptions.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, foreignDataWrapperCatalog = foreignDataWrapperCatalog.toOption.get, foreignDataWrapperName = foreignDataWrapperName.toOption.get, foreignServerType = foreignServerType.toOption.get, foreignServerVersion = foreignServerVersion.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get)) + else Left(List[Either[String, Any]](oid, srvoptions, foreignServerCatalog, foreignServerName, foreignDataWrapperCatalog, foreignDataWrapperName, foreignServerType, foreignServerVersion, authorizationIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignServersViewRow] = new JsonEncoder[PgForeignServersViewRow] { + override def unsafeEncode(a: PgForeignServersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgForeignServerId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""srvoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.srvoptions, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperCatalog, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperName, indent, out) + out.write(",") + out.write(""""foreign_server_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerType, indent, out) + out.write(",") + out.write(""""foreign_server_version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerVersion, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewStructure.scala new file mode 100644 index 0000000000..959314dd23 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_servers/PgForeignServersViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_servers` + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignServersViewStructure[Row](val prefix: Option[String], val extract: Row => PgForeignServersViewRow, val merge: (Row, PgForeignServersViewRow) => Row) + extends Relation[PgForeignServersViewFields, PgForeignServersViewRow, Row] + with PgForeignServersViewFields[Row] { outer => + + override val oid = new Field[PgForeignServerId, Row](prefix, "oid", None, None)(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val srvoptions = new OptField[Array[String], Row](prefix, "srvoptions", None, None)(x => extract(x).srvoptions, (row, value) => merge(row, extract(row).copy(srvoptions = value))) + override val foreignServerCatalog = new OptField[String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val foreignDataWrapperCatalog = new OptField[String, Row](prefix, "foreign_data_wrapper_catalog", None, None)(x => extract(x).foreignDataWrapperCatalog, (row, value) => merge(row, extract(row).copy(foreignDataWrapperCatalog = value))) + override val foreignDataWrapperName = new OptField[String, Row](prefix, "foreign_data_wrapper_name", None, None)(x => extract(x).foreignDataWrapperName, (row, value) => merge(row, extract(row).copy(foreignDataWrapperName = value))) + override val foreignServerType = new OptField[String, Row](prefix, "foreign_server_type", None, None)(x => extract(x).foreignServerType, (row, value) => merge(row, extract(row).copy(foreignServerType = value))) + override val foreignServerVersion = new OptField[String, Row](prefix, "foreign_server_version", None, None)(x => extract(x).foreignServerVersion, (row, value) => merge(row, extract(row).copy(foreignServerVersion = value))) + override val authorizationIdentifier = new OptField[String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, srvoptions, foreignServerCatalog, foreignServerName, foreignDataWrapperCatalog, foreignDataWrapperName, foreignServerType, foreignServerVersion, authorizationIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignServersViewRow, merge: (NewRow, PgForeignServersViewRow) => NewRow): PgForeignServersViewStructure[NewRow] = + new PgForeignServersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewFields.scala new file mode 100644 index 0000000000..01f82c8a07 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_table_columns` + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgForeignTableColumnsViewFields[Row] { + val nspname: Field[String, Row] + val relname: Field[String, Row] + val attname: Field[String, Row] + val attfdwoptions: OptField[Array[String], Row] +} +object PgForeignTableColumnsViewFields extends PgForeignTableColumnsViewStructure[PgForeignTableColumnsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepo.scala new file mode 100644 index 0000000000..8d1cb46cfb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_table_columns` + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignTableColumnsViewRepo { + def select: SelectBuilder[PgForeignTableColumnsViewFields, PgForeignTableColumnsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignTableColumnsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepoImpl.scala new file mode 100644 index 0000000000..5c15448797 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_table_columns` + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignTableColumnsViewRepoImpl extends PgForeignTableColumnsViewRepo { + override def select: SelectBuilder[PgForeignTableColumnsViewFields, PgForeignTableColumnsViewRow] = { + SelectBuilderSql("information_schema._pg_foreign_table_columns", PgForeignTableColumnsViewFields, PgForeignTableColumnsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignTableColumnsViewRow] = { + sql"""select "nspname", "relname", "attname", "attfdwoptions" from information_schema._pg_foreign_table_columns""".query(PgForeignTableColumnsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRow.scala new file mode 100644 index 0000000000..5c5b822d3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewRow.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_table_columns` + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignTableColumnsViewRow( + /** Points to [[pg_catalog.pg_namespace.PgNamespaceRow.nspname]] */ + nspname: String, + /** Points to [[pg_catalog.pg_class.PgClassRow.relname]] */ + relname: String, + /** Points to [[pg_catalog.pg_attribute.PgAttributeRow.attname]] */ + attname: String, + /** Points to [[pg_catalog.pg_attribute.PgAttributeRow.attfdwoptions]] */ + attfdwoptions: Option[Array[String]] +) + +object PgForeignTableColumnsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignTableColumnsViewRow] = new JdbcDecoder[PgForeignTableColumnsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignTableColumnsViewRow) = + columIndex + 3 -> + PgForeignTableColumnsViewRow( + nspname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + attname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + attfdwoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignTableColumnsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val nspname = jsonObj.get("nspname").toRight("Missing field 'nspname'").flatMap(_.as(JsonDecoder.string)) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val attname = jsonObj.get("attname").toRight("Missing field 'attname'").flatMap(_.as(JsonDecoder.string)) + val attfdwoptions = jsonObj.get("attfdwoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (nspname.isRight && relname.isRight && attname.isRight && attfdwoptions.isRight) + Right(PgForeignTableColumnsViewRow(nspname = nspname.toOption.get, relname = relname.toOption.get, attname = attname.toOption.get, attfdwoptions = attfdwoptions.toOption.get)) + else Left(List[Either[String, Any]](nspname, relname, attname, attfdwoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignTableColumnsViewRow] = new JsonEncoder[PgForeignTableColumnsViewRow] { + override def unsafeEncode(a: PgForeignTableColumnsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""nspname":""") + JsonEncoder.string.unsafeEncode(a.nspname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""attname":""") + JsonEncoder.string.unsafeEncode(a.attname, indent, out) + out.write(",") + out.write(""""attfdwoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.attfdwoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewStructure.scala new file mode 100644 index 0000000000..c5d74eb094 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_table_columns/PgForeignTableColumnsViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_table_columns` + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignTableColumnsViewStructure[Row](val prefix: Option[String], val extract: Row => PgForeignTableColumnsViewRow, val merge: (Row, PgForeignTableColumnsViewRow) => Row) + extends Relation[PgForeignTableColumnsViewFields, PgForeignTableColumnsViewRow, Row] + with PgForeignTableColumnsViewFields[Row] { outer => + + override val nspname = new Field[String, Row](prefix, "nspname", None, None)(x => extract(x).nspname, (row, value) => merge(row, extract(row).copy(nspname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val attname = new Field[String, Row](prefix, "attname", None, None)(x => extract(x).attname, (row, value) => merge(row, extract(row).copy(attname = value))) + override val attfdwoptions = new OptField[Array[String], Row](prefix, "attfdwoptions", None, None)(x => extract(x).attfdwoptions, (row, value) => merge(row, extract(row).copy(attfdwoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](nspname, relname, attname, attfdwoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignTableColumnsViewRow, merge: (NewRow, PgForeignTableColumnsViewRow) => NewRow): PgForeignTableColumnsViewStructure[NewRow] = + new PgForeignTableColumnsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewFields.scala new file mode 100644 index 0000000000..aea9f23cc1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_tables` + +import typo.dsl.SqlExpr.OptField + +trait PgForeignTablesViewFields[Row] { + val foreignTableCatalog: OptField[String, Row] + val foreignTableSchema: OptField[String, Row] + val foreignTableName: OptField[String, Row] + val ftoptions: OptField[Array[String], Row] + val foreignServerCatalog: OptField[String, Row] + val foreignServerName: OptField[String, Row] + val authorizationIdentifier: OptField[String, Row] +} +object PgForeignTablesViewFields extends PgForeignTablesViewStructure[PgForeignTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepo.scala new file mode 100644 index 0000000000..7193ce6c1a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_tables` + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignTablesViewRepo { + def select: SelectBuilder[PgForeignTablesViewFields, PgForeignTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepoImpl.scala new file mode 100644 index 0000000000..a4e3037a09 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_tables` + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignTablesViewRepoImpl extends PgForeignTablesViewRepo { + override def select: SelectBuilder[PgForeignTablesViewFields, PgForeignTablesViewRow] = { + SelectBuilderSql("information_schema._pg_foreign_tables", PgForeignTablesViewFields, PgForeignTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignTablesViewRow] = { + sql"""select "foreign_table_catalog", "foreign_table_schema", "foreign_table_name", "ftoptions", "foreign_server_catalog", "foreign_server_name", "authorization_identifier" from information_schema._pg_foreign_tables""".query(PgForeignTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRow.scala new file mode 100644 index 0000000000..07b5b8f3ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_tables` + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignTablesViewRow( + foreignTableCatalog: /* nullability unknown */ Option[String], + foreignTableSchema: /* nullability unknown */ Option[String], + foreignTableName: /* nullability unknown */ Option[String], + /** Points to [[pg_catalog.pg_foreign_table.PgForeignTableRow.ftoptions]] */ + ftoptions: Option[Array[String]], + foreignServerCatalog: /* nullability unknown */ Option[String], + foreignServerName: /* nullability unknown */ Option[String], + authorizationIdentifier: /* nullability unknown */ Option[String] +) + +object PgForeignTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignTablesViewRow] = new JdbcDecoder[PgForeignTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignTablesViewRow) = + columIndex + 6 -> + PgForeignTablesViewRow( + foreignTableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignTableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignTableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + ftoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignTableCatalog = jsonObj.get("foreign_table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableSchema = jsonObj.get("foreign_table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableName = jsonObj.get("foreign_table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ftoptions = jsonObj.get("ftoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignTableCatalog.isRight && foreignTableSchema.isRight && foreignTableName.isRight && ftoptions.isRight && foreignServerCatalog.isRight && foreignServerName.isRight && authorizationIdentifier.isRight) + Right(PgForeignTablesViewRow(foreignTableCatalog = foreignTableCatalog.toOption.get, foreignTableSchema = foreignTableSchema.toOption.get, foreignTableName = foreignTableName.toOption.get, ftoptions = ftoptions.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get)) + else Left(List[Either[String, Any]](foreignTableCatalog, foreignTableSchema, foreignTableName, ftoptions, foreignServerCatalog, foreignServerName, authorizationIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignTablesViewRow] = new JsonEncoder[PgForeignTablesViewRow] { + override def unsafeEncode(a: PgForeignTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableCatalog, indent, out) + out.write(",") + out.write(""""foreign_table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableSchema, indent, out) + out.write(",") + out.write(""""foreign_table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableName, indent, out) + out.write(",") + out.write(""""ftoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.ftoptions, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewStructure.scala new file mode 100644 index 0000000000..f595f17ac0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_foreign_tables/PgForeignTablesViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_foreign_tables` + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgForeignTablesViewRow, val merge: (Row, PgForeignTablesViewRow) => Row) + extends Relation[PgForeignTablesViewFields, PgForeignTablesViewRow, Row] + with PgForeignTablesViewFields[Row] { outer => + + override val foreignTableCatalog = new OptField[String, Row](prefix, "foreign_table_catalog", None, None)(x => extract(x).foreignTableCatalog, (row, value) => merge(row, extract(row).copy(foreignTableCatalog = value))) + override val foreignTableSchema = new OptField[String, Row](prefix, "foreign_table_schema", None, None)(x => extract(x).foreignTableSchema, (row, value) => merge(row, extract(row).copy(foreignTableSchema = value))) + override val foreignTableName = new OptField[String, Row](prefix, "foreign_table_name", None, None)(x => extract(x).foreignTableName, (row, value) => merge(row, extract(row).copy(foreignTableName = value))) + override val ftoptions = new OptField[Array[String], Row](prefix, "ftoptions", None, None)(x => extract(x).ftoptions, (row, value) => merge(row, extract(row).copy(ftoptions = value))) + override val foreignServerCatalog = new OptField[String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val authorizationIdentifier = new OptField[String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignTableCatalog, foreignTableSchema, foreignTableName, ftoptions, foreignServerCatalog, foreignServerName, authorizationIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignTablesViewRow, merge: (NewRow, PgForeignTablesViewRow) => NewRow): PgForeignTablesViewStructure[NewRow] = + new PgForeignTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewFields.scala new file mode 100644 index 0000000000..d1a8c1e5c7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_user_mappings` + +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgUserMappingsViewFields[Row] { + val oid: Field[PgUserMappingId, Row] + val umoptions: OptField[Array[String], Row] + val umuser: Field[/* oid */ Long, Row] + val authorizationIdentifier: OptField[String, Row] + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] + val srvowner: OptField[/* nullability unknown */ String, Row] +} +object PgUserMappingsViewFields extends PgUserMappingsViewStructure[PgUserMappingsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepo.scala new file mode 100644 index 0000000000..ab8479b19a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_user_mappings` + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgUserMappingsViewRepo { + def select: SelectBuilder[PgUserMappingsViewFields, PgUserMappingsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgUserMappingsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepoImpl.scala new file mode 100644 index 0000000000..89e6b2f1d6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_user_mappings` + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgUserMappingsViewRepoImpl extends PgUserMappingsViewRepo { + override def select: SelectBuilder[PgUserMappingsViewFields, PgUserMappingsViewRow] = { + SelectBuilderSql("information_schema._pg_user_mappings", PgUserMappingsViewFields, PgUserMappingsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgUserMappingsViewRow] = { + sql"""select "oid", "umoptions", "umuser", "authorization_identifier", "foreign_server_catalog", "foreign_server_name", "srvowner" from information_schema._pg_user_mappings""".query(PgUserMappingsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRow.scala new file mode 100644 index 0000000000..6b8f1e815f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_user_mappings` + +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgUserMappingsViewRow( + /** Points to [[pg_catalog.pg_user_mapping.PgUserMappingRow.oid]] */ + oid: PgUserMappingId, + /** Points to [[pg_catalog.pg_user_mapping.PgUserMappingRow.umoptions]] */ + umoptions: Option[Array[String]], + /** Points to [[pg_catalog.pg_user_mapping.PgUserMappingRow.umuser]] */ + umuser: /* oid */ Long, + authorizationIdentifier: /* nullability unknown */ Option[String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.authorizationIdentifier]] */ + srvowner: Option[/* nullability unknown */ String] +) + +object PgUserMappingsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgUserMappingsViewRow] = new JdbcDecoder[PgUserMappingsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgUserMappingsViewRow) = + columIndex + 6 -> + PgUserMappingsViewRow( + oid = PgUserMappingId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + umoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 1, rs)._2, + umuser = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + srvowner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgUserMappingsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgUserMappingId.jsonDecoder)) + val umoptions = jsonObj.get("umoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val umuser = jsonObj.get("umuser").toRight("Missing field 'umuser'").flatMap(_.as(JsonDecoder.long)) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val srvowner = jsonObj.get("srvowner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && umoptions.isRight && umuser.isRight && authorizationIdentifier.isRight && foreignServerCatalog.isRight && foreignServerName.isRight && srvowner.isRight) + Right(PgUserMappingsViewRow(oid = oid.toOption.get, umoptions = umoptions.toOption.get, umuser = umuser.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, srvowner = srvowner.toOption.get)) + else Left(List[Either[String, Any]](oid, umoptions, umuser, authorizationIdentifier, foreignServerCatalog, foreignServerName, srvowner).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgUserMappingsViewRow] = new JsonEncoder[PgUserMappingsViewRow] { + override def unsafeEncode(a: PgUserMappingsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgUserMappingId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""umoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.umoptions, indent, out) + out.write(",") + out.write(""""umuser":""") + JsonEncoder.long.unsafeEncode(a.umuser, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""srvowner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.srvowner, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewStructure.scala new file mode 100644 index 0000000000..2d21de8c59 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/_pg_user_mappings/PgUserMappingsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package `_pg_user_mappings` + +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgUserMappingsViewStructure[Row](val prefix: Option[String], val extract: Row => PgUserMappingsViewRow, val merge: (Row, PgUserMappingsViewRow) => Row) + extends Relation[PgUserMappingsViewFields, PgUserMappingsViewRow, Row] + with PgUserMappingsViewFields[Row] { outer => + + override val oid = new Field[PgUserMappingId, Row](prefix, "oid", None, None)(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val umoptions = new OptField[Array[String], Row](prefix, "umoptions", None, None)(x => extract(x).umoptions, (row, value) => merge(row, extract(row).copy(umoptions = value))) + override val umuser = new Field[/* oid */ Long, Row](prefix, "umuser", None, None)(x => extract(x).umuser, (row, value) => merge(row, extract(row).copy(umuser = value))) + override val authorizationIdentifier = new OptField[String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val srvowner = new OptField[/* nullability unknown */ String, Row](prefix, "srvowner", None, None)(x => extract(x).srvowner, (row, value) => merge(row, extract(row).copy(srvowner = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, umoptions, umuser, authorizationIdentifier, foreignServerCatalog, foreignServerName, srvowner) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgUserMappingsViewRow, merge: (NewRow, PgUserMappingsViewRow) => NewRow): PgUserMappingsViewStructure[NewRow] = + new PgUserMappingsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewFields.scala new file mode 100644 index 0000000000..ad0f6a41c7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewFields.scala @@ -0,0 +1,18 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package administrable_role_authorizations + +import typo.dsl.SqlExpr.OptField + +trait AdministrableRoleAuthorizationsViewFields[Row] { + val grantee: OptField[/* nullability unknown */ String, Row] + val roleName: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object AdministrableRoleAuthorizationsViewFields extends AdministrableRoleAuthorizationsViewStructure[AdministrableRoleAuthorizationsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepo.scala new file mode 100644 index 0000000000..692306e5cf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package administrable_role_authorizations + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AdministrableRoleAuthorizationsViewRepo { + def select: SelectBuilder[AdministrableRoleAuthorizationsViewFields, AdministrableRoleAuthorizationsViewRow] + def selectAll: ZStream[ZConnection, Throwable, AdministrableRoleAuthorizationsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepoImpl.scala new file mode 100644 index 0000000000..1961e40799 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package administrable_role_authorizations + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AdministrableRoleAuthorizationsViewRepoImpl extends AdministrableRoleAuthorizationsViewRepo { + override def select: SelectBuilder[AdministrableRoleAuthorizationsViewFields, AdministrableRoleAuthorizationsViewRow] = { + SelectBuilderSql("information_schema.administrable_role_authorizations", AdministrableRoleAuthorizationsViewFields, AdministrableRoleAuthorizationsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AdministrableRoleAuthorizationsViewRow] = { + sql"""select "grantee", "role_name", "is_grantable" from information_schema.administrable_role_authorizations""".query(AdministrableRoleAuthorizationsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRow.scala new file mode 100644 index 0000000000..a23e137bd8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package administrable_role_authorizations + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AdministrableRoleAuthorizationsViewRow( + /** Points to [[applicable_roles.ApplicableRolesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[applicable_roles.ApplicableRolesViewRow.roleName]] */ + roleName: Option[/* nullability unknown */ String], + /** Points to [[applicable_roles.ApplicableRolesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object AdministrableRoleAuthorizationsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AdministrableRoleAuthorizationsViewRow] = new JdbcDecoder[AdministrableRoleAuthorizationsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AdministrableRoleAuthorizationsViewRow) = + columIndex + 2 -> + AdministrableRoleAuthorizationsViewRow( + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + roleName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AdministrableRoleAuthorizationsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val roleName = jsonObj.get("role_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantee.isRight && roleName.isRight && isGrantable.isRight) + Right(AdministrableRoleAuthorizationsViewRow(grantee = grantee.toOption.get, roleName = roleName.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantee, roleName, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AdministrableRoleAuthorizationsViewRow] = new JsonEncoder[AdministrableRoleAuthorizationsViewRow] { + override def unsafeEncode(a: AdministrableRoleAuthorizationsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""role_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.roleName, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewStructure.scala new file mode 100644 index 0000000000..e5b088aa2b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/administrable_role_authorizations/AdministrableRoleAuthorizationsViewStructure.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package administrable_role_authorizations + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class AdministrableRoleAuthorizationsViewStructure[Row](val prefix: Option[String], val extract: Row => AdministrableRoleAuthorizationsViewRow, val merge: (Row, AdministrableRoleAuthorizationsViewRow) => Row) + extends Relation[AdministrableRoleAuthorizationsViewFields, AdministrableRoleAuthorizationsViewRow, Row] + with AdministrableRoleAuthorizationsViewFields[Row] { outer => + + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val roleName = new OptField[/* nullability unknown */ String, Row](prefix, "role_name", None, None)(x => extract(x).roleName, (row, value) => merge(row, extract(row).copy(roleName = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantee, roleName, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AdministrableRoleAuthorizationsViewRow, merge: (NewRow, AdministrableRoleAuthorizationsViewRow) => NewRow): AdministrableRoleAuthorizationsViewStructure[NewRow] = + new AdministrableRoleAuthorizationsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewFields.scala new file mode 100644 index 0000000000..e1eb8fad96 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewFields.scala @@ -0,0 +1,18 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package applicable_roles + +import typo.dsl.SqlExpr.OptField + +trait ApplicableRolesViewFields[Row] { + val grantee: OptField[String, Row] + val roleName: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] +} +object ApplicableRolesViewFields extends ApplicableRolesViewStructure[ApplicableRolesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepo.scala new file mode 100644 index 0000000000..1af4ab730f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package applicable_roles + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ApplicableRolesViewRepo { + def select: SelectBuilder[ApplicableRolesViewFields, ApplicableRolesViewRow] + def selectAll: ZStream[ZConnection, Throwable, ApplicableRolesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepoImpl.scala new file mode 100644 index 0000000000..cf60d36203 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package applicable_roles + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ApplicableRolesViewRepoImpl extends ApplicableRolesViewRepo { + override def select: SelectBuilder[ApplicableRolesViewFields, ApplicableRolesViewRow] = { + SelectBuilderSql("information_schema.applicable_roles", ApplicableRolesViewFields, ApplicableRolesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ApplicableRolesViewRow] = { + sql"""select "grantee", "role_name", "is_grantable" from information_schema.applicable_roles""".query(ApplicableRolesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRow.scala new file mode 100644 index 0000000000..26d768c591 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewRow.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package applicable_roles + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ApplicableRolesViewRow( + grantee: /* nullability unknown */ Option[String], + roleName: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object ApplicableRolesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ApplicableRolesViewRow] = new JdbcDecoder[ApplicableRolesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ApplicableRolesViewRow) = + columIndex + 2 -> + ApplicableRolesViewRow( + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + roleName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ApplicableRolesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val roleName = jsonObj.get("role_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantee.isRight && roleName.isRight && isGrantable.isRight) + Right(ApplicableRolesViewRow(grantee = grantee.toOption.get, roleName = roleName.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantee, roleName, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ApplicableRolesViewRow] = new JsonEncoder[ApplicableRolesViewRow] { + override def unsafeEncode(a: ApplicableRolesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""role_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.roleName, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewStructure.scala new file mode 100644 index 0000000000..8995a0e2fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/applicable_roles/ApplicableRolesViewStructure.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package applicable_roles + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ApplicableRolesViewStructure[Row](val prefix: Option[String], val extract: Row => ApplicableRolesViewRow, val merge: (Row, ApplicableRolesViewRow) => Row) + extends Relation[ApplicableRolesViewFields, ApplicableRolesViewRow, Row] + with ApplicableRolesViewFields[Row] { outer => + + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val roleName = new OptField[String, Row](prefix, "role_name", None, None)(x => extract(x).roleName, (row, value) => merge(row, extract(row).copy(roleName = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantee, roleName, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ApplicableRolesViewRow, merge: (NewRow, ApplicableRolesViewRow) => NewRow): ApplicableRolesViewStructure[NewRow] = + new ApplicableRolesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewFields.scala new file mode 100644 index 0000000000..37e0d7defa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewFields.scala @@ -0,0 +1,46 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package attributes + +import typo.dsl.SqlExpr.OptField + +trait AttributesViewFields[Row] { + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val attributeName: OptField[String, Row] + val ordinalPosition: OptField[Int, Row] + val attributeDefault: OptField[String, Row] + val isNullable: OptField[/* max 3 chars */ String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val attributeUdtCatalog: OptField[String, Row] + val attributeUdtSchema: OptField[String, Row] + val attributeUdtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] + val isDerivedReferenceAttribute: OptField[/* max 3 chars */ String, Row] +} +object AttributesViewFields extends AttributesViewStructure[AttributesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepo.scala new file mode 100644 index 0000000000..dd01d13d16 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package attributes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AttributesViewRepo { + def select: SelectBuilder[AttributesViewFields, AttributesViewRow] + def selectAll: ZStream[ZConnection, Throwable, AttributesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepoImpl.scala new file mode 100644 index 0000000000..d726361185 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package attributes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AttributesViewRepoImpl extends AttributesViewRepo { + override def select: SelectBuilder[AttributesViewFields, AttributesViewRow] = { + SelectBuilderSql("information_schema.attributes", AttributesViewFields, AttributesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AttributesViewRow] = { + sql"""select "udt_catalog", "udt_schema", "udt_name", "attribute_name", "ordinal_position", "attribute_default", "is_nullable", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "attribute_udt_catalog", "attribute_udt_schema", "attribute_udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier", "is_derived_reference_attribute" from information_schema.attributes""".query(AttributesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRow.scala new file mode 100644 index 0000000000..83c947666d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewRow.scala @@ -0,0 +1,223 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package attributes + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AttributesViewRow( + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + attributeName: /* nullability unknown */ Option[String], + ordinalPosition: /* nullability unknown */ Option[Int], + attributeDefault: /* nullability unknown */ Option[String], + isNullable: /* nullability unknown */ Option[/* max 3 chars */ String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + attributeUdtCatalog: /* nullability unknown */ Option[String], + attributeUdtSchema: /* nullability unknown */ Option[String], + attributeUdtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String], + isDerivedReferenceAttribute: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object AttributesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AttributesViewRow] = new JdbcDecoder[AttributesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AttributesViewRow) = + columIndex + 30 -> + AttributesViewRow( + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + attributeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + ordinalPosition = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 4, rs)._2, + attributeDefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isNullable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 16, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 17, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 18, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 19, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 21, rs)._2, + attributeUdtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + attributeUdtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + attributeUdtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 24, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 25, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 27, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 28, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 29, rs)._2, + isDerivedReferenceAttribute = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 30, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AttributesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val attributeName = jsonObj.get("attribute_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ordinalPosition = jsonObj.get("ordinal_position").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val attributeDefault = jsonObj.get("attribute_default").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isNullable = jsonObj.get("is_nullable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val attributeUdtCatalog = jsonObj.get("attribute_udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val attributeUdtSchema = jsonObj.get("attribute_udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val attributeUdtName = jsonObj.get("attribute_udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isDerivedReferenceAttribute = jsonObj.get("is_derived_reference_attribute").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (udtCatalog.isRight && udtSchema.isRight && udtName.isRight && attributeName.isRight && ordinalPosition.isRight && attributeDefault.isRight && isNullable.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && attributeUdtCatalog.isRight && attributeUdtSchema.isRight && attributeUdtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight && isDerivedReferenceAttribute.isRight) + Right(AttributesViewRow(udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, attributeName = attributeName.toOption.get, ordinalPosition = ordinalPosition.toOption.get, attributeDefault = attributeDefault.toOption.get, isNullable = isNullable.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, attributeUdtCatalog = attributeUdtCatalog.toOption.get, attributeUdtSchema = attributeUdtSchema.toOption.get, attributeUdtName = attributeUdtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get, isDerivedReferenceAttribute = isDerivedReferenceAttribute.toOption.get)) + else Left(List[Either[String, Any]](udtCatalog, udtSchema, udtName, attributeName, ordinalPosition, attributeDefault, isNullable, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, attributeUdtCatalog, attributeUdtSchema, attributeUdtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, isDerivedReferenceAttribute).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AttributesViewRow] = new JsonEncoder[AttributesViewRow] { + override def unsafeEncode(a: AttributesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""attribute_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.attributeName, indent, out) + out.write(",") + out.write(""""ordinal_position":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.ordinalPosition, indent, out) + out.write(",") + out.write(""""attribute_default":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.attributeDefault, indent, out) + out.write(",") + out.write(""""is_nullable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isNullable, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""attribute_udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.attributeUdtCatalog, indent, out) + out.write(",") + out.write(""""attribute_udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.attributeUdtSchema, indent, out) + out.write(",") + out.write(""""attribute_udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.attributeUdtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write(",") + out.write(""""is_derived_reference_attribute":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isDerivedReferenceAttribute, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewStructure.scala new file mode 100644 index 0000000000..a794705166 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/attributes/AttributesViewStructure.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package attributes + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class AttributesViewStructure[Row](val prefix: Option[String], val extract: Row => AttributesViewRow, val merge: (Row, AttributesViewRow) => Row) + extends Relation[AttributesViewFields, AttributesViewRow, Row] + with AttributesViewFields[Row] { outer => + + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val attributeName = new OptField[String, Row](prefix, "attribute_name", None, None)(x => extract(x).attributeName, (row, value) => merge(row, extract(row).copy(attributeName = value))) + override val ordinalPosition = new OptField[Int, Row](prefix, "ordinal_position", None, None)(x => extract(x).ordinalPosition, (row, value) => merge(row, extract(row).copy(ordinalPosition = value))) + override val attributeDefault = new OptField[String, Row](prefix, "attribute_default", None, None)(x => extract(x).attributeDefault, (row, value) => merge(row, extract(row).copy(attributeDefault = value))) + override val isNullable = new OptField[/* max 3 chars */ String, Row](prefix, "is_nullable", None, None)(x => extract(x).isNullable, (row, value) => merge(row, extract(row).copy(isNullable = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val attributeUdtCatalog = new OptField[String, Row](prefix, "attribute_udt_catalog", None, None)(x => extract(x).attributeUdtCatalog, (row, value) => merge(row, extract(row).copy(attributeUdtCatalog = value))) + override val attributeUdtSchema = new OptField[String, Row](prefix, "attribute_udt_schema", None, None)(x => extract(x).attributeUdtSchema, (row, value) => merge(row, extract(row).copy(attributeUdtSchema = value))) + override val attributeUdtName = new OptField[String, Row](prefix, "attribute_udt_name", None, None)(x => extract(x).attributeUdtName, (row, value) => merge(row, extract(row).copy(attributeUdtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + override val isDerivedReferenceAttribute = new OptField[/* max 3 chars */ String, Row](prefix, "is_derived_reference_attribute", None, None)(x => extract(x).isDerivedReferenceAttribute, (row, value) => merge(row, extract(row).copy(isDerivedReferenceAttribute = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](udtCatalog, udtSchema, udtName, attributeName, ordinalPosition, attributeDefault, isNullable, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, attributeUdtCatalog, attributeUdtSchema, attributeUdtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, isDerivedReferenceAttribute) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AttributesViewRow, merge: (NewRow, AttributesViewRow) => NewRow): AttributesViewStructure[NewRow] = + new AttributesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewFields.scala new file mode 100644 index 0000000000..cae8459b0d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package character_sets + +import typo.dsl.SqlExpr.OptField + +trait CharacterSetsViewFields[Row] { + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val characterRepertoire: OptField[String, Row] + val formOfUse: OptField[String, Row] + val defaultCollateCatalog: OptField[String, Row] + val defaultCollateSchema: OptField[String, Row] + val defaultCollateName: OptField[String, Row] +} +object CharacterSetsViewFields extends CharacterSetsViewStructure[CharacterSetsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepo.scala new file mode 100644 index 0000000000..c91faed503 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package character_sets + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CharacterSetsViewRepo { + def select: SelectBuilder[CharacterSetsViewFields, CharacterSetsViewRow] + def selectAll: ZStream[ZConnection, Throwable, CharacterSetsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepoImpl.scala new file mode 100644 index 0000000000..e73abf7f64 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package character_sets + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CharacterSetsViewRepoImpl extends CharacterSetsViewRepo { + override def select: SelectBuilder[CharacterSetsViewFields, CharacterSetsViewRow] = { + SelectBuilderSql("information_schema.character_sets", CharacterSetsViewFields, CharacterSetsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CharacterSetsViewRow] = { + sql"""select "character_set_catalog", "character_set_schema", "character_set_name", "character_repertoire", "form_of_use", "default_collate_catalog", "default_collate_schema", "default_collate_name" from information_schema.character_sets""".query(CharacterSetsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRow.scala new file mode 100644 index 0000000000..be34cb3a68 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package character_sets + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CharacterSetsViewRow( + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + characterRepertoire: /* nullability unknown */ Option[String], + formOfUse: /* nullability unknown */ Option[String], + defaultCollateCatalog: /* nullability unknown */ Option[String], + defaultCollateSchema: /* nullability unknown */ Option[String], + defaultCollateName: /* nullability unknown */ Option[String] +) + +object CharacterSetsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CharacterSetsViewRow] = new JdbcDecoder[CharacterSetsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CharacterSetsViewRow) = + columIndex + 7 -> + CharacterSetsViewRow( + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + characterRepertoire = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + formOfUse = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + defaultCollateCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + defaultCollateSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + defaultCollateName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CharacterSetsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterRepertoire = jsonObj.get("character_repertoire").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val formOfUse = jsonObj.get("form_of_use").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCollateCatalog = jsonObj.get("default_collate_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCollateSchema = jsonObj.get("default_collate_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCollateName = jsonObj.get("default_collate_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && characterRepertoire.isRight && formOfUse.isRight && defaultCollateCatalog.isRight && defaultCollateSchema.isRight && defaultCollateName.isRight) + Right(CharacterSetsViewRow(characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, characterRepertoire = characterRepertoire.toOption.get, formOfUse = formOfUse.toOption.get, defaultCollateCatalog = defaultCollateCatalog.toOption.get, defaultCollateSchema = defaultCollateSchema.toOption.get, defaultCollateName = defaultCollateName.toOption.get)) + else Left(List[Either[String, Any]](characterSetCatalog, characterSetSchema, characterSetName, characterRepertoire, formOfUse, defaultCollateCatalog, defaultCollateSchema, defaultCollateName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CharacterSetsViewRow] = new JsonEncoder[CharacterSetsViewRow] { + override def unsafeEncode(a: CharacterSetsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""character_repertoire":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterRepertoire, indent, out) + out.write(",") + out.write(""""form_of_use":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.formOfUse, indent, out) + out.write(",") + out.write(""""default_collate_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCollateCatalog, indent, out) + out.write(",") + out.write(""""default_collate_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCollateSchema, indent, out) + out.write(",") + out.write(""""default_collate_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCollateName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewStructure.scala new file mode 100644 index 0000000000..e706a62313 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/character_sets/CharacterSetsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package character_sets + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CharacterSetsViewStructure[Row](val prefix: Option[String], val extract: Row => CharacterSetsViewRow, val merge: (Row, CharacterSetsViewRow) => Row) + extends Relation[CharacterSetsViewFields, CharacterSetsViewRow, Row] + with CharacterSetsViewFields[Row] { outer => + + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val characterRepertoire = new OptField[String, Row](prefix, "character_repertoire", None, None)(x => extract(x).characterRepertoire, (row, value) => merge(row, extract(row).copy(characterRepertoire = value))) + override val formOfUse = new OptField[String, Row](prefix, "form_of_use", None, None)(x => extract(x).formOfUse, (row, value) => merge(row, extract(row).copy(formOfUse = value))) + override val defaultCollateCatalog = new OptField[String, Row](prefix, "default_collate_catalog", None, None)(x => extract(x).defaultCollateCatalog, (row, value) => merge(row, extract(row).copy(defaultCollateCatalog = value))) + override val defaultCollateSchema = new OptField[String, Row](prefix, "default_collate_schema", None, None)(x => extract(x).defaultCollateSchema, (row, value) => merge(row, extract(row).copy(defaultCollateSchema = value))) + override val defaultCollateName = new OptField[String, Row](prefix, "default_collate_name", None, None)(x => extract(x).defaultCollateName, (row, value) => merge(row, extract(row).copy(defaultCollateName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](characterSetCatalog, characterSetSchema, characterSetName, characterRepertoire, formOfUse, defaultCollateCatalog, defaultCollateSchema, defaultCollateName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CharacterSetsViewRow, merge: (NewRow, CharacterSetsViewRow) => NewRow): CharacterSetsViewStructure[NewRow] = + new CharacterSetsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewFields.scala new file mode 100644 index 0000000000..783e3b53b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraint_routine_usage + +import typo.dsl.SqlExpr.OptField + +trait CheckConstraintRoutineUsageViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] +} +object CheckConstraintRoutineUsageViewFields extends CheckConstraintRoutineUsageViewStructure[CheckConstraintRoutineUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepo.scala new file mode 100644 index 0000000000..c586435bea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraint_routine_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CheckConstraintRoutineUsageViewRepo { + def select: SelectBuilder[CheckConstraintRoutineUsageViewFields, CheckConstraintRoutineUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, CheckConstraintRoutineUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepoImpl.scala new file mode 100644 index 0000000000..5ee27002fe --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraint_routine_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CheckConstraintRoutineUsageViewRepoImpl extends CheckConstraintRoutineUsageViewRepo { + override def select: SelectBuilder[CheckConstraintRoutineUsageViewFields, CheckConstraintRoutineUsageViewRow] = { + SelectBuilderSql("information_schema.check_constraint_routine_usage", CheckConstraintRoutineUsageViewFields, CheckConstraintRoutineUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CheckConstraintRoutineUsageViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "specific_catalog", "specific_schema", "specific_name" from information_schema.check_constraint_routine_usage""".query(CheckConstraintRoutineUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRow.scala new file mode 100644 index 0000000000..d98b08ee6f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraint_routine_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CheckConstraintRoutineUsageViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String] +) + +object CheckConstraintRoutineUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CheckConstraintRoutineUsageViewRow] = new JdbcDecoder[CheckConstraintRoutineUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CheckConstraintRoutineUsageViewRow) = + columIndex + 5 -> + CheckConstraintRoutineUsageViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CheckConstraintRoutineUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && specificCatalog.isRight && specificSchema.isRight && specificName.isRight) + Right(CheckConstraintRoutineUsageViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, specificCatalog, specificSchema, specificName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CheckConstraintRoutineUsageViewRow] = new JsonEncoder[CheckConstraintRoutineUsageViewRow] { + override def unsafeEncode(a: CheckConstraintRoutineUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewStructure.scala new file mode 100644 index 0000000000..551b70c8c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraint_routine_usage/CheckConstraintRoutineUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraint_routine_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CheckConstraintRoutineUsageViewStructure[Row](val prefix: Option[String], val extract: Row => CheckConstraintRoutineUsageViewRow, val merge: (Row, CheckConstraintRoutineUsageViewRow) => Row) + extends Relation[CheckConstraintRoutineUsageViewFields, CheckConstraintRoutineUsageViewRow, Row] + with CheckConstraintRoutineUsageViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, specificCatalog, specificSchema, specificName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CheckConstraintRoutineUsageViewRow, merge: (NewRow, CheckConstraintRoutineUsageViewRow) => NewRow): CheckConstraintRoutineUsageViewStructure[NewRow] = + new CheckConstraintRoutineUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewFields.scala new file mode 100644 index 0000000000..9c4f114ff8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraints + +import typo.dsl.SqlExpr.OptField + +trait CheckConstraintsViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val checkClause: OptField[String, Row] +} +object CheckConstraintsViewFields extends CheckConstraintsViewStructure[CheckConstraintsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepo.scala new file mode 100644 index 0000000000..ce9a3dd15a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraints + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CheckConstraintsViewRepo { + def select: SelectBuilder[CheckConstraintsViewFields, CheckConstraintsViewRow] + def selectAll: ZStream[ZConnection, Throwable, CheckConstraintsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepoImpl.scala new file mode 100644 index 0000000000..fcfd79cc3b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraints + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CheckConstraintsViewRepoImpl extends CheckConstraintsViewRepo { + override def select: SelectBuilder[CheckConstraintsViewFields, CheckConstraintsViewRow] = { + SelectBuilderSql("information_schema.check_constraints", CheckConstraintsViewFields, CheckConstraintsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CheckConstraintsViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "check_clause" from information_schema.check_constraints""".query(CheckConstraintsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRow.scala new file mode 100644 index 0000000000..2251913786 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraints + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CheckConstraintsViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + checkClause: /* nullability unknown */ Option[String] +) + +object CheckConstraintsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CheckConstraintsViewRow] = new JdbcDecoder[CheckConstraintsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CheckConstraintsViewRow) = + columIndex + 3 -> + CheckConstraintsViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + checkClause = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CheckConstraintsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val checkClause = jsonObj.get("check_clause").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && checkClause.isRight) + Right(CheckConstraintsViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, checkClause = checkClause.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, checkClause).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CheckConstraintsViewRow] = new JsonEncoder[CheckConstraintsViewRow] { + override def unsafeEncode(a: CheckConstraintsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""check_clause":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.checkClause, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewStructure.scala new file mode 100644 index 0000000000..700385b500 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/check_constraints/CheckConstraintsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package check_constraints + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CheckConstraintsViewStructure[Row](val prefix: Option[String], val extract: Row => CheckConstraintsViewRow, val merge: (Row, CheckConstraintsViewRow) => Row) + extends Relation[CheckConstraintsViewFields, CheckConstraintsViewRow, Row] + with CheckConstraintsViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val checkClause = new OptField[String, Row](prefix, "check_clause", None, None)(x => extract(x).checkClause, (row, value) => merge(row, extract(row).copy(checkClause = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, checkClause) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CheckConstraintsViewRow, merge: (NewRow, CheckConstraintsViewRow) => NewRow): CheckConstraintsViewStructure[NewRow] = + new CheckConstraintsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewFields.scala new file mode 100644 index 0000000000..8acfcf734a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collation_character_set_applicability + +import typo.dsl.SqlExpr.OptField + +trait CollationCharacterSetApplicabilityViewFields[Row] { + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] +} +object CollationCharacterSetApplicabilityViewFields extends CollationCharacterSetApplicabilityViewStructure[CollationCharacterSetApplicabilityViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepo.scala new file mode 100644 index 0000000000..a1d85ac488 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collation_character_set_applicability + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CollationCharacterSetApplicabilityViewRepo { + def select: SelectBuilder[CollationCharacterSetApplicabilityViewFields, CollationCharacterSetApplicabilityViewRow] + def selectAll: ZStream[ZConnection, Throwable, CollationCharacterSetApplicabilityViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepoImpl.scala new file mode 100644 index 0000000000..3c87a39e62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collation_character_set_applicability + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CollationCharacterSetApplicabilityViewRepoImpl extends CollationCharacterSetApplicabilityViewRepo { + override def select: SelectBuilder[CollationCharacterSetApplicabilityViewFields, CollationCharacterSetApplicabilityViewRow] = { + SelectBuilderSql("information_schema.collation_character_set_applicability", CollationCharacterSetApplicabilityViewFields, CollationCharacterSetApplicabilityViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CollationCharacterSetApplicabilityViewRow] = { + sql"""select "collation_catalog", "collation_schema", "collation_name", "character_set_catalog", "character_set_schema", "character_set_name" from information_schema.collation_character_set_applicability""".query(CollationCharacterSetApplicabilityViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRow.scala new file mode 100644 index 0000000000..86df5e7b31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collation_character_set_applicability + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CollationCharacterSetApplicabilityViewRow( + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String] +) + +object CollationCharacterSetApplicabilityViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CollationCharacterSetApplicabilityViewRow] = new JdbcDecoder[CollationCharacterSetApplicabilityViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CollationCharacterSetApplicabilityViewRow) = + columIndex + 5 -> + CollationCharacterSetApplicabilityViewRow( + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CollationCharacterSetApplicabilityViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (collationCatalog.isRight && collationSchema.isRight && collationName.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight) + Right(CollationCharacterSetApplicabilityViewRow(collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get)) + else Left(List[Either[String, Any]](collationCatalog, collationSchema, collationName, characterSetCatalog, characterSetSchema, characterSetName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CollationCharacterSetApplicabilityViewRow] = new JsonEncoder[CollationCharacterSetApplicabilityViewRow] { + override def unsafeEncode(a: CollationCharacterSetApplicabilityViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewStructure.scala new file mode 100644 index 0000000000..ebbc01c3d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collation_character_set_applicability/CollationCharacterSetApplicabilityViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collation_character_set_applicability + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CollationCharacterSetApplicabilityViewStructure[Row](val prefix: Option[String], val extract: Row => CollationCharacterSetApplicabilityViewRow, val merge: (Row, CollationCharacterSetApplicabilityViewRow) => Row) + extends Relation[CollationCharacterSetApplicabilityViewFields, CollationCharacterSetApplicabilityViewRow, Row] + with CollationCharacterSetApplicabilityViewFields[Row] { outer => + + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](collationCatalog, collationSchema, collationName, characterSetCatalog, characterSetSchema, characterSetName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CollationCharacterSetApplicabilityViewRow, merge: (NewRow, CollationCharacterSetApplicabilityViewRow) => NewRow): CollationCharacterSetApplicabilityViewStructure[NewRow] = + new CollationCharacterSetApplicabilityViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewFields.scala new file mode 100644 index 0000000000..6958b5f2b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collations + +import typo.dsl.SqlExpr.OptField + +trait CollationsViewFields[Row] { + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val padAttribute: OptField[String, Row] +} +object CollationsViewFields extends CollationsViewStructure[CollationsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepo.scala new file mode 100644 index 0000000000..73625667bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collations + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CollationsViewRepo { + def select: SelectBuilder[CollationsViewFields, CollationsViewRow] + def selectAll: ZStream[ZConnection, Throwable, CollationsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepoImpl.scala new file mode 100644 index 0000000000..0b1437f0a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collations + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CollationsViewRepoImpl extends CollationsViewRepo { + override def select: SelectBuilder[CollationsViewFields, CollationsViewRow] = { + SelectBuilderSql("information_schema.collations", CollationsViewFields, CollationsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CollationsViewRow] = { + sql"""select "collation_catalog", "collation_schema", "collation_name", "pad_attribute" from information_schema.collations""".query(CollationsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRow.scala new file mode 100644 index 0000000000..36d8540478 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collations + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CollationsViewRow( + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + padAttribute: /* nullability unknown */ Option[String] +) + +object CollationsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CollationsViewRow] = new JdbcDecoder[CollationsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CollationsViewRow) = + columIndex + 3 -> + CollationsViewRow( + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + padAttribute = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CollationsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val padAttribute = jsonObj.get("pad_attribute").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (collationCatalog.isRight && collationSchema.isRight && collationName.isRight && padAttribute.isRight) + Right(CollationsViewRow(collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, padAttribute = padAttribute.toOption.get)) + else Left(List[Either[String, Any]](collationCatalog, collationSchema, collationName, padAttribute).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CollationsViewRow] = new JsonEncoder[CollationsViewRow] { + override def unsafeEncode(a: CollationsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""pad_attribute":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.padAttribute, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewStructure.scala new file mode 100644 index 0000000000..e4b36dd2fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/collations/CollationsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package collations + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CollationsViewStructure[Row](val prefix: Option[String], val extract: Row => CollationsViewRow, val merge: (Row, CollationsViewRow) => Row) + extends Relation[CollationsViewFields, CollationsViewRow, Row] + with CollationsViewFields[Row] { outer => + + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val padAttribute = new OptField[String, Row](prefix, "pad_attribute", None, None)(x => extract(x).padAttribute, (row, value) => merge(row, extract(row).copy(padAttribute = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](collationCatalog, collationSchema, collationName, padAttribute) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CollationsViewRow, merge: (NewRow, CollationsViewRow) => NewRow): CollationsViewStructure[NewRow] = + new CollationsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewFields.scala new file mode 100644 index 0000000000..43e60cf159 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_column_usage + +import typo.dsl.SqlExpr.OptField + +trait ColumnColumnUsageViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val dependentColumn: OptField[String, Row] +} +object ColumnColumnUsageViewFields extends ColumnColumnUsageViewStructure[ColumnColumnUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepo.scala new file mode 100644 index 0000000000..3b7baa60fa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_column_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnColumnUsageViewRepo { + def select: SelectBuilder[ColumnColumnUsageViewFields, ColumnColumnUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnColumnUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepoImpl.scala new file mode 100644 index 0000000000..78956fdbad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_column_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnColumnUsageViewRepoImpl extends ColumnColumnUsageViewRepo { + override def select: SelectBuilder[ColumnColumnUsageViewFields, ColumnColumnUsageViewRow] = { + SelectBuilderSql("information_schema.column_column_usage", ColumnColumnUsageViewFields, ColumnColumnUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnColumnUsageViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "column_name", "dependent_column" from information_schema.column_column_usage""".query(ColumnColumnUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRow.scala new file mode 100644 index 0000000000..1bfb45d94e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewRow.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_column_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnColumnUsageViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + dependentColumn: /* nullability unknown */ Option[String] +) + +object ColumnColumnUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnColumnUsageViewRow] = new JdbcDecoder[ColumnColumnUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnColumnUsageViewRow) = + columIndex + 4 -> + ColumnColumnUsageViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + dependentColumn = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnColumnUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dependentColumn = jsonObj.get("dependent_column").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && dependentColumn.isRight) + Right(ColumnColumnUsageViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, dependentColumn = dependentColumn.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, columnName, dependentColumn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnColumnUsageViewRow] = new JsonEncoder[ColumnColumnUsageViewRow] { + override def unsafeEncode(a: ColumnColumnUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""dependent_column":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dependentColumn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewStructure.scala new file mode 100644 index 0000000000..c5ca1b622c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_column_usage/ColumnColumnUsageViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_column_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnColumnUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnColumnUsageViewRow, val merge: (Row, ColumnColumnUsageViewRow) => Row) + extends Relation[ColumnColumnUsageViewFields, ColumnColumnUsageViewRow, Row] + with ColumnColumnUsageViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val dependentColumn = new OptField[String, Row](prefix, "dependent_column", None, None)(x => extract(x).dependentColumn, (row, value) => merge(row, extract(row).copy(dependentColumn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, columnName, dependentColumn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnColumnUsageViewRow, merge: (NewRow, ColumnColumnUsageViewRow) => NewRow): ColumnColumnUsageViewStructure[NewRow] = + new ColumnColumnUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewFields.scala new file mode 100644 index 0000000000..920306424a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_domain_usage + +import typo.dsl.SqlExpr.OptField + +trait ColumnDomainUsageViewFields[Row] { + val domainCatalog: OptField[String, Row] + val domainSchema: OptField[String, Row] + val domainName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] +} +object ColumnDomainUsageViewFields extends ColumnDomainUsageViewStructure[ColumnDomainUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepo.scala new file mode 100644 index 0000000000..71ea675c40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_domain_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnDomainUsageViewRepo { + def select: SelectBuilder[ColumnDomainUsageViewFields, ColumnDomainUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnDomainUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepoImpl.scala new file mode 100644 index 0000000000..7b45827369 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_domain_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnDomainUsageViewRepoImpl extends ColumnDomainUsageViewRepo { + override def select: SelectBuilder[ColumnDomainUsageViewFields, ColumnDomainUsageViewRow] = { + SelectBuilderSql("information_schema.column_domain_usage", ColumnDomainUsageViewFields, ColumnDomainUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnDomainUsageViewRow] = { + sql"""select "domain_catalog", "domain_schema", "domain_name", "table_catalog", "table_schema", "table_name", "column_name" from information_schema.column_domain_usage""".query(ColumnDomainUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRow.scala new file mode 100644 index 0000000000..9017932692 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_domain_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnDomainUsageViewRow( + domainCatalog: /* nullability unknown */ Option[String], + domainSchema: /* nullability unknown */ Option[String], + domainName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String] +) + +object ColumnDomainUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnDomainUsageViewRow] = new JdbcDecoder[ColumnDomainUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnDomainUsageViewRow) = + columIndex + 6 -> + ColumnDomainUsageViewRow( + domainCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + domainSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + domainName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnDomainUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val domainCatalog = jsonObj.get("domain_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainSchema = jsonObj.get("domain_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainName = jsonObj.get("domain_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (domainCatalog.isRight && domainSchema.isRight && domainName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight) + Right(ColumnDomainUsageViewRow(domainCatalog = domainCatalog.toOption.get, domainSchema = domainSchema.toOption.get, domainName = domainName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get)) + else Left(List[Either[String, Any]](domainCatalog, domainSchema, domainName, tableCatalog, tableSchema, tableName, columnName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnDomainUsageViewRow] = new JsonEncoder[ColumnDomainUsageViewRow] { + override def unsafeEncode(a: ColumnDomainUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""domain_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainCatalog, indent, out) + out.write(",") + out.write(""""domain_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainSchema, indent, out) + out.write(",") + out.write(""""domain_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewStructure.scala new file mode 100644 index 0000000000..58019d70a0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_domain_usage/ColumnDomainUsageViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_domain_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnDomainUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnDomainUsageViewRow, val merge: (Row, ColumnDomainUsageViewRow) => Row) + extends Relation[ColumnDomainUsageViewFields, ColumnDomainUsageViewRow, Row] + with ColumnDomainUsageViewFields[Row] { outer => + + override val domainCatalog = new OptField[String, Row](prefix, "domain_catalog", None, None)(x => extract(x).domainCatalog, (row, value) => merge(row, extract(row).copy(domainCatalog = value))) + override val domainSchema = new OptField[String, Row](prefix, "domain_schema", None, None)(x => extract(x).domainSchema, (row, value) => merge(row, extract(row).copy(domainSchema = value))) + override val domainName = new OptField[String, Row](prefix, "domain_name", None, None)(x => extract(x).domainName, (row, value) => merge(row, extract(row).copy(domainName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](domainCatalog, domainSchema, domainName, tableCatalog, tableSchema, tableName, columnName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnDomainUsageViewRow, merge: (NewRow, ColumnDomainUsageViewRow) => NewRow): ColumnDomainUsageViewStructure[NewRow] = + new ColumnDomainUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewFields.scala new file mode 100644 index 0000000000..21483c0732 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_options + +import typo.dsl.SqlExpr.OptField + +trait ColumnOptionsViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val optionName: OptField[String, Row] + val optionValue: OptField[String, Row] +} +object ColumnOptionsViewFields extends ColumnOptionsViewStructure[ColumnOptionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepo.scala new file mode 100644 index 0000000000..2b5145754c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_options + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnOptionsViewRepo { + def select: SelectBuilder[ColumnOptionsViewFields, ColumnOptionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnOptionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepoImpl.scala new file mode 100644 index 0000000000..65a616f254 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_options + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnOptionsViewRepoImpl extends ColumnOptionsViewRepo { + override def select: SelectBuilder[ColumnOptionsViewFields, ColumnOptionsViewRow] = { + SelectBuilderSql("information_schema.column_options", ColumnOptionsViewFields, ColumnOptionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnOptionsViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "column_name", "option_name", "option_value" from information_schema.column_options""".query(ColumnOptionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRow.scala new file mode 100644 index 0000000000..185fac17fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_options + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnOptionsViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + optionName: /* nullability unknown */ Option[String], + optionValue: /* nullability unknown */ Option[String] +) + +object ColumnOptionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnOptionsViewRow] = new JdbcDecoder[ColumnOptionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnOptionsViewRow) = + columIndex + 5 -> + ColumnOptionsViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + optionName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + optionValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnOptionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionName = jsonObj.get("option_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionValue = jsonObj.get("option_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && optionName.isRight && optionValue.isRight) + Right(ColumnOptionsViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, optionName = optionName.toOption.get, optionValue = optionValue.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, columnName, optionName, optionValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnOptionsViewRow] = new JsonEncoder[ColumnOptionsViewRow] { + override def unsafeEncode(a: ColumnOptionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""option_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionName, indent, out) + out.write(",") + out.write(""""option_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewStructure.scala new file mode 100644 index 0000000000..81345a010d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_options/ColumnOptionsViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_options + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnOptionsViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnOptionsViewRow, val merge: (Row, ColumnOptionsViewRow) => Row) + extends Relation[ColumnOptionsViewFields, ColumnOptionsViewRow, Row] + with ColumnOptionsViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val optionName = new OptField[String, Row](prefix, "option_name", None, None)(x => extract(x).optionName, (row, value) => merge(row, extract(row).copy(optionName = value))) + override val optionValue = new OptField[String, Row](prefix, "option_value", None, None)(x => extract(x).optionValue, (row, value) => merge(row, extract(row).copy(optionValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, columnName, optionName, optionValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnOptionsViewRow, merge: (NewRow, ColumnOptionsViewRow) => NewRow): ColumnOptionsViewStructure[NewRow] = + new ColumnOptionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewFields.scala new file mode 100644 index 0000000000..cb5347db8d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_privileges + +import typo.dsl.SqlExpr.OptField + +trait ColumnPrivilegesViewFields[Row] { + val grantor: OptField[String, Row] + val grantee: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val privilegeType: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] +} +object ColumnPrivilegesViewFields extends ColumnPrivilegesViewStructure[ColumnPrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepo.scala new file mode 100644 index 0000000000..0ddfe59662 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnPrivilegesViewRepo { + def select: SelectBuilder[ColumnPrivilegesViewFields, ColumnPrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnPrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..18679c9d38 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnPrivilegesViewRepoImpl extends ColumnPrivilegesViewRepo { + override def select: SelectBuilder[ColumnPrivilegesViewFields, ColumnPrivilegesViewRow] = { + SelectBuilderSql("information_schema.column_privileges", ColumnPrivilegesViewFields, ColumnPrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnPrivilegesViewRow] = { + sql"""select "grantor", "grantee", "table_catalog", "table_schema", "table_name", "column_name", "privilege_type", "is_grantable" from information_schema.column_privileges""".query(ColumnPrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRow.scala new file mode 100644 index 0000000000..0815187105 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnPrivilegesViewRow( + grantor: /* nullability unknown */ Option[String], + grantee: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + privilegeType: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object ColumnPrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnPrivilegesViewRow] = new JdbcDecoder[ColumnPrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnPrivilegesViewRow) = + columIndex + 7 -> + ColumnPrivilegesViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnPrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(ColumnPrivilegesViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, tableCatalog, tableSchema, tableName, columnName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnPrivilegesViewRow] = new JsonEncoder[ColumnPrivilegesViewRow] { + override def unsafeEncode(a: ColumnPrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewStructure.scala new file mode 100644 index 0000000000..33cd9376b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_privileges/ColumnPrivilegesViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnPrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnPrivilegesViewRow, val merge: (Row, ColumnPrivilegesViewRow) => Row) + extends Relation[ColumnPrivilegesViewFields, ColumnPrivilegesViewRow, Row] + with ColumnPrivilegesViewFields[Row] { outer => + + override val grantor = new OptField[String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val privilegeType = new OptField[String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, tableCatalog, tableSchema, tableName, columnName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnPrivilegesViewRow, merge: (NewRow, ColumnPrivilegesViewRow) => NewRow): ColumnPrivilegesViewStructure[NewRow] = + new ColumnPrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewFields.scala new file mode 100644 index 0000000000..acaac7868b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_udt_usage + +import typo.dsl.SqlExpr.OptField + +trait ColumnUdtUsageViewFields[Row] { + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] +} +object ColumnUdtUsageViewFields extends ColumnUdtUsageViewStructure[ColumnUdtUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepo.scala new file mode 100644 index 0000000000..7a0cfbadc5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_udt_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnUdtUsageViewRepo { + def select: SelectBuilder[ColumnUdtUsageViewFields, ColumnUdtUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnUdtUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepoImpl.scala new file mode 100644 index 0000000000..1efbb2a9ce --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_udt_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnUdtUsageViewRepoImpl extends ColumnUdtUsageViewRepo { + override def select: SelectBuilder[ColumnUdtUsageViewFields, ColumnUdtUsageViewRow] = { + SelectBuilderSql("information_schema.column_udt_usage", ColumnUdtUsageViewFields, ColumnUdtUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnUdtUsageViewRow] = { + sql"""select "udt_catalog", "udt_schema", "udt_name", "table_catalog", "table_schema", "table_name", "column_name" from information_schema.column_udt_usage""".query(ColumnUdtUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRow.scala new file mode 100644 index 0000000000..f8607b1619 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_udt_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnUdtUsageViewRow( + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String] +) + +object ColumnUdtUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnUdtUsageViewRow] = new JdbcDecoder[ColumnUdtUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnUdtUsageViewRow) = + columIndex + 6 -> + ColumnUdtUsageViewRow( + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnUdtUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (udtCatalog.isRight && udtSchema.isRight && udtName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight) + Right(ColumnUdtUsageViewRow(udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get)) + else Left(List[Either[String, Any]](udtCatalog, udtSchema, udtName, tableCatalog, tableSchema, tableName, columnName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnUdtUsageViewRow] = new JsonEncoder[ColumnUdtUsageViewRow] { + override def unsafeEncode(a: ColumnUdtUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewStructure.scala new file mode 100644 index 0000000000..5ec2796b45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/column_udt_usage/ColumnUdtUsageViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package column_udt_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnUdtUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnUdtUsageViewRow, val merge: (Row, ColumnUdtUsageViewRow) => Row) + extends Relation[ColumnUdtUsageViewFields, ColumnUdtUsageViewRow, Row] + with ColumnUdtUsageViewFields[Row] { outer => + + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](udtCatalog, udtSchema, udtName, tableCatalog, tableSchema, tableName, columnName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnUdtUsageViewRow, merge: (NewRow, ColumnUdtUsageViewRow) => NewRow): ColumnUdtUsageViewStructure[NewRow] = + new ColumnUdtUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewFields.scala new file mode 100644 index 0000000000..9738820ac3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewFields.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package columns + +import typo.dsl.SqlExpr.OptField + +trait ColumnsViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val ordinalPosition: OptField[Int, Row] + val columnDefault: OptField[String, Row] + val isNullable: OptField[/* max 3 chars */ String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val domainCatalog: OptField[String, Row] + val domainSchema: OptField[String, Row] + val domainName: OptField[String, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] + val isSelfReferencing: OptField[/* max 3 chars */ String, Row] + val isIdentity: OptField[/* max 3 chars */ String, Row] + val identityGeneration: OptField[String, Row] + val identityStart: OptField[String, Row] + val identityIncrement: OptField[String, Row] + val identityMaximum: OptField[String, Row] + val identityMinimum: OptField[String, Row] + val identityCycle: OptField[/* max 3 chars */ String, Row] + val isGenerated: OptField[String, Row] + val generationExpression: OptField[String, Row] + val isUpdatable: OptField[/* max 3 chars */ String, Row] +} +object ColumnsViewFields extends ColumnsViewStructure[ColumnsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepo.scala new file mode 100644 index 0000000000..a924087301 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package columns + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ColumnsViewRepo { + def select: SelectBuilder[ColumnsViewFields, ColumnsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ColumnsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepoImpl.scala new file mode 100644 index 0000000000..9afce25968 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package columns + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ColumnsViewRepoImpl extends ColumnsViewRepo { + override def select: SelectBuilder[ColumnsViewFields, ColumnsViewRow] = { + SelectBuilderSql("information_schema.columns", ColumnsViewFields, ColumnsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ColumnsViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "column_name", "ordinal_position", "column_default", "is_nullable", "data_type", "character_maximum_length", "character_octet_length", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "domain_catalog", "domain_schema", "domain_name", "udt_catalog", "udt_schema", "udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier", "is_self_referencing", "is_identity", "identity_generation", "identity_start", "identity_increment", "identity_maximum", "identity_minimum", "identity_cycle", "is_generated", "generation_expression", "is_updatable" from information_schema.columns""".query(ColumnsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRow.scala new file mode 100644 index 0000000000..f8d80d866e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewRow.scala @@ -0,0 +1,301 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package columns + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ColumnsViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + ordinalPosition: /* nullability unknown */ Option[Int], + columnDefault: /* nullability unknown */ Option[String], + isNullable: /* nullability unknown */ Option[/* max 3 chars */ String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + domainCatalog: /* nullability unknown */ Option[String], + domainSchema: /* nullability unknown */ Option[String], + domainName: /* nullability unknown */ Option[String], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String], + isSelfReferencing: /* nullability unknown */ Option[/* max 3 chars */ String], + isIdentity: /* nullability unknown */ Option[/* max 3 chars */ String], + identityGeneration: /* nullability unknown */ Option[String], + identityStart: /* nullability unknown */ Option[String], + identityIncrement: /* nullability unknown */ Option[String], + identityMaximum: /* nullability unknown */ Option[String], + identityMinimum: /* nullability unknown */ Option[String], + identityCycle: /* nullability unknown */ Option[/* max 3 chars */ String], + isGenerated: /* nullability unknown */ Option[String], + generationExpression: /* nullability unknown */ Option[String], + isUpdatable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object ColumnsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ColumnsViewRow] = new JdbcDecoder[ColumnsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ColumnsViewRow) = + columIndex + 43 -> + ColumnsViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + ordinalPosition = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 4, rs)._2, + columnDefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isNullable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 10, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 11, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 12, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 13, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 15, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 19, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + domainCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + domainSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + domainName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 24, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 25, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 27, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 29, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 30, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 31, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 32, rs)._2, + isSelfReferencing = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 33, rs)._2, + isIdentity = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 34, rs)._2, + identityGeneration = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 35, rs)._2, + identityStart = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 36, rs)._2, + identityIncrement = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 37, rs)._2, + identityMaximum = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 38, rs)._2, + identityMinimum = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 39, rs)._2, + identityCycle = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 40, rs)._2, + isGenerated = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 41, rs)._2, + generationExpression = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 42, rs)._2, + isUpdatable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 43, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ColumnsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ordinalPosition = jsonObj.get("ordinal_position").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val columnDefault = jsonObj.get("column_default").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isNullable = jsonObj.get("is_nullable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainCatalog = jsonObj.get("domain_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainSchema = jsonObj.get("domain_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainName = jsonObj.get("domain_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isSelfReferencing = jsonObj.get("is_self_referencing").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isIdentity = jsonObj.get("is_identity").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityGeneration = jsonObj.get("identity_generation").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityStart = jsonObj.get("identity_start").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityIncrement = jsonObj.get("identity_increment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityMaximum = jsonObj.get("identity_maximum").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityMinimum = jsonObj.get("identity_minimum").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val identityCycle = jsonObj.get("identity_cycle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGenerated = jsonObj.get("is_generated").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val generationExpression = jsonObj.get("generation_expression").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isUpdatable = jsonObj.get("is_updatable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && ordinalPosition.isRight && columnDefault.isRight && isNullable.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && domainCatalog.isRight && domainSchema.isRight && domainName.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight && isSelfReferencing.isRight && isIdentity.isRight && identityGeneration.isRight && identityStart.isRight && identityIncrement.isRight && identityMaximum.isRight && identityMinimum.isRight && identityCycle.isRight && isGenerated.isRight && generationExpression.isRight && isUpdatable.isRight) + Right(ColumnsViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, ordinalPosition = ordinalPosition.toOption.get, columnDefault = columnDefault.toOption.get, isNullable = isNullable.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, domainCatalog = domainCatalog.toOption.get, domainSchema = domainSchema.toOption.get, domainName = domainName.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get, isSelfReferencing = isSelfReferencing.toOption.get, isIdentity = isIdentity.toOption.get, identityGeneration = identityGeneration.toOption.get, identityStart = identityStart.toOption.get, identityIncrement = identityIncrement.toOption.get, identityMaximum = identityMaximum.toOption.get, identityMinimum = identityMinimum.toOption.get, identityCycle = identityCycle.toOption.get, isGenerated = isGenerated.toOption.get, generationExpression = generationExpression.toOption.get, isUpdatable = isUpdatable.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, columnName, ordinalPosition, columnDefault, isNullable, dataType, characterMaximumLength, characterOctetLength, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, domainCatalog, domainSchema, domainName, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, isSelfReferencing, isIdentity, identityGeneration, identityStart, identityIncrement, identityMaximum, identityMinimum, identityCycle, isGenerated, generationExpression, isUpdatable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ColumnsViewRow] = new JsonEncoder[ColumnsViewRow] { + override def unsafeEncode(a: ColumnsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""ordinal_position":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.ordinalPosition, indent, out) + out.write(",") + out.write(""""column_default":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnDefault, indent, out) + out.write(",") + out.write(""""is_nullable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isNullable, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""domain_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainCatalog, indent, out) + out.write(",") + out.write(""""domain_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainSchema, indent, out) + out.write(",") + out.write(""""domain_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainName, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write(",") + out.write(""""is_self_referencing":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isSelfReferencing, indent, out) + out.write(",") + out.write(""""is_identity":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isIdentity, indent, out) + out.write(",") + out.write(""""identity_generation":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityGeneration, indent, out) + out.write(",") + out.write(""""identity_start":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityStart, indent, out) + out.write(",") + out.write(""""identity_increment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityIncrement, indent, out) + out.write(",") + out.write(""""identity_maximum":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityMaximum, indent, out) + out.write(",") + out.write(""""identity_minimum":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityMinimum, indent, out) + out.write(",") + out.write(""""identity_cycle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.identityCycle, indent, out) + out.write(",") + out.write(""""is_generated":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGenerated, indent, out) + out.write(",") + out.write(""""generation_expression":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.generationExpression, indent, out) + out.write(",") + out.write(""""is_updatable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isUpdatable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewStructure.scala new file mode 100644 index 0000000000..3b7b8b7958 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/columns/ColumnsViewStructure.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package columns + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ColumnsViewStructure[Row](val prefix: Option[String], val extract: Row => ColumnsViewRow, val merge: (Row, ColumnsViewRow) => Row) + extends Relation[ColumnsViewFields, ColumnsViewRow, Row] + with ColumnsViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val ordinalPosition = new OptField[Int, Row](prefix, "ordinal_position", None, None)(x => extract(x).ordinalPosition, (row, value) => merge(row, extract(row).copy(ordinalPosition = value))) + override val columnDefault = new OptField[String, Row](prefix, "column_default", None, None)(x => extract(x).columnDefault, (row, value) => merge(row, extract(row).copy(columnDefault = value))) + override val isNullable = new OptField[/* max 3 chars */ String, Row](prefix, "is_nullable", None, None)(x => extract(x).isNullable, (row, value) => merge(row, extract(row).copy(isNullable = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val domainCatalog = new OptField[String, Row](prefix, "domain_catalog", None, None)(x => extract(x).domainCatalog, (row, value) => merge(row, extract(row).copy(domainCatalog = value))) + override val domainSchema = new OptField[String, Row](prefix, "domain_schema", None, None)(x => extract(x).domainSchema, (row, value) => merge(row, extract(row).copy(domainSchema = value))) + override val domainName = new OptField[String, Row](prefix, "domain_name", None, None)(x => extract(x).domainName, (row, value) => merge(row, extract(row).copy(domainName = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + override val isSelfReferencing = new OptField[/* max 3 chars */ String, Row](prefix, "is_self_referencing", None, None)(x => extract(x).isSelfReferencing, (row, value) => merge(row, extract(row).copy(isSelfReferencing = value))) + override val isIdentity = new OptField[/* max 3 chars */ String, Row](prefix, "is_identity", None, None)(x => extract(x).isIdentity, (row, value) => merge(row, extract(row).copy(isIdentity = value))) + override val identityGeneration = new OptField[String, Row](prefix, "identity_generation", None, None)(x => extract(x).identityGeneration, (row, value) => merge(row, extract(row).copy(identityGeneration = value))) + override val identityStart = new OptField[String, Row](prefix, "identity_start", None, None)(x => extract(x).identityStart, (row, value) => merge(row, extract(row).copy(identityStart = value))) + override val identityIncrement = new OptField[String, Row](prefix, "identity_increment", None, None)(x => extract(x).identityIncrement, (row, value) => merge(row, extract(row).copy(identityIncrement = value))) + override val identityMaximum = new OptField[String, Row](prefix, "identity_maximum", None, None)(x => extract(x).identityMaximum, (row, value) => merge(row, extract(row).copy(identityMaximum = value))) + override val identityMinimum = new OptField[String, Row](prefix, "identity_minimum", None, None)(x => extract(x).identityMinimum, (row, value) => merge(row, extract(row).copy(identityMinimum = value))) + override val identityCycle = new OptField[/* max 3 chars */ String, Row](prefix, "identity_cycle", None, None)(x => extract(x).identityCycle, (row, value) => merge(row, extract(row).copy(identityCycle = value))) + override val isGenerated = new OptField[String, Row](prefix, "is_generated", None, None)(x => extract(x).isGenerated, (row, value) => merge(row, extract(row).copy(isGenerated = value))) + override val generationExpression = new OptField[String, Row](prefix, "generation_expression", None, None)(x => extract(x).generationExpression, (row, value) => merge(row, extract(row).copy(generationExpression = value))) + override val isUpdatable = new OptField[/* max 3 chars */ String, Row](prefix, "is_updatable", None, None)(x => extract(x).isUpdatable, (row, value) => merge(row, extract(row).copy(isUpdatable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, columnName, ordinalPosition, columnDefault, isNullable, dataType, characterMaximumLength, characterOctetLength, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, domainCatalog, domainSchema, domainName, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, isSelfReferencing, isIdentity, identityGeneration, identityStart, identityIncrement, identityMaximum, identityMinimum, identityCycle, isGenerated, generationExpression, isUpdatable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ColumnsViewRow, merge: (NewRow, ColumnsViewRow) => NewRow): ColumnsViewStructure[NewRow] = + new ColumnsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewFields.scala new file mode 100644 index 0000000000..d7e913f3a6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_column_usage + +import typo.dsl.SqlExpr.OptField + +trait ConstraintColumnUsageViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] +} +object ConstraintColumnUsageViewFields extends ConstraintColumnUsageViewStructure[ConstraintColumnUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepo.scala new file mode 100644 index 0000000000..56888f91f5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_column_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ConstraintColumnUsageViewRepo { + def select: SelectBuilder[ConstraintColumnUsageViewFields, ConstraintColumnUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ConstraintColumnUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepoImpl.scala new file mode 100644 index 0000000000..5e6f920753 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_column_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ConstraintColumnUsageViewRepoImpl extends ConstraintColumnUsageViewRepo { + override def select: SelectBuilder[ConstraintColumnUsageViewFields, ConstraintColumnUsageViewRow] = { + SelectBuilderSql("information_schema.constraint_column_usage", ConstraintColumnUsageViewFields, ConstraintColumnUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ConstraintColumnUsageViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "column_name", "constraint_catalog", "constraint_schema", "constraint_name" from information_schema.constraint_column_usage""".query(ConstraintColumnUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRow.scala new file mode 100644 index 0000000000..4f0d061127 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_column_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ConstraintColumnUsageViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String] +) + +object ConstraintColumnUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ConstraintColumnUsageViewRow] = new JdbcDecoder[ConstraintColumnUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ConstraintColumnUsageViewRow) = + columIndex + 6 -> + ConstraintColumnUsageViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ConstraintColumnUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight) + Right(ConstraintColumnUsageViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, columnName, constraintCatalog, constraintSchema, constraintName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ConstraintColumnUsageViewRow] = new JsonEncoder[ConstraintColumnUsageViewRow] { + override def unsafeEncode(a: ConstraintColumnUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewStructure.scala new file mode 100644 index 0000000000..556367517c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_column_usage/ConstraintColumnUsageViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_column_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ConstraintColumnUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ConstraintColumnUsageViewRow, val merge: (Row, ConstraintColumnUsageViewRow) => Row) + extends Relation[ConstraintColumnUsageViewFields, ConstraintColumnUsageViewRow, Row] + with ConstraintColumnUsageViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, columnName, constraintCatalog, constraintSchema, constraintName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ConstraintColumnUsageViewRow, merge: (NewRow, ConstraintColumnUsageViewRow) => NewRow): ConstraintColumnUsageViewStructure[NewRow] = + new ConstraintColumnUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewFields.scala new file mode 100644 index 0000000000..bbc8542c9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_table_usage + +import typo.dsl.SqlExpr.OptField + +trait ConstraintTableUsageViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] +} +object ConstraintTableUsageViewFields extends ConstraintTableUsageViewStructure[ConstraintTableUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepo.scala new file mode 100644 index 0000000000..33fa563437 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_table_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ConstraintTableUsageViewRepo { + def select: SelectBuilder[ConstraintTableUsageViewFields, ConstraintTableUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ConstraintTableUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepoImpl.scala new file mode 100644 index 0000000000..f6e4b90841 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_table_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ConstraintTableUsageViewRepoImpl extends ConstraintTableUsageViewRepo { + override def select: SelectBuilder[ConstraintTableUsageViewFields, ConstraintTableUsageViewRow] = { + SelectBuilderSql("information_schema.constraint_table_usage", ConstraintTableUsageViewFields, ConstraintTableUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ConstraintTableUsageViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "constraint_catalog", "constraint_schema", "constraint_name" from information_schema.constraint_table_usage""".query(ConstraintTableUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRow.scala new file mode 100644 index 0000000000..88b29943dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_table_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ConstraintTableUsageViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String] +) + +object ConstraintTableUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ConstraintTableUsageViewRow] = new JdbcDecoder[ConstraintTableUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ConstraintTableUsageViewRow) = + columIndex + 5 -> + ConstraintTableUsageViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ConstraintTableUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight) + Right(ConstraintTableUsageViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, constraintCatalog, constraintSchema, constraintName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ConstraintTableUsageViewRow] = new JsonEncoder[ConstraintTableUsageViewRow] { + override def unsafeEncode(a: ConstraintTableUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewStructure.scala new file mode 100644 index 0000000000..f6d5f3aa84 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/constraint_table_usage/ConstraintTableUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package constraint_table_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ConstraintTableUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ConstraintTableUsageViewRow, val merge: (Row, ConstraintTableUsageViewRow) => Row) + extends Relation[ConstraintTableUsageViewFields, ConstraintTableUsageViewRow, Row] + with ConstraintTableUsageViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, constraintCatalog, constraintSchema, constraintName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ConstraintTableUsageViewRow, merge: (NewRow, ConstraintTableUsageViewRow) => NewRow): ConstraintTableUsageViewStructure[NewRow] = + new ConstraintTableUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewFields.scala new file mode 100644 index 0000000000..a65411de08 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package data_type_privileges + +import typo.dsl.SqlExpr.OptField + +trait DataTypePrivilegesViewFields[Row] { + val objectCatalog: OptField[String, Row] + val objectSchema: OptField[String, Row] + val objectName: OptField[String, Row] + val objectType: OptField[String, Row] + val dtdIdentifier: OptField[String, Row] +} +object DataTypePrivilegesViewFields extends DataTypePrivilegesViewStructure[DataTypePrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepo.scala new file mode 100644 index 0000000000..44171d5bfd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package data_type_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DataTypePrivilegesViewRepo { + def select: SelectBuilder[DataTypePrivilegesViewFields, DataTypePrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, DataTypePrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..ce3a1d15d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package data_type_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DataTypePrivilegesViewRepoImpl extends DataTypePrivilegesViewRepo { + override def select: SelectBuilder[DataTypePrivilegesViewFields, DataTypePrivilegesViewRow] = { + SelectBuilderSql("information_schema.data_type_privileges", DataTypePrivilegesViewFields, DataTypePrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DataTypePrivilegesViewRow] = { + sql"""select "object_catalog", "object_schema", "object_name", "object_type", "dtd_identifier" from information_schema.data_type_privileges""".query(DataTypePrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRow.scala new file mode 100644 index 0000000000..40a946ed2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewRow.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package data_type_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DataTypePrivilegesViewRow( + objectCatalog: /* nullability unknown */ Option[String], + objectSchema: /* nullability unknown */ Option[String], + objectName: /* nullability unknown */ Option[String], + objectType: /* nullability unknown */ Option[String], + dtdIdentifier: /* nullability unknown */ Option[String] +) + +object DataTypePrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DataTypePrivilegesViewRow] = new JdbcDecoder[DataTypePrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DataTypePrivilegesViewRow) = + columIndex + 4 -> + DataTypePrivilegesViewRow( + objectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + objectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + objectName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + objectType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DataTypePrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objectCatalog = jsonObj.get("object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectSchema = jsonObj.get("object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectName = jsonObj.get("object_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectType = jsonObj.get("object_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (objectCatalog.isRight && objectSchema.isRight && objectName.isRight && objectType.isRight && dtdIdentifier.isRight) + Right(DataTypePrivilegesViewRow(objectCatalog = objectCatalog.toOption.get, objectSchema = objectSchema.toOption.get, objectName = objectName.toOption.get, objectType = objectType.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get)) + else Left(List[Either[String, Any]](objectCatalog, objectSchema, objectName, objectType, dtdIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DataTypePrivilegesViewRow] = new JsonEncoder[DataTypePrivilegesViewRow] { + override def unsafeEncode(a: DataTypePrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectCatalog, indent, out) + out.write(",") + out.write(""""object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectSchema, indent, out) + out.write(",") + out.write(""""object_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectName, indent, out) + out.write(",") + out.write(""""object_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectType, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewStructure.scala new file mode 100644 index 0000000000..27c7509d19 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/data_type_privileges/DataTypePrivilegesViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package data_type_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DataTypePrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => DataTypePrivilegesViewRow, val merge: (Row, DataTypePrivilegesViewRow) => Row) + extends Relation[DataTypePrivilegesViewFields, DataTypePrivilegesViewRow, Row] + with DataTypePrivilegesViewFields[Row] { outer => + + override val objectCatalog = new OptField[String, Row](prefix, "object_catalog", None, None)(x => extract(x).objectCatalog, (row, value) => merge(row, extract(row).copy(objectCatalog = value))) + override val objectSchema = new OptField[String, Row](prefix, "object_schema", None, None)(x => extract(x).objectSchema, (row, value) => merge(row, extract(row).copy(objectSchema = value))) + override val objectName = new OptField[String, Row](prefix, "object_name", None, None)(x => extract(x).objectName, (row, value) => merge(row, extract(row).copy(objectName = value))) + override val objectType = new OptField[String, Row](prefix, "object_type", None, None)(x => extract(x).objectType, (row, value) => merge(row, extract(row).copy(objectType = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objectCatalog, objectSchema, objectName, objectType, dtdIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DataTypePrivilegesViewRow, merge: (NewRow, DataTypePrivilegesViewRow) => NewRow): DataTypePrivilegesViewStructure[NewRow] = + new DataTypePrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewFields.scala new file mode 100644 index 0000000000..5cb997145a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_constraints + +import typo.dsl.SqlExpr.OptField + +trait DomainConstraintsViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val domainCatalog: OptField[String, Row] + val domainSchema: OptField[String, Row] + val domainName: OptField[String, Row] + val isDeferrable: OptField[/* max 3 chars */ String, Row] + val initiallyDeferred: OptField[/* max 3 chars */ String, Row] +} +object DomainConstraintsViewFields extends DomainConstraintsViewStructure[DomainConstraintsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepo.scala new file mode 100644 index 0000000000..3c1ac4f859 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_constraints + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DomainConstraintsViewRepo { + def select: SelectBuilder[DomainConstraintsViewFields, DomainConstraintsViewRow] + def selectAll: ZStream[ZConnection, Throwable, DomainConstraintsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepoImpl.scala new file mode 100644 index 0000000000..a1ab5bea16 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_constraints + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DomainConstraintsViewRepoImpl extends DomainConstraintsViewRepo { + override def select: SelectBuilder[DomainConstraintsViewFields, DomainConstraintsViewRow] = { + SelectBuilderSql("information_schema.domain_constraints", DomainConstraintsViewFields, DomainConstraintsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DomainConstraintsViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "domain_catalog", "domain_schema", "domain_name", "is_deferrable", "initially_deferred" from information_schema.domain_constraints""".query(DomainConstraintsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRow.scala new file mode 100644 index 0000000000..ae72878b9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_constraints + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DomainConstraintsViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + domainCatalog: /* nullability unknown */ Option[String], + domainSchema: /* nullability unknown */ Option[String], + domainName: /* nullability unknown */ Option[String], + isDeferrable: /* nullability unknown */ Option[/* max 3 chars */ String], + initiallyDeferred: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object DomainConstraintsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DomainConstraintsViewRow] = new JdbcDecoder[DomainConstraintsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DomainConstraintsViewRow) = + columIndex + 7 -> + DomainConstraintsViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + domainCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + domainSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + domainName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isDeferrable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + initiallyDeferred = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DomainConstraintsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainCatalog = jsonObj.get("domain_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainSchema = jsonObj.get("domain_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainName = jsonObj.get("domain_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isDeferrable = jsonObj.get("is_deferrable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val initiallyDeferred = jsonObj.get("initially_deferred").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && domainCatalog.isRight && domainSchema.isRight && domainName.isRight && isDeferrable.isRight && initiallyDeferred.isRight) + Right(DomainConstraintsViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, domainCatalog = domainCatalog.toOption.get, domainSchema = domainSchema.toOption.get, domainName = domainName.toOption.get, isDeferrable = isDeferrable.toOption.get, initiallyDeferred = initiallyDeferred.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, domainCatalog, domainSchema, domainName, isDeferrable, initiallyDeferred).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DomainConstraintsViewRow] = new JsonEncoder[DomainConstraintsViewRow] { + override def unsafeEncode(a: DomainConstraintsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""domain_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainCatalog, indent, out) + out.write(",") + out.write(""""domain_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainSchema, indent, out) + out.write(",") + out.write(""""domain_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainName, indent, out) + out.write(",") + out.write(""""is_deferrable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isDeferrable, indent, out) + out.write(",") + out.write(""""initially_deferred":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.initiallyDeferred, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewStructure.scala new file mode 100644 index 0000000000..fdb7771b0e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_constraints/DomainConstraintsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_constraints + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DomainConstraintsViewStructure[Row](val prefix: Option[String], val extract: Row => DomainConstraintsViewRow, val merge: (Row, DomainConstraintsViewRow) => Row) + extends Relation[DomainConstraintsViewFields, DomainConstraintsViewRow, Row] + with DomainConstraintsViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val domainCatalog = new OptField[String, Row](prefix, "domain_catalog", None, None)(x => extract(x).domainCatalog, (row, value) => merge(row, extract(row).copy(domainCatalog = value))) + override val domainSchema = new OptField[String, Row](prefix, "domain_schema", None, None)(x => extract(x).domainSchema, (row, value) => merge(row, extract(row).copy(domainSchema = value))) + override val domainName = new OptField[String, Row](prefix, "domain_name", None, None)(x => extract(x).domainName, (row, value) => merge(row, extract(row).copy(domainName = value))) + override val isDeferrable = new OptField[/* max 3 chars */ String, Row](prefix, "is_deferrable", None, None)(x => extract(x).isDeferrable, (row, value) => merge(row, extract(row).copy(isDeferrable = value))) + override val initiallyDeferred = new OptField[/* max 3 chars */ String, Row](prefix, "initially_deferred", None, None)(x => extract(x).initiallyDeferred, (row, value) => merge(row, extract(row).copy(initiallyDeferred = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, domainCatalog, domainSchema, domainName, isDeferrable, initiallyDeferred) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DomainConstraintsViewRow, merge: (NewRow, DomainConstraintsViewRow) => NewRow): DomainConstraintsViewStructure[NewRow] = + new DomainConstraintsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewFields.scala new file mode 100644 index 0000000000..b17742aae6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_udt_usage + +import typo.dsl.SqlExpr.OptField + +trait DomainUdtUsageViewFields[Row] { + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val domainCatalog: OptField[String, Row] + val domainSchema: OptField[String, Row] + val domainName: OptField[String, Row] +} +object DomainUdtUsageViewFields extends DomainUdtUsageViewStructure[DomainUdtUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepo.scala new file mode 100644 index 0000000000..5efd745adb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_udt_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DomainUdtUsageViewRepo { + def select: SelectBuilder[DomainUdtUsageViewFields, DomainUdtUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, DomainUdtUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepoImpl.scala new file mode 100644 index 0000000000..a79278a44b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_udt_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DomainUdtUsageViewRepoImpl extends DomainUdtUsageViewRepo { + override def select: SelectBuilder[DomainUdtUsageViewFields, DomainUdtUsageViewRow] = { + SelectBuilderSql("information_schema.domain_udt_usage", DomainUdtUsageViewFields, DomainUdtUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DomainUdtUsageViewRow] = { + sql"""select "udt_catalog", "udt_schema", "udt_name", "domain_catalog", "domain_schema", "domain_name" from information_schema.domain_udt_usage""".query(DomainUdtUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRow.scala new file mode 100644 index 0000000000..231751ea0b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_udt_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DomainUdtUsageViewRow( + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + domainCatalog: /* nullability unknown */ Option[String], + domainSchema: /* nullability unknown */ Option[String], + domainName: /* nullability unknown */ Option[String] +) + +object DomainUdtUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DomainUdtUsageViewRow] = new JdbcDecoder[DomainUdtUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DomainUdtUsageViewRow) = + columIndex + 5 -> + DomainUdtUsageViewRow( + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + domainCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + domainSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + domainName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DomainUdtUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainCatalog = jsonObj.get("domain_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainSchema = jsonObj.get("domain_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainName = jsonObj.get("domain_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (udtCatalog.isRight && udtSchema.isRight && udtName.isRight && domainCatalog.isRight && domainSchema.isRight && domainName.isRight) + Right(DomainUdtUsageViewRow(udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, domainCatalog = domainCatalog.toOption.get, domainSchema = domainSchema.toOption.get, domainName = domainName.toOption.get)) + else Left(List[Either[String, Any]](udtCatalog, udtSchema, udtName, domainCatalog, domainSchema, domainName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DomainUdtUsageViewRow] = new JsonEncoder[DomainUdtUsageViewRow] { + override def unsafeEncode(a: DomainUdtUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""domain_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainCatalog, indent, out) + out.write(",") + out.write(""""domain_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainSchema, indent, out) + out.write(",") + out.write(""""domain_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewStructure.scala new file mode 100644 index 0000000000..75260f9469 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domain_udt_usage/DomainUdtUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domain_udt_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DomainUdtUsageViewStructure[Row](val prefix: Option[String], val extract: Row => DomainUdtUsageViewRow, val merge: (Row, DomainUdtUsageViewRow) => Row) + extends Relation[DomainUdtUsageViewFields, DomainUdtUsageViewRow, Row] + with DomainUdtUsageViewFields[Row] { outer => + + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val domainCatalog = new OptField[String, Row](prefix, "domain_catalog", None, None)(x => extract(x).domainCatalog, (row, value) => merge(row, extract(row).copy(domainCatalog = value))) + override val domainSchema = new OptField[String, Row](prefix, "domain_schema", None, None)(x => extract(x).domainSchema, (row, value) => merge(row, extract(row).copy(domainSchema = value))) + override val domainName = new OptField[String, Row](prefix, "domain_name", None, None)(x => extract(x).domainName, (row, value) => merge(row, extract(row).copy(domainName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](udtCatalog, udtSchema, udtName, domainCatalog, domainSchema, domainName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DomainUdtUsageViewRow, merge: (NewRow, DomainUdtUsageViewRow) => NewRow): DomainUdtUsageViewStructure[NewRow] = + new DomainUdtUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewFields.scala new file mode 100644 index 0000000000..b79b1ea42d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewFields.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domains + +import typo.dsl.SqlExpr.OptField + +trait DomainsViewFields[Row] { + val domainCatalog: OptField[String, Row] + val domainSchema: OptField[String, Row] + val domainName: OptField[String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val domainDefault: OptField[String, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] +} +object DomainsViewFields extends DomainsViewStructure[DomainsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepo.scala new file mode 100644 index 0000000000..a6686cd72c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domains + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DomainsViewRepo { + def select: SelectBuilder[DomainsViewFields, DomainsViewRow] + def selectAll: ZStream[ZConnection, Throwable, DomainsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepoImpl.scala new file mode 100644 index 0000000000..8604d14edd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domains + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DomainsViewRepoImpl extends DomainsViewRepo { + override def select: SelectBuilder[DomainsViewFields, DomainsViewRow] = { + SelectBuilderSql("information_schema.domains", DomainsViewFields, DomainsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DomainsViewRow] = { + sql"""select "domain_catalog", "domain_schema", "domain_name", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "domain_default", "udt_catalog", "udt_schema", "udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier" from information_schema.domains""".query(DomainsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRow.scala new file mode 100644 index 0000000000..9cef54f113 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewRow.scala @@ -0,0 +1,199 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domains + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DomainsViewRow( + domainCatalog: /* nullability unknown */ Option[String], + domainSchema: /* nullability unknown */ Option[String], + domainName: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + domainDefault: /* nullability unknown */ Option[String], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String] +) + +object DomainsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DomainsViewRow] = new JdbcDecoder[DomainsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DomainsViewRow) = + columIndex + 26 -> + DomainsViewRow( + domainCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + domainSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + domainName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 4, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 5, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 12, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 13, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 14, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 15, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 17, rs)._2, + domainDefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 19, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 24, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 25, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DomainsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val domainCatalog = jsonObj.get("domain_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainSchema = jsonObj.get("domain_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val domainName = jsonObj.get("domain_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val domainDefault = jsonObj.get("domain_default").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (domainCatalog.isRight && domainSchema.isRight && domainName.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && domainDefault.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight) + Right(DomainsViewRow(domainCatalog = domainCatalog.toOption.get, domainSchema = domainSchema.toOption.get, domainName = domainName.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, domainDefault = domainDefault.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get)) + else Left(List[Either[String, Any]](domainCatalog, domainSchema, domainName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, domainDefault, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DomainsViewRow] = new JsonEncoder[DomainsViewRow] { + override def unsafeEncode(a: DomainsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""domain_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainCatalog, indent, out) + out.write(",") + out.write(""""domain_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainSchema, indent, out) + out.write(",") + out.write(""""domain_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainName, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""domain_default":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainDefault, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewStructure.scala new file mode 100644 index 0000000000..edef5622e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/domains/DomainsViewStructure.scala @@ -0,0 +1,51 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package domains + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DomainsViewStructure[Row](val prefix: Option[String], val extract: Row => DomainsViewRow, val merge: (Row, DomainsViewRow) => Row) + extends Relation[DomainsViewFields, DomainsViewRow, Row] + with DomainsViewFields[Row] { outer => + + override val domainCatalog = new OptField[String, Row](prefix, "domain_catalog", None, None)(x => extract(x).domainCatalog, (row, value) => merge(row, extract(row).copy(domainCatalog = value))) + override val domainSchema = new OptField[String, Row](prefix, "domain_schema", None, None)(x => extract(x).domainSchema, (row, value) => merge(row, extract(row).copy(domainSchema = value))) + override val domainName = new OptField[String, Row](prefix, "domain_name", None, None)(x => extract(x).domainName, (row, value) => merge(row, extract(row).copy(domainName = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val domainDefault = new OptField[String, Row](prefix, "domain_default", None, None)(x => extract(x).domainDefault, (row, value) => merge(row, extract(row).copy(domainDefault = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](domainCatalog, domainSchema, domainName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, domainDefault, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DomainsViewRow, merge: (NewRow, DomainsViewRow) => NewRow): DomainsViewStructure[NewRow] = + new DomainsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewFields.scala new file mode 100644 index 0000000000..1c997881d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewFields.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package element_types + +import typo.dsl.SqlExpr.OptField + +trait ElementTypesViewFields[Row] { + val objectCatalog: OptField[String, Row] + val objectSchema: OptField[String, Row] + val objectName: OptField[String, Row] + val objectType: OptField[String, Row] + val collectionTypeIdentifier: OptField[String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val domainDefault: OptField[String, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] +} +object ElementTypesViewFields extends ElementTypesViewStructure[ElementTypesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepo.scala new file mode 100644 index 0000000000..e94df212a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package element_types + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ElementTypesViewRepo { + def select: SelectBuilder[ElementTypesViewFields, ElementTypesViewRow] + def selectAll: ZStream[ZConnection, Throwable, ElementTypesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepoImpl.scala new file mode 100644 index 0000000000..44eb414160 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package element_types + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ElementTypesViewRepoImpl extends ElementTypesViewRepo { + override def select: SelectBuilder[ElementTypesViewFields, ElementTypesViewRow] = { + SelectBuilderSql("information_schema.element_types", ElementTypesViewFields, ElementTypesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ElementTypesViewRow] = { + sql"""select "object_catalog", "object_schema", "object_name", "object_type", "collection_type_identifier", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "domain_default", "udt_catalog", "udt_schema", "udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier" from information_schema.element_types""".query(ElementTypesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRow.scala new file mode 100644 index 0000000000..78f0fce5bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewRow.scala @@ -0,0 +1,211 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package element_types + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ElementTypesViewRow( + objectCatalog: /* nullability unknown */ Option[String], + objectSchema: /* nullability unknown */ Option[String], + objectName: /* nullability unknown */ Option[String], + objectType: /* nullability unknown */ Option[String], + collectionTypeIdentifier: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + domainDefault: /* nullability unknown */ Option[String], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String] +) + +object ElementTypesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ElementTypesViewRow] = new JdbcDecoder[ElementTypesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ElementTypesViewRow) = + columIndex + 28 -> + ElementTypesViewRow( + objectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + objectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + objectName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + objectType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + collectionTypeIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 6, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 14, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 15, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 16, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 17, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 19, rs)._2, + domainDefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 24, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 25, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 27, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ElementTypesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objectCatalog = jsonObj.get("object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectSchema = jsonObj.get("object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectName = jsonObj.get("object_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectType = jsonObj.get("object_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collectionTypeIdentifier = jsonObj.get("collection_type_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val domainDefault = jsonObj.get("domain_default").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (objectCatalog.isRight && objectSchema.isRight && objectName.isRight && objectType.isRight && collectionTypeIdentifier.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && domainDefault.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight) + Right(ElementTypesViewRow(objectCatalog = objectCatalog.toOption.get, objectSchema = objectSchema.toOption.get, objectName = objectName.toOption.get, objectType = objectType.toOption.get, collectionTypeIdentifier = collectionTypeIdentifier.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, domainDefault = domainDefault.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get)) + else Left(List[Either[String, Any]](objectCatalog, objectSchema, objectName, objectType, collectionTypeIdentifier, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, domainDefault, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ElementTypesViewRow] = new JsonEncoder[ElementTypesViewRow] { + override def unsafeEncode(a: ElementTypesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectCatalog, indent, out) + out.write(",") + out.write(""""object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectSchema, indent, out) + out.write(",") + out.write(""""object_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectName, indent, out) + out.write(",") + out.write(""""object_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectType, indent, out) + out.write(",") + out.write(""""collection_type_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collectionTypeIdentifier, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""domain_default":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.domainDefault, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewStructure.scala new file mode 100644 index 0000000000..6e60f55314 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/element_types/ElementTypesViewStructure.scala @@ -0,0 +1,53 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package element_types + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ElementTypesViewStructure[Row](val prefix: Option[String], val extract: Row => ElementTypesViewRow, val merge: (Row, ElementTypesViewRow) => Row) + extends Relation[ElementTypesViewFields, ElementTypesViewRow, Row] + with ElementTypesViewFields[Row] { outer => + + override val objectCatalog = new OptField[String, Row](prefix, "object_catalog", None, None)(x => extract(x).objectCatalog, (row, value) => merge(row, extract(row).copy(objectCatalog = value))) + override val objectSchema = new OptField[String, Row](prefix, "object_schema", None, None)(x => extract(x).objectSchema, (row, value) => merge(row, extract(row).copy(objectSchema = value))) + override val objectName = new OptField[String, Row](prefix, "object_name", None, None)(x => extract(x).objectName, (row, value) => merge(row, extract(row).copy(objectName = value))) + override val objectType = new OptField[String, Row](prefix, "object_type", None, None)(x => extract(x).objectType, (row, value) => merge(row, extract(row).copy(objectType = value))) + override val collectionTypeIdentifier = new OptField[String, Row](prefix, "collection_type_identifier", None, None)(x => extract(x).collectionTypeIdentifier, (row, value) => merge(row, extract(row).copy(collectionTypeIdentifier = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val domainDefault = new OptField[String, Row](prefix, "domain_default", None, None)(x => extract(x).domainDefault, (row, value) => merge(row, extract(row).copy(domainDefault = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objectCatalog, objectSchema, objectName, objectType, collectionTypeIdentifier, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, domainDefault, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ElementTypesViewRow, merge: (NewRow, ElementTypesViewRow) => NewRow): ElementTypesViewStructure[NewRow] = + new ElementTypesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewFields.scala new file mode 100644 index 0000000000..98512ab812 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewFields.scala @@ -0,0 +1,16 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package enabled_roles + +import typo.dsl.SqlExpr.OptField + +trait EnabledRolesViewFields[Row] { + val roleName: OptField[String, Row] +} +object EnabledRolesViewFields extends EnabledRolesViewStructure[EnabledRolesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepo.scala new file mode 100644 index 0000000000..d8d4b3ef01 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package enabled_roles + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EnabledRolesViewRepo { + def select: SelectBuilder[EnabledRolesViewFields, EnabledRolesViewRow] + def selectAll: ZStream[ZConnection, Throwable, EnabledRolesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepoImpl.scala new file mode 100644 index 0000000000..c963ec4a1f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package enabled_roles + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EnabledRolesViewRepoImpl extends EnabledRolesViewRepo { + override def select: SelectBuilder[EnabledRolesViewFields, EnabledRolesViewRow] = { + SelectBuilderSql("information_schema.enabled_roles", EnabledRolesViewFields, EnabledRolesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EnabledRolesViewRow] = { + sql"""select "role_name" from information_schema.enabled_roles""".query(EnabledRolesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRow.scala new file mode 100644 index 0000000000..38731799d5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewRow.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package enabled_roles + +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EnabledRolesViewRow( + roleName: /* nullability unknown */ Option[String] +) + +object EnabledRolesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EnabledRolesViewRow] = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).map(v => EnabledRolesViewRow(roleName = v)) + implicit lazy val jsonDecoder: JsonDecoder[EnabledRolesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val roleName = jsonObj.get("role_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (roleName.isRight) + Right(EnabledRolesViewRow(roleName = roleName.toOption.get)) + else Left(List[Either[String, Any]](roleName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EnabledRolesViewRow] = new JsonEncoder[EnabledRolesViewRow] { + override def unsafeEncode(a: EnabledRolesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""role_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.roleName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewStructure.scala new file mode 100644 index 0000000000..b81527d0b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/enabled_roles/EnabledRolesViewStructure.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package enabled_roles + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EnabledRolesViewStructure[Row](val prefix: Option[String], val extract: Row => EnabledRolesViewRow, val merge: (Row, EnabledRolesViewRow) => Row) + extends Relation[EnabledRolesViewFields, EnabledRolesViewRow, Row] + with EnabledRolesViewFields[Row] { outer => + + override val roleName = new OptField[String, Row](prefix, "role_name", None, None)(x => extract(x).roleName, (row, value) => merge(row, extract(row).copy(roleName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](roleName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EnabledRolesViewRow, merge: (NewRow, EnabledRolesViewRow) => NewRow): EnabledRolesViewStructure[NewRow] = + new EnabledRolesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewFields.scala new file mode 100644 index 0000000000..de1f2670f3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrapper_options + +import typo.dsl.SqlExpr.OptField + +trait ForeignDataWrapperOptionsViewFields[Row] { + val foreignDataWrapperCatalog: OptField[/* nullability unknown */ String, Row] + val foreignDataWrapperName: OptField[/* nullability unknown */ String, Row] + val optionName: OptField[String, Row] + val optionValue: OptField[String, Row] +} +object ForeignDataWrapperOptionsViewFields extends ForeignDataWrapperOptionsViewStructure[ForeignDataWrapperOptionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepo.scala new file mode 100644 index 0000000000..f2efbd78ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrapper_options + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignDataWrapperOptionsViewRepo { + def select: SelectBuilder[ForeignDataWrapperOptionsViewFields, ForeignDataWrapperOptionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignDataWrapperOptionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepoImpl.scala new file mode 100644 index 0000000000..1c76201d65 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrapper_options + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignDataWrapperOptionsViewRepoImpl extends ForeignDataWrapperOptionsViewRepo { + override def select: SelectBuilder[ForeignDataWrapperOptionsViewFields, ForeignDataWrapperOptionsViewRow] = { + SelectBuilderSql("information_schema.foreign_data_wrapper_options", ForeignDataWrapperOptionsViewFields, ForeignDataWrapperOptionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignDataWrapperOptionsViewRow] = { + sql"""select "foreign_data_wrapper_catalog", "foreign_data_wrapper_name", "option_name", "option_value" from information_schema.foreign_data_wrapper_options""".query(ForeignDataWrapperOptionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRow.scala new file mode 100644 index 0000000000..14c3f0128e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrapper_options + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignDataWrapperOptionsViewRow( + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.foreignDataWrapperCatalog]] */ + foreignDataWrapperCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.foreignDataWrapperName]] */ + foreignDataWrapperName: Option[/* nullability unknown */ String], + optionName: /* nullability unknown */ Option[String], + optionValue: /* nullability unknown */ Option[String] +) + +object ForeignDataWrapperOptionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignDataWrapperOptionsViewRow] = new JdbcDecoder[ForeignDataWrapperOptionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignDataWrapperOptionsViewRow) = + columIndex + 3 -> + ForeignDataWrapperOptionsViewRow( + foreignDataWrapperCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignDataWrapperName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + optionName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + optionValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignDataWrapperOptionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignDataWrapperCatalog = jsonObj.get("foreign_data_wrapper_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperName = jsonObj.get("foreign_data_wrapper_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionName = jsonObj.get("option_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionValue = jsonObj.get("option_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignDataWrapperCatalog.isRight && foreignDataWrapperName.isRight && optionName.isRight && optionValue.isRight) + Right(ForeignDataWrapperOptionsViewRow(foreignDataWrapperCatalog = foreignDataWrapperCatalog.toOption.get, foreignDataWrapperName = foreignDataWrapperName.toOption.get, optionName = optionName.toOption.get, optionValue = optionValue.toOption.get)) + else Left(List[Either[String, Any]](foreignDataWrapperCatalog, foreignDataWrapperName, optionName, optionValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignDataWrapperOptionsViewRow] = new JsonEncoder[ForeignDataWrapperOptionsViewRow] { + override def unsafeEncode(a: ForeignDataWrapperOptionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_data_wrapper_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperCatalog, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperName, indent, out) + out.write(",") + out.write(""""option_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionName, indent, out) + out.write(",") + out.write(""""option_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewStructure.scala new file mode 100644 index 0000000000..56a9c55a86 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrapper_options/ForeignDataWrapperOptionsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrapper_options + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignDataWrapperOptionsViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignDataWrapperOptionsViewRow, val merge: (Row, ForeignDataWrapperOptionsViewRow) => Row) + extends Relation[ForeignDataWrapperOptionsViewFields, ForeignDataWrapperOptionsViewRow, Row] + with ForeignDataWrapperOptionsViewFields[Row] { outer => + + override val foreignDataWrapperCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_catalog", None, None)(x => extract(x).foreignDataWrapperCatalog, (row, value) => merge(row, extract(row).copy(foreignDataWrapperCatalog = value))) + override val foreignDataWrapperName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_name", None, None)(x => extract(x).foreignDataWrapperName, (row, value) => merge(row, extract(row).copy(foreignDataWrapperName = value))) + override val optionName = new OptField[String, Row](prefix, "option_name", None, None)(x => extract(x).optionName, (row, value) => merge(row, extract(row).copy(optionName = value))) + override val optionValue = new OptField[String, Row](prefix, "option_value", None, None)(x => extract(x).optionValue, (row, value) => merge(row, extract(row).copy(optionValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignDataWrapperCatalog, foreignDataWrapperName, optionName, optionValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignDataWrapperOptionsViewRow, merge: (NewRow, ForeignDataWrapperOptionsViewRow) => NewRow): ForeignDataWrapperOptionsViewStructure[NewRow] = + new ForeignDataWrapperOptionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewFields.scala new file mode 100644 index 0000000000..9c558fd720 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrappers + +import typo.dsl.SqlExpr.OptField + +trait ForeignDataWrappersViewFields[Row] { + val foreignDataWrapperCatalog: OptField[/* nullability unknown */ String, Row] + val foreignDataWrapperName: OptField[/* nullability unknown */ String, Row] + val authorizationIdentifier: OptField[/* nullability unknown */ String, Row] + val libraryName: OptField[String, Row] + val foreignDataWrapperLanguage: OptField[/* nullability unknown */ String, Row] +} +object ForeignDataWrappersViewFields extends ForeignDataWrappersViewStructure[ForeignDataWrappersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepo.scala new file mode 100644 index 0000000000..53db03338e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrappers + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignDataWrappersViewRepo { + def select: SelectBuilder[ForeignDataWrappersViewFields, ForeignDataWrappersViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignDataWrappersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepoImpl.scala new file mode 100644 index 0000000000..90ef59d7ce --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrappers + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignDataWrappersViewRepoImpl extends ForeignDataWrappersViewRepo { + override def select: SelectBuilder[ForeignDataWrappersViewFields, ForeignDataWrappersViewRow] = { + SelectBuilderSql("information_schema.foreign_data_wrappers", ForeignDataWrappersViewFields, ForeignDataWrappersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignDataWrappersViewRow] = { + sql"""select "foreign_data_wrapper_catalog", "foreign_data_wrapper_name", "authorization_identifier", "library_name", "foreign_data_wrapper_language" from information_schema.foreign_data_wrappers""".query(ForeignDataWrappersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRow.scala new file mode 100644 index 0000000000..caef63abff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrappers + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignDataWrappersViewRow( + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.foreignDataWrapperCatalog]] */ + foreignDataWrapperCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.foreignDataWrapperName]] */ + foreignDataWrapperName: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.authorizationIdentifier]] */ + authorizationIdentifier: Option[/* nullability unknown */ String], + libraryName: /* nullability unknown */ Option[String], + /** Points to [[`_pg_foreign_data_wrappers`.PgForeignDataWrappersViewRow.foreignDataWrapperLanguage]] */ + foreignDataWrapperLanguage: Option[/* nullability unknown */ String] +) + +object ForeignDataWrappersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignDataWrappersViewRow] = new JdbcDecoder[ForeignDataWrappersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignDataWrappersViewRow) = + columIndex + 4 -> + ForeignDataWrappersViewRow( + foreignDataWrapperCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignDataWrapperName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + libraryName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignDataWrapperLanguage = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignDataWrappersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignDataWrapperCatalog = jsonObj.get("foreign_data_wrapper_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperName = jsonObj.get("foreign_data_wrapper_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val libraryName = jsonObj.get("library_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperLanguage = jsonObj.get("foreign_data_wrapper_language").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignDataWrapperCatalog.isRight && foreignDataWrapperName.isRight && authorizationIdentifier.isRight && libraryName.isRight && foreignDataWrapperLanguage.isRight) + Right(ForeignDataWrappersViewRow(foreignDataWrapperCatalog = foreignDataWrapperCatalog.toOption.get, foreignDataWrapperName = foreignDataWrapperName.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get, libraryName = libraryName.toOption.get, foreignDataWrapperLanguage = foreignDataWrapperLanguage.toOption.get)) + else Left(List[Either[String, Any]](foreignDataWrapperCatalog, foreignDataWrapperName, authorizationIdentifier, libraryName, foreignDataWrapperLanguage).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignDataWrappersViewRow] = new JsonEncoder[ForeignDataWrappersViewRow] { + override def unsafeEncode(a: ForeignDataWrappersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_data_wrapper_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperCatalog, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperName, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write(",") + out.write(""""library_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.libraryName, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_language":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperLanguage, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewStructure.scala new file mode 100644 index 0000000000..6514d53b39 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_data_wrappers/ForeignDataWrappersViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_data_wrappers + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignDataWrappersViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignDataWrappersViewRow, val merge: (Row, ForeignDataWrappersViewRow) => Row) + extends Relation[ForeignDataWrappersViewFields, ForeignDataWrappersViewRow, Row] + with ForeignDataWrappersViewFields[Row] { outer => + + override val foreignDataWrapperCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_catalog", None, None)(x => extract(x).foreignDataWrapperCatalog, (row, value) => merge(row, extract(row).copy(foreignDataWrapperCatalog = value))) + override val foreignDataWrapperName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_name", None, None)(x => extract(x).foreignDataWrapperName, (row, value) => merge(row, extract(row).copy(foreignDataWrapperName = value))) + override val authorizationIdentifier = new OptField[/* nullability unknown */ String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + override val libraryName = new OptField[String, Row](prefix, "library_name", None, None)(x => extract(x).libraryName, (row, value) => merge(row, extract(row).copy(libraryName = value))) + override val foreignDataWrapperLanguage = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_language", None, None)(x => extract(x).foreignDataWrapperLanguage, (row, value) => merge(row, extract(row).copy(foreignDataWrapperLanguage = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignDataWrapperCatalog, foreignDataWrapperName, authorizationIdentifier, libraryName, foreignDataWrapperLanguage) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignDataWrappersViewRow, merge: (NewRow, ForeignDataWrappersViewRow) => NewRow): ForeignDataWrappersViewStructure[NewRow] = + new ForeignDataWrappersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewFields.scala new file mode 100644 index 0000000000..2955cd121c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_server_options + +import typo.dsl.SqlExpr.OptField + +trait ForeignServerOptionsViewFields[Row] { + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] + val optionName: OptField[String, Row] + val optionValue: OptField[String, Row] +} +object ForeignServerOptionsViewFields extends ForeignServerOptionsViewStructure[ForeignServerOptionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepo.scala new file mode 100644 index 0000000000..ec4c492197 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_server_options + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignServerOptionsViewRepo { + def select: SelectBuilder[ForeignServerOptionsViewFields, ForeignServerOptionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignServerOptionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepoImpl.scala new file mode 100644 index 0000000000..b0f5ea7895 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_server_options + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignServerOptionsViewRepoImpl extends ForeignServerOptionsViewRepo { + override def select: SelectBuilder[ForeignServerOptionsViewFields, ForeignServerOptionsViewRow] = { + SelectBuilderSql("information_schema.foreign_server_options", ForeignServerOptionsViewFields, ForeignServerOptionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignServerOptionsViewRow] = { + sql"""select "foreign_server_catalog", "foreign_server_name", "option_name", "option_value" from information_schema.foreign_server_options""".query(ForeignServerOptionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRow.scala new file mode 100644 index 0000000000..8b1673fcb1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_server_options + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignServerOptionsViewRow( + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String], + optionName: /* nullability unknown */ Option[String], + optionValue: /* nullability unknown */ Option[String] +) + +object ForeignServerOptionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignServerOptionsViewRow] = new JdbcDecoder[ForeignServerOptionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignServerOptionsViewRow) = + columIndex + 3 -> + ForeignServerOptionsViewRow( + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + optionName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + optionValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignServerOptionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionName = jsonObj.get("option_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionValue = jsonObj.get("option_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignServerCatalog.isRight && foreignServerName.isRight && optionName.isRight && optionValue.isRight) + Right(ForeignServerOptionsViewRow(foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, optionName = optionName.toOption.get, optionValue = optionValue.toOption.get)) + else Left(List[Either[String, Any]](foreignServerCatalog, foreignServerName, optionName, optionValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignServerOptionsViewRow] = new JsonEncoder[ForeignServerOptionsViewRow] { + override def unsafeEncode(a: ForeignServerOptionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""option_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionName, indent, out) + out.write(",") + out.write(""""option_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewStructure.scala new file mode 100644 index 0000000000..f0f59a2b7e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_server_options/ForeignServerOptionsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_server_options + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignServerOptionsViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignServerOptionsViewRow, val merge: (Row, ForeignServerOptionsViewRow) => Row) + extends Relation[ForeignServerOptionsViewFields, ForeignServerOptionsViewRow, Row] + with ForeignServerOptionsViewFields[Row] { outer => + + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val optionName = new OptField[String, Row](prefix, "option_name", None, None)(x => extract(x).optionName, (row, value) => merge(row, extract(row).copy(optionName = value))) + override val optionValue = new OptField[String, Row](prefix, "option_value", None, None)(x => extract(x).optionValue, (row, value) => merge(row, extract(row).copy(optionValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignServerCatalog, foreignServerName, optionName, optionValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignServerOptionsViewRow, merge: (NewRow, ForeignServerOptionsViewRow) => NewRow): ForeignServerOptionsViewStructure[NewRow] = + new ForeignServerOptionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewFields.scala new file mode 100644 index 0000000000..6db882d58d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_servers + +import typo.dsl.SqlExpr.OptField + +trait ForeignServersViewFields[Row] { + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] + val foreignDataWrapperCatalog: OptField[/* nullability unknown */ String, Row] + val foreignDataWrapperName: OptField[/* nullability unknown */ String, Row] + val foreignServerType: OptField[/* nullability unknown */ String, Row] + val foreignServerVersion: OptField[/* nullability unknown */ String, Row] + val authorizationIdentifier: OptField[/* nullability unknown */ String, Row] +} +object ForeignServersViewFields extends ForeignServersViewStructure[ForeignServersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepo.scala new file mode 100644 index 0000000000..e53b62cdec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_servers + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignServersViewRepo { + def select: SelectBuilder[ForeignServersViewFields, ForeignServersViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignServersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepoImpl.scala new file mode 100644 index 0000000000..07a35c8dca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_servers + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignServersViewRepoImpl extends ForeignServersViewRepo { + override def select: SelectBuilder[ForeignServersViewFields, ForeignServersViewRow] = { + SelectBuilderSql("information_schema.foreign_servers", ForeignServersViewFields, ForeignServersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignServersViewRow] = { + sql"""select "foreign_server_catalog", "foreign_server_name", "foreign_data_wrapper_catalog", "foreign_data_wrapper_name", "foreign_server_type", "foreign_server_version", "authorization_identifier" from information_schema.foreign_servers""".query(ForeignServersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRow.scala new file mode 100644 index 0000000000..525b1bc0ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_servers + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignServersViewRow( + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignDataWrapperCatalog]] */ + foreignDataWrapperCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignDataWrapperName]] */ + foreignDataWrapperName: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerType]] */ + foreignServerType: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.foreignServerVersion]] */ + foreignServerVersion: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_servers`.PgForeignServersViewRow.authorizationIdentifier]] */ + authorizationIdentifier: Option[/* nullability unknown */ String] +) + +object ForeignServersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignServersViewRow] = new JdbcDecoder[ForeignServersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignServersViewRow) = + columIndex + 6 -> + ForeignServersViewRow( + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignDataWrapperCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + foreignDataWrapperName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignServerType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + foreignServerVersion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignServersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperCatalog = jsonObj.get("foreign_data_wrapper_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignDataWrapperName = jsonObj.get("foreign_data_wrapper_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerType = jsonObj.get("foreign_server_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerVersion = jsonObj.get("foreign_server_version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignServerCatalog.isRight && foreignServerName.isRight && foreignDataWrapperCatalog.isRight && foreignDataWrapperName.isRight && foreignServerType.isRight && foreignServerVersion.isRight && authorizationIdentifier.isRight) + Right(ForeignServersViewRow(foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, foreignDataWrapperCatalog = foreignDataWrapperCatalog.toOption.get, foreignDataWrapperName = foreignDataWrapperName.toOption.get, foreignServerType = foreignServerType.toOption.get, foreignServerVersion = foreignServerVersion.toOption.get, authorizationIdentifier = authorizationIdentifier.toOption.get)) + else Left(List[Either[String, Any]](foreignServerCatalog, foreignServerName, foreignDataWrapperCatalog, foreignDataWrapperName, foreignServerType, foreignServerVersion, authorizationIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignServersViewRow] = new JsonEncoder[ForeignServersViewRow] { + override def unsafeEncode(a: ForeignServersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperCatalog, indent, out) + out.write(",") + out.write(""""foreign_data_wrapper_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignDataWrapperName, indent, out) + out.write(",") + out.write(""""foreign_server_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerType, indent, out) + out.write(",") + out.write(""""foreign_server_version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerVersion, indent, out) + out.write(",") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewStructure.scala new file mode 100644 index 0000000000..15540b66a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_servers/ForeignServersViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_servers + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignServersViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignServersViewRow, val merge: (Row, ForeignServersViewRow) => Row) + extends Relation[ForeignServersViewFields, ForeignServersViewRow, Row] + with ForeignServersViewFields[Row] { outer => + + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val foreignDataWrapperCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_catalog", None, None)(x => extract(x).foreignDataWrapperCatalog, (row, value) => merge(row, extract(row).copy(foreignDataWrapperCatalog = value))) + override val foreignDataWrapperName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_data_wrapper_name", None, None)(x => extract(x).foreignDataWrapperName, (row, value) => merge(row, extract(row).copy(foreignDataWrapperName = value))) + override val foreignServerType = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_type", None, None)(x => extract(x).foreignServerType, (row, value) => merge(row, extract(row).copy(foreignServerType = value))) + override val foreignServerVersion = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_version", None, None)(x => extract(x).foreignServerVersion, (row, value) => merge(row, extract(row).copy(foreignServerVersion = value))) + override val authorizationIdentifier = new OptField[/* nullability unknown */ String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignServerCatalog, foreignServerName, foreignDataWrapperCatalog, foreignDataWrapperName, foreignServerType, foreignServerVersion, authorizationIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignServersViewRow, merge: (NewRow, ForeignServersViewRow) => NewRow): ForeignServersViewStructure[NewRow] = + new ForeignServersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewFields.scala new file mode 100644 index 0000000000..7d85058a77 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_table_options + +import typo.dsl.SqlExpr.OptField + +trait ForeignTableOptionsViewFields[Row] { + val foreignTableCatalog: OptField[/* nullability unknown */ String, Row] + val foreignTableSchema: OptField[/* nullability unknown */ String, Row] + val foreignTableName: OptField[/* nullability unknown */ String, Row] + val optionName: OptField[String, Row] + val optionValue: OptField[String, Row] +} +object ForeignTableOptionsViewFields extends ForeignTableOptionsViewStructure[ForeignTableOptionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepo.scala new file mode 100644 index 0000000000..f05a2f944a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_table_options + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignTableOptionsViewRepo { + def select: SelectBuilder[ForeignTableOptionsViewFields, ForeignTableOptionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignTableOptionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepoImpl.scala new file mode 100644 index 0000000000..e8705910cb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_table_options + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignTableOptionsViewRepoImpl extends ForeignTableOptionsViewRepo { + override def select: SelectBuilder[ForeignTableOptionsViewFields, ForeignTableOptionsViewRow] = { + SelectBuilderSql("information_schema.foreign_table_options", ForeignTableOptionsViewFields, ForeignTableOptionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignTableOptionsViewRow] = { + sql"""select "foreign_table_catalog", "foreign_table_schema", "foreign_table_name", "option_name", "option_value" from information_schema.foreign_table_options""".query(ForeignTableOptionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRow.scala new file mode 100644 index 0000000000..90d06b0d73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewRow.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_table_options + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignTableOptionsViewRow( + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableCatalog]] */ + foreignTableCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableSchema]] */ + foreignTableSchema: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableName]] */ + foreignTableName: Option[/* nullability unknown */ String], + optionName: /* nullability unknown */ Option[String], + optionValue: /* nullability unknown */ Option[String] +) + +object ForeignTableOptionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignTableOptionsViewRow] = new JdbcDecoder[ForeignTableOptionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignTableOptionsViewRow) = + columIndex + 4 -> + ForeignTableOptionsViewRow( + foreignTableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignTableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignTableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + optionName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + optionValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignTableOptionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignTableCatalog = jsonObj.get("foreign_table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableSchema = jsonObj.get("foreign_table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableName = jsonObj.get("foreign_table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionName = jsonObj.get("option_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionValue = jsonObj.get("option_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignTableCatalog.isRight && foreignTableSchema.isRight && foreignTableName.isRight && optionName.isRight && optionValue.isRight) + Right(ForeignTableOptionsViewRow(foreignTableCatalog = foreignTableCatalog.toOption.get, foreignTableSchema = foreignTableSchema.toOption.get, foreignTableName = foreignTableName.toOption.get, optionName = optionName.toOption.get, optionValue = optionValue.toOption.get)) + else Left(List[Either[String, Any]](foreignTableCatalog, foreignTableSchema, foreignTableName, optionName, optionValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignTableOptionsViewRow] = new JsonEncoder[ForeignTableOptionsViewRow] { + override def unsafeEncode(a: ForeignTableOptionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableCatalog, indent, out) + out.write(",") + out.write(""""foreign_table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableSchema, indent, out) + out.write(",") + out.write(""""foreign_table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableName, indent, out) + out.write(",") + out.write(""""option_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionName, indent, out) + out.write(",") + out.write(""""option_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewStructure.scala new file mode 100644 index 0000000000..08a9533d7f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_table_options/ForeignTableOptionsViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_table_options + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignTableOptionsViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignTableOptionsViewRow, val merge: (Row, ForeignTableOptionsViewRow) => Row) + extends Relation[ForeignTableOptionsViewFields, ForeignTableOptionsViewRow, Row] + with ForeignTableOptionsViewFields[Row] { outer => + + override val foreignTableCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_catalog", None, None)(x => extract(x).foreignTableCatalog, (row, value) => merge(row, extract(row).copy(foreignTableCatalog = value))) + override val foreignTableSchema = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_schema", None, None)(x => extract(x).foreignTableSchema, (row, value) => merge(row, extract(row).copy(foreignTableSchema = value))) + override val foreignTableName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_name", None, None)(x => extract(x).foreignTableName, (row, value) => merge(row, extract(row).copy(foreignTableName = value))) + override val optionName = new OptField[String, Row](prefix, "option_name", None, None)(x => extract(x).optionName, (row, value) => merge(row, extract(row).copy(optionName = value))) + override val optionValue = new OptField[String, Row](prefix, "option_value", None, None)(x => extract(x).optionValue, (row, value) => merge(row, extract(row).copy(optionValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignTableCatalog, foreignTableSchema, foreignTableName, optionName, optionValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignTableOptionsViewRow, merge: (NewRow, ForeignTableOptionsViewRow) => NewRow): ForeignTableOptionsViewStructure[NewRow] = + new ForeignTableOptionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewFields.scala new file mode 100644 index 0000000000..8afb0a6578 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_tables + +import typo.dsl.SqlExpr.OptField + +trait ForeignTablesViewFields[Row] { + val foreignTableCatalog: OptField[/* nullability unknown */ String, Row] + val foreignTableSchema: OptField[/* nullability unknown */ String, Row] + val foreignTableName: OptField[/* nullability unknown */ String, Row] + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] +} +object ForeignTablesViewFields extends ForeignTablesViewStructure[ForeignTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepo.scala new file mode 100644 index 0000000000..01aa3ebc24 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ForeignTablesViewRepo { + def select: SelectBuilder[ForeignTablesViewFields, ForeignTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, ForeignTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepoImpl.scala new file mode 100644 index 0000000000..a5899c2055 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ForeignTablesViewRepoImpl extends ForeignTablesViewRepo { + override def select: SelectBuilder[ForeignTablesViewFields, ForeignTablesViewRow] = { + SelectBuilderSql("information_schema.foreign_tables", ForeignTablesViewFields, ForeignTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ForeignTablesViewRow] = { + sql"""select "foreign_table_catalog", "foreign_table_schema", "foreign_table_name", "foreign_server_catalog", "foreign_server_name" from information_schema.foreign_tables""".query(ForeignTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRow.scala new file mode 100644 index 0000000000..3327b9aa42 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewRow.scala @@ -0,0 +1,72 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_tables + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ForeignTablesViewRow( + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableCatalog]] */ + foreignTableCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableSchema]] */ + foreignTableSchema: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignTableName]] */ + foreignTableName: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_foreign_tables`.PgForeignTablesViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String] +) + +object ForeignTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ForeignTablesViewRow] = new JdbcDecoder[ForeignTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ForeignTablesViewRow) = + columIndex + 4 -> + ForeignTablesViewRow( + foreignTableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignTableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignTableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ForeignTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val foreignTableCatalog = jsonObj.get("foreign_table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableSchema = jsonObj.get("foreign_table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignTableName = jsonObj.get("foreign_table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (foreignTableCatalog.isRight && foreignTableSchema.isRight && foreignTableName.isRight && foreignServerCatalog.isRight && foreignServerName.isRight) + Right(ForeignTablesViewRow(foreignTableCatalog = foreignTableCatalog.toOption.get, foreignTableSchema = foreignTableSchema.toOption.get, foreignTableName = foreignTableName.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get)) + else Left(List[Either[String, Any]](foreignTableCatalog, foreignTableSchema, foreignTableName, foreignServerCatalog, foreignServerName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ForeignTablesViewRow] = new JsonEncoder[ForeignTablesViewRow] { + override def unsafeEncode(a: ForeignTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""foreign_table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableCatalog, indent, out) + out.write(",") + out.write(""""foreign_table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableSchema, indent, out) + out.write(",") + out.write(""""foreign_table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignTableName, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewStructure.scala new file mode 100644 index 0000000000..b76673e086 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/foreign_tables/ForeignTablesViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package foreign_tables + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ForeignTablesViewStructure[Row](val prefix: Option[String], val extract: Row => ForeignTablesViewRow, val merge: (Row, ForeignTablesViewRow) => Row) + extends Relation[ForeignTablesViewFields, ForeignTablesViewRow, Row] + with ForeignTablesViewFields[Row] { outer => + + override val foreignTableCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_catalog", None, None)(x => extract(x).foreignTableCatalog, (row, value) => merge(row, extract(row).copy(foreignTableCatalog = value))) + override val foreignTableSchema = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_schema", None, None)(x => extract(x).foreignTableSchema, (row, value) => merge(row, extract(row).copy(foreignTableSchema = value))) + override val foreignTableName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_table_name", None, None)(x => extract(x).foreignTableName, (row, value) => merge(row, extract(row).copy(foreignTableName = value))) + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](foreignTableCatalog, foreignTableSchema, foreignTableName, foreignServerCatalog, foreignServerName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ForeignTablesViewRow, merge: (NewRow, ForeignTablesViewRow) => NewRow): ForeignTablesViewStructure[NewRow] = + new ForeignTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewFields.scala new file mode 100644 index 0000000000..fad8ddb06e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewFields.scala @@ -0,0 +1,16 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package information_schema_catalog_name + +import typo.dsl.SqlExpr.OptField + +trait InformationSchemaCatalogNameViewFields[Row] { + val catalogName: OptField[String, Row] +} +object InformationSchemaCatalogNameViewFields extends InformationSchemaCatalogNameViewStructure[InformationSchemaCatalogNameViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepo.scala new file mode 100644 index 0000000000..a55935cca2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package information_schema_catalog_name + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait InformationSchemaCatalogNameViewRepo { + def select: SelectBuilder[InformationSchemaCatalogNameViewFields, InformationSchemaCatalogNameViewRow] + def selectAll: ZStream[ZConnection, Throwable, InformationSchemaCatalogNameViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepoImpl.scala new file mode 100644 index 0000000000..156a7cb6fe --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package information_schema_catalog_name + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object InformationSchemaCatalogNameViewRepoImpl extends InformationSchemaCatalogNameViewRepo { + override def select: SelectBuilder[InformationSchemaCatalogNameViewFields, InformationSchemaCatalogNameViewRow] = { + SelectBuilderSql("information_schema.information_schema_catalog_name", InformationSchemaCatalogNameViewFields, InformationSchemaCatalogNameViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, InformationSchemaCatalogNameViewRow] = { + sql"""select "catalog_name" from information_schema.information_schema_catalog_name""".query(InformationSchemaCatalogNameViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRow.scala new file mode 100644 index 0000000000..eab3295a66 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewRow.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package information_schema_catalog_name + +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class InformationSchemaCatalogNameViewRow( + catalogName: /* nullability unknown */ Option[String] +) + +object InformationSchemaCatalogNameViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[InformationSchemaCatalogNameViewRow] = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).map(v => InformationSchemaCatalogNameViewRow(catalogName = v)) + implicit lazy val jsonDecoder: JsonDecoder[InformationSchemaCatalogNameViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val catalogName = jsonObj.get("catalog_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (catalogName.isRight) + Right(InformationSchemaCatalogNameViewRow(catalogName = catalogName.toOption.get)) + else Left(List[Either[String, Any]](catalogName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[InformationSchemaCatalogNameViewRow] = new JsonEncoder[InformationSchemaCatalogNameViewRow] { + override def unsafeEncode(a: InformationSchemaCatalogNameViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""catalog_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.catalogName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewStructure.scala new file mode 100644 index 0000000000..054f1751be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/information_schema_catalog_name/InformationSchemaCatalogNameViewStructure.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package information_schema_catalog_name + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class InformationSchemaCatalogNameViewStructure[Row](val prefix: Option[String], val extract: Row => InformationSchemaCatalogNameViewRow, val merge: (Row, InformationSchemaCatalogNameViewRow) => Row) + extends Relation[InformationSchemaCatalogNameViewFields, InformationSchemaCatalogNameViewRow, Row] + with InformationSchemaCatalogNameViewFields[Row] { outer => + + override val catalogName = new OptField[String, Row](prefix, "catalog_name", None, None)(x => extract(x).catalogName, (row, value) => merge(row, extract(row).copy(catalogName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](catalogName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => InformationSchemaCatalogNameViewRow, merge: (NewRow, InformationSchemaCatalogNameViewRow) => NewRow): InformationSchemaCatalogNameViewStructure[NewRow] = + new InformationSchemaCatalogNameViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewFields.scala new file mode 100644 index 0000000000..d5bbbd618e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package key_column_usage + +import typo.dsl.SqlExpr.OptField + +trait KeyColumnUsageViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] + val ordinalPosition: OptField[Int, Row] + val positionInUniqueConstraint: OptField[Int, Row] +} +object KeyColumnUsageViewFields extends KeyColumnUsageViewStructure[KeyColumnUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepo.scala new file mode 100644 index 0000000000..8f09312b51 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package key_column_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait KeyColumnUsageViewRepo { + def select: SelectBuilder[KeyColumnUsageViewFields, KeyColumnUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, KeyColumnUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepoImpl.scala new file mode 100644 index 0000000000..fdfbf55c06 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package key_column_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object KeyColumnUsageViewRepoImpl extends KeyColumnUsageViewRepo { + override def select: SelectBuilder[KeyColumnUsageViewFields, KeyColumnUsageViewRow] = { + SelectBuilderSql("information_schema.key_column_usage", KeyColumnUsageViewFields, KeyColumnUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, KeyColumnUsageViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "table_catalog", "table_schema", "table_name", "column_name", "ordinal_position", "position_in_unique_constraint" from information_schema.key_column_usage""".query(KeyColumnUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRow.scala new file mode 100644 index 0000000000..fa99525f42 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package key_column_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class KeyColumnUsageViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String], + ordinalPosition: /* nullability unknown */ Option[Int], + positionInUniqueConstraint: /* nullability unknown */ Option[Int] +) + +object KeyColumnUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[KeyColumnUsageViewRow] = new JdbcDecoder[KeyColumnUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, KeyColumnUsageViewRow) = + columIndex + 8 -> + KeyColumnUsageViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + ordinalPosition = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + positionInUniqueConstraint = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[KeyColumnUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ordinalPosition = jsonObj.get("ordinal_position").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val positionInUniqueConstraint = jsonObj.get("position_in_unique_constraint").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && ordinalPosition.isRight && positionInUniqueConstraint.isRight) + Right(KeyColumnUsageViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, ordinalPosition = ordinalPosition.toOption.get, positionInUniqueConstraint = positionInUniqueConstraint.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, tableCatalog, tableSchema, tableName, columnName, ordinalPosition, positionInUniqueConstraint).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[KeyColumnUsageViewRow] = new JsonEncoder[KeyColumnUsageViewRow] { + override def unsafeEncode(a: KeyColumnUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""ordinal_position":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.ordinalPosition, indent, out) + out.write(",") + out.write(""""position_in_unique_constraint":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.positionInUniqueConstraint, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewStructure.scala new file mode 100644 index 0000000000..a9fd10bab1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/key_column_usage/KeyColumnUsageViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package key_column_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class KeyColumnUsageViewStructure[Row](val prefix: Option[String], val extract: Row => KeyColumnUsageViewRow, val merge: (Row, KeyColumnUsageViewRow) => Row) + extends Relation[KeyColumnUsageViewFields, KeyColumnUsageViewRow, Row] + with KeyColumnUsageViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val ordinalPosition = new OptField[Int, Row](prefix, "ordinal_position", None, None)(x => extract(x).ordinalPosition, (row, value) => merge(row, extract(row).copy(ordinalPosition = value))) + override val positionInUniqueConstraint = new OptField[Int, Row](prefix, "position_in_unique_constraint", None, None)(x => extract(x).positionInUniqueConstraint, (row, value) => merge(row, extract(row).copy(positionInUniqueConstraint = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, tableCatalog, tableSchema, tableName, columnName, ordinalPosition, positionInUniqueConstraint) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => KeyColumnUsageViewRow, merge: (NewRow, KeyColumnUsageViewRow) => NewRow): KeyColumnUsageViewStructure[NewRow] = + new KeyColumnUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewFields.scala new file mode 100644 index 0000000000..3f2c90c7ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewFields.scala @@ -0,0 +1,47 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package parameters + +import typo.dsl.SqlExpr.OptField + +trait ParametersViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val ordinalPosition: OptField[Int, Row] + val parameterMode: OptField[String, Row] + val isResult: OptField[/* max 3 chars */ String, Row] + val asLocator: OptField[/* max 3 chars */ String, Row] + val parameterName: OptField[String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] + val parameterDefault: OptField[String, Row] +} +object ParametersViewFields extends ParametersViewStructure[ParametersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepo.scala new file mode 100644 index 0000000000..cc156c4cb7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package parameters + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ParametersViewRepo { + def select: SelectBuilder[ParametersViewFields, ParametersViewRow] + def selectAll: ZStream[ZConnection, Throwable, ParametersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepoImpl.scala new file mode 100644 index 0000000000..da914d3e25 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package parameters + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ParametersViewRepoImpl extends ParametersViewRepo { + override def select: SelectBuilder[ParametersViewFields, ParametersViewRow] = { + SelectBuilderSql("information_schema.parameters", ParametersViewFields, ParametersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ParametersViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "ordinal_position", "parameter_mode", "is_result", "as_locator", "parameter_name", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "udt_catalog", "udt_schema", "udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier", "parameter_default" from information_schema.parameters""".query(ParametersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRow.scala new file mode 100644 index 0000000000..0b824d6863 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewRow.scala @@ -0,0 +1,229 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package parameters + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ParametersViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + ordinalPosition: /* nullability unknown */ Option[Int], + parameterMode: /* nullability unknown */ Option[String], + isResult: /* nullability unknown */ Option[/* max 3 chars */ String], + asLocator: /* nullability unknown */ Option[/* max 3 chars */ String], + parameterName: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String], + parameterDefault: /* nullability unknown */ Option[String] +) + +object ParametersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ParametersViewRow] = new JdbcDecoder[ParametersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ParametersViewRow) = + columIndex + 31 -> + ParametersViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + ordinalPosition = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + parameterMode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + isResult = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + asLocator = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + parameterName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 10, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 17, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 18, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 19, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 20, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 22, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 24, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 25, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 27, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 29, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 30, rs)._2, + parameterDefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 31, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ParametersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ordinalPosition = jsonObj.get("ordinal_position").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val parameterMode = jsonObj.get("parameter_mode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isResult = jsonObj.get("is_result").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val asLocator = jsonObj.get("as_locator").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val parameterName = jsonObj.get("parameter_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val parameterDefault = jsonObj.get("parameter_default").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && ordinalPosition.isRight && parameterMode.isRight && isResult.isRight && asLocator.isRight && parameterName.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight && parameterDefault.isRight) + Right(ParametersViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, ordinalPosition = ordinalPosition.toOption.get, parameterMode = parameterMode.toOption.get, isResult = isResult.toOption.get, asLocator = asLocator.toOption.get, parameterName = parameterName.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get, parameterDefault = parameterDefault.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, ordinalPosition, parameterMode, isResult, asLocator, parameterName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, parameterDefault).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ParametersViewRow] = new JsonEncoder[ParametersViewRow] { + override def unsafeEncode(a: ParametersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""ordinal_position":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.ordinalPosition, indent, out) + out.write(",") + out.write(""""parameter_mode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.parameterMode, indent, out) + out.write(",") + out.write(""""is_result":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isResult, indent, out) + out.write(",") + out.write(""""as_locator":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.asLocator, indent, out) + out.write(",") + out.write(""""parameter_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.parameterName, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write(",") + out.write(""""parameter_default":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.parameterDefault, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewStructure.scala new file mode 100644 index 0000000000..aa42d6e5c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/parameters/ParametersViewStructure.scala @@ -0,0 +1,56 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package parameters + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ParametersViewStructure[Row](val prefix: Option[String], val extract: Row => ParametersViewRow, val merge: (Row, ParametersViewRow) => Row) + extends Relation[ParametersViewFields, ParametersViewRow, Row] + with ParametersViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val ordinalPosition = new OptField[Int, Row](prefix, "ordinal_position", None, None)(x => extract(x).ordinalPosition, (row, value) => merge(row, extract(row).copy(ordinalPosition = value))) + override val parameterMode = new OptField[String, Row](prefix, "parameter_mode", None, None)(x => extract(x).parameterMode, (row, value) => merge(row, extract(row).copy(parameterMode = value))) + override val isResult = new OptField[/* max 3 chars */ String, Row](prefix, "is_result", None, None)(x => extract(x).isResult, (row, value) => merge(row, extract(row).copy(isResult = value))) + override val asLocator = new OptField[/* max 3 chars */ String, Row](prefix, "as_locator", None, None)(x => extract(x).asLocator, (row, value) => merge(row, extract(row).copy(asLocator = value))) + override val parameterName = new OptField[String, Row](prefix, "parameter_name", None, None)(x => extract(x).parameterName, (row, value) => merge(row, extract(row).copy(parameterName = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + override val parameterDefault = new OptField[String, Row](prefix, "parameter_default", None, None)(x => extract(x).parameterDefault, (row, value) => merge(row, extract(row).copy(parameterDefault = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, ordinalPosition, parameterMode, isResult, asLocator, parameterName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, udtCatalog, udtSchema, udtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, parameterDefault) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ParametersViewRow, merge: (NewRow, ParametersViewRow) => NewRow): ParametersViewStructure[NewRow] = + new ParametersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewFields.scala new file mode 100644 index 0000000000..8903ae48b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package referential_constraints + +import typo.dsl.SqlExpr.OptField + +trait ReferentialConstraintsViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val uniqueConstraintCatalog: OptField[String, Row] + val uniqueConstraintSchema: OptField[String, Row] + val uniqueConstraintName: OptField[String, Row] + val matchOption: OptField[String, Row] + val updateRule: OptField[String, Row] + val deleteRule: OptField[String, Row] +} +object ReferentialConstraintsViewFields extends ReferentialConstraintsViewStructure[ReferentialConstraintsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepo.scala new file mode 100644 index 0000000000..67df40a44c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package referential_constraints + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ReferentialConstraintsViewRepo { + def select: SelectBuilder[ReferentialConstraintsViewFields, ReferentialConstraintsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ReferentialConstraintsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepoImpl.scala new file mode 100644 index 0000000000..65d4e8b641 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package referential_constraints + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ReferentialConstraintsViewRepoImpl extends ReferentialConstraintsViewRepo { + override def select: SelectBuilder[ReferentialConstraintsViewFields, ReferentialConstraintsViewRow] = { + SelectBuilderSql("information_schema.referential_constraints", ReferentialConstraintsViewFields, ReferentialConstraintsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ReferentialConstraintsViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "unique_constraint_catalog", "unique_constraint_schema", "unique_constraint_name", "match_option", "update_rule", "delete_rule" from information_schema.referential_constraints""".query(ReferentialConstraintsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRow.scala new file mode 100644 index 0000000000..63e10cbd9c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package referential_constraints + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ReferentialConstraintsViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + uniqueConstraintCatalog: /* nullability unknown */ Option[String], + uniqueConstraintSchema: /* nullability unknown */ Option[String], + uniqueConstraintName: /* nullability unknown */ Option[String], + matchOption: /* nullability unknown */ Option[String], + updateRule: /* nullability unknown */ Option[String], + deleteRule: /* nullability unknown */ Option[String] +) + +object ReferentialConstraintsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ReferentialConstraintsViewRow] = new JdbcDecoder[ReferentialConstraintsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ReferentialConstraintsViewRow) = + columIndex + 8 -> + ReferentialConstraintsViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + uniqueConstraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + uniqueConstraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + uniqueConstraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + matchOption = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + updateRule = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + deleteRule = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ReferentialConstraintsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val uniqueConstraintCatalog = jsonObj.get("unique_constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val uniqueConstraintSchema = jsonObj.get("unique_constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val uniqueConstraintName = jsonObj.get("unique_constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val matchOption = jsonObj.get("match_option").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val updateRule = jsonObj.get("update_rule").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val deleteRule = jsonObj.get("delete_rule").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && uniqueConstraintCatalog.isRight && uniqueConstraintSchema.isRight && uniqueConstraintName.isRight && matchOption.isRight && updateRule.isRight && deleteRule.isRight) + Right(ReferentialConstraintsViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, uniqueConstraintCatalog = uniqueConstraintCatalog.toOption.get, uniqueConstraintSchema = uniqueConstraintSchema.toOption.get, uniqueConstraintName = uniqueConstraintName.toOption.get, matchOption = matchOption.toOption.get, updateRule = updateRule.toOption.get, deleteRule = deleteRule.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, uniqueConstraintCatalog, uniqueConstraintSchema, uniqueConstraintName, matchOption, updateRule, deleteRule).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ReferentialConstraintsViewRow] = new JsonEncoder[ReferentialConstraintsViewRow] { + override def unsafeEncode(a: ReferentialConstraintsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""unique_constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.uniqueConstraintCatalog, indent, out) + out.write(",") + out.write(""""unique_constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.uniqueConstraintSchema, indent, out) + out.write(",") + out.write(""""unique_constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.uniqueConstraintName, indent, out) + out.write(",") + out.write(""""match_option":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.matchOption, indent, out) + out.write(",") + out.write(""""update_rule":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.updateRule, indent, out) + out.write(",") + out.write(""""delete_rule":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.deleteRule, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewStructure.scala new file mode 100644 index 0000000000..2d1b85e002 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/referential_constraints/ReferentialConstraintsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package referential_constraints + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ReferentialConstraintsViewStructure[Row](val prefix: Option[String], val extract: Row => ReferentialConstraintsViewRow, val merge: (Row, ReferentialConstraintsViewRow) => Row) + extends Relation[ReferentialConstraintsViewFields, ReferentialConstraintsViewRow, Row] + with ReferentialConstraintsViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val uniqueConstraintCatalog = new OptField[String, Row](prefix, "unique_constraint_catalog", None, None)(x => extract(x).uniqueConstraintCatalog, (row, value) => merge(row, extract(row).copy(uniqueConstraintCatalog = value))) + override val uniqueConstraintSchema = new OptField[String, Row](prefix, "unique_constraint_schema", None, None)(x => extract(x).uniqueConstraintSchema, (row, value) => merge(row, extract(row).copy(uniqueConstraintSchema = value))) + override val uniqueConstraintName = new OptField[String, Row](prefix, "unique_constraint_name", None, None)(x => extract(x).uniqueConstraintName, (row, value) => merge(row, extract(row).copy(uniqueConstraintName = value))) + override val matchOption = new OptField[String, Row](prefix, "match_option", None, None)(x => extract(x).matchOption, (row, value) => merge(row, extract(row).copy(matchOption = value))) + override val updateRule = new OptField[String, Row](prefix, "update_rule", None, None)(x => extract(x).updateRule, (row, value) => merge(row, extract(row).copy(updateRule = value))) + override val deleteRule = new OptField[String, Row](prefix, "delete_rule", None, None)(x => extract(x).deleteRule, (row, value) => merge(row, extract(row).copy(deleteRule = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, uniqueConstraintCatalog, uniqueConstraintSchema, uniqueConstraintName, matchOption, updateRule, deleteRule) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ReferentialConstraintsViewRow, merge: (NewRow, ReferentialConstraintsViewRow) => NewRow): ReferentialConstraintsViewStructure[NewRow] = + new ReferentialConstraintsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewFields.scala new file mode 100644 index 0000000000..a2e47527ef --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_column_grants + +import typo.dsl.SqlExpr.OptField + +trait RoleColumnGrantsViewFields[Row] { + val grantor: OptField[/* nullability unknown */ String, Row] + val grantee: OptField[/* nullability unknown */ String, Row] + val tableCatalog: OptField[/* nullability unknown */ String, Row] + val tableSchema: OptField[/* nullability unknown */ String, Row] + val tableName: OptField[/* nullability unknown */ String, Row] + val columnName: OptField[/* nullability unknown */ String, Row] + val privilegeType: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object RoleColumnGrantsViewFields extends RoleColumnGrantsViewStructure[RoleColumnGrantsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepo.scala new file mode 100644 index 0000000000..11d90507c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_column_grants + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoleColumnGrantsViewRepo { + def select: SelectBuilder[RoleColumnGrantsViewFields, RoleColumnGrantsViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoleColumnGrantsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepoImpl.scala new file mode 100644 index 0000000000..f8f39adcdc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_column_grants + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoleColumnGrantsViewRepoImpl extends RoleColumnGrantsViewRepo { + override def select: SelectBuilder[RoleColumnGrantsViewFields, RoleColumnGrantsViewRow] = { + SelectBuilderSql("information_schema.role_column_grants", RoleColumnGrantsViewFields, RoleColumnGrantsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoleColumnGrantsViewRow] = { + sql"""select "grantor", "grantee", "table_catalog", "table_schema", "table_name", "column_name", "privilege_type", "is_grantable" from information_schema.role_column_grants""".query(RoleColumnGrantsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRow.scala new file mode 100644 index 0000000000..585826dfa3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewRow.scala @@ -0,0 +1,93 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_column_grants + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoleColumnGrantsViewRow( + /** Points to [[column_privileges.ColumnPrivilegesViewRow.grantor]] */ + grantor: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.tableCatalog]] */ + tableCatalog: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.tableSchema]] */ + tableSchema: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.tableName]] */ + tableName: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.columnName]] */ + columnName: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.privilegeType]] */ + privilegeType: Option[/* nullability unknown */ String], + /** Points to [[column_privileges.ColumnPrivilegesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object RoleColumnGrantsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoleColumnGrantsViewRow] = new JdbcDecoder[RoleColumnGrantsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoleColumnGrantsViewRow) = + columIndex + 7 -> + RoleColumnGrantsViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoleColumnGrantsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(RoleColumnGrantsViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, tableCatalog, tableSchema, tableName, columnName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoleColumnGrantsViewRow] = new JsonEncoder[RoleColumnGrantsViewRow] { + override def unsafeEncode(a: RoleColumnGrantsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewStructure.scala new file mode 100644 index 0000000000..ac2f8487b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_column_grants/RoleColumnGrantsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_column_grants + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoleColumnGrantsViewStructure[Row](val prefix: Option[String], val extract: Row => RoleColumnGrantsViewRow, val merge: (Row, RoleColumnGrantsViewRow) => Row) + extends Relation[RoleColumnGrantsViewFields, RoleColumnGrantsViewRow, Row] + with RoleColumnGrantsViewFields[Row] { outer => + + override val grantor = new OptField[/* nullability unknown */ String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val tableCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[/* nullability unknown */ String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[/* nullability unknown */ String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[/* nullability unknown */ String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + override val privilegeType = new OptField[/* nullability unknown */ String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, tableCatalog, tableSchema, tableName, columnName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoleColumnGrantsViewRow, merge: (NewRow, RoleColumnGrantsViewRow) => NewRow): RoleColumnGrantsViewStructure[NewRow] = + new RoleColumnGrantsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewFields.scala new file mode 100644 index 0000000000..52d14542ce --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_routine_grants + +import typo.dsl.SqlExpr.OptField + +trait RoleRoutineGrantsViewFields[Row] { + val grantor: OptField[/* nullability unknown */ String, Row] + val grantee: OptField[/* nullability unknown */ String, Row] + val specificCatalog: OptField[/* nullability unknown */ String, Row] + val specificSchema: OptField[/* nullability unknown */ String, Row] + val specificName: OptField[/* nullability unknown */ String, Row] + val routineCatalog: OptField[/* nullability unknown */ String, Row] + val routineSchema: OptField[/* nullability unknown */ String, Row] + val routineName: OptField[/* nullability unknown */ String, Row] + val privilegeType: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object RoleRoutineGrantsViewFields extends RoleRoutineGrantsViewStructure[RoleRoutineGrantsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepo.scala new file mode 100644 index 0000000000..2cc530fae3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_routine_grants + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoleRoutineGrantsViewRepo { + def select: SelectBuilder[RoleRoutineGrantsViewFields, RoleRoutineGrantsViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoleRoutineGrantsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepoImpl.scala new file mode 100644 index 0000000000..22ecb50375 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_routine_grants + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoleRoutineGrantsViewRepoImpl extends RoleRoutineGrantsViewRepo { + override def select: SelectBuilder[RoleRoutineGrantsViewFields, RoleRoutineGrantsViewRow] = { + SelectBuilderSql("information_schema.role_routine_grants", RoleRoutineGrantsViewFields, RoleRoutineGrantsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoleRoutineGrantsViewRow] = { + sql"""select "grantor", "grantee", "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "privilege_type", "is_grantable" from information_schema.role_routine_grants""".query(RoleRoutineGrantsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRow.scala new file mode 100644 index 0000000000..e1b14ce2cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewRow.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_routine_grants + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoleRoutineGrantsViewRow( + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.grantor]] */ + grantor: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.specificCatalog]] */ + specificCatalog: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.specificSchema]] */ + specificSchema: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.specificName]] */ + specificName: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.routineCatalog]] */ + routineCatalog: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.routineSchema]] */ + routineSchema: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.routineName]] */ + routineName: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.privilegeType]] */ + privilegeType: Option[/* nullability unknown */ String], + /** Points to [[routine_privileges.RoutinePrivilegesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object RoleRoutineGrantsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoleRoutineGrantsViewRow] = new JdbcDecoder[RoleRoutineGrantsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoleRoutineGrantsViewRow) = + columIndex + 9 -> + RoleRoutineGrantsViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoleRoutineGrantsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(RoleRoutineGrantsViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoleRoutineGrantsViewRow] = new JsonEncoder[RoleRoutineGrantsViewRow] { + override def unsafeEncode(a: RoleRoutineGrantsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewStructure.scala new file mode 100644 index 0000000000..2621f269f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_routine_grants/RoleRoutineGrantsViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_routine_grants + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoleRoutineGrantsViewStructure[Row](val prefix: Option[String], val extract: Row => RoleRoutineGrantsViewRow, val merge: (Row, RoleRoutineGrantsViewRow) => Row) + extends Relation[RoleRoutineGrantsViewFields, RoleRoutineGrantsViewRow, Row] + with RoleRoutineGrantsViewFields[Row] { outer => + + override val grantor = new OptField[/* nullability unknown */ String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val specificCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[/* nullability unknown */ String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[/* nullability unknown */ String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[/* nullability unknown */ String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[/* nullability unknown */ String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val privilegeType = new OptField[/* nullability unknown */ String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoleRoutineGrantsViewRow, merge: (NewRow, RoleRoutineGrantsViewRow) => NewRow): RoleRoutineGrantsViewStructure[NewRow] = + new RoleRoutineGrantsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewFields.scala new file mode 100644 index 0000000000..c084f61146 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_table_grants + +import typo.dsl.SqlExpr.OptField + +trait RoleTableGrantsViewFields[Row] { + val grantor: OptField[/* nullability unknown */ String, Row] + val grantee: OptField[/* nullability unknown */ String, Row] + val tableCatalog: OptField[/* nullability unknown */ String, Row] + val tableSchema: OptField[/* nullability unknown */ String, Row] + val tableName: OptField[/* nullability unknown */ String, Row] + val privilegeType: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] + val withHierarchy: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object RoleTableGrantsViewFields extends RoleTableGrantsViewStructure[RoleTableGrantsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepo.scala new file mode 100644 index 0000000000..e481e3cb77 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_table_grants + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoleTableGrantsViewRepo { + def select: SelectBuilder[RoleTableGrantsViewFields, RoleTableGrantsViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoleTableGrantsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepoImpl.scala new file mode 100644 index 0000000000..08626c4b5e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_table_grants + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoleTableGrantsViewRepoImpl extends RoleTableGrantsViewRepo { + override def select: SelectBuilder[RoleTableGrantsViewFields, RoleTableGrantsViewRow] = { + SelectBuilderSql("information_schema.role_table_grants", RoleTableGrantsViewFields, RoleTableGrantsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoleTableGrantsViewRow] = { + sql"""select "grantor", "grantee", "table_catalog", "table_schema", "table_name", "privilege_type", "is_grantable", "with_hierarchy" from information_schema.role_table_grants""".query(RoleTableGrantsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRow.scala new file mode 100644 index 0000000000..458c9d30d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewRow.scala @@ -0,0 +1,93 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_table_grants + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoleTableGrantsViewRow( + /** Points to [[table_privileges.TablePrivilegesViewRow.grantor]] */ + grantor: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.tableCatalog]] */ + tableCatalog: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.tableSchema]] */ + tableSchema: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.tableName]] */ + tableName: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.privilegeType]] */ + privilegeType: Option[/* nullability unknown */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String], + /** Points to [[table_privileges.TablePrivilegesViewRow.withHierarchy]] */ + withHierarchy: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object RoleTableGrantsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoleTableGrantsViewRow] = new JdbcDecoder[RoleTableGrantsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoleTableGrantsViewRow) = + columIndex + 7 -> + RoleTableGrantsViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + withHierarchy = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoleTableGrantsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val withHierarchy = jsonObj.get("with_hierarchy").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && privilegeType.isRight && isGrantable.isRight && withHierarchy.isRight) + Right(RoleTableGrantsViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get, withHierarchy = withHierarchy.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, tableCatalog, tableSchema, tableName, privilegeType, isGrantable, withHierarchy).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoleTableGrantsViewRow] = new JsonEncoder[RoleTableGrantsViewRow] { + override def unsafeEncode(a: RoleTableGrantsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write(",") + out.write(""""with_hierarchy":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.withHierarchy, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewStructure.scala new file mode 100644 index 0000000000..a62d7aa282 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_table_grants/RoleTableGrantsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_table_grants + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoleTableGrantsViewStructure[Row](val prefix: Option[String], val extract: Row => RoleTableGrantsViewRow, val merge: (Row, RoleTableGrantsViewRow) => Row) + extends Relation[RoleTableGrantsViewFields, RoleTableGrantsViewRow, Row] + with RoleTableGrantsViewFields[Row] { outer => + + override val grantor = new OptField[/* nullability unknown */ String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val tableCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[/* nullability unknown */ String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[/* nullability unknown */ String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val privilegeType = new OptField[/* nullability unknown */ String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + override val withHierarchy = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "with_hierarchy", None, None)(x => extract(x).withHierarchy, (row, value) => merge(row, extract(row).copy(withHierarchy = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, tableCatalog, tableSchema, tableName, privilegeType, isGrantable, withHierarchy) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoleTableGrantsViewRow, merge: (NewRow, RoleTableGrantsViewRow) => NewRow): RoleTableGrantsViewStructure[NewRow] = + new RoleTableGrantsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewFields.scala new file mode 100644 index 0000000000..55c4cb38c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_udt_grants + +import typo.dsl.SqlExpr.OptField + +trait RoleUdtGrantsViewFields[Row] { + val grantor: OptField[/* nullability unknown */ String, Row] + val grantee: OptField[/* nullability unknown */ String, Row] + val udtCatalog: OptField[/* nullability unknown */ String, Row] + val udtSchema: OptField[/* nullability unknown */ String, Row] + val udtName: OptField[/* nullability unknown */ String, Row] + val privilegeType: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object RoleUdtGrantsViewFields extends RoleUdtGrantsViewStructure[RoleUdtGrantsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepo.scala new file mode 100644 index 0000000000..b03803c084 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_udt_grants + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoleUdtGrantsViewRepo { + def select: SelectBuilder[RoleUdtGrantsViewFields, RoleUdtGrantsViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoleUdtGrantsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepoImpl.scala new file mode 100644 index 0000000000..e02e9ba2fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_udt_grants + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoleUdtGrantsViewRepoImpl extends RoleUdtGrantsViewRepo { + override def select: SelectBuilder[RoleUdtGrantsViewFields, RoleUdtGrantsViewRow] = { + SelectBuilderSql("information_schema.role_udt_grants", RoleUdtGrantsViewFields, RoleUdtGrantsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoleUdtGrantsViewRow] = { + sql"""select "grantor", "grantee", "udt_catalog", "udt_schema", "udt_name", "privilege_type", "is_grantable" from information_schema.role_udt_grants""".query(RoleUdtGrantsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRow.scala new file mode 100644 index 0000000000..30f4c2144f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_udt_grants + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoleUdtGrantsViewRow( + /** Points to [[udt_privileges.UdtPrivilegesViewRow.grantor]] */ + grantor: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.udtCatalog]] */ + udtCatalog: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.udtSchema]] */ + udtSchema: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.udtName]] */ + udtName: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.privilegeType]] */ + privilegeType: Option[/* nullability unknown */ String], + /** Points to [[udt_privileges.UdtPrivilegesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object RoleUdtGrantsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoleUdtGrantsViewRow] = new JdbcDecoder[RoleUdtGrantsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoleUdtGrantsViewRow) = + columIndex + 6 -> + RoleUdtGrantsViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoleUdtGrantsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(RoleUdtGrantsViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, udtCatalog, udtSchema, udtName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoleUdtGrantsViewRow] = new JsonEncoder[RoleUdtGrantsViewRow] { + override def unsafeEncode(a: RoleUdtGrantsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewStructure.scala new file mode 100644 index 0000000000..f4bfabbd5f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_udt_grants/RoleUdtGrantsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_udt_grants + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoleUdtGrantsViewStructure[Row](val prefix: Option[String], val extract: Row => RoleUdtGrantsViewRow, val merge: (Row, RoleUdtGrantsViewRow) => Row) + extends Relation[RoleUdtGrantsViewFields, RoleUdtGrantsViewRow, Row] + with RoleUdtGrantsViewFields[Row] { outer => + + override val grantor = new OptField[/* nullability unknown */ String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val udtCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[/* nullability unknown */ String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[/* nullability unknown */ String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val privilegeType = new OptField[/* nullability unknown */ String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, udtCatalog, udtSchema, udtName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoleUdtGrantsViewRow, merge: (NewRow, RoleUdtGrantsViewRow) => NewRow): RoleUdtGrantsViewStructure[NewRow] = + new RoleUdtGrantsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewFields.scala new file mode 100644 index 0000000000..7f264c1cdb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_usage_grants + +import typo.dsl.SqlExpr.OptField + +trait RoleUsageGrantsViewFields[Row] { + val grantor: OptField[/* nullability unknown */ String, Row] + val grantee: OptField[/* nullability unknown */ String, Row] + val objectCatalog: OptField[/* nullability unknown */ String, Row] + val objectSchema: OptField[/* nullability unknown */ String, Row] + val objectName: OptField[/* nullability unknown */ String, Row] + val objectType: OptField[/* nullability unknown */ String, Row] + val privilegeType: OptField[/* nullability unknown */ String, Row] + val isGrantable: OptField[/* nullability unknown */ /* max 3 chars */ String, Row] +} +object RoleUsageGrantsViewFields extends RoleUsageGrantsViewStructure[RoleUsageGrantsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepo.scala new file mode 100644 index 0000000000..7f320a0e06 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_usage_grants + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoleUsageGrantsViewRepo { + def select: SelectBuilder[RoleUsageGrantsViewFields, RoleUsageGrantsViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoleUsageGrantsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepoImpl.scala new file mode 100644 index 0000000000..3dddd055c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_usage_grants + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoleUsageGrantsViewRepoImpl extends RoleUsageGrantsViewRepo { + override def select: SelectBuilder[RoleUsageGrantsViewFields, RoleUsageGrantsViewRow] = { + SelectBuilderSql("information_schema.role_usage_grants", RoleUsageGrantsViewFields, RoleUsageGrantsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoleUsageGrantsViewRow] = { + sql"""select "grantor", "grantee", "object_catalog", "object_schema", "object_name", "object_type", "privilege_type", "is_grantable" from information_schema.role_usage_grants""".query(RoleUsageGrantsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRow.scala new file mode 100644 index 0000000000..29bfd2590d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewRow.scala @@ -0,0 +1,93 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_usage_grants + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoleUsageGrantsViewRow( + /** Points to [[usage_privileges.UsagePrivilegesViewRow.grantor]] */ + grantor: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.grantee]] */ + grantee: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.objectCatalog]] */ + objectCatalog: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.objectSchema]] */ + objectSchema: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.objectName]] */ + objectName: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.objectType]] */ + objectType: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.privilegeType]] */ + privilegeType: Option[/* nullability unknown */ String], + /** Points to [[usage_privileges.UsagePrivilegesViewRow.isGrantable]] */ + isGrantable: Option[/* nullability unknown */ /* max 3 chars */ String] +) + +object RoleUsageGrantsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoleUsageGrantsViewRow] = new JdbcDecoder[RoleUsageGrantsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoleUsageGrantsViewRow) = + columIndex + 7 -> + RoleUsageGrantsViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + objectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + objectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + objectName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + objectType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoleUsageGrantsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectCatalog = jsonObj.get("object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectSchema = jsonObj.get("object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectName = jsonObj.get("object_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectType = jsonObj.get("object_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && objectCatalog.isRight && objectSchema.isRight && objectName.isRight && objectType.isRight && privilegeType.isRight && isGrantable.isRight) + Right(RoleUsageGrantsViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, objectCatalog = objectCatalog.toOption.get, objectSchema = objectSchema.toOption.get, objectName = objectName.toOption.get, objectType = objectType.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, objectCatalog, objectSchema, objectName, objectType, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoleUsageGrantsViewRow] = new JsonEncoder[RoleUsageGrantsViewRow] { + override def unsafeEncode(a: RoleUsageGrantsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectCatalog, indent, out) + out.write(",") + out.write(""""object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectSchema, indent, out) + out.write(",") + out.write(""""object_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectName, indent, out) + out.write(",") + out.write(""""object_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectType, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewStructure.scala new file mode 100644 index 0000000000..5e56c47a4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/role_usage_grants/RoleUsageGrantsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package role_usage_grants + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoleUsageGrantsViewStructure[Row](val prefix: Option[String], val extract: Row => RoleUsageGrantsViewRow, val merge: (Row, RoleUsageGrantsViewRow) => Row) + extends Relation[RoleUsageGrantsViewFields, RoleUsageGrantsViewRow, Row] + with RoleUsageGrantsViewFields[Row] { outer => + + override val grantor = new OptField[/* nullability unknown */ String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[/* nullability unknown */ String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val objectCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "object_catalog", None, None)(x => extract(x).objectCatalog, (row, value) => merge(row, extract(row).copy(objectCatalog = value))) + override val objectSchema = new OptField[/* nullability unknown */ String, Row](prefix, "object_schema", None, None)(x => extract(x).objectSchema, (row, value) => merge(row, extract(row).copy(objectSchema = value))) + override val objectName = new OptField[/* nullability unknown */ String, Row](prefix, "object_name", None, None)(x => extract(x).objectName, (row, value) => merge(row, extract(row).copy(objectName = value))) + override val objectType = new OptField[/* nullability unknown */ String, Row](prefix, "object_type", None, None)(x => extract(x).objectType, (row, value) => merge(row, extract(row).copy(objectType = value))) + override val privilegeType = new OptField[/* nullability unknown */ String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* nullability unknown */ /* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, objectCatalog, objectSchema, objectName, objectType, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoleUsageGrantsViewRow, merge: (NewRow, RoleUsageGrantsViewRow) => NewRow): RoleUsageGrantsViewStructure[NewRow] = + new RoleUsageGrantsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewFields.scala new file mode 100644 index 0000000000..538fb79eb3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_column_usage + +import typo.dsl.SqlExpr.OptField + +trait RoutineColumnUsageViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] +} +object RoutineColumnUsageViewFields extends RoutineColumnUsageViewStructure[RoutineColumnUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepo.scala new file mode 100644 index 0000000000..c249292858 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_column_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutineColumnUsageViewRepo { + def select: SelectBuilder[RoutineColumnUsageViewFields, RoutineColumnUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutineColumnUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepoImpl.scala new file mode 100644 index 0000000000..6fe349cc5b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_column_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutineColumnUsageViewRepoImpl extends RoutineColumnUsageViewRepo { + override def select: SelectBuilder[RoutineColumnUsageViewFields, RoutineColumnUsageViewRow] = { + SelectBuilderSql("information_schema.routine_column_usage", RoutineColumnUsageViewFields, RoutineColumnUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutineColumnUsageViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "table_catalog", "table_schema", "table_name", "column_name" from information_schema.routine_column_usage""".query(RoutineColumnUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRow.scala new file mode 100644 index 0000000000..4ca4534e97 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_column_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutineColumnUsageViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String] +) + +object RoutineColumnUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutineColumnUsageViewRow] = new JdbcDecoder[RoutineColumnUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutineColumnUsageViewRow) = + columIndex + 9 -> + RoutineColumnUsageViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutineColumnUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight) + Right(RoutineColumnUsageViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, tableCatalog, tableSchema, tableName, columnName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutineColumnUsageViewRow] = new JsonEncoder[RoutineColumnUsageViewRow] { + override def unsafeEncode(a: RoutineColumnUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewStructure.scala new file mode 100644 index 0000000000..a7d3fe240b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_column_usage/RoutineColumnUsageViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_column_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutineColumnUsageViewStructure[Row](val prefix: Option[String], val extract: Row => RoutineColumnUsageViewRow, val merge: (Row, RoutineColumnUsageViewRow) => Row) + extends Relation[RoutineColumnUsageViewFields, RoutineColumnUsageViewRow, Row] + with RoutineColumnUsageViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, tableCatalog, tableSchema, tableName, columnName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutineColumnUsageViewRow, merge: (NewRow, RoutineColumnUsageViewRow) => NewRow): RoutineColumnUsageViewStructure[NewRow] = + new RoutineColumnUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewFields.scala new file mode 100644 index 0000000000..e92e75355d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_privileges + +import typo.dsl.SqlExpr.OptField + +trait RoutinePrivilegesViewFields[Row] { + val grantor: OptField[String, Row] + val grantee: OptField[String, Row] + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] + val privilegeType: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] +} +object RoutinePrivilegesViewFields extends RoutinePrivilegesViewStructure[RoutinePrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepo.scala new file mode 100644 index 0000000000..ebcabc0529 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutinePrivilegesViewRepo { + def select: SelectBuilder[RoutinePrivilegesViewFields, RoutinePrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutinePrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..9145774e2f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutinePrivilegesViewRepoImpl extends RoutinePrivilegesViewRepo { + override def select: SelectBuilder[RoutinePrivilegesViewFields, RoutinePrivilegesViewRow] = { + SelectBuilderSql("information_schema.routine_privileges", RoutinePrivilegesViewFields, RoutinePrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutinePrivilegesViewRow] = { + sql"""select "grantor", "grantee", "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "privilege_type", "is_grantable" from information_schema.routine_privileges""".query(RoutinePrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRow.scala new file mode 100644 index 0000000000..4ae501016c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutinePrivilegesViewRow( + grantor: /* nullability unknown */ Option[String], + grantee: /* nullability unknown */ Option[String], + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String], + privilegeType: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object RoutinePrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutinePrivilegesViewRow] = new JdbcDecoder[RoutinePrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutinePrivilegesViewRow) = + columIndex + 9 -> + RoutinePrivilegesViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutinePrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(RoutinePrivilegesViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutinePrivilegesViewRow] = new JsonEncoder[RoutinePrivilegesViewRow] { + override def unsafeEncode(a: RoutinePrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewStructure.scala new file mode 100644 index 0000000000..6b4008cede --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_privileges/RoutinePrivilegesViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutinePrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => RoutinePrivilegesViewRow, val merge: (Row, RoutinePrivilegesViewRow) => Row) + extends Relation[RoutinePrivilegesViewFields, RoutinePrivilegesViewRow, Row] + with RoutinePrivilegesViewFields[Row] { outer => + + override val grantor = new OptField[String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val privilegeType = new OptField[String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutinePrivilegesViewRow, merge: (NewRow, RoutinePrivilegesViewRow) => NewRow): RoutinePrivilegesViewStructure[NewRow] = + new RoutinePrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewFields.scala new file mode 100644 index 0000000000..69f04d9ddd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_routine_usage + +import typo.dsl.SqlExpr.OptField + +trait RoutineRoutineUsageViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] +} +object RoutineRoutineUsageViewFields extends RoutineRoutineUsageViewStructure[RoutineRoutineUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepo.scala new file mode 100644 index 0000000000..c9d4ea6cf0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_routine_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutineRoutineUsageViewRepo { + def select: SelectBuilder[RoutineRoutineUsageViewFields, RoutineRoutineUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutineRoutineUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepoImpl.scala new file mode 100644 index 0000000000..699519b0f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_routine_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutineRoutineUsageViewRepoImpl extends RoutineRoutineUsageViewRepo { + override def select: SelectBuilder[RoutineRoutineUsageViewFields, RoutineRoutineUsageViewRow] = { + SelectBuilderSql("information_schema.routine_routine_usage", RoutineRoutineUsageViewFields, RoutineRoutineUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutineRoutineUsageViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name" from information_schema.routine_routine_usage""".query(RoutineRoutineUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRow.scala new file mode 100644 index 0000000000..3845266e3f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_routine_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutineRoutineUsageViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String] +) + +object RoutineRoutineUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutineRoutineUsageViewRow] = new JdbcDecoder[RoutineRoutineUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutineRoutineUsageViewRow) = + columIndex + 5 -> + RoutineRoutineUsageViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutineRoutineUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight) + Right(RoutineRoutineUsageViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutineRoutineUsageViewRow] = new JsonEncoder[RoutineRoutineUsageViewRow] { + override def unsafeEncode(a: RoutineRoutineUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewStructure.scala new file mode 100644 index 0000000000..bf53ab1885 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_routine_usage/RoutineRoutineUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_routine_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutineRoutineUsageViewStructure[Row](val prefix: Option[String], val extract: Row => RoutineRoutineUsageViewRow, val merge: (Row, RoutineRoutineUsageViewRow) => Row) + extends Relation[RoutineRoutineUsageViewFields, RoutineRoutineUsageViewRow, Row] + with RoutineRoutineUsageViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutineRoutineUsageViewRow, merge: (NewRow, RoutineRoutineUsageViewRow) => NewRow): RoutineRoutineUsageViewStructure[NewRow] = + new RoutineRoutineUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewFields.scala new file mode 100644 index 0000000000..aa7e081d51 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_sequence_usage + +import typo.dsl.SqlExpr.OptField + +trait RoutineSequenceUsageViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] + val sequenceCatalog: OptField[String, Row] + val sequenceSchema: OptField[String, Row] + val sequenceName: OptField[String, Row] +} +object RoutineSequenceUsageViewFields extends RoutineSequenceUsageViewStructure[RoutineSequenceUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepo.scala new file mode 100644 index 0000000000..cc415f0001 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_sequence_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutineSequenceUsageViewRepo { + def select: SelectBuilder[RoutineSequenceUsageViewFields, RoutineSequenceUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutineSequenceUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepoImpl.scala new file mode 100644 index 0000000000..1bcd7d8c18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_sequence_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutineSequenceUsageViewRepoImpl extends RoutineSequenceUsageViewRepo { + override def select: SelectBuilder[RoutineSequenceUsageViewFields, RoutineSequenceUsageViewRow] = { + SelectBuilderSql("information_schema.routine_sequence_usage", RoutineSequenceUsageViewFields, RoutineSequenceUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutineSequenceUsageViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "sequence_catalog", "sequence_schema", "sequence_name" from information_schema.routine_sequence_usage""".query(RoutineSequenceUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRow.scala new file mode 100644 index 0000000000..b10e7484ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_sequence_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutineSequenceUsageViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String], + sequenceCatalog: /* nullability unknown */ Option[String], + sequenceSchema: /* nullability unknown */ Option[String], + sequenceName: /* nullability unknown */ Option[String] +) + +object RoutineSequenceUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutineSequenceUsageViewRow] = new JdbcDecoder[RoutineSequenceUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutineSequenceUsageViewRow) = + columIndex + 8 -> + RoutineSequenceUsageViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + sequenceCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + sequenceSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + sequenceName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutineSequenceUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sequenceCatalog = jsonObj.get("sequence_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sequenceSchema = jsonObj.get("sequence_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sequenceName = jsonObj.get("sequence_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && sequenceCatalog.isRight && sequenceSchema.isRight && sequenceName.isRight) + Right(RoutineSequenceUsageViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, sequenceCatalog = sequenceCatalog.toOption.get, sequenceSchema = sequenceSchema.toOption.get, sequenceName = sequenceName.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, sequenceCatalog, sequenceSchema, sequenceName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutineSequenceUsageViewRow] = new JsonEncoder[RoutineSequenceUsageViewRow] { + override def unsafeEncode(a: RoutineSequenceUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""sequence_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceCatalog, indent, out) + out.write(",") + out.write(""""sequence_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceSchema, indent, out) + out.write(",") + out.write(""""sequence_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewStructure.scala new file mode 100644 index 0000000000..1652829492 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_sequence_usage/RoutineSequenceUsageViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_sequence_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutineSequenceUsageViewStructure[Row](val prefix: Option[String], val extract: Row => RoutineSequenceUsageViewRow, val merge: (Row, RoutineSequenceUsageViewRow) => Row) + extends Relation[RoutineSequenceUsageViewFields, RoutineSequenceUsageViewRow, Row] + with RoutineSequenceUsageViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val sequenceCatalog = new OptField[String, Row](prefix, "sequence_catalog", None, None)(x => extract(x).sequenceCatalog, (row, value) => merge(row, extract(row).copy(sequenceCatalog = value))) + override val sequenceSchema = new OptField[String, Row](prefix, "sequence_schema", None, None)(x => extract(x).sequenceSchema, (row, value) => merge(row, extract(row).copy(sequenceSchema = value))) + override val sequenceName = new OptField[String, Row](prefix, "sequence_name", None, None)(x => extract(x).sequenceName, (row, value) => merge(row, extract(row).copy(sequenceName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, sequenceCatalog, sequenceSchema, sequenceName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutineSequenceUsageViewRow, merge: (NewRow, RoutineSequenceUsageViewRow) => NewRow): RoutineSequenceUsageViewStructure[NewRow] = + new RoutineSequenceUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewFields.scala new file mode 100644 index 0000000000..ca8ee4712e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_table_usage + +import typo.dsl.SqlExpr.OptField + +trait RoutineTableUsageViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] +} +object RoutineTableUsageViewFields extends RoutineTableUsageViewStructure[RoutineTableUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepo.scala new file mode 100644 index 0000000000..3eaa1ef082 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_table_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutineTableUsageViewRepo { + def select: SelectBuilder[RoutineTableUsageViewFields, RoutineTableUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutineTableUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepoImpl.scala new file mode 100644 index 0000000000..5316f44742 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_table_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutineTableUsageViewRepoImpl extends RoutineTableUsageViewRepo { + override def select: SelectBuilder[RoutineTableUsageViewFields, RoutineTableUsageViewRow] = { + SelectBuilderSql("information_schema.routine_table_usage", RoutineTableUsageViewFields, RoutineTableUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutineTableUsageViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "table_catalog", "table_schema", "table_name" from information_schema.routine_table_usage""".query(RoutineTableUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRow.scala new file mode 100644 index 0000000000..4b995703ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_table_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutineTableUsageViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String] +) + +object RoutineTableUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutineTableUsageViewRow] = new JdbcDecoder[RoutineTableUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutineTableUsageViewRow) = + columIndex + 8 -> + RoutineTableUsageViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutineTableUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight) + Right(RoutineTableUsageViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, tableCatalog, tableSchema, tableName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutineTableUsageViewRow] = new JsonEncoder[RoutineTableUsageViewRow] { + override def unsafeEncode(a: RoutineTableUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewStructure.scala new file mode 100644 index 0000000000..8e82fa6217 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routine_table_usage/RoutineTableUsageViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routine_table_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutineTableUsageViewStructure[Row](val prefix: Option[String], val extract: Row => RoutineTableUsageViewRow, val merge: (Row, RoutineTableUsageViewRow) => Row) + extends Relation[RoutineTableUsageViewFields, RoutineTableUsageViewRow, Row] + with RoutineTableUsageViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, tableCatalog, tableSchema, tableName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutineTableUsageViewRow, merge: (NewRow, RoutineTableUsageViewRow) => NewRow): RoutineTableUsageViewStructure[NewRow] = + new RoutineTableUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewFields.scala new file mode 100644 index 0000000000..fb37cd1cc0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewFields.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routines + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait RoutinesViewFields[Row] { + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val routineCatalog: OptField[String, Row] + val routineSchema: OptField[String, Row] + val routineName: OptField[String, Row] + val routineType: OptField[String, Row] + val moduleCatalog: OptField[String, Row] + val moduleSchema: OptField[String, Row] + val moduleName: OptField[String, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val typeUdtCatalog: OptField[String, Row] + val typeUdtSchema: OptField[String, Row] + val typeUdtName: OptField[String, Row] + val scopeCatalog: OptField[String, Row] + val scopeSchema: OptField[String, Row] + val scopeName: OptField[String, Row] + val maximumCardinality: OptField[Int, Row] + val dtdIdentifier: OptField[String, Row] + val routineBody: OptField[String, Row] + val routineDefinition: OptField[String, Row] + val externalName: OptField[String, Row] + val externalLanguage: OptField[String, Row] + val parameterStyle: OptField[String, Row] + val isDeterministic: OptField[/* max 3 chars */ String, Row] + val sqlDataAccess: OptField[String, Row] + val isNullCall: OptField[/* max 3 chars */ String, Row] + val sqlPath: OptField[String, Row] + val schemaLevelRoutine: OptField[/* max 3 chars */ String, Row] + val maxDynamicResultSets: OptField[Int, Row] + val isUserDefinedCast: OptField[/* max 3 chars */ String, Row] + val isImplicitlyInvocable: OptField[/* max 3 chars */ String, Row] + val securityType: OptField[String, Row] + val toSqlSpecificCatalog: OptField[String, Row] + val toSqlSpecificSchema: OptField[String, Row] + val toSqlSpecificName: OptField[String, Row] + val asLocator: OptField[/* max 3 chars */ String, Row] + val created: OptField[TypoInstant, Row] + val lastAltered: OptField[TypoInstant, Row] + val newSavepointLevel: OptField[/* max 3 chars */ String, Row] + val isUdtDependent: OptField[/* max 3 chars */ String, Row] + val resultCastFromDataType: OptField[String, Row] + val resultCastAsLocator: OptField[/* max 3 chars */ String, Row] + val resultCastCharMaxLength: OptField[Int, Row] + val resultCastCharOctetLength: OptField[Int, Row] + val resultCastCharSetCatalog: OptField[String, Row] + val resultCastCharSetSchema: OptField[String, Row] + val resultCastCharSetName: OptField[String, Row] + val resultCastCollationCatalog: OptField[String, Row] + val resultCastCollationSchema: OptField[String, Row] + val resultCastCollationName: OptField[String, Row] + val resultCastNumericPrecision: OptField[Int, Row] + val resultCastNumericPrecisionRadix: OptField[Int, Row] + val resultCastNumericScale: OptField[Int, Row] + val resultCastDatetimePrecision: OptField[Int, Row] + val resultCastIntervalType: OptField[String, Row] + val resultCastIntervalPrecision: OptField[Int, Row] + val resultCastTypeUdtCatalog: OptField[String, Row] + val resultCastTypeUdtSchema: OptField[String, Row] + val resultCastTypeUdtName: OptField[String, Row] + val resultCastScopeCatalog: OptField[String, Row] + val resultCastScopeSchema: OptField[String, Row] + val resultCastScopeName: OptField[String, Row] + val resultCastMaximumCardinality: OptField[Int, Row] + val resultCastDtdIdentifier: OptField[String, Row] +} +object RoutinesViewFields extends RoutinesViewStructure[RoutinesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepo.scala new file mode 100644 index 0000000000..38cc5161f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routines + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait RoutinesViewRepo { + def select: SelectBuilder[RoutinesViewFields, RoutinesViewRow] + def selectAll: ZStream[ZConnection, Throwable, RoutinesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepoImpl.scala new file mode 100644 index 0000000000..dfa15c2df0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routines + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object RoutinesViewRepoImpl extends RoutinesViewRepo { + override def select: SelectBuilder[RoutinesViewFields, RoutinesViewRow] = { + SelectBuilderSql("information_schema.routines", RoutinesViewFields, RoutinesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, RoutinesViewRow] = { + sql"""select "specific_catalog", "specific_schema", "specific_name", "routine_catalog", "routine_schema", "routine_name", "routine_type", "module_catalog", "module_schema", "module_name", "udt_catalog", "udt_schema", "udt_name", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "type_udt_catalog", "type_udt_schema", "type_udt_name", "scope_catalog", "scope_schema", "scope_name", "maximum_cardinality", "dtd_identifier", "routine_body", "routine_definition", "external_name", "external_language", "parameter_style", "is_deterministic", "sql_data_access", "is_null_call", "sql_path", "schema_level_routine", "max_dynamic_result_sets", "is_user_defined_cast", "is_implicitly_invocable", "security_type", "to_sql_specific_catalog", "to_sql_specific_schema", "to_sql_specific_name", "as_locator", "created"::text, "last_altered"::text, "new_savepoint_level", "is_udt_dependent", "result_cast_from_data_type", "result_cast_as_locator", "result_cast_char_max_length", "result_cast_char_octet_length", "result_cast_char_set_catalog", "result_cast_char_set_schema", "result_cast_char_set_name", "result_cast_collation_catalog", "result_cast_collation_schema", "result_cast_collation_name", "result_cast_numeric_precision", "result_cast_numeric_precision_radix", "result_cast_numeric_scale", "result_cast_datetime_precision", "result_cast_interval_type", "result_cast_interval_precision", "result_cast_type_udt_catalog", "result_cast_type_udt_schema", "result_cast_type_udt_name", "result_cast_scope_catalog", "result_cast_scope_schema", "result_cast_scope_name", "result_cast_maximum_cardinality", "result_cast_dtd_identifier" from information_schema.routines""".query(RoutinesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRow.scala new file mode 100644 index 0000000000..f8d4f61ca2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewRow.scala @@ -0,0 +1,530 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routines + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class RoutinesViewRow( + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + routineCatalog: /* nullability unknown */ Option[String], + routineSchema: /* nullability unknown */ Option[String], + routineName: /* nullability unknown */ Option[String], + routineType: /* nullability unknown */ Option[String], + moduleCatalog: /* nullability unknown */ Option[String], + moduleSchema: /* nullability unknown */ Option[String], + moduleName: /* nullability unknown */ Option[String], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + typeUdtCatalog: /* nullability unknown */ Option[String], + typeUdtSchema: /* nullability unknown */ Option[String], + typeUdtName: /* nullability unknown */ Option[String], + scopeCatalog: /* nullability unknown */ Option[String], + scopeSchema: /* nullability unknown */ Option[String], + scopeName: /* nullability unknown */ Option[String], + maximumCardinality: /* nullability unknown */ Option[Int], + dtdIdentifier: /* nullability unknown */ Option[String], + routineBody: /* nullability unknown */ Option[String], + routineDefinition: /* nullability unknown */ Option[String], + externalName: /* nullability unknown */ Option[String], + externalLanguage: /* nullability unknown */ Option[String], + parameterStyle: /* nullability unknown */ Option[String], + isDeterministic: /* nullability unknown */ Option[/* max 3 chars */ String], + sqlDataAccess: /* nullability unknown */ Option[String], + isNullCall: /* nullability unknown */ Option[/* max 3 chars */ String], + sqlPath: /* nullability unknown */ Option[String], + schemaLevelRoutine: /* nullability unknown */ Option[/* max 3 chars */ String], + maxDynamicResultSets: /* nullability unknown */ Option[Int], + isUserDefinedCast: /* nullability unknown */ Option[/* max 3 chars */ String], + isImplicitlyInvocable: /* nullability unknown */ Option[/* max 3 chars */ String], + securityType: /* nullability unknown */ Option[String], + toSqlSpecificCatalog: /* nullability unknown */ Option[String], + toSqlSpecificSchema: /* nullability unknown */ Option[String], + toSqlSpecificName: /* nullability unknown */ Option[String], + asLocator: /* nullability unknown */ Option[/* max 3 chars */ String], + created: /* nullability unknown */ Option[TypoInstant], + lastAltered: /* nullability unknown */ Option[TypoInstant], + newSavepointLevel: /* nullability unknown */ Option[/* max 3 chars */ String], + isUdtDependent: /* nullability unknown */ Option[/* max 3 chars */ String], + resultCastFromDataType: /* nullability unknown */ Option[String], + resultCastAsLocator: /* nullability unknown */ Option[/* max 3 chars */ String], + resultCastCharMaxLength: /* nullability unknown */ Option[Int], + resultCastCharOctetLength: /* nullability unknown */ Option[Int], + resultCastCharSetCatalog: /* nullability unknown */ Option[String], + resultCastCharSetSchema: /* nullability unknown */ Option[String], + resultCastCharSetName: /* nullability unknown */ Option[String], + resultCastCollationCatalog: /* nullability unknown */ Option[String], + resultCastCollationSchema: /* nullability unknown */ Option[String], + resultCastCollationName: /* nullability unknown */ Option[String], + resultCastNumericPrecision: /* nullability unknown */ Option[Int], + resultCastNumericPrecisionRadix: /* nullability unknown */ Option[Int], + resultCastNumericScale: /* nullability unknown */ Option[Int], + resultCastDatetimePrecision: /* nullability unknown */ Option[Int], + resultCastIntervalType: /* nullability unknown */ Option[String], + resultCastIntervalPrecision: /* nullability unknown */ Option[Int], + resultCastTypeUdtCatalog: /* nullability unknown */ Option[String], + resultCastTypeUdtSchema: /* nullability unknown */ Option[String], + resultCastTypeUdtName: /* nullability unknown */ Option[String], + resultCastScopeCatalog: /* nullability unknown */ Option[String], + resultCastScopeSchema: /* nullability unknown */ Option[String], + resultCastScopeName: /* nullability unknown */ Option[String], + resultCastMaximumCardinality: /* nullability unknown */ Option[Int], + resultCastDtdIdentifier: /* nullability unknown */ Option[String] +) + +object RoutinesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[RoutinesViewRow] = new JdbcDecoder[RoutinesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, RoutinesViewRow) = + columIndex + 81 -> + RoutinesViewRow( + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + routineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + routineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + routineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + routineType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + moduleCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + moduleSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + moduleName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 14, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 15, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 19, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 22, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 23, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 24, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 25, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 27, rs)._2, + typeUdtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2, + typeUdtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 29, rs)._2, + typeUdtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 30, rs)._2, + scopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 31, rs)._2, + scopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 32, rs)._2, + scopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 33, rs)._2, + maximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 34, rs)._2, + dtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 35, rs)._2, + routineBody = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 36, rs)._2, + routineDefinition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 37, rs)._2, + externalName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 38, rs)._2, + externalLanguage = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 39, rs)._2, + parameterStyle = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 40, rs)._2, + isDeterministic = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 41, rs)._2, + sqlDataAccess = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 42, rs)._2, + isNullCall = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 43, rs)._2, + sqlPath = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 44, rs)._2, + schemaLevelRoutine = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 45, rs)._2, + maxDynamicResultSets = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 46, rs)._2, + isUserDefinedCast = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 47, rs)._2, + isImplicitlyInvocable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 48, rs)._2, + securityType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 49, rs)._2, + toSqlSpecificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 50, rs)._2, + toSqlSpecificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 51, rs)._2, + toSqlSpecificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 52, rs)._2, + asLocator = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 53, rs)._2, + created = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 54, rs)._2, + lastAltered = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 55, rs)._2, + newSavepointLevel = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 56, rs)._2, + isUdtDependent = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 57, rs)._2, + resultCastFromDataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 58, rs)._2, + resultCastAsLocator = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 59, rs)._2, + resultCastCharMaxLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 60, rs)._2, + resultCastCharOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 61, rs)._2, + resultCastCharSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 62, rs)._2, + resultCastCharSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 63, rs)._2, + resultCastCharSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 64, rs)._2, + resultCastCollationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 65, rs)._2, + resultCastCollationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 66, rs)._2, + resultCastCollationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 67, rs)._2, + resultCastNumericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 68, rs)._2, + resultCastNumericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 69, rs)._2, + resultCastNumericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 70, rs)._2, + resultCastDatetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 71, rs)._2, + resultCastIntervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 72, rs)._2, + resultCastIntervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 73, rs)._2, + resultCastTypeUdtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 74, rs)._2, + resultCastTypeUdtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 75, rs)._2, + resultCastTypeUdtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 76, rs)._2, + resultCastScopeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 77, rs)._2, + resultCastScopeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 78, rs)._2, + resultCastScopeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 79, rs)._2, + resultCastMaximumCardinality = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 80, rs)._2, + resultCastDtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 81, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[RoutinesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineCatalog = jsonObj.get("routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineSchema = jsonObj.get("routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineName = jsonObj.get("routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineType = jsonObj.get("routine_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val moduleCatalog = jsonObj.get("module_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val moduleSchema = jsonObj.get("module_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val moduleName = jsonObj.get("module_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val typeUdtCatalog = jsonObj.get("type_udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val typeUdtSchema = jsonObj.get("type_udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val typeUdtName = jsonObj.get("type_udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeCatalog = jsonObj.get("scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeSchema = jsonObj.get("scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val scopeName = jsonObj.get("scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumCardinality = jsonObj.get("maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val dtdIdentifier = jsonObj.get("dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineBody = jsonObj.get("routine_body").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val routineDefinition = jsonObj.get("routine_definition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val externalName = jsonObj.get("external_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val externalLanguage = jsonObj.get("external_language").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val parameterStyle = jsonObj.get("parameter_style").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isDeterministic = jsonObj.get("is_deterministic").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sqlDataAccess = jsonObj.get("sql_data_access").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isNullCall = jsonObj.get("is_null_call").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sqlPath = jsonObj.get("sql_path").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val schemaLevelRoutine = jsonObj.get("schema_level_routine").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maxDynamicResultSets = jsonObj.get("max_dynamic_result_sets").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val isUserDefinedCast = jsonObj.get("is_user_defined_cast").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isImplicitlyInvocable = jsonObj.get("is_implicitly_invocable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val securityType = jsonObj.get("security_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val toSqlSpecificCatalog = jsonObj.get("to_sql_specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val toSqlSpecificSchema = jsonObj.get("to_sql_specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val toSqlSpecificName = jsonObj.get("to_sql_specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val asLocator = jsonObj.get("as_locator").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val created = jsonObj.get("created").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAltered = jsonObj.get("last_altered").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val newSavepointLevel = jsonObj.get("new_savepoint_level").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isUdtDependent = jsonObj.get("is_udt_dependent").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastFromDataType = jsonObj.get("result_cast_from_data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastAsLocator = jsonObj.get("result_cast_as_locator").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCharMaxLength = jsonObj.get("result_cast_char_max_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastCharOctetLength = jsonObj.get("result_cast_char_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastCharSetCatalog = jsonObj.get("result_cast_char_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCharSetSchema = jsonObj.get("result_cast_char_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCharSetName = jsonObj.get("result_cast_char_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCollationCatalog = jsonObj.get("result_cast_collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCollationSchema = jsonObj.get("result_cast_collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastCollationName = jsonObj.get("result_cast_collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastNumericPrecision = jsonObj.get("result_cast_numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastNumericPrecisionRadix = jsonObj.get("result_cast_numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastNumericScale = jsonObj.get("result_cast_numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastDatetimePrecision = jsonObj.get("result_cast_datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastIntervalType = jsonObj.get("result_cast_interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastIntervalPrecision = jsonObj.get("result_cast_interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastTypeUdtCatalog = jsonObj.get("result_cast_type_udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastTypeUdtSchema = jsonObj.get("result_cast_type_udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastTypeUdtName = jsonObj.get("result_cast_type_udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastScopeCatalog = jsonObj.get("result_cast_scope_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastScopeSchema = jsonObj.get("result_cast_scope_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastScopeName = jsonObj.get("result_cast_scope_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resultCastMaximumCardinality = jsonObj.get("result_cast_maximum_cardinality").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val resultCastDtdIdentifier = jsonObj.get("result_cast_dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (specificCatalog.isRight && specificSchema.isRight && specificName.isRight && routineCatalog.isRight && routineSchema.isRight && routineName.isRight && routineType.isRight && moduleCatalog.isRight && moduleSchema.isRight && moduleName.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && typeUdtCatalog.isRight && typeUdtSchema.isRight && typeUdtName.isRight && scopeCatalog.isRight && scopeSchema.isRight && scopeName.isRight && maximumCardinality.isRight && dtdIdentifier.isRight && routineBody.isRight && routineDefinition.isRight && externalName.isRight && externalLanguage.isRight && parameterStyle.isRight && isDeterministic.isRight && sqlDataAccess.isRight && isNullCall.isRight && sqlPath.isRight && schemaLevelRoutine.isRight && maxDynamicResultSets.isRight && isUserDefinedCast.isRight && isImplicitlyInvocable.isRight && securityType.isRight && toSqlSpecificCatalog.isRight && toSqlSpecificSchema.isRight && toSqlSpecificName.isRight && asLocator.isRight && created.isRight && lastAltered.isRight && newSavepointLevel.isRight && isUdtDependent.isRight && resultCastFromDataType.isRight && resultCastAsLocator.isRight && resultCastCharMaxLength.isRight && resultCastCharOctetLength.isRight && resultCastCharSetCatalog.isRight && resultCastCharSetSchema.isRight && resultCastCharSetName.isRight && resultCastCollationCatalog.isRight && resultCastCollationSchema.isRight && resultCastCollationName.isRight && resultCastNumericPrecision.isRight && resultCastNumericPrecisionRadix.isRight && resultCastNumericScale.isRight && resultCastDatetimePrecision.isRight && resultCastIntervalType.isRight && resultCastIntervalPrecision.isRight && resultCastTypeUdtCatalog.isRight && resultCastTypeUdtSchema.isRight && resultCastTypeUdtName.isRight && resultCastScopeCatalog.isRight && resultCastScopeSchema.isRight && resultCastScopeName.isRight && resultCastMaximumCardinality.isRight && resultCastDtdIdentifier.isRight) + Right(RoutinesViewRow(specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, routineCatalog = routineCatalog.toOption.get, routineSchema = routineSchema.toOption.get, routineName = routineName.toOption.get, routineType = routineType.toOption.get, moduleCatalog = moduleCatalog.toOption.get, moduleSchema = moduleSchema.toOption.get, moduleName = moduleName.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, typeUdtCatalog = typeUdtCatalog.toOption.get, typeUdtSchema = typeUdtSchema.toOption.get, typeUdtName = typeUdtName.toOption.get, scopeCatalog = scopeCatalog.toOption.get, scopeSchema = scopeSchema.toOption.get, scopeName = scopeName.toOption.get, maximumCardinality = maximumCardinality.toOption.get, dtdIdentifier = dtdIdentifier.toOption.get, routineBody = routineBody.toOption.get, routineDefinition = routineDefinition.toOption.get, externalName = externalName.toOption.get, externalLanguage = externalLanguage.toOption.get, parameterStyle = parameterStyle.toOption.get, isDeterministic = isDeterministic.toOption.get, sqlDataAccess = sqlDataAccess.toOption.get, isNullCall = isNullCall.toOption.get, sqlPath = sqlPath.toOption.get, schemaLevelRoutine = schemaLevelRoutine.toOption.get, maxDynamicResultSets = maxDynamicResultSets.toOption.get, isUserDefinedCast = isUserDefinedCast.toOption.get, isImplicitlyInvocable = isImplicitlyInvocable.toOption.get, securityType = securityType.toOption.get, toSqlSpecificCatalog = toSqlSpecificCatalog.toOption.get, toSqlSpecificSchema = toSqlSpecificSchema.toOption.get, toSqlSpecificName = toSqlSpecificName.toOption.get, asLocator = asLocator.toOption.get, created = created.toOption.get, lastAltered = lastAltered.toOption.get, newSavepointLevel = newSavepointLevel.toOption.get, isUdtDependent = isUdtDependent.toOption.get, resultCastFromDataType = resultCastFromDataType.toOption.get, resultCastAsLocator = resultCastAsLocator.toOption.get, resultCastCharMaxLength = resultCastCharMaxLength.toOption.get, resultCastCharOctetLength = resultCastCharOctetLength.toOption.get, resultCastCharSetCatalog = resultCastCharSetCatalog.toOption.get, resultCastCharSetSchema = resultCastCharSetSchema.toOption.get, resultCastCharSetName = resultCastCharSetName.toOption.get, resultCastCollationCatalog = resultCastCollationCatalog.toOption.get, resultCastCollationSchema = resultCastCollationSchema.toOption.get, resultCastCollationName = resultCastCollationName.toOption.get, resultCastNumericPrecision = resultCastNumericPrecision.toOption.get, resultCastNumericPrecisionRadix = resultCastNumericPrecisionRadix.toOption.get, resultCastNumericScale = resultCastNumericScale.toOption.get, resultCastDatetimePrecision = resultCastDatetimePrecision.toOption.get, resultCastIntervalType = resultCastIntervalType.toOption.get, resultCastIntervalPrecision = resultCastIntervalPrecision.toOption.get, resultCastTypeUdtCatalog = resultCastTypeUdtCatalog.toOption.get, resultCastTypeUdtSchema = resultCastTypeUdtSchema.toOption.get, resultCastTypeUdtName = resultCastTypeUdtName.toOption.get, resultCastScopeCatalog = resultCastScopeCatalog.toOption.get, resultCastScopeSchema = resultCastScopeSchema.toOption.get, resultCastScopeName = resultCastScopeName.toOption.get, resultCastMaximumCardinality = resultCastMaximumCardinality.toOption.get, resultCastDtdIdentifier = resultCastDtdIdentifier.toOption.get)) + else Left(List[Either[String, Any]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, routineType, moduleCatalog, moduleSchema, moduleName, udtCatalog, udtSchema, udtName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, typeUdtCatalog, typeUdtSchema, typeUdtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, routineBody, routineDefinition, externalName, externalLanguage, parameterStyle, isDeterministic, sqlDataAccess, isNullCall, sqlPath, schemaLevelRoutine, maxDynamicResultSets, isUserDefinedCast, isImplicitlyInvocable, securityType, toSqlSpecificCatalog, toSqlSpecificSchema, toSqlSpecificName, asLocator, created, lastAltered, newSavepointLevel, isUdtDependent, resultCastFromDataType, resultCastAsLocator, resultCastCharMaxLength, resultCastCharOctetLength, resultCastCharSetCatalog, resultCastCharSetSchema, resultCastCharSetName, resultCastCollationCatalog, resultCastCollationSchema, resultCastCollationName, resultCastNumericPrecision, resultCastNumericPrecisionRadix, resultCastNumericScale, resultCastDatetimePrecision, resultCastIntervalType, resultCastIntervalPrecision, resultCastTypeUdtCatalog, resultCastTypeUdtSchema, resultCastTypeUdtName, resultCastScopeCatalog, resultCastScopeSchema, resultCastScopeName, resultCastMaximumCardinality, resultCastDtdIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[RoutinesViewRow] = new JsonEncoder[RoutinesViewRow] { + override def unsafeEncode(a: RoutinesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineCatalog, indent, out) + out.write(",") + out.write(""""routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineSchema, indent, out) + out.write(",") + out.write(""""routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineName, indent, out) + out.write(",") + out.write(""""routine_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineType, indent, out) + out.write(",") + out.write(""""module_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.moduleCatalog, indent, out) + out.write(",") + out.write(""""module_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.moduleSchema, indent, out) + out.write(",") + out.write(""""module_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.moduleName, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""type_udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.typeUdtCatalog, indent, out) + out.write(",") + out.write(""""type_udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.typeUdtSchema, indent, out) + out.write(",") + out.write(""""type_udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.typeUdtName, indent, out) + out.write(",") + out.write(""""scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeCatalog, indent, out) + out.write(",") + out.write(""""scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeSchema, indent, out) + out.write(",") + out.write(""""scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.scopeName, indent, out) + out.write(",") + out.write(""""maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maximumCardinality, indent, out) + out.write(",") + out.write(""""dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dtdIdentifier, indent, out) + out.write(",") + out.write(""""routine_body":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineBody, indent, out) + out.write(",") + out.write(""""routine_definition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.routineDefinition, indent, out) + out.write(",") + out.write(""""external_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.externalName, indent, out) + out.write(",") + out.write(""""external_language":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.externalLanguage, indent, out) + out.write(",") + out.write(""""parameter_style":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.parameterStyle, indent, out) + out.write(",") + out.write(""""is_deterministic":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isDeterministic, indent, out) + out.write(",") + out.write(""""sql_data_access":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sqlDataAccess, indent, out) + out.write(",") + out.write(""""is_null_call":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isNullCall, indent, out) + out.write(",") + out.write(""""sql_path":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sqlPath, indent, out) + out.write(",") + out.write(""""schema_level_routine":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaLevelRoutine, indent, out) + out.write(",") + out.write(""""max_dynamic_result_sets":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maxDynamicResultSets, indent, out) + out.write(",") + out.write(""""is_user_defined_cast":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isUserDefinedCast, indent, out) + out.write(",") + out.write(""""is_implicitly_invocable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isImplicitlyInvocable, indent, out) + out.write(",") + out.write(""""security_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.securityType, indent, out) + out.write(",") + out.write(""""to_sql_specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.toSqlSpecificCatalog, indent, out) + out.write(",") + out.write(""""to_sql_specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.toSqlSpecificSchema, indent, out) + out.write(",") + out.write(""""to_sql_specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.toSqlSpecificName, indent, out) + out.write(",") + out.write(""""as_locator":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.asLocator, indent, out) + out.write(",") + out.write(""""created":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.created, indent, out) + out.write(",") + out.write(""""last_altered":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAltered, indent, out) + out.write(",") + out.write(""""new_savepoint_level":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.newSavepointLevel, indent, out) + out.write(",") + out.write(""""is_udt_dependent":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isUdtDependent, indent, out) + out.write(",") + out.write(""""result_cast_from_data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastFromDataType, indent, out) + out.write(",") + out.write(""""result_cast_as_locator":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastAsLocator, indent, out) + out.write(",") + out.write(""""result_cast_char_max_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastCharMaxLength, indent, out) + out.write(",") + out.write(""""result_cast_char_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastCharOctetLength, indent, out) + out.write(",") + out.write(""""result_cast_char_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCharSetCatalog, indent, out) + out.write(",") + out.write(""""result_cast_char_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCharSetSchema, indent, out) + out.write(",") + out.write(""""result_cast_char_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCharSetName, indent, out) + out.write(",") + out.write(""""result_cast_collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCollationCatalog, indent, out) + out.write(",") + out.write(""""result_cast_collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCollationSchema, indent, out) + out.write(",") + out.write(""""result_cast_collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastCollationName, indent, out) + out.write(",") + out.write(""""result_cast_numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastNumericPrecision, indent, out) + out.write(",") + out.write(""""result_cast_numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastNumericPrecisionRadix, indent, out) + out.write(",") + out.write(""""result_cast_numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastNumericScale, indent, out) + out.write(",") + out.write(""""result_cast_datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastDatetimePrecision, indent, out) + out.write(",") + out.write(""""result_cast_interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastIntervalType, indent, out) + out.write(",") + out.write(""""result_cast_interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastIntervalPrecision, indent, out) + out.write(",") + out.write(""""result_cast_type_udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastTypeUdtCatalog, indent, out) + out.write(",") + out.write(""""result_cast_type_udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastTypeUdtSchema, indent, out) + out.write(",") + out.write(""""result_cast_type_udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastTypeUdtName, indent, out) + out.write(",") + out.write(""""result_cast_scope_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastScopeCatalog, indent, out) + out.write(",") + out.write(""""result_cast_scope_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastScopeSchema, indent, out) + out.write(",") + out.write(""""result_cast_scope_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastScopeName, indent, out) + out.write(",") + out.write(""""result_cast_maximum_cardinality":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.resultCastMaximumCardinality, indent, out) + out.write(",") + out.write(""""result_cast_dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resultCastDtdIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewStructure.scala new file mode 100644 index 0000000000..18abe7bfca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/routines/RoutinesViewStructure.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package routines + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class RoutinesViewStructure[Row](val prefix: Option[String], val extract: Row => RoutinesViewRow, val merge: (Row, RoutinesViewRow) => Row) + extends Relation[RoutinesViewFields, RoutinesViewRow, Row] + with RoutinesViewFields[Row] { outer => + + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val routineCatalog = new OptField[String, Row](prefix, "routine_catalog", None, None)(x => extract(x).routineCatalog, (row, value) => merge(row, extract(row).copy(routineCatalog = value))) + override val routineSchema = new OptField[String, Row](prefix, "routine_schema", None, None)(x => extract(x).routineSchema, (row, value) => merge(row, extract(row).copy(routineSchema = value))) + override val routineName = new OptField[String, Row](prefix, "routine_name", None, None)(x => extract(x).routineName, (row, value) => merge(row, extract(row).copy(routineName = value))) + override val routineType = new OptField[String, Row](prefix, "routine_type", None, None)(x => extract(x).routineType, (row, value) => merge(row, extract(row).copy(routineType = value))) + override val moduleCatalog = new OptField[String, Row](prefix, "module_catalog", None, None)(x => extract(x).moduleCatalog, (row, value) => merge(row, extract(row).copy(moduleCatalog = value))) + override val moduleSchema = new OptField[String, Row](prefix, "module_schema", None, None)(x => extract(x).moduleSchema, (row, value) => merge(row, extract(row).copy(moduleSchema = value))) + override val moduleName = new OptField[String, Row](prefix, "module_name", None, None)(x => extract(x).moduleName, (row, value) => merge(row, extract(row).copy(moduleName = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val typeUdtCatalog = new OptField[String, Row](prefix, "type_udt_catalog", None, None)(x => extract(x).typeUdtCatalog, (row, value) => merge(row, extract(row).copy(typeUdtCatalog = value))) + override val typeUdtSchema = new OptField[String, Row](prefix, "type_udt_schema", None, None)(x => extract(x).typeUdtSchema, (row, value) => merge(row, extract(row).copy(typeUdtSchema = value))) + override val typeUdtName = new OptField[String, Row](prefix, "type_udt_name", None, None)(x => extract(x).typeUdtName, (row, value) => merge(row, extract(row).copy(typeUdtName = value))) + override val scopeCatalog = new OptField[String, Row](prefix, "scope_catalog", None, None)(x => extract(x).scopeCatalog, (row, value) => merge(row, extract(row).copy(scopeCatalog = value))) + override val scopeSchema = new OptField[String, Row](prefix, "scope_schema", None, None)(x => extract(x).scopeSchema, (row, value) => merge(row, extract(row).copy(scopeSchema = value))) + override val scopeName = new OptField[String, Row](prefix, "scope_name", None, None)(x => extract(x).scopeName, (row, value) => merge(row, extract(row).copy(scopeName = value))) + override val maximumCardinality = new OptField[Int, Row](prefix, "maximum_cardinality", None, None)(x => extract(x).maximumCardinality, (row, value) => merge(row, extract(row).copy(maximumCardinality = value))) + override val dtdIdentifier = new OptField[String, Row](prefix, "dtd_identifier", None, None)(x => extract(x).dtdIdentifier, (row, value) => merge(row, extract(row).copy(dtdIdentifier = value))) + override val routineBody = new OptField[String, Row](prefix, "routine_body", None, None)(x => extract(x).routineBody, (row, value) => merge(row, extract(row).copy(routineBody = value))) + override val routineDefinition = new OptField[String, Row](prefix, "routine_definition", None, None)(x => extract(x).routineDefinition, (row, value) => merge(row, extract(row).copy(routineDefinition = value))) + override val externalName = new OptField[String, Row](prefix, "external_name", None, None)(x => extract(x).externalName, (row, value) => merge(row, extract(row).copy(externalName = value))) + override val externalLanguage = new OptField[String, Row](prefix, "external_language", None, None)(x => extract(x).externalLanguage, (row, value) => merge(row, extract(row).copy(externalLanguage = value))) + override val parameterStyle = new OptField[String, Row](prefix, "parameter_style", None, None)(x => extract(x).parameterStyle, (row, value) => merge(row, extract(row).copy(parameterStyle = value))) + override val isDeterministic = new OptField[/* max 3 chars */ String, Row](prefix, "is_deterministic", None, None)(x => extract(x).isDeterministic, (row, value) => merge(row, extract(row).copy(isDeterministic = value))) + override val sqlDataAccess = new OptField[String, Row](prefix, "sql_data_access", None, None)(x => extract(x).sqlDataAccess, (row, value) => merge(row, extract(row).copy(sqlDataAccess = value))) + override val isNullCall = new OptField[/* max 3 chars */ String, Row](prefix, "is_null_call", None, None)(x => extract(x).isNullCall, (row, value) => merge(row, extract(row).copy(isNullCall = value))) + override val sqlPath = new OptField[String, Row](prefix, "sql_path", None, None)(x => extract(x).sqlPath, (row, value) => merge(row, extract(row).copy(sqlPath = value))) + override val schemaLevelRoutine = new OptField[/* max 3 chars */ String, Row](prefix, "schema_level_routine", None, None)(x => extract(x).schemaLevelRoutine, (row, value) => merge(row, extract(row).copy(schemaLevelRoutine = value))) + override val maxDynamicResultSets = new OptField[Int, Row](prefix, "max_dynamic_result_sets", None, None)(x => extract(x).maxDynamicResultSets, (row, value) => merge(row, extract(row).copy(maxDynamicResultSets = value))) + override val isUserDefinedCast = new OptField[/* max 3 chars */ String, Row](prefix, "is_user_defined_cast", None, None)(x => extract(x).isUserDefinedCast, (row, value) => merge(row, extract(row).copy(isUserDefinedCast = value))) + override val isImplicitlyInvocable = new OptField[/* max 3 chars */ String, Row](prefix, "is_implicitly_invocable", None, None)(x => extract(x).isImplicitlyInvocable, (row, value) => merge(row, extract(row).copy(isImplicitlyInvocable = value))) + override val securityType = new OptField[String, Row](prefix, "security_type", None, None)(x => extract(x).securityType, (row, value) => merge(row, extract(row).copy(securityType = value))) + override val toSqlSpecificCatalog = new OptField[String, Row](prefix, "to_sql_specific_catalog", None, None)(x => extract(x).toSqlSpecificCatalog, (row, value) => merge(row, extract(row).copy(toSqlSpecificCatalog = value))) + override val toSqlSpecificSchema = new OptField[String, Row](prefix, "to_sql_specific_schema", None, None)(x => extract(x).toSqlSpecificSchema, (row, value) => merge(row, extract(row).copy(toSqlSpecificSchema = value))) + override val toSqlSpecificName = new OptField[String, Row](prefix, "to_sql_specific_name", None, None)(x => extract(x).toSqlSpecificName, (row, value) => merge(row, extract(row).copy(toSqlSpecificName = value))) + override val asLocator = new OptField[/* max 3 chars */ String, Row](prefix, "as_locator", None, None)(x => extract(x).asLocator, (row, value) => merge(row, extract(row).copy(asLocator = value))) + override val created = new OptField[TypoInstant, Row](prefix, "created", Some("text"), None)(x => extract(x).created, (row, value) => merge(row, extract(row).copy(created = value))) + override val lastAltered = new OptField[TypoInstant, Row](prefix, "last_altered", Some("text"), None)(x => extract(x).lastAltered, (row, value) => merge(row, extract(row).copy(lastAltered = value))) + override val newSavepointLevel = new OptField[/* max 3 chars */ String, Row](prefix, "new_savepoint_level", None, None)(x => extract(x).newSavepointLevel, (row, value) => merge(row, extract(row).copy(newSavepointLevel = value))) + override val isUdtDependent = new OptField[/* max 3 chars */ String, Row](prefix, "is_udt_dependent", None, None)(x => extract(x).isUdtDependent, (row, value) => merge(row, extract(row).copy(isUdtDependent = value))) + override val resultCastFromDataType = new OptField[String, Row](prefix, "result_cast_from_data_type", None, None)(x => extract(x).resultCastFromDataType, (row, value) => merge(row, extract(row).copy(resultCastFromDataType = value))) + override val resultCastAsLocator = new OptField[/* max 3 chars */ String, Row](prefix, "result_cast_as_locator", None, None)(x => extract(x).resultCastAsLocator, (row, value) => merge(row, extract(row).copy(resultCastAsLocator = value))) + override val resultCastCharMaxLength = new OptField[Int, Row](prefix, "result_cast_char_max_length", None, None)(x => extract(x).resultCastCharMaxLength, (row, value) => merge(row, extract(row).copy(resultCastCharMaxLength = value))) + override val resultCastCharOctetLength = new OptField[Int, Row](prefix, "result_cast_char_octet_length", None, None)(x => extract(x).resultCastCharOctetLength, (row, value) => merge(row, extract(row).copy(resultCastCharOctetLength = value))) + override val resultCastCharSetCatalog = new OptField[String, Row](prefix, "result_cast_char_set_catalog", None, None)(x => extract(x).resultCastCharSetCatalog, (row, value) => merge(row, extract(row).copy(resultCastCharSetCatalog = value))) + override val resultCastCharSetSchema = new OptField[String, Row](prefix, "result_cast_char_set_schema", None, None)(x => extract(x).resultCastCharSetSchema, (row, value) => merge(row, extract(row).copy(resultCastCharSetSchema = value))) + override val resultCastCharSetName = new OptField[String, Row](prefix, "result_cast_char_set_name", None, None)(x => extract(x).resultCastCharSetName, (row, value) => merge(row, extract(row).copy(resultCastCharSetName = value))) + override val resultCastCollationCatalog = new OptField[String, Row](prefix, "result_cast_collation_catalog", None, None)(x => extract(x).resultCastCollationCatalog, (row, value) => merge(row, extract(row).copy(resultCastCollationCatalog = value))) + override val resultCastCollationSchema = new OptField[String, Row](prefix, "result_cast_collation_schema", None, None)(x => extract(x).resultCastCollationSchema, (row, value) => merge(row, extract(row).copy(resultCastCollationSchema = value))) + override val resultCastCollationName = new OptField[String, Row](prefix, "result_cast_collation_name", None, None)(x => extract(x).resultCastCollationName, (row, value) => merge(row, extract(row).copy(resultCastCollationName = value))) + override val resultCastNumericPrecision = new OptField[Int, Row](prefix, "result_cast_numeric_precision", None, None)(x => extract(x).resultCastNumericPrecision, (row, value) => merge(row, extract(row).copy(resultCastNumericPrecision = value))) + override val resultCastNumericPrecisionRadix = new OptField[Int, Row](prefix, "result_cast_numeric_precision_radix", None, None)(x => extract(x).resultCastNumericPrecisionRadix, (row, value) => merge(row, extract(row).copy(resultCastNumericPrecisionRadix = value))) + override val resultCastNumericScale = new OptField[Int, Row](prefix, "result_cast_numeric_scale", None, None)(x => extract(x).resultCastNumericScale, (row, value) => merge(row, extract(row).copy(resultCastNumericScale = value))) + override val resultCastDatetimePrecision = new OptField[Int, Row](prefix, "result_cast_datetime_precision", None, None)(x => extract(x).resultCastDatetimePrecision, (row, value) => merge(row, extract(row).copy(resultCastDatetimePrecision = value))) + override val resultCastIntervalType = new OptField[String, Row](prefix, "result_cast_interval_type", None, None)(x => extract(x).resultCastIntervalType, (row, value) => merge(row, extract(row).copy(resultCastIntervalType = value))) + override val resultCastIntervalPrecision = new OptField[Int, Row](prefix, "result_cast_interval_precision", None, None)(x => extract(x).resultCastIntervalPrecision, (row, value) => merge(row, extract(row).copy(resultCastIntervalPrecision = value))) + override val resultCastTypeUdtCatalog = new OptField[String, Row](prefix, "result_cast_type_udt_catalog", None, None)(x => extract(x).resultCastTypeUdtCatalog, (row, value) => merge(row, extract(row).copy(resultCastTypeUdtCatalog = value))) + override val resultCastTypeUdtSchema = new OptField[String, Row](prefix, "result_cast_type_udt_schema", None, None)(x => extract(x).resultCastTypeUdtSchema, (row, value) => merge(row, extract(row).copy(resultCastTypeUdtSchema = value))) + override val resultCastTypeUdtName = new OptField[String, Row](prefix, "result_cast_type_udt_name", None, None)(x => extract(x).resultCastTypeUdtName, (row, value) => merge(row, extract(row).copy(resultCastTypeUdtName = value))) + override val resultCastScopeCatalog = new OptField[String, Row](prefix, "result_cast_scope_catalog", None, None)(x => extract(x).resultCastScopeCatalog, (row, value) => merge(row, extract(row).copy(resultCastScopeCatalog = value))) + override val resultCastScopeSchema = new OptField[String, Row](prefix, "result_cast_scope_schema", None, None)(x => extract(x).resultCastScopeSchema, (row, value) => merge(row, extract(row).copy(resultCastScopeSchema = value))) + override val resultCastScopeName = new OptField[String, Row](prefix, "result_cast_scope_name", None, None)(x => extract(x).resultCastScopeName, (row, value) => merge(row, extract(row).copy(resultCastScopeName = value))) + override val resultCastMaximumCardinality = new OptField[Int, Row](prefix, "result_cast_maximum_cardinality", None, None)(x => extract(x).resultCastMaximumCardinality, (row, value) => merge(row, extract(row).copy(resultCastMaximumCardinality = value))) + override val resultCastDtdIdentifier = new OptField[String, Row](prefix, "result_cast_dtd_identifier", None, None)(x => extract(x).resultCastDtdIdentifier, (row, value) => merge(row, extract(row).copy(resultCastDtdIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specificCatalog, specificSchema, specificName, routineCatalog, routineSchema, routineName, routineType, moduleCatalog, moduleSchema, moduleName, udtCatalog, udtSchema, udtName, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, typeUdtCatalog, typeUdtSchema, typeUdtName, scopeCatalog, scopeSchema, scopeName, maximumCardinality, dtdIdentifier, routineBody, routineDefinition, externalName, externalLanguage, parameterStyle, isDeterministic, sqlDataAccess, isNullCall, sqlPath, schemaLevelRoutine, maxDynamicResultSets, isUserDefinedCast, isImplicitlyInvocable, securityType, toSqlSpecificCatalog, toSqlSpecificSchema, toSqlSpecificName, asLocator, created, lastAltered, newSavepointLevel, isUdtDependent, resultCastFromDataType, resultCastAsLocator, resultCastCharMaxLength, resultCastCharOctetLength, resultCastCharSetCatalog, resultCastCharSetSchema, resultCastCharSetName, resultCastCollationCatalog, resultCastCollationSchema, resultCastCollationName, resultCastNumericPrecision, resultCastNumericPrecisionRadix, resultCastNumericScale, resultCastDatetimePrecision, resultCastIntervalType, resultCastIntervalPrecision, resultCastTypeUdtCatalog, resultCastTypeUdtSchema, resultCastTypeUdtName, resultCastScopeCatalog, resultCastScopeSchema, resultCastScopeName, resultCastMaximumCardinality, resultCastDtdIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => RoutinesViewRow, merge: (NewRow, RoutinesViewRow) => NewRow): RoutinesViewStructure[NewRow] = + new RoutinesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewFields.scala new file mode 100644 index 0000000000..2fbf9c5ee7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package schemata + +import typo.dsl.SqlExpr.OptField + +trait SchemataViewFields[Row] { + val catalogName: OptField[String, Row] + val schemaName: OptField[String, Row] + val schemaOwner: OptField[String, Row] + val defaultCharacterSetCatalog: OptField[String, Row] + val defaultCharacterSetSchema: OptField[String, Row] + val defaultCharacterSetName: OptField[String, Row] + val sqlPath: OptField[String, Row] +} +object SchemataViewFields extends SchemataViewStructure[SchemataViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepo.scala new file mode 100644 index 0000000000..54a5633d6f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package schemata + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SchemataViewRepo { + def select: SelectBuilder[SchemataViewFields, SchemataViewRow] + def selectAll: ZStream[ZConnection, Throwable, SchemataViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepoImpl.scala new file mode 100644 index 0000000000..0cc95a675c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package schemata + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SchemataViewRepoImpl extends SchemataViewRepo { + override def select: SelectBuilder[SchemataViewFields, SchemataViewRow] = { + SelectBuilderSql("information_schema.schemata", SchemataViewFields, SchemataViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SchemataViewRow] = { + sql"""select "catalog_name", "schema_name", "schema_owner", "default_character_set_catalog", "default_character_set_schema", "default_character_set_name", "sql_path" from information_schema.schemata""".query(SchemataViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRow.scala new file mode 100644 index 0000000000..c406f06b4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package schemata + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SchemataViewRow( + catalogName: /* nullability unknown */ Option[String], + schemaName: /* nullability unknown */ Option[String], + schemaOwner: /* nullability unknown */ Option[String], + defaultCharacterSetCatalog: /* nullability unknown */ Option[String], + defaultCharacterSetSchema: /* nullability unknown */ Option[String], + defaultCharacterSetName: /* nullability unknown */ Option[String], + sqlPath: /* nullability unknown */ Option[String] +) + +object SchemataViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SchemataViewRow] = new JdbcDecoder[SchemataViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SchemataViewRow) = + columIndex + 6 -> + SchemataViewRow( + catalogName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + schemaOwner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + defaultCharacterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + defaultCharacterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + defaultCharacterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + sqlPath = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SchemataViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val catalogName = jsonObj.get("catalog_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val schemaName = jsonObj.get("schema_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val schemaOwner = jsonObj.get("schema_owner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCharacterSetCatalog = jsonObj.get("default_character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCharacterSetSchema = jsonObj.get("default_character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultCharacterSetName = jsonObj.get("default_character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sqlPath = jsonObj.get("sql_path").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (catalogName.isRight && schemaName.isRight && schemaOwner.isRight && defaultCharacterSetCatalog.isRight && defaultCharacterSetSchema.isRight && defaultCharacterSetName.isRight && sqlPath.isRight) + Right(SchemataViewRow(catalogName = catalogName.toOption.get, schemaName = schemaName.toOption.get, schemaOwner = schemaOwner.toOption.get, defaultCharacterSetCatalog = defaultCharacterSetCatalog.toOption.get, defaultCharacterSetSchema = defaultCharacterSetSchema.toOption.get, defaultCharacterSetName = defaultCharacterSetName.toOption.get, sqlPath = sqlPath.toOption.get)) + else Left(List[Either[String, Any]](catalogName, schemaName, schemaOwner, defaultCharacterSetCatalog, defaultCharacterSetSchema, defaultCharacterSetName, sqlPath).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SchemataViewRow] = new JsonEncoder[SchemataViewRow] { + override def unsafeEncode(a: SchemataViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""catalog_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.catalogName, indent, out) + out.write(",") + out.write(""""schema_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaName, indent, out) + out.write(",") + out.write(""""schema_owner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaOwner, indent, out) + out.write(",") + out.write(""""default_character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCharacterSetCatalog, indent, out) + out.write(",") + out.write(""""default_character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCharacterSetSchema, indent, out) + out.write(",") + out.write(""""default_character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultCharacterSetName, indent, out) + out.write(",") + out.write(""""sql_path":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sqlPath, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewStructure.scala new file mode 100644 index 0000000000..3d5d0f120d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/schemata/SchemataViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package schemata + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SchemataViewStructure[Row](val prefix: Option[String], val extract: Row => SchemataViewRow, val merge: (Row, SchemataViewRow) => Row) + extends Relation[SchemataViewFields, SchemataViewRow, Row] + with SchemataViewFields[Row] { outer => + + override val catalogName = new OptField[String, Row](prefix, "catalog_name", None, None)(x => extract(x).catalogName, (row, value) => merge(row, extract(row).copy(catalogName = value))) + override val schemaName = new OptField[String, Row](prefix, "schema_name", None, None)(x => extract(x).schemaName, (row, value) => merge(row, extract(row).copy(schemaName = value))) + override val schemaOwner = new OptField[String, Row](prefix, "schema_owner", None, None)(x => extract(x).schemaOwner, (row, value) => merge(row, extract(row).copy(schemaOwner = value))) + override val defaultCharacterSetCatalog = new OptField[String, Row](prefix, "default_character_set_catalog", None, None)(x => extract(x).defaultCharacterSetCatalog, (row, value) => merge(row, extract(row).copy(defaultCharacterSetCatalog = value))) + override val defaultCharacterSetSchema = new OptField[String, Row](prefix, "default_character_set_schema", None, None)(x => extract(x).defaultCharacterSetSchema, (row, value) => merge(row, extract(row).copy(defaultCharacterSetSchema = value))) + override val defaultCharacterSetName = new OptField[String, Row](prefix, "default_character_set_name", None, None)(x => extract(x).defaultCharacterSetName, (row, value) => merge(row, extract(row).copy(defaultCharacterSetName = value))) + override val sqlPath = new OptField[String, Row](prefix, "sql_path", None, None)(x => extract(x).sqlPath, (row, value) => merge(row, extract(row).copy(sqlPath = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](catalogName, schemaName, schemaOwner, defaultCharacterSetCatalog, defaultCharacterSetSchema, defaultCharacterSetName, sqlPath) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SchemataViewRow, merge: (NewRow, SchemataViewRow) => NewRow): SchemataViewStructure[NewRow] = + new SchemataViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewFields.scala new file mode 100644 index 0000000000..4a44c5f408 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sequences + +import typo.dsl.SqlExpr.OptField + +trait SequencesViewFields[Row] { + val sequenceCatalog: OptField[String, Row] + val sequenceSchema: OptField[String, Row] + val sequenceName: OptField[String, Row] + val dataType: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val startValue: OptField[String, Row] + val minimumValue: OptField[String, Row] + val maximumValue: OptField[String, Row] + val increment: OptField[String, Row] + val cycleOption: OptField[/* max 3 chars */ String, Row] +} +object SequencesViewFields extends SequencesViewStructure[SequencesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepo.scala new file mode 100644 index 0000000000..59e5c073af --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sequences + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SequencesViewRepo { + def select: SelectBuilder[SequencesViewFields, SequencesViewRow] + def selectAll: ZStream[ZConnection, Throwable, SequencesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepoImpl.scala new file mode 100644 index 0000000000..32dc6c6fb5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sequences + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SequencesViewRepoImpl extends SequencesViewRepo { + override def select: SelectBuilder[SequencesViewFields, SequencesViewRow] = { + SelectBuilderSql("information_schema.sequences", SequencesViewFields, SequencesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SequencesViewRow] = { + sql"""select "sequence_catalog", "sequence_schema", "sequence_name", "data_type", "numeric_precision", "numeric_precision_radix", "numeric_scale", "start_value", "minimum_value", "maximum_value", "increment", "cycle_option" from information_schema.sequences""".query(SequencesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRow.scala new file mode 100644 index 0000000000..fb6bc3d922 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sequences + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SequencesViewRow( + sequenceCatalog: /* nullability unknown */ Option[String], + sequenceSchema: /* nullability unknown */ Option[String], + sequenceName: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + startValue: /* nullability unknown */ Option[String], + minimumValue: /* nullability unknown */ Option[String], + maximumValue: /* nullability unknown */ Option[String], + increment: /* nullability unknown */ Option[String], + cycleOption: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object SequencesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SequencesViewRow] = new JdbcDecoder[SequencesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SequencesViewRow) = + columIndex + 11 -> + SequencesViewRow( + sequenceCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + sequenceSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + sequenceName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 4, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 5, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 6, rs)._2, + startValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + minimumValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + maximumValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + increment = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + cycleOption = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SequencesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val sequenceCatalog = jsonObj.get("sequence_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sequenceSchema = jsonObj.get("sequence_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sequenceName = jsonObj.get("sequence_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val startValue = jsonObj.get("start_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val minimumValue = jsonObj.get("minimum_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maximumValue = jsonObj.get("maximum_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val increment = jsonObj.get("increment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val cycleOption = jsonObj.get("cycle_option").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (sequenceCatalog.isRight && sequenceSchema.isRight && sequenceName.isRight && dataType.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && startValue.isRight && minimumValue.isRight && maximumValue.isRight && increment.isRight && cycleOption.isRight) + Right(SequencesViewRow(sequenceCatalog = sequenceCatalog.toOption.get, sequenceSchema = sequenceSchema.toOption.get, sequenceName = sequenceName.toOption.get, dataType = dataType.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, startValue = startValue.toOption.get, minimumValue = minimumValue.toOption.get, maximumValue = maximumValue.toOption.get, increment = increment.toOption.get, cycleOption = cycleOption.toOption.get)) + else Left(List[Either[String, Any]](sequenceCatalog, sequenceSchema, sequenceName, dataType, numericPrecision, numericPrecisionRadix, numericScale, startValue, minimumValue, maximumValue, increment, cycleOption).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SequencesViewRow] = new JsonEncoder[SequencesViewRow] { + override def unsafeEncode(a: SequencesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""sequence_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceCatalog, indent, out) + out.write(",") + out.write(""""sequence_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceSchema, indent, out) + out.write(",") + out.write(""""sequence_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceName, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""start_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.startValue, indent, out) + out.write(",") + out.write(""""minimum_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.minimumValue, indent, out) + out.write(",") + out.write(""""maximum_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.maximumValue, indent, out) + out.write(",") + out.write(""""increment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.increment, indent, out) + out.write(",") + out.write(""""cycle_option":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.cycleOption, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewStructure.scala new file mode 100644 index 0000000000..8716395321 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sequences/SequencesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sequences + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SequencesViewStructure[Row](val prefix: Option[String], val extract: Row => SequencesViewRow, val merge: (Row, SequencesViewRow) => Row) + extends Relation[SequencesViewFields, SequencesViewRow, Row] + with SequencesViewFields[Row] { outer => + + override val sequenceCatalog = new OptField[String, Row](prefix, "sequence_catalog", None, None)(x => extract(x).sequenceCatalog, (row, value) => merge(row, extract(row).copy(sequenceCatalog = value))) + override val sequenceSchema = new OptField[String, Row](prefix, "sequence_schema", None, None)(x => extract(x).sequenceSchema, (row, value) => merge(row, extract(row).copy(sequenceSchema = value))) + override val sequenceName = new OptField[String, Row](prefix, "sequence_name", None, None)(x => extract(x).sequenceName, (row, value) => merge(row, extract(row).copy(sequenceName = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val startValue = new OptField[String, Row](prefix, "start_value", None, None)(x => extract(x).startValue, (row, value) => merge(row, extract(row).copy(startValue = value))) + override val minimumValue = new OptField[String, Row](prefix, "minimum_value", None, None)(x => extract(x).minimumValue, (row, value) => merge(row, extract(row).copy(minimumValue = value))) + override val maximumValue = new OptField[String, Row](prefix, "maximum_value", None, None)(x => extract(x).maximumValue, (row, value) => merge(row, extract(row).copy(maximumValue = value))) + override val increment = new OptField[String, Row](prefix, "increment", None, None)(x => extract(x).increment, (row, value) => merge(row, extract(row).copy(increment = value))) + override val cycleOption = new OptField[/* max 3 chars */ String, Row](prefix, "cycle_option", None, None)(x => extract(x).cycleOption, (row, value) => merge(row, extract(row).copy(cycleOption = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](sequenceCatalog, sequenceSchema, sequenceName, dataType, numericPrecision, numericPrecisionRadix, numericScale, startValue, minimumValue, maximumValue, increment, cycleOption) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SequencesViewRow, merge: (NewRow, SequencesViewRow) => NewRow): SequencesViewStructure[NewRow] = + new SequencesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesFields.scala new file mode 100644 index 0000000000..73ebf18516 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_features + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.SqlExpr.OptField + +trait SqlFeaturesFields[Row] { + val featureId: OptField[CharacterData, Row] + val featureName: OptField[CharacterData, Row] + val subFeatureId: OptField[CharacterData, Row] + val subFeatureName: OptField[CharacterData, Row] + val isSupported: OptField[YesOrNo, Row] + val isVerifiedBy: OptField[CharacterData, Row] + val comments: OptField[CharacterData, Row] +} +object SqlFeaturesFields extends SqlFeaturesStructure[SqlFeaturesRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepo.scala new file mode 100644 index 0000000000..2d0e740e7a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_features + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SqlFeaturesRepo { + def delete: DeleteBuilder[SqlFeaturesFields, SqlFeaturesRow] + def insert(unsaved: SqlFeaturesRow): ZIO[ZConnection, Throwable, SqlFeaturesRow] + def select: SelectBuilder[SqlFeaturesFields, SqlFeaturesRow] + def selectAll: ZStream[ZConnection, Throwable, SqlFeaturesRow] + def update: UpdateBuilder[SqlFeaturesFields, SqlFeaturesRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepoImpl.scala new file mode 100644 index 0000000000..600b42e59a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRepoImpl.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_features + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SqlFeaturesRepoImpl extends SqlFeaturesRepo { + override def delete: DeleteBuilder[SqlFeaturesFields, SqlFeaturesRow] = { + DeleteBuilder("information_schema.sql_features", SqlFeaturesFields) + } + override def insert(unsaved: SqlFeaturesRow): ZIO[ZConnection, Throwable, SqlFeaturesRow] = { + sql"""insert into information_schema.sql_features("feature_id", "feature_name", "sub_feature_id", "sub_feature_name", "is_supported", "is_verified_by", "comments") + values (${Segment.paramSegment(unsaved.featureId)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.featureName)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.subFeatureId)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.subFeatureName)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.isSupported)(Setter.optionParamSetter(YesOrNo.setter))}::varchar, ${Segment.paramSegment(unsaved.isVerifiedBy)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(CharacterData.setter))}::varchar) + returning "feature_id", "feature_name", "sub_feature_id", "sub_feature_name", "is_supported", "is_verified_by", "comments" + """.insertReturning(SqlFeaturesRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[SqlFeaturesFields, SqlFeaturesRow] = { + SelectBuilderSql("information_schema.sql_features", SqlFeaturesFields, SqlFeaturesRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SqlFeaturesRow] = { + sql"""select "feature_id", "feature_name", "sub_feature_id", "sub_feature_name", "is_supported", "is_verified_by", "comments" from information_schema.sql_features""".query(SqlFeaturesRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[SqlFeaturesFields, SqlFeaturesRow] = { + UpdateBuilder("information_schema.sql_features", SqlFeaturesFields, SqlFeaturesRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRow.scala new file mode 100644 index 0000000000..12b866ce4b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_features + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SqlFeaturesRow( + featureId: Option[CharacterData], + featureName: Option[CharacterData], + subFeatureId: Option[CharacterData], + subFeatureName: Option[CharacterData], + isSupported: Option[YesOrNo], + isVerifiedBy: Option[CharacterData], + comments: Option[CharacterData] +) + +object SqlFeaturesRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SqlFeaturesRow] = new JdbcDecoder[SqlFeaturesRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SqlFeaturesRow) = + columIndex + 6 -> + SqlFeaturesRow( + featureId = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + featureName = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + subFeatureId = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + subFeatureName = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + isSupported = JdbcDecoder.optionDecoder(YesOrNo.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + isVerifiedBy = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + comments = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SqlFeaturesRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val featureId = jsonObj.get("feature_id").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val featureName = jsonObj.get("feature_name").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val subFeatureId = jsonObj.get("sub_feature_id").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val subFeatureName = jsonObj.get("sub_feature_name").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val isSupported = jsonObj.get("is_supported").fold[Either[String, Option[YesOrNo]]](Right(None))(_.as(JsonDecoder.option(YesOrNo.jsonDecoder))) + val isVerifiedBy = jsonObj.get("is_verified_by").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val comments = jsonObj.get("comments").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + if (featureId.isRight && featureName.isRight && subFeatureId.isRight && subFeatureName.isRight && isSupported.isRight && isVerifiedBy.isRight && comments.isRight) + Right(SqlFeaturesRow(featureId = featureId.toOption.get, featureName = featureName.toOption.get, subFeatureId = subFeatureId.toOption.get, subFeatureName = subFeatureName.toOption.get, isSupported = isSupported.toOption.get, isVerifiedBy = isVerifiedBy.toOption.get, comments = comments.toOption.get)) + else Left(List[Either[String, Any]](featureId, featureName, subFeatureId, subFeatureName, isSupported, isVerifiedBy, comments).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SqlFeaturesRow] = new JsonEncoder[SqlFeaturesRow] { + override def unsafeEncode(a: SqlFeaturesRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""feature_id":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.featureId, indent, out) + out.write(",") + out.write(""""feature_name":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.featureName, indent, out) + out.write(",") + out.write(""""sub_feature_id":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.subFeatureId, indent, out) + out.write(",") + out.write(""""sub_feature_name":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.subFeatureName, indent, out) + out.write(",") + out.write(""""is_supported":""") + JsonEncoder.option(YesOrNo.jsonEncoder).unsafeEncode(a.isSupported, indent, out) + out.write(",") + out.write(""""is_verified_by":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.isVerifiedBy, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.comments, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesStructure.scala new file mode 100644 index 0000000000..86974467f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_features/SqlFeaturesStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_features + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SqlFeaturesStructure[Row](val prefix: Option[String], val extract: Row => SqlFeaturesRow, val merge: (Row, SqlFeaturesRow) => Row) + extends Relation[SqlFeaturesFields, SqlFeaturesRow, Row] + with SqlFeaturesFields[Row] { outer => + + override val featureId = new OptField[CharacterData, Row](prefix, "feature_id", None, Some("varchar"))(x => extract(x).featureId, (row, value) => merge(row, extract(row).copy(featureId = value))) + override val featureName = new OptField[CharacterData, Row](prefix, "feature_name", None, Some("varchar"))(x => extract(x).featureName, (row, value) => merge(row, extract(row).copy(featureName = value))) + override val subFeatureId = new OptField[CharacterData, Row](prefix, "sub_feature_id", None, Some("varchar"))(x => extract(x).subFeatureId, (row, value) => merge(row, extract(row).copy(subFeatureId = value))) + override val subFeatureName = new OptField[CharacterData, Row](prefix, "sub_feature_name", None, Some("varchar"))(x => extract(x).subFeatureName, (row, value) => merge(row, extract(row).copy(subFeatureName = value))) + override val isSupported = new OptField[YesOrNo, Row](prefix, "is_supported", None, Some("varchar"))(x => extract(x).isSupported, (row, value) => merge(row, extract(row).copy(isSupported = value))) + override val isVerifiedBy = new OptField[CharacterData, Row](prefix, "is_verified_by", None, Some("varchar"))(x => extract(x).isVerifiedBy, (row, value) => merge(row, extract(row).copy(isVerifiedBy = value))) + override val comments = new OptField[CharacterData, Row](prefix, "comments", None, Some("varchar"))(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](featureId, featureName, subFeatureId, subFeatureName, isSupported, isVerifiedBy, comments) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SqlFeaturesRow, merge: (NewRow, SqlFeaturesRow) => NewRow): SqlFeaturesStructure[NewRow] = + new SqlFeaturesStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoFields.scala new file mode 100644 index 0000000000..880907254f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_implementation_info + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.SqlExpr.OptField + +trait SqlImplementationInfoFields[Row] { + val implementationInfoId: OptField[CharacterData, Row] + val implementationInfoName: OptField[CharacterData, Row] + val integerValue: OptField[CardinalNumber, Row] + val characterValue: OptField[CharacterData, Row] + val comments: OptField[CharacterData, Row] +} +object SqlImplementationInfoFields extends SqlImplementationInfoStructure[SqlImplementationInfoRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepo.scala new file mode 100644 index 0000000000..bfa0ac15f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_implementation_info + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SqlImplementationInfoRepo { + def delete: DeleteBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] + def insert(unsaved: SqlImplementationInfoRow): ZIO[ZConnection, Throwable, SqlImplementationInfoRow] + def select: SelectBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] + def selectAll: ZStream[ZConnection, Throwable, SqlImplementationInfoRow] + def update: UpdateBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepoImpl.scala new file mode 100644 index 0000000000..34844592ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRepoImpl.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_implementation_info + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SqlImplementationInfoRepoImpl extends SqlImplementationInfoRepo { + override def delete: DeleteBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] = { + DeleteBuilder("information_schema.sql_implementation_info", SqlImplementationInfoFields) + } + override def insert(unsaved: SqlImplementationInfoRow): ZIO[ZConnection, Throwable, SqlImplementationInfoRow] = { + sql"""insert into information_schema.sql_implementation_info("implementation_info_id", "implementation_info_name", "integer_value", "character_value", "comments") + values (${Segment.paramSegment(unsaved.implementationInfoId)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.implementationInfoName)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.integerValue)(Setter.optionParamSetter(CardinalNumber.setter))}::int4, ${Segment.paramSegment(unsaved.characterValue)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(CharacterData.setter))}::varchar) + returning "implementation_info_id", "implementation_info_name", "integer_value", "character_value", "comments" + """.insertReturning(SqlImplementationInfoRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] = { + SelectBuilderSql("information_schema.sql_implementation_info", SqlImplementationInfoFields, SqlImplementationInfoRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SqlImplementationInfoRow] = { + sql"""select "implementation_info_id", "implementation_info_name", "integer_value", "character_value", "comments" from information_schema.sql_implementation_info""".query(SqlImplementationInfoRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[SqlImplementationInfoFields, SqlImplementationInfoRow] = { + UpdateBuilder("information_schema.sql_implementation_info", SqlImplementationInfoFields, SqlImplementationInfoRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRow.scala new file mode 100644 index 0000000000..83c2736cc8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoRow.scala @@ -0,0 +1,69 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_implementation_info + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SqlImplementationInfoRow( + implementationInfoId: Option[CharacterData], + implementationInfoName: Option[CharacterData], + integerValue: Option[CardinalNumber], + characterValue: Option[CharacterData], + comments: Option[CharacterData] +) + +object SqlImplementationInfoRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SqlImplementationInfoRow] = new JdbcDecoder[SqlImplementationInfoRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SqlImplementationInfoRow) = + columIndex + 4 -> + SqlImplementationInfoRow( + implementationInfoId = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + implementationInfoName = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + integerValue = JdbcDecoder.optionDecoder(CardinalNumber.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + characterValue = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + comments = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SqlImplementationInfoRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val implementationInfoId = jsonObj.get("implementation_info_id").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val implementationInfoName = jsonObj.get("implementation_info_name").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val integerValue = jsonObj.get("integer_value").fold[Either[String, Option[CardinalNumber]]](Right(None))(_.as(JsonDecoder.option(CardinalNumber.jsonDecoder))) + val characterValue = jsonObj.get("character_value").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val comments = jsonObj.get("comments").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + if (implementationInfoId.isRight && implementationInfoName.isRight && integerValue.isRight && characterValue.isRight && comments.isRight) + Right(SqlImplementationInfoRow(implementationInfoId = implementationInfoId.toOption.get, implementationInfoName = implementationInfoName.toOption.get, integerValue = integerValue.toOption.get, characterValue = characterValue.toOption.get, comments = comments.toOption.get)) + else Left(List[Either[String, Any]](implementationInfoId, implementationInfoName, integerValue, characterValue, comments).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SqlImplementationInfoRow] = new JsonEncoder[SqlImplementationInfoRow] { + override def unsafeEncode(a: SqlImplementationInfoRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""implementation_info_id":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.implementationInfoId, indent, out) + out.write(",") + out.write(""""implementation_info_name":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.implementationInfoName, indent, out) + out.write(",") + out.write(""""integer_value":""") + JsonEncoder.option(CardinalNumber.jsonEncoder).unsafeEncode(a.integerValue, indent, out) + out.write(",") + out.write(""""character_value":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.characterValue, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.comments, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoStructure.scala new file mode 100644 index 0000000000..fd3cc58fa1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_implementation_info/SqlImplementationInfoStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_implementation_info + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SqlImplementationInfoStructure[Row](val prefix: Option[String], val extract: Row => SqlImplementationInfoRow, val merge: (Row, SqlImplementationInfoRow) => Row) + extends Relation[SqlImplementationInfoFields, SqlImplementationInfoRow, Row] + with SqlImplementationInfoFields[Row] { outer => + + override val implementationInfoId = new OptField[CharacterData, Row](prefix, "implementation_info_id", None, Some("varchar"))(x => extract(x).implementationInfoId, (row, value) => merge(row, extract(row).copy(implementationInfoId = value))) + override val implementationInfoName = new OptField[CharacterData, Row](prefix, "implementation_info_name", None, Some("varchar"))(x => extract(x).implementationInfoName, (row, value) => merge(row, extract(row).copy(implementationInfoName = value))) + override val integerValue = new OptField[CardinalNumber, Row](prefix, "integer_value", None, Some("int4"))(x => extract(x).integerValue, (row, value) => merge(row, extract(row).copy(integerValue = value))) + override val characterValue = new OptField[CharacterData, Row](prefix, "character_value", None, Some("varchar"))(x => extract(x).characterValue, (row, value) => merge(row, extract(row).copy(characterValue = value))) + override val comments = new OptField[CharacterData, Row](prefix, "comments", None, Some("varchar"))(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](implementationInfoId, implementationInfoName, integerValue, characterValue, comments) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SqlImplementationInfoRow, merge: (NewRow, SqlImplementationInfoRow) => NewRow): SqlImplementationInfoStructure[NewRow] = + new SqlImplementationInfoStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsFields.scala new file mode 100644 index 0000000000..8644b11968 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_parts + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.SqlExpr.OptField + +trait SqlPartsFields[Row] { + val featureId: OptField[CharacterData, Row] + val featureName: OptField[CharacterData, Row] + val isSupported: OptField[YesOrNo, Row] + val isVerifiedBy: OptField[CharacterData, Row] + val comments: OptField[CharacterData, Row] +} +object SqlPartsFields extends SqlPartsStructure[SqlPartsRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepo.scala new file mode 100644 index 0000000000..a8da63750d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_parts + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SqlPartsRepo { + def delete: DeleteBuilder[SqlPartsFields, SqlPartsRow] + def insert(unsaved: SqlPartsRow): ZIO[ZConnection, Throwable, SqlPartsRow] + def select: SelectBuilder[SqlPartsFields, SqlPartsRow] + def selectAll: ZStream[ZConnection, Throwable, SqlPartsRow] + def update: UpdateBuilder[SqlPartsFields, SqlPartsRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepoImpl.scala new file mode 100644 index 0000000000..1826a9b315 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRepoImpl.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_parts + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SqlPartsRepoImpl extends SqlPartsRepo { + override def delete: DeleteBuilder[SqlPartsFields, SqlPartsRow] = { + DeleteBuilder("information_schema.sql_parts", SqlPartsFields) + } + override def insert(unsaved: SqlPartsRow): ZIO[ZConnection, Throwable, SqlPartsRow] = { + sql"""insert into information_schema.sql_parts("feature_id", "feature_name", "is_supported", "is_verified_by", "comments") + values (${Segment.paramSegment(unsaved.featureId)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.featureName)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.isSupported)(Setter.optionParamSetter(YesOrNo.setter))}::varchar, ${Segment.paramSegment(unsaved.isVerifiedBy)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(CharacterData.setter))}::varchar) + returning "feature_id", "feature_name", "is_supported", "is_verified_by", "comments" + """.insertReturning(SqlPartsRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[SqlPartsFields, SqlPartsRow] = { + SelectBuilderSql("information_schema.sql_parts", SqlPartsFields, SqlPartsRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SqlPartsRow] = { + sql"""select "feature_id", "feature_name", "is_supported", "is_verified_by", "comments" from information_schema.sql_parts""".query(SqlPartsRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[SqlPartsFields, SqlPartsRow] = { + UpdateBuilder("information_schema.sql_parts", SqlPartsFields, SqlPartsRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRow.scala new file mode 100644 index 0000000000..4ae34d4929 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsRow.scala @@ -0,0 +1,69 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_parts + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SqlPartsRow( + featureId: Option[CharacterData], + featureName: Option[CharacterData], + isSupported: Option[YesOrNo], + isVerifiedBy: Option[CharacterData], + comments: Option[CharacterData] +) + +object SqlPartsRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SqlPartsRow] = new JdbcDecoder[SqlPartsRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SqlPartsRow) = + columIndex + 4 -> + SqlPartsRow( + featureId = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + featureName = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + isSupported = JdbcDecoder.optionDecoder(YesOrNo.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + isVerifiedBy = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + comments = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SqlPartsRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val featureId = jsonObj.get("feature_id").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val featureName = jsonObj.get("feature_name").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val isSupported = jsonObj.get("is_supported").fold[Either[String, Option[YesOrNo]]](Right(None))(_.as(JsonDecoder.option(YesOrNo.jsonDecoder))) + val isVerifiedBy = jsonObj.get("is_verified_by").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val comments = jsonObj.get("comments").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + if (featureId.isRight && featureName.isRight && isSupported.isRight && isVerifiedBy.isRight && comments.isRight) + Right(SqlPartsRow(featureId = featureId.toOption.get, featureName = featureName.toOption.get, isSupported = isSupported.toOption.get, isVerifiedBy = isVerifiedBy.toOption.get, comments = comments.toOption.get)) + else Left(List[Either[String, Any]](featureId, featureName, isSupported, isVerifiedBy, comments).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SqlPartsRow] = new JsonEncoder[SqlPartsRow] { + override def unsafeEncode(a: SqlPartsRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""feature_id":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.featureId, indent, out) + out.write(",") + out.write(""""feature_name":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.featureName, indent, out) + out.write(",") + out.write(""""is_supported":""") + JsonEncoder.option(YesOrNo.jsonEncoder).unsafeEncode(a.isSupported, indent, out) + out.write(",") + out.write(""""is_verified_by":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.isVerifiedBy, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.comments, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsStructure.scala new file mode 100644 index 0000000000..d19fda982a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_parts/SqlPartsStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_parts + +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SqlPartsStructure[Row](val prefix: Option[String], val extract: Row => SqlPartsRow, val merge: (Row, SqlPartsRow) => Row) + extends Relation[SqlPartsFields, SqlPartsRow, Row] + with SqlPartsFields[Row] { outer => + + override val featureId = new OptField[CharacterData, Row](prefix, "feature_id", None, Some("varchar"))(x => extract(x).featureId, (row, value) => merge(row, extract(row).copy(featureId = value))) + override val featureName = new OptField[CharacterData, Row](prefix, "feature_name", None, Some("varchar"))(x => extract(x).featureName, (row, value) => merge(row, extract(row).copy(featureName = value))) + override val isSupported = new OptField[YesOrNo, Row](prefix, "is_supported", None, Some("varchar"))(x => extract(x).isSupported, (row, value) => merge(row, extract(row).copy(isSupported = value))) + override val isVerifiedBy = new OptField[CharacterData, Row](prefix, "is_verified_by", None, Some("varchar"))(x => extract(x).isVerifiedBy, (row, value) => merge(row, extract(row).copy(isVerifiedBy = value))) + override val comments = new OptField[CharacterData, Row](prefix, "comments", None, Some("varchar"))(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](featureId, featureName, isSupported, isVerifiedBy, comments) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SqlPartsRow, merge: (NewRow, SqlPartsRow) => NewRow): SqlPartsStructure[NewRow] = + new SqlPartsStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingFields.scala new file mode 100644 index 0000000000..8d4874c096 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_sizing + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.SqlExpr.OptField + +trait SqlSizingFields[Row] { + val sizingId: OptField[CardinalNumber, Row] + val sizingName: OptField[CharacterData, Row] + val supportedValue: OptField[CardinalNumber, Row] + val comments: OptField[CharacterData, Row] +} +object SqlSizingFields extends SqlSizingStructure[SqlSizingRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepo.scala new file mode 100644 index 0000000000..2133dadb4e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_sizing + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SqlSizingRepo { + def delete: DeleteBuilder[SqlSizingFields, SqlSizingRow] + def insert(unsaved: SqlSizingRow): ZIO[ZConnection, Throwable, SqlSizingRow] + def select: SelectBuilder[SqlSizingFields, SqlSizingRow] + def selectAll: ZStream[ZConnection, Throwable, SqlSizingRow] + def update: UpdateBuilder[SqlSizingFields, SqlSizingRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepoImpl.scala new file mode 100644 index 0000000000..f095ebca5d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRepoImpl.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_sizing + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SqlSizingRepoImpl extends SqlSizingRepo { + override def delete: DeleteBuilder[SqlSizingFields, SqlSizingRow] = { + DeleteBuilder("information_schema.sql_sizing", SqlSizingFields) + } + override def insert(unsaved: SqlSizingRow): ZIO[ZConnection, Throwable, SqlSizingRow] = { + sql"""insert into information_schema.sql_sizing("sizing_id", "sizing_name", "supported_value", "comments") + values (${Segment.paramSegment(unsaved.sizingId)(Setter.optionParamSetter(CardinalNumber.setter))}::int4, ${Segment.paramSegment(unsaved.sizingName)(Setter.optionParamSetter(CharacterData.setter))}::varchar, ${Segment.paramSegment(unsaved.supportedValue)(Setter.optionParamSetter(CardinalNumber.setter))}::int4, ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(CharacterData.setter))}::varchar) + returning "sizing_id", "sizing_name", "supported_value", "comments" + """.insertReturning(SqlSizingRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[SqlSizingFields, SqlSizingRow] = { + SelectBuilderSql("information_schema.sql_sizing", SqlSizingFields, SqlSizingRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SqlSizingRow] = { + sql"""select "sizing_id", "sizing_name", "supported_value", "comments" from information_schema.sql_sizing""".query(SqlSizingRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[SqlSizingFields, SqlSizingRow] = { + UpdateBuilder("information_schema.sql_sizing", SqlSizingFields, SqlSizingRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRow.scala new file mode 100644 index 0000000000..49243246cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_sizing + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SqlSizingRow( + sizingId: Option[CardinalNumber], + sizingName: Option[CharacterData], + supportedValue: Option[CardinalNumber], + comments: Option[CharacterData] +) + +object SqlSizingRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SqlSizingRow] = new JdbcDecoder[SqlSizingRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SqlSizingRow) = + columIndex + 3 -> + SqlSizingRow( + sizingId = JdbcDecoder.optionDecoder(CardinalNumber.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + sizingName = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + supportedValue = JdbcDecoder.optionDecoder(CardinalNumber.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + comments = JdbcDecoder.optionDecoder(CharacterData.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SqlSizingRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val sizingId = jsonObj.get("sizing_id").fold[Either[String, Option[CardinalNumber]]](Right(None))(_.as(JsonDecoder.option(CardinalNumber.jsonDecoder))) + val sizingName = jsonObj.get("sizing_name").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + val supportedValue = jsonObj.get("supported_value").fold[Either[String, Option[CardinalNumber]]](Right(None))(_.as(JsonDecoder.option(CardinalNumber.jsonDecoder))) + val comments = jsonObj.get("comments").fold[Either[String, Option[CharacterData]]](Right(None))(_.as(JsonDecoder.option(CharacterData.jsonDecoder))) + if (sizingId.isRight && sizingName.isRight && supportedValue.isRight && comments.isRight) + Right(SqlSizingRow(sizingId = sizingId.toOption.get, sizingName = sizingName.toOption.get, supportedValue = supportedValue.toOption.get, comments = comments.toOption.get)) + else Left(List[Either[String, Any]](sizingId, sizingName, supportedValue, comments).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SqlSizingRow] = new JsonEncoder[SqlSizingRow] { + override def unsafeEncode(a: SqlSizingRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""sizing_id":""") + JsonEncoder.option(CardinalNumber.jsonEncoder).unsafeEncode(a.sizingId, indent, out) + out.write(",") + out.write(""""sizing_name":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.sizingName, indent, out) + out.write(",") + out.write(""""supported_value":""") + JsonEncoder.option(CardinalNumber.jsonEncoder).unsafeEncode(a.supportedValue, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(CharacterData.jsonEncoder).unsafeEncode(a.comments, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingStructure.scala new file mode 100644 index 0000000000..feaaffaeca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/sql_sizing/SqlSizingStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package sql_sizing + +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SqlSizingStructure[Row](val prefix: Option[String], val extract: Row => SqlSizingRow, val merge: (Row, SqlSizingRow) => Row) + extends Relation[SqlSizingFields, SqlSizingRow, Row] + with SqlSizingFields[Row] { outer => + + override val sizingId = new OptField[CardinalNumber, Row](prefix, "sizing_id", None, Some("int4"))(x => extract(x).sizingId, (row, value) => merge(row, extract(row).copy(sizingId = value))) + override val sizingName = new OptField[CharacterData, Row](prefix, "sizing_name", None, Some("varchar"))(x => extract(x).sizingName, (row, value) => merge(row, extract(row).copy(sizingName = value))) + override val supportedValue = new OptField[CardinalNumber, Row](prefix, "supported_value", None, Some("int4"))(x => extract(x).supportedValue, (row, value) => merge(row, extract(row).copy(supportedValue = value))) + override val comments = new OptField[CharacterData, Row](prefix, "comments", None, Some("varchar"))(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](sizingId, sizingName, supportedValue, comments) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SqlSizingRow, merge: (NewRow, SqlSizingRow) => NewRow): SqlSizingStructure[NewRow] = + new SqlSizingStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewFields.scala new file mode 100644 index 0000000000..a9506ca506 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_constraints + +import typo.dsl.SqlExpr.OptField + +trait TableConstraintsViewFields[Row] { + val constraintCatalog: OptField[String, Row] + val constraintSchema: OptField[String, Row] + val constraintName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val constraintType: OptField[String, Row] + val isDeferrable: OptField[/* max 3 chars */ String, Row] + val initiallyDeferred: OptField[/* max 3 chars */ String, Row] + val enforced: OptField[/* max 3 chars */ String, Row] +} +object TableConstraintsViewFields extends TableConstraintsViewStructure[TableConstraintsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepo.scala new file mode 100644 index 0000000000..e06052ca5e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_constraints + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TableConstraintsViewRepo { + def select: SelectBuilder[TableConstraintsViewFields, TableConstraintsViewRow] + def selectAll: ZStream[ZConnection, Throwable, TableConstraintsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepoImpl.scala new file mode 100644 index 0000000000..5816ca985e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_constraints + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TableConstraintsViewRepoImpl extends TableConstraintsViewRepo { + override def select: SelectBuilder[TableConstraintsViewFields, TableConstraintsViewRow] = { + SelectBuilderSql("information_schema.table_constraints", TableConstraintsViewFields, TableConstraintsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TableConstraintsViewRow] = { + sql"""select "constraint_catalog", "constraint_schema", "constraint_name", "table_catalog", "table_schema", "table_name", "constraint_type", "is_deferrable", "initially_deferred", "enforced" from information_schema.table_constraints""".query(TableConstraintsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRow.scala new file mode 100644 index 0000000000..c81bad5043 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_constraints + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TableConstraintsViewRow( + constraintCatalog: /* nullability unknown */ Option[String], + constraintSchema: /* nullability unknown */ Option[String], + constraintName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + constraintType: /* nullability unknown */ Option[String], + isDeferrable: /* nullability unknown */ Option[/* max 3 chars */ String], + initiallyDeferred: /* nullability unknown */ Option[/* max 3 chars */ String], + enforced: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object TableConstraintsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TableConstraintsViewRow] = new JdbcDecoder[TableConstraintsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TableConstraintsViewRow) = + columIndex + 9 -> + TableConstraintsViewRow( + constraintCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + constraintSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + constraintName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + constraintType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isDeferrable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + initiallyDeferred = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + enforced = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TableConstraintsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val constraintCatalog = jsonObj.get("constraint_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintSchema = jsonObj.get("constraint_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintName = jsonObj.get("constraint_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val constraintType = jsonObj.get("constraint_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isDeferrable = jsonObj.get("is_deferrable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val initiallyDeferred = jsonObj.get("initially_deferred").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val enforced = jsonObj.get("enforced").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (constraintCatalog.isRight && constraintSchema.isRight && constraintName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && constraintType.isRight && isDeferrable.isRight && initiallyDeferred.isRight && enforced.isRight) + Right(TableConstraintsViewRow(constraintCatalog = constraintCatalog.toOption.get, constraintSchema = constraintSchema.toOption.get, constraintName = constraintName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, constraintType = constraintType.toOption.get, isDeferrable = isDeferrable.toOption.get, initiallyDeferred = initiallyDeferred.toOption.get, enforced = enforced.toOption.get)) + else Left(List[Either[String, Any]](constraintCatalog, constraintSchema, constraintName, tableCatalog, tableSchema, tableName, constraintType, isDeferrable, initiallyDeferred, enforced).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TableConstraintsViewRow] = new JsonEncoder[TableConstraintsViewRow] { + override def unsafeEncode(a: TableConstraintsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""constraint_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintCatalog, indent, out) + out.write(",") + out.write(""""constraint_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintSchema, indent, out) + out.write(",") + out.write(""""constraint_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""constraint_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.constraintType, indent, out) + out.write(",") + out.write(""""is_deferrable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isDeferrable, indent, out) + out.write(",") + out.write(""""initially_deferred":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.initiallyDeferred, indent, out) + out.write(",") + out.write(""""enforced":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.enforced, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewStructure.scala new file mode 100644 index 0000000000..e6c544b856 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_constraints/TableConstraintsViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_constraints + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TableConstraintsViewStructure[Row](val prefix: Option[String], val extract: Row => TableConstraintsViewRow, val merge: (Row, TableConstraintsViewRow) => Row) + extends Relation[TableConstraintsViewFields, TableConstraintsViewRow, Row] + with TableConstraintsViewFields[Row] { outer => + + override val constraintCatalog = new OptField[String, Row](prefix, "constraint_catalog", None, None)(x => extract(x).constraintCatalog, (row, value) => merge(row, extract(row).copy(constraintCatalog = value))) + override val constraintSchema = new OptField[String, Row](prefix, "constraint_schema", None, None)(x => extract(x).constraintSchema, (row, value) => merge(row, extract(row).copy(constraintSchema = value))) + override val constraintName = new OptField[String, Row](prefix, "constraint_name", None, None)(x => extract(x).constraintName, (row, value) => merge(row, extract(row).copy(constraintName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val constraintType = new OptField[String, Row](prefix, "constraint_type", None, None)(x => extract(x).constraintType, (row, value) => merge(row, extract(row).copy(constraintType = value))) + override val isDeferrable = new OptField[/* max 3 chars */ String, Row](prefix, "is_deferrable", None, None)(x => extract(x).isDeferrable, (row, value) => merge(row, extract(row).copy(isDeferrable = value))) + override val initiallyDeferred = new OptField[/* max 3 chars */ String, Row](prefix, "initially_deferred", None, None)(x => extract(x).initiallyDeferred, (row, value) => merge(row, extract(row).copy(initiallyDeferred = value))) + override val enforced = new OptField[/* max 3 chars */ String, Row](prefix, "enforced", None, None)(x => extract(x).enforced, (row, value) => merge(row, extract(row).copy(enforced = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](constraintCatalog, constraintSchema, constraintName, tableCatalog, tableSchema, tableName, constraintType, isDeferrable, initiallyDeferred, enforced) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TableConstraintsViewRow, merge: (NewRow, TableConstraintsViewRow) => NewRow): TableConstraintsViewStructure[NewRow] = + new TableConstraintsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewFields.scala new file mode 100644 index 0000000000..4780224375 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_privileges + +import typo.dsl.SqlExpr.OptField + +trait TablePrivilegesViewFields[Row] { + val grantor: OptField[String, Row] + val grantee: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val privilegeType: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] + val withHierarchy: OptField[/* max 3 chars */ String, Row] +} +object TablePrivilegesViewFields extends TablePrivilegesViewStructure[TablePrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepo.scala new file mode 100644 index 0000000000..32c537ec2a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TablePrivilegesViewRepo { + def select: SelectBuilder[TablePrivilegesViewFields, TablePrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, TablePrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..07323433fb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TablePrivilegesViewRepoImpl extends TablePrivilegesViewRepo { + override def select: SelectBuilder[TablePrivilegesViewFields, TablePrivilegesViewRow] = { + SelectBuilderSql("information_schema.table_privileges", TablePrivilegesViewFields, TablePrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TablePrivilegesViewRow] = { + sql"""select "grantor", "grantee", "table_catalog", "table_schema", "table_name", "privilege_type", "is_grantable", "with_hierarchy" from information_schema.table_privileges""".query(TablePrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRow.scala new file mode 100644 index 0000000000..39e5710b72 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TablePrivilegesViewRow( + grantor: /* nullability unknown */ Option[String], + grantee: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + privilegeType: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String], + withHierarchy: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object TablePrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TablePrivilegesViewRow] = new JdbcDecoder[TablePrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TablePrivilegesViewRow) = + columIndex + 7 -> + TablePrivilegesViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + withHierarchy = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TablePrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val withHierarchy = jsonObj.get("with_hierarchy").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && privilegeType.isRight && isGrantable.isRight && withHierarchy.isRight) + Right(TablePrivilegesViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get, withHierarchy = withHierarchy.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, tableCatalog, tableSchema, tableName, privilegeType, isGrantable, withHierarchy).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TablePrivilegesViewRow] = new JsonEncoder[TablePrivilegesViewRow] { + override def unsafeEncode(a: TablePrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write(",") + out.write(""""with_hierarchy":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.withHierarchy, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewStructure.scala new file mode 100644 index 0000000000..f03e2cf413 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/table_privileges/TablePrivilegesViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package table_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TablePrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => TablePrivilegesViewRow, val merge: (Row, TablePrivilegesViewRow) => Row) + extends Relation[TablePrivilegesViewFields, TablePrivilegesViewRow, Row] + with TablePrivilegesViewFields[Row] { outer => + + override val grantor = new OptField[String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val privilegeType = new OptField[String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + override val withHierarchy = new OptField[/* max 3 chars */ String, Row](prefix, "with_hierarchy", None, None)(x => extract(x).withHierarchy, (row, value) => merge(row, extract(row).copy(withHierarchy = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, tableCatalog, tableSchema, tableName, privilegeType, isGrantable, withHierarchy) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TablePrivilegesViewRow, merge: (NewRow, TablePrivilegesViewRow) => NewRow): TablePrivilegesViewStructure[NewRow] = + new TablePrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewFields.scala new file mode 100644 index 0000000000..44bfdee499 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package tables + +import typo.dsl.SqlExpr.OptField + +trait TablesViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val tableType: OptField[String, Row] + val selfReferencingColumnName: OptField[String, Row] + val referenceGeneration: OptField[String, Row] + val userDefinedTypeCatalog: OptField[String, Row] + val userDefinedTypeSchema: OptField[String, Row] + val userDefinedTypeName: OptField[String, Row] + val isInsertableInto: OptField[/* max 3 chars */ String, Row] + val isTyped: OptField[/* max 3 chars */ String, Row] + val commitAction: OptField[String, Row] +} +object TablesViewFields extends TablesViewStructure[TablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepo.scala new file mode 100644 index 0000000000..ded0898778 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TablesViewRepo { + def select: SelectBuilder[TablesViewFields, TablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, TablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepoImpl.scala new file mode 100644 index 0000000000..e1d4a4b346 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TablesViewRepoImpl extends TablesViewRepo { + override def select: SelectBuilder[TablesViewFields, TablesViewRow] = { + SelectBuilderSql("information_schema.tables", TablesViewFields, TablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TablesViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "table_type", "self_referencing_column_name", "reference_generation", "user_defined_type_catalog", "user_defined_type_schema", "user_defined_type_name", "is_insertable_into", "is_typed", "commit_action" from information_schema.tables""".query(TablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRow.scala new file mode 100644 index 0000000000..8fb5988f0e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package tables + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TablesViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + tableType: /* nullability unknown */ Option[String], + selfReferencingColumnName: /* nullability unknown */ Option[String], + referenceGeneration: /* nullability unknown */ Option[String], + userDefinedTypeCatalog: /* nullability unknown */ Option[String], + userDefinedTypeSchema: /* nullability unknown */ Option[String], + userDefinedTypeName: /* nullability unknown */ Option[String], + isInsertableInto: /* nullability unknown */ Option[/* max 3 chars */ String], + isTyped: /* nullability unknown */ Option[/* max 3 chars */ String], + commitAction: /* nullability unknown */ Option[String] +) + +object TablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TablesViewRow] = new JdbcDecoder[TablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TablesViewRow) = + columIndex + 11 -> + TablesViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + selfReferencingColumnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + referenceGeneration = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + userDefinedTypeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + userDefinedTypeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + userDefinedTypeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + isInsertableInto = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + isTyped = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + commitAction = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableType = jsonObj.get("table_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val selfReferencingColumnName = jsonObj.get("self_referencing_column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val referenceGeneration = jsonObj.get("reference_generation").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeCatalog = jsonObj.get("user_defined_type_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeSchema = jsonObj.get("user_defined_type_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeName = jsonObj.get("user_defined_type_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isInsertableInto = jsonObj.get("is_insertable_into").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isTyped = jsonObj.get("is_typed").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val commitAction = jsonObj.get("commit_action").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && tableType.isRight && selfReferencingColumnName.isRight && referenceGeneration.isRight && userDefinedTypeCatalog.isRight && userDefinedTypeSchema.isRight && userDefinedTypeName.isRight && isInsertableInto.isRight && isTyped.isRight && commitAction.isRight) + Right(TablesViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, tableType = tableType.toOption.get, selfReferencingColumnName = selfReferencingColumnName.toOption.get, referenceGeneration = referenceGeneration.toOption.get, userDefinedTypeCatalog = userDefinedTypeCatalog.toOption.get, userDefinedTypeSchema = userDefinedTypeSchema.toOption.get, userDefinedTypeName = userDefinedTypeName.toOption.get, isInsertableInto = isInsertableInto.toOption.get, isTyped = isTyped.toOption.get, commitAction = commitAction.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, tableType, selfReferencingColumnName, referenceGeneration, userDefinedTypeCatalog, userDefinedTypeSchema, userDefinedTypeName, isInsertableInto, isTyped, commitAction).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TablesViewRow] = new JsonEncoder[TablesViewRow] { + override def unsafeEncode(a: TablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""table_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableType, indent, out) + out.write(",") + out.write(""""self_referencing_column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.selfReferencingColumnName, indent, out) + out.write(",") + out.write(""""reference_generation":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.referenceGeneration, indent, out) + out.write(",") + out.write(""""user_defined_type_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeCatalog, indent, out) + out.write(",") + out.write(""""user_defined_type_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeSchema, indent, out) + out.write(",") + out.write(""""user_defined_type_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeName, indent, out) + out.write(",") + out.write(""""is_insertable_into":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isInsertableInto, indent, out) + out.write(",") + out.write(""""is_typed":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isTyped, indent, out) + out.write(",") + out.write(""""commit_action":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.commitAction, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewStructure.scala new file mode 100644 index 0000000000..27b6a098b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/tables/TablesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package tables + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TablesViewStructure[Row](val prefix: Option[String], val extract: Row => TablesViewRow, val merge: (Row, TablesViewRow) => Row) + extends Relation[TablesViewFields, TablesViewRow, Row] + with TablesViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val tableType = new OptField[String, Row](prefix, "table_type", None, None)(x => extract(x).tableType, (row, value) => merge(row, extract(row).copy(tableType = value))) + override val selfReferencingColumnName = new OptField[String, Row](prefix, "self_referencing_column_name", None, None)(x => extract(x).selfReferencingColumnName, (row, value) => merge(row, extract(row).copy(selfReferencingColumnName = value))) + override val referenceGeneration = new OptField[String, Row](prefix, "reference_generation", None, None)(x => extract(x).referenceGeneration, (row, value) => merge(row, extract(row).copy(referenceGeneration = value))) + override val userDefinedTypeCatalog = new OptField[String, Row](prefix, "user_defined_type_catalog", None, None)(x => extract(x).userDefinedTypeCatalog, (row, value) => merge(row, extract(row).copy(userDefinedTypeCatalog = value))) + override val userDefinedTypeSchema = new OptField[String, Row](prefix, "user_defined_type_schema", None, None)(x => extract(x).userDefinedTypeSchema, (row, value) => merge(row, extract(row).copy(userDefinedTypeSchema = value))) + override val userDefinedTypeName = new OptField[String, Row](prefix, "user_defined_type_name", None, None)(x => extract(x).userDefinedTypeName, (row, value) => merge(row, extract(row).copy(userDefinedTypeName = value))) + override val isInsertableInto = new OptField[/* max 3 chars */ String, Row](prefix, "is_insertable_into", None, None)(x => extract(x).isInsertableInto, (row, value) => merge(row, extract(row).copy(isInsertableInto = value))) + override val isTyped = new OptField[/* max 3 chars */ String, Row](prefix, "is_typed", None, None)(x => extract(x).isTyped, (row, value) => merge(row, extract(row).copy(isTyped = value))) + override val commitAction = new OptField[String, Row](prefix, "commit_action", None, None)(x => extract(x).commitAction, (row, value) => merge(row, extract(row).copy(commitAction = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, tableType, selfReferencingColumnName, referenceGeneration, userDefinedTypeCatalog, userDefinedTypeSchema, userDefinedTypeName, isInsertableInto, isTyped, commitAction) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TablesViewRow, merge: (NewRow, TablesViewRow) => NewRow): TablesViewStructure[NewRow] = + new TablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewFields.scala new file mode 100644 index 0000000000..abee6d8234 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package transforms + +import typo.dsl.SqlExpr.OptField + +trait TransformsViewFields[Row] { + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] + val groupName: OptField[String, Row] + val transformType: OptField[String, Row] +} +object TransformsViewFields extends TransformsViewStructure[TransformsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepo.scala new file mode 100644 index 0000000000..03f829b87a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package transforms + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TransformsViewRepo { + def select: SelectBuilder[TransformsViewFields, TransformsViewRow] + def selectAll: ZStream[ZConnection, Throwable, TransformsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepoImpl.scala new file mode 100644 index 0000000000..a6dd42480e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package transforms + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TransformsViewRepoImpl extends TransformsViewRepo { + override def select: SelectBuilder[TransformsViewFields, TransformsViewRow] = { + SelectBuilderSql("information_schema.transforms", TransformsViewFields, TransformsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TransformsViewRow] = { + sql"""select "udt_catalog", "udt_schema", "udt_name", "specific_catalog", "specific_schema", "specific_name", "group_name", "transform_type" from information_schema.transforms""".query(TransformsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRow.scala new file mode 100644 index 0000000000..6ab24577cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package transforms + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TransformsViewRow( + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String], + groupName: /* nullability unknown */ Option[String], + transformType: /* nullability unknown */ Option[String] +) + +object TransformsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TransformsViewRow] = new JdbcDecoder[TransformsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TransformsViewRow) = + columIndex + 7 -> + TransformsViewRow( + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + groupName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + transformType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TransformsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val groupName = jsonObj.get("group_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val transformType = jsonObj.get("transform_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (udtCatalog.isRight && udtSchema.isRight && udtName.isRight && specificCatalog.isRight && specificSchema.isRight && specificName.isRight && groupName.isRight && transformType.isRight) + Right(TransformsViewRow(udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get, groupName = groupName.toOption.get, transformType = transformType.toOption.get)) + else Left(List[Either[String, Any]](udtCatalog, udtSchema, udtName, specificCatalog, specificSchema, specificName, groupName, transformType).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TransformsViewRow] = new JsonEncoder[TransformsViewRow] { + override def unsafeEncode(a: TransformsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write(",") + out.write(""""group_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.groupName, indent, out) + out.write(",") + out.write(""""transform_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.transformType, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewStructure.scala new file mode 100644 index 0000000000..7706dafeaa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/transforms/TransformsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package transforms + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TransformsViewStructure[Row](val prefix: Option[String], val extract: Row => TransformsViewRow, val merge: (Row, TransformsViewRow) => Row) + extends Relation[TransformsViewFields, TransformsViewRow, Row] + with TransformsViewFields[Row] { outer => + + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + override val groupName = new OptField[String, Row](prefix, "group_name", None, None)(x => extract(x).groupName, (row, value) => merge(row, extract(row).copy(groupName = value))) + override val transformType = new OptField[String, Row](prefix, "transform_type", None, None)(x => extract(x).transformType, (row, value) => merge(row, extract(row).copy(transformType = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](udtCatalog, udtSchema, udtName, specificCatalog, specificSchema, specificName, groupName, transformType) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TransformsViewRow, merge: (NewRow, TransformsViewRow) => NewRow): TransformsViewStructure[NewRow] = + new TransformsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewFields.scala new file mode 100644 index 0000000000..5bb7eb62ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggered_update_columns + +import typo.dsl.SqlExpr.OptField + +trait TriggeredUpdateColumnsViewFields[Row] { + val triggerCatalog: OptField[String, Row] + val triggerSchema: OptField[String, Row] + val triggerName: OptField[String, Row] + val eventObjectCatalog: OptField[String, Row] + val eventObjectSchema: OptField[String, Row] + val eventObjectTable: OptField[String, Row] + val eventObjectColumn: OptField[String, Row] +} +object TriggeredUpdateColumnsViewFields extends TriggeredUpdateColumnsViewStructure[TriggeredUpdateColumnsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepo.scala new file mode 100644 index 0000000000..6bb2963df2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggered_update_columns + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TriggeredUpdateColumnsViewRepo { + def select: SelectBuilder[TriggeredUpdateColumnsViewFields, TriggeredUpdateColumnsViewRow] + def selectAll: ZStream[ZConnection, Throwable, TriggeredUpdateColumnsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepoImpl.scala new file mode 100644 index 0000000000..e2f2adbab8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggered_update_columns + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TriggeredUpdateColumnsViewRepoImpl extends TriggeredUpdateColumnsViewRepo { + override def select: SelectBuilder[TriggeredUpdateColumnsViewFields, TriggeredUpdateColumnsViewRow] = { + SelectBuilderSql("information_schema.triggered_update_columns", TriggeredUpdateColumnsViewFields, TriggeredUpdateColumnsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TriggeredUpdateColumnsViewRow] = { + sql"""select "trigger_catalog", "trigger_schema", "trigger_name", "event_object_catalog", "event_object_schema", "event_object_table", "event_object_column" from information_schema.triggered_update_columns""".query(TriggeredUpdateColumnsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRow.scala new file mode 100644 index 0000000000..573fd9ebde --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggered_update_columns + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TriggeredUpdateColumnsViewRow( + triggerCatalog: /* nullability unknown */ Option[String], + triggerSchema: /* nullability unknown */ Option[String], + triggerName: /* nullability unknown */ Option[String], + eventObjectCatalog: /* nullability unknown */ Option[String], + eventObjectSchema: /* nullability unknown */ Option[String], + eventObjectTable: /* nullability unknown */ Option[String], + eventObjectColumn: /* nullability unknown */ Option[String] +) + +object TriggeredUpdateColumnsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TriggeredUpdateColumnsViewRow] = new JdbcDecoder[TriggeredUpdateColumnsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TriggeredUpdateColumnsViewRow) = + columIndex + 6 -> + TriggeredUpdateColumnsViewRow( + triggerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + triggerSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + triggerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + eventObjectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + eventObjectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + eventObjectTable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + eventObjectColumn = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TriggeredUpdateColumnsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val triggerCatalog = jsonObj.get("trigger_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val triggerSchema = jsonObj.get("trigger_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val triggerName = jsonObj.get("trigger_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectCatalog = jsonObj.get("event_object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectSchema = jsonObj.get("event_object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectTable = jsonObj.get("event_object_table").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectColumn = jsonObj.get("event_object_column").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (triggerCatalog.isRight && triggerSchema.isRight && triggerName.isRight && eventObjectCatalog.isRight && eventObjectSchema.isRight && eventObjectTable.isRight && eventObjectColumn.isRight) + Right(TriggeredUpdateColumnsViewRow(triggerCatalog = triggerCatalog.toOption.get, triggerSchema = triggerSchema.toOption.get, triggerName = triggerName.toOption.get, eventObjectCatalog = eventObjectCatalog.toOption.get, eventObjectSchema = eventObjectSchema.toOption.get, eventObjectTable = eventObjectTable.toOption.get, eventObjectColumn = eventObjectColumn.toOption.get)) + else Left(List[Either[String, Any]](triggerCatalog, triggerSchema, triggerName, eventObjectCatalog, eventObjectSchema, eventObjectTable, eventObjectColumn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TriggeredUpdateColumnsViewRow] = new JsonEncoder[TriggeredUpdateColumnsViewRow] { + override def unsafeEncode(a: TriggeredUpdateColumnsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""trigger_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerCatalog, indent, out) + out.write(",") + out.write(""""trigger_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerSchema, indent, out) + out.write(",") + out.write(""""trigger_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerName, indent, out) + out.write(",") + out.write(""""event_object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectCatalog, indent, out) + out.write(",") + out.write(""""event_object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectSchema, indent, out) + out.write(",") + out.write(""""event_object_table":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectTable, indent, out) + out.write(",") + out.write(""""event_object_column":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectColumn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewStructure.scala new file mode 100644 index 0000000000..a3779f19fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggered_update_columns/TriggeredUpdateColumnsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggered_update_columns + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TriggeredUpdateColumnsViewStructure[Row](val prefix: Option[String], val extract: Row => TriggeredUpdateColumnsViewRow, val merge: (Row, TriggeredUpdateColumnsViewRow) => Row) + extends Relation[TriggeredUpdateColumnsViewFields, TriggeredUpdateColumnsViewRow, Row] + with TriggeredUpdateColumnsViewFields[Row] { outer => + + override val triggerCatalog = new OptField[String, Row](prefix, "trigger_catalog", None, None)(x => extract(x).triggerCatalog, (row, value) => merge(row, extract(row).copy(triggerCatalog = value))) + override val triggerSchema = new OptField[String, Row](prefix, "trigger_schema", None, None)(x => extract(x).triggerSchema, (row, value) => merge(row, extract(row).copy(triggerSchema = value))) + override val triggerName = new OptField[String, Row](prefix, "trigger_name", None, None)(x => extract(x).triggerName, (row, value) => merge(row, extract(row).copy(triggerName = value))) + override val eventObjectCatalog = new OptField[String, Row](prefix, "event_object_catalog", None, None)(x => extract(x).eventObjectCatalog, (row, value) => merge(row, extract(row).copy(eventObjectCatalog = value))) + override val eventObjectSchema = new OptField[String, Row](prefix, "event_object_schema", None, None)(x => extract(x).eventObjectSchema, (row, value) => merge(row, extract(row).copy(eventObjectSchema = value))) + override val eventObjectTable = new OptField[String, Row](prefix, "event_object_table", None, None)(x => extract(x).eventObjectTable, (row, value) => merge(row, extract(row).copy(eventObjectTable = value))) + override val eventObjectColumn = new OptField[String, Row](prefix, "event_object_column", None, None)(x => extract(x).eventObjectColumn, (row, value) => merge(row, extract(row).copy(eventObjectColumn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](triggerCatalog, triggerSchema, triggerName, eventObjectCatalog, eventObjectSchema, eventObjectTable, eventObjectColumn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TriggeredUpdateColumnsViewRow, merge: (NewRow, TriggeredUpdateColumnsViewRow) => NewRow): TriggeredUpdateColumnsViewStructure[NewRow] = + new TriggeredUpdateColumnsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewFields.scala new file mode 100644 index 0000000000..ca76672129 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggers + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait TriggersViewFields[Row] { + val triggerCatalog: OptField[String, Row] + val triggerSchema: OptField[String, Row] + val triggerName: OptField[String, Row] + val eventManipulation: OptField[String, Row] + val eventObjectCatalog: OptField[String, Row] + val eventObjectSchema: OptField[String, Row] + val eventObjectTable: OptField[String, Row] + val actionOrder: OptField[Int, Row] + val actionCondition: OptField[String, Row] + val actionStatement: OptField[String, Row] + val actionOrientation: OptField[String, Row] + val actionTiming: OptField[String, Row] + val actionReferenceOldTable: OptField[String, Row] + val actionReferenceNewTable: OptField[String, Row] + val actionReferenceOldRow: OptField[String, Row] + val actionReferenceNewRow: OptField[String, Row] + val created: OptField[TypoInstant, Row] +} +object TriggersViewFields extends TriggersViewStructure[TriggersViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepo.scala new file mode 100644 index 0000000000..2dce8d37c7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggers + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TriggersViewRepo { + def select: SelectBuilder[TriggersViewFields, TriggersViewRow] + def selectAll: ZStream[ZConnection, Throwable, TriggersViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepoImpl.scala new file mode 100644 index 0000000000..6b1558e8ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggers + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TriggersViewRepoImpl extends TriggersViewRepo { + override def select: SelectBuilder[TriggersViewFields, TriggersViewRow] = { + SelectBuilderSql("information_schema.triggers", TriggersViewFields, TriggersViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TriggersViewRow] = { + sql"""select "trigger_catalog", "trigger_schema", "trigger_name", "event_manipulation", "event_object_catalog", "event_object_schema", "event_object_table", "action_order", "action_condition", "action_statement", "action_orientation", "action_timing", "action_reference_old_table", "action_reference_new_table", "action_reference_old_row", "action_reference_new_row", "created"::text from information_schema.triggers""".query(TriggersViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRow.scala new file mode 100644 index 0000000000..3403114606 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewRow.scala @@ -0,0 +1,140 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggers + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TriggersViewRow( + triggerCatalog: /* nullability unknown */ Option[String], + triggerSchema: /* nullability unknown */ Option[String], + triggerName: /* nullability unknown */ Option[String], + eventManipulation: /* nullability unknown */ Option[String], + eventObjectCatalog: /* nullability unknown */ Option[String], + eventObjectSchema: /* nullability unknown */ Option[String], + eventObjectTable: /* nullability unknown */ Option[String], + actionOrder: /* nullability unknown */ Option[Int], + actionCondition: /* nullability unknown */ Option[String], + actionStatement: /* nullability unknown */ Option[String], + actionOrientation: /* nullability unknown */ Option[String], + actionTiming: /* nullability unknown */ Option[String], + actionReferenceOldTable: /* nullability unknown */ Option[String], + actionReferenceNewTable: /* nullability unknown */ Option[String], + actionReferenceOldRow: /* nullability unknown */ Option[String], + actionReferenceNewRow: /* nullability unknown */ Option[String], + created: /* nullability unknown */ Option[TypoInstant] +) + +object TriggersViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TriggersViewRow] = new JdbcDecoder[TriggersViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TriggersViewRow) = + columIndex + 16 -> + TriggersViewRow( + triggerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + triggerSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + triggerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + eventManipulation = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + eventObjectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + eventObjectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + eventObjectTable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + actionOrder = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + actionCondition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + actionStatement = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + actionOrientation = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + actionTiming = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + actionReferenceOldTable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + actionReferenceNewTable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + actionReferenceOldRow = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + actionReferenceNewRow = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + created = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TriggersViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val triggerCatalog = jsonObj.get("trigger_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val triggerSchema = jsonObj.get("trigger_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val triggerName = jsonObj.get("trigger_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventManipulation = jsonObj.get("event_manipulation").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectCatalog = jsonObj.get("event_object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectSchema = jsonObj.get("event_object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val eventObjectTable = jsonObj.get("event_object_table").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionOrder = jsonObj.get("action_order").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val actionCondition = jsonObj.get("action_condition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionStatement = jsonObj.get("action_statement").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionOrientation = jsonObj.get("action_orientation").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionTiming = jsonObj.get("action_timing").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionReferenceOldTable = jsonObj.get("action_reference_old_table").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionReferenceNewTable = jsonObj.get("action_reference_new_table").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionReferenceOldRow = jsonObj.get("action_reference_old_row").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val actionReferenceNewRow = jsonObj.get("action_reference_new_row").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val created = jsonObj.get("created").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (triggerCatalog.isRight && triggerSchema.isRight && triggerName.isRight && eventManipulation.isRight && eventObjectCatalog.isRight && eventObjectSchema.isRight && eventObjectTable.isRight && actionOrder.isRight && actionCondition.isRight && actionStatement.isRight && actionOrientation.isRight && actionTiming.isRight && actionReferenceOldTable.isRight && actionReferenceNewTable.isRight && actionReferenceOldRow.isRight && actionReferenceNewRow.isRight && created.isRight) + Right(TriggersViewRow(triggerCatalog = triggerCatalog.toOption.get, triggerSchema = triggerSchema.toOption.get, triggerName = triggerName.toOption.get, eventManipulation = eventManipulation.toOption.get, eventObjectCatalog = eventObjectCatalog.toOption.get, eventObjectSchema = eventObjectSchema.toOption.get, eventObjectTable = eventObjectTable.toOption.get, actionOrder = actionOrder.toOption.get, actionCondition = actionCondition.toOption.get, actionStatement = actionStatement.toOption.get, actionOrientation = actionOrientation.toOption.get, actionTiming = actionTiming.toOption.get, actionReferenceOldTable = actionReferenceOldTable.toOption.get, actionReferenceNewTable = actionReferenceNewTable.toOption.get, actionReferenceOldRow = actionReferenceOldRow.toOption.get, actionReferenceNewRow = actionReferenceNewRow.toOption.get, created = created.toOption.get)) + else Left(List[Either[String, Any]](triggerCatalog, triggerSchema, triggerName, eventManipulation, eventObjectCatalog, eventObjectSchema, eventObjectTable, actionOrder, actionCondition, actionStatement, actionOrientation, actionTiming, actionReferenceOldTable, actionReferenceNewTable, actionReferenceOldRow, actionReferenceNewRow, created).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TriggersViewRow] = new JsonEncoder[TriggersViewRow] { + override def unsafeEncode(a: TriggersViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""trigger_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerCatalog, indent, out) + out.write(",") + out.write(""""trigger_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerSchema, indent, out) + out.write(",") + out.write(""""trigger_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.triggerName, indent, out) + out.write(",") + out.write(""""event_manipulation":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventManipulation, indent, out) + out.write(",") + out.write(""""event_object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectCatalog, indent, out) + out.write(",") + out.write(""""event_object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectSchema, indent, out) + out.write(",") + out.write(""""event_object_table":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.eventObjectTable, indent, out) + out.write(",") + out.write(""""action_order":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.actionOrder, indent, out) + out.write(",") + out.write(""""action_condition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionCondition, indent, out) + out.write(",") + out.write(""""action_statement":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionStatement, indent, out) + out.write(",") + out.write(""""action_orientation":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionOrientation, indent, out) + out.write(",") + out.write(""""action_timing":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionTiming, indent, out) + out.write(",") + out.write(""""action_reference_old_table":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionReferenceOldTable, indent, out) + out.write(",") + out.write(""""action_reference_new_table":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionReferenceNewTable, indent, out) + out.write(",") + out.write(""""action_reference_old_row":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionReferenceOldRow, indent, out) + out.write(",") + out.write(""""action_reference_new_row":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.actionReferenceNewRow, indent, out) + out.write(",") + out.write(""""created":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.created, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewStructure.scala new file mode 100644 index 0000000000..61e48ba513 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/triggers/TriggersViewStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package triggers + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class TriggersViewStructure[Row](val prefix: Option[String], val extract: Row => TriggersViewRow, val merge: (Row, TriggersViewRow) => Row) + extends Relation[TriggersViewFields, TriggersViewRow, Row] + with TriggersViewFields[Row] { outer => + + override val triggerCatalog = new OptField[String, Row](prefix, "trigger_catalog", None, None)(x => extract(x).triggerCatalog, (row, value) => merge(row, extract(row).copy(triggerCatalog = value))) + override val triggerSchema = new OptField[String, Row](prefix, "trigger_schema", None, None)(x => extract(x).triggerSchema, (row, value) => merge(row, extract(row).copy(triggerSchema = value))) + override val triggerName = new OptField[String, Row](prefix, "trigger_name", None, None)(x => extract(x).triggerName, (row, value) => merge(row, extract(row).copy(triggerName = value))) + override val eventManipulation = new OptField[String, Row](prefix, "event_manipulation", None, None)(x => extract(x).eventManipulation, (row, value) => merge(row, extract(row).copy(eventManipulation = value))) + override val eventObjectCatalog = new OptField[String, Row](prefix, "event_object_catalog", None, None)(x => extract(x).eventObjectCatalog, (row, value) => merge(row, extract(row).copy(eventObjectCatalog = value))) + override val eventObjectSchema = new OptField[String, Row](prefix, "event_object_schema", None, None)(x => extract(x).eventObjectSchema, (row, value) => merge(row, extract(row).copy(eventObjectSchema = value))) + override val eventObjectTable = new OptField[String, Row](prefix, "event_object_table", None, None)(x => extract(x).eventObjectTable, (row, value) => merge(row, extract(row).copy(eventObjectTable = value))) + override val actionOrder = new OptField[Int, Row](prefix, "action_order", None, None)(x => extract(x).actionOrder, (row, value) => merge(row, extract(row).copy(actionOrder = value))) + override val actionCondition = new OptField[String, Row](prefix, "action_condition", None, None)(x => extract(x).actionCondition, (row, value) => merge(row, extract(row).copy(actionCondition = value))) + override val actionStatement = new OptField[String, Row](prefix, "action_statement", None, None)(x => extract(x).actionStatement, (row, value) => merge(row, extract(row).copy(actionStatement = value))) + override val actionOrientation = new OptField[String, Row](prefix, "action_orientation", None, None)(x => extract(x).actionOrientation, (row, value) => merge(row, extract(row).copy(actionOrientation = value))) + override val actionTiming = new OptField[String, Row](prefix, "action_timing", None, None)(x => extract(x).actionTiming, (row, value) => merge(row, extract(row).copy(actionTiming = value))) + override val actionReferenceOldTable = new OptField[String, Row](prefix, "action_reference_old_table", None, None)(x => extract(x).actionReferenceOldTable, (row, value) => merge(row, extract(row).copy(actionReferenceOldTable = value))) + override val actionReferenceNewTable = new OptField[String, Row](prefix, "action_reference_new_table", None, None)(x => extract(x).actionReferenceNewTable, (row, value) => merge(row, extract(row).copy(actionReferenceNewTable = value))) + override val actionReferenceOldRow = new OptField[String, Row](prefix, "action_reference_old_row", None, None)(x => extract(x).actionReferenceOldRow, (row, value) => merge(row, extract(row).copy(actionReferenceOldRow = value))) + override val actionReferenceNewRow = new OptField[String, Row](prefix, "action_reference_new_row", None, None)(x => extract(x).actionReferenceNewRow, (row, value) => merge(row, extract(row).copy(actionReferenceNewRow = value))) + override val created = new OptField[TypoInstant, Row](prefix, "created", Some("text"), None)(x => extract(x).created, (row, value) => merge(row, extract(row).copy(created = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](triggerCatalog, triggerSchema, triggerName, eventManipulation, eventObjectCatalog, eventObjectSchema, eventObjectTable, actionOrder, actionCondition, actionStatement, actionOrientation, actionTiming, actionReferenceOldTable, actionReferenceNewTable, actionReferenceOldRow, actionReferenceNewRow, created) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TriggersViewRow, merge: (NewRow, TriggersViewRow) => NewRow): TriggersViewStructure[NewRow] = + new TriggersViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewFields.scala new file mode 100644 index 0000000000..4f2b94f41c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package udt_privileges + +import typo.dsl.SqlExpr.OptField + +trait UdtPrivilegesViewFields[Row] { + val grantor: OptField[String, Row] + val grantee: OptField[String, Row] + val udtCatalog: OptField[String, Row] + val udtSchema: OptField[String, Row] + val udtName: OptField[String, Row] + val privilegeType: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] +} +object UdtPrivilegesViewFields extends UdtPrivilegesViewStructure[UdtPrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepo.scala new file mode 100644 index 0000000000..1cbf6bf243 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package udt_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UdtPrivilegesViewRepo { + def select: SelectBuilder[UdtPrivilegesViewFields, UdtPrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, UdtPrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..315b49858f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package udt_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UdtPrivilegesViewRepoImpl extends UdtPrivilegesViewRepo { + override def select: SelectBuilder[UdtPrivilegesViewFields, UdtPrivilegesViewRow] = { + SelectBuilderSql("information_schema.udt_privileges", UdtPrivilegesViewFields, UdtPrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UdtPrivilegesViewRow] = { + sql"""select "grantor", "grantee", "udt_catalog", "udt_schema", "udt_name", "privilege_type", "is_grantable" from information_schema.udt_privileges""".query(UdtPrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRow.scala new file mode 100644 index 0000000000..2517b408fa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package udt_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UdtPrivilegesViewRow( + grantor: /* nullability unknown */ Option[String], + grantee: /* nullability unknown */ Option[String], + udtCatalog: /* nullability unknown */ Option[String], + udtSchema: /* nullability unknown */ Option[String], + udtName: /* nullability unknown */ Option[String], + privilegeType: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object UdtPrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UdtPrivilegesViewRow] = new JdbcDecoder[UdtPrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UdtPrivilegesViewRow) = + columIndex + 6 -> + UdtPrivilegesViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + udtCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + udtSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + udtName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UdtPrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtCatalog = jsonObj.get("udt_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtSchema = jsonObj.get("udt_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val udtName = jsonObj.get("udt_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && udtCatalog.isRight && udtSchema.isRight && udtName.isRight && privilegeType.isRight && isGrantable.isRight) + Right(UdtPrivilegesViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, udtCatalog = udtCatalog.toOption.get, udtSchema = udtSchema.toOption.get, udtName = udtName.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, udtCatalog, udtSchema, udtName, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UdtPrivilegesViewRow] = new JsonEncoder[UdtPrivilegesViewRow] { + override def unsafeEncode(a: UdtPrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""udt_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtCatalog, indent, out) + out.write(",") + out.write(""""udt_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtSchema, indent, out) + out.write(",") + out.write(""""udt_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.udtName, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewStructure.scala new file mode 100644 index 0000000000..27bf531ca2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/udt_privileges/UdtPrivilegesViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package udt_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UdtPrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => UdtPrivilegesViewRow, val merge: (Row, UdtPrivilegesViewRow) => Row) + extends Relation[UdtPrivilegesViewFields, UdtPrivilegesViewRow, Row] + with UdtPrivilegesViewFields[Row] { outer => + + override val grantor = new OptField[String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val udtCatalog = new OptField[String, Row](prefix, "udt_catalog", None, None)(x => extract(x).udtCatalog, (row, value) => merge(row, extract(row).copy(udtCatalog = value))) + override val udtSchema = new OptField[String, Row](prefix, "udt_schema", None, None)(x => extract(x).udtSchema, (row, value) => merge(row, extract(row).copy(udtSchema = value))) + override val udtName = new OptField[String, Row](prefix, "udt_name", None, None)(x => extract(x).udtName, (row, value) => merge(row, extract(row).copy(udtName = value))) + override val privilegeType = new OptField[String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, udtCatalog, udtSchema, udtName, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UdtPrivilegesViewRow, merge: (NewRow, UdtPrivilegesViewRow) => NewRow): UdtPrivilegesViewStructure[NewRow] = + new UdtPrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewFields.scala new file mode 100644 index 0000000000..9ee9a7d828 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package usage_privileges + +import typo.dsl.SqlExpr.OptField + +trait UsagePrivilegesViewFields[Row] { + val grantor: OptField[String, Row] + val grantee: OptField[String, Row] + val objectCatalog: OptField[String, Row] + val objectSchema: OptField[String, Row] + val objectName: OptField[String, Row] + val objectType: OptField[String, Row] + val privilegeType: OptField[String, Row] + val isGrantable: OptField[/* max 3 chars */ String, Row] +} +object UsagePrivilegesViewFields extends UsagePrivilegesViewStructure[UsagePrivilegesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepo.scala new file mode 100644 index 0000000000..9d410e8acc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package usage_privileges + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UsagePrivilegesViewRepo { + def select: SelectBuilder[UsagePrivilegesViewFields, UsagePrivilegesViewRow] + def selectAll: ZStream[ZConnection, Throwable, UsagePrivilegesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepoImpl.scala new file mode 100644 index 0000000000..4c1b6493ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package usage_privileges + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UsagePrivilegesViewRepoImpl extends UsagePrivilegesViewRepo { + override def select: SelectBuilder[UsagePrivilegesViewFields, UsagePrivilegesViewRow] = { + SelectBuilderSql("information_schema.usage_privileges", UsagePrivilegesViewFields, UsagePrivilegesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UsagePrivilegesViewRow] = { + sql"""select "grantor", "grantee", "object_catalog", "object_schema", "object_name", "object_type", "privilege_type", "is_grantable" from information_schema.usage_privileges""".query(UsagePrivilegesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRow.scala new file mode 100644 index 0000000000..c542223263 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package usage_privileges + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UsagePrivilegesViewRow( + grantor: /* nullability unknown */ Option[String], + grantee: /* nullability unknown */ Option[String], + objectCatalog: /* nullability unknown */ Option[String], + objectSchema: /* nullability unknown */ Option[String], + objectName: /* nullability unknown */ Option[String], + objectType: /* nullability unknown */ Option[String], + privilegeType: /* nullability unknown */ Option[String], + isGrantable: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object UsagePrivilegesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UsagePrivilegesViewRow] = new JdbcDecoder[UsagePrivilegesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UsagePrivilegesViewRow) = + columIndex + 7 -> + UsagePrivilegesViewRow( + grantor = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + grantee = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + objectCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + objectSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + objectName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + objectType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + privilegeType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isGrantable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UsagePrivilegesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val grantor = jsonObj.get("grantor").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val grantee = jsonObj.get("grantee").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectCatalog = jsonObj.get("object_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectSchema = jsonObj.get("object_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectName = jsonObj.get("object_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objectType = jsonObj.get("object_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val privilegeType = jsonObj.get("privilege_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isGrantable = jsonObj.get("is_grantable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (grantor.isRight && grantee.isRight && objectCatalog.isRight && objectSchema.isRight && objectName.isRight && objectType.isRight && privilegeType.isRight && isGrantable.isRight) + Right(UsagePrivilegesViewRow(grantor = grantor.toOption.get, grantee = grantee.toOption.get, objectCatalog = objectCatalog.toOption.get, objectSchema = objectSchema.toOption.get, objectName = objectName.toOption.get, objectType = objectType.toOption.get, privilegeType = privilegeType.toOption.get, isGrantable = isGrantable.toOption.get)) + else Left(List[Either[String, Any]](grantor, grantee, objectCatalog, objectSchema, objectName, objectType, privilegeType, isGrantable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UsagePrivilegesViewRow] = new JsonEncoder[UsagePrivilegesViewRow] { + override def unsafeEncode(a: UsagePrivilegesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""grantor":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""grantee":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.grantee, indent, out) + out.write(",") + out.write(""""object_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectCatalog, indent, out) + out.write(",") + out.write(""""object_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectSchema, indent, out) + out.write(",") + out.write(""""object_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectName, indent, out) + out.write(",") + out.write(""""object_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objectType, indent, out) + out.write(",") + out.write(""""privilege_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.privilegeType, indent, out) + out.write(",") + out.write(""""is_grantable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isGrantable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewStructure.scala new file mode 100644 index 0000000000..7249e7a6b1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/usage_privileges/UsagePrivilegesViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package usage_privileges + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UsagePrivilegesViewStructure[Row](val prefix: Option[String], val extract: Row => UsagePrivilegesViewRow, val merge: (Row, UsagePrivilegesViewRow) => Row) + extends Relation[UsagePrivilegesViewFields, UsagePrivilegesViewRow, Row] + with UsagePrivilegesViewFields[Row] { outer => + + override val grantor = new OptField[String, Row](prefix, "grantor", None, None)(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val grantee = new OptField[String, Row](prefix, "grantee", None, None)(x => extract(x).grantee, (row, value) => merge(row, extract(row).copy(grantee = value))) + override val objectCatalog = new OptField[String, Row](prefix, "object_catalog", None, None)(x => extract(x).objectCatalog, (row, value) => merge(row, extract(row).copy(objectCatalog = value))) + override val objectSchema = new OptField[String, Row](prefix, "object_schema", None, None)(x => extract(x).objectSchema, (row, value) => merge(row, extract(row).copy(objectSchema = value))) + override val objectName = new OptField[String, Row](prefix, "object_name", None, None)(x => extract(x).objectName, (row, value) => merge(row, extract(row).copy(objectName = value))) + override val objectType = new OptField[String, Row](prefix, "object_type", None, None)(x => extract(x).objectType, (row, value) => merge(row, extract(row).copy(objectType = value))) + override val privilegeType = new OptField[String, Row](prefix, "privilege_type", None, None)(x => extract(x).privilegeType, (row, value) => merge(row, extract(row).copy(privilegeType = value))) + override val isGrantable = new OptField[/* max 3 chars */ String, Row](prefix, "is_grantable", None, None)(x => extract(x).isGrantable, (row, value) => merge(row, extract(row).copy(isGrantable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](grantor, grantee, objectCatalog, objectSchema, objectName, objectType, privilegeType, isGrantable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UsagePrivilegesViewRow, merge: (NewRow, UsagePrivilegesViewRow) => NewRow): UsagePrivilegesViewStructure[NewRow] = + new UsagePrivilegesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewFields.scala new file mode 100644 index 0000000000..7847288dd3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewFields.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_defined_types + +import typo.dsl.SqlExpr.OptField + +trait UserDefinedTypesViewFields[Row] { + val userDefinedTypeCatalog: OptField[String, Row] + val userDefinedTypeSchema: OptField[String, Row] + val userDefinedTypeName: OptField[String, Row] + val userDefinedTypeCategory: OptField[String, Row] + val isInstantiable: OptField[/* max 3 chars */ String, Row] + val isFinal: OptField[/* max 3 chars */ String, Row] + val orderingForm: OptField[String, Row] + val orderingCategory: OptField[String, Row] + val orderingRoutineCatalog: OptField[String, Row] + val orderingRoutineSchema: OptField[String, Row] + val orderingRoutineName: OptField[String, Row] + val referenceType: OptField[String, Row] + val dataType: OptField[String, Row] + val characterMaximumLength: OptField[Int, Row] + val characterOctetLength: OptField[Int, Row] + val characterSetCatalog: OptField[String, Row] + val characterSetSchema: OptField[String, Row] + val characterSetName: OptField[String, Row] + val collationCatalog: OptField[String, Row] + val collationSchema: OptField[String, Row] + val collationName: OptField[String, Row] + val numericPrecision: OptField[Int, Row] + val numericPrecisionRadix: OptField[Int, Row] + val numericScale: OptField[Int, Row] + val datetimePrecision: OptField[Int, Row] + val intervalType: OptField[String, Row] + val intervalPrecision: OptField[Int, Row] + val sourceDtdIdentifier: OptField[String, Row] + val refDtdIdentifier: OptField[String, Row] +} +object UserDefinedTypesViewFields extends UserDefinedTypesViewStructure[UserDefinedTypesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepo.scala new file mode 100644 index 0000000000..94ff85a4a7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_defined_types + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UserDefinedTypesViewRepo { + def select: SelectBuilder[UserDefinedTypesViewFields, UserDefinedTypesViewRow] + def selectAll: ZStream[ZConnection, Throwable, UserDefinedTypesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepoImpl.scala new file mode 100644 index 0000000000..51f7ee7ec6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_defined_types + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UserDefinedTypesViewRepoImpl extends UserDefinedTypesViewRepo { + override def select: SelectBuilder[UserDefinedTypesViewFields, UserDefinedTypesViewRow] = { + SelectBuilderSql("information_schema.user_defined_types", UserDefinedTypesViewFields, UserDefinedTypesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UserDefinedTypesViewRow] = { + sql"""select "user_defined_type_catalog", "user_defined_type_schema", "user_defined_type_name", "user_defined_type_category", "is_instantiable", "is_final", "ordering_form", "ordering_category", "ordering_routine_catalog", "ordering_routine_schema", "ordering_routine_name", "reference_type", "data_type", "character_maximum_length", "character_octet_length", "character_set_catalog", "character_set_schema", "character_set_name", "collation_catalog", "collation_schema", "collation_name", "numeric_precision", "numeric_precision_radix", "numeric_scale", "datetime_precision", "interval_type", "interval_precision", "source_dtd_identifier", "ref_dtd_identifier" from information_schema.user_defined_types""".query(UserDefinedTypesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRow.scala new file mode 100644 index 0000000000..6c060b8f29 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewRow.scala @@ -0,0 +1,211 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_defined_types + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UserDefinedTypesViewRow( + userDefinedTypeCatalog: /* nullability unknown */ Option[String], + userDefinedTypeSchema: /* nullability unknown */ Option[String], + userDefinedTypeName: /* nullability unknown */ Option[String], + userDefinedTypeCategory: /* nullability unknown */ Option[String], + isInstantiable: /* nullability unknown */ Option[/* max 3 chars */ String], + isFinal: /* nullability unknown */ Option[/* max 3 chars */ String], + orderingForm: /* nullability unknown */ Option[String], + orderingCategory: /* nullability unknown */ Option[String], + orderingRoutineCatalog: /* nullability unknown */ Option[String], + orderingRoutineSchema: /* nullability unknown */ Option[String], + orderingRoutineName: /* nullability unknown */ Option[String], + referenceType: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[String], + characterMaximumLength: /* nullability unknown */ Option[Int], + characterOctetLength: /* nullability unknown */ Option[Int], + characterSetCatalog: /* nullability unknown */ Option[String], + characterSetSchema: /* nullability unknown */ Option[String], + characterSetName: /* nullability unknown */ Option[String], + collationCatalog: /* nullability unknown */ Option[String], + collationSchema: /* nullability unknown */ Option[String], + collationName: /* nullability unknown */ Option[String], + numericPrecision: /* nullability unknown */ Option[Int], + numericPrecisionRadix: /* nullability unknown */ Option[Int], + numericScale: /* nullability unknown */ Option[Int], + datetimePrecision: /* nullability unknown */ Option[Int], + intervalType: /* nullability unknown */ Option[String], + intervalPrecision: /* nullability unknown */ Option[Int], + sourceDtdIdentifier: /* nullability unknown */ Option[String], + refDtdIdentifier: /* nullability unknown */ Option[String] +) + +object UserDefinedTypesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UserDefinedTypesViewRow] = new JdbcDecoder[UserDefinedTypesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UserDefinedTypesViewRow) = + columIndex + 28 -> + UserDefinedTypesViewRow( + userDefinedTypeCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + userDefinedTypeSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + userDefinedTypeName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + userDefinedTypeCategory = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + isInstantiable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + isFinal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + orderingForm = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + orderingCategory = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + orderingRoutineCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + orderingRoutineSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + orderingRoutineName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + referenceType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + dataType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + characterMaximumLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 13, rs)._2, + characterOctetLength = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 14, rs)._2, + characterSetCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + characterSetSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + characterSetName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + collationCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + collationSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 19, rs)._2, + collationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + numericPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 21, rs)._2, + numericPrecisionRadix = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 22, rs)._2, + numericScale = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 23, rs)._2, + datetimePrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 24, rs)._2, + intervalType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 25, rs)._2, + intervalPrecision = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 26, rs)._2, + sourceDtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 27, rs)._2, + refDtdIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UserDefinedTypesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val userDefinedTypeCatalog = jsonObj.get("user_defined_type_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeSchema = jsonObj.get("user_defined_type_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeName = jsonObj.get("user_defined_type_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val userDefinedTypeCategory = jsonObj.get("user_defined_type_category").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isInstantiable = jsonObj.get("is_instantiable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isFinal = jsonObj.get("is_final").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderingForm = jsonObj.get("ordering_form").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderingCategory = jsonObj.get("ordering_category").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderingRoutineCatalog = jsonObj.get("ordering_routine_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderingRoutineSchema = jsonObj.get("ordering_routine_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderingRoutineName = jsonObj.get("ordering_routine_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val referenceType = jsonObj.get("reference_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterMaximumLength = jsonObj.get("character_maximum_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterOctetLength = jsonObj.get("character_octet_length").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val characterSetCatalog = jsonObj.get("character_set_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetSchema = jsonObj.get("character_set_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val characterSetName = jsonObj.get("character_set_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationCatalog = jsonObj.get("collation_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationSchema = jsonObj.get("collation_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val collationName = jsonObj.get("collation_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numericPrecision = jsonObj.get("numeric_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericPrecisionRadix = jsonObj.get("numeric_precision_radix").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numericScale = jsonObj.get("numeric_scale").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datetimePrecision = jsonObj.get("datetime_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val intervalType = jsonObj.get("interval_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val intervalPrecision = jsonObj.get("interval_precision").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val sourceDtdIdentifier = jsonObj.get("source_dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val refDtdIdentifier = jsonObj.get("ref_dtd_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (userDefinedTypeCatalog.isRight && userDefinedTypeSchema.isRight && userDefinedTypeName.isRight && userDefinedTypeCategory.isRight && isInstantiable.isRight && isFinal.isRight && orderingForm.isRight && orderingCategory.isRight && orderingRoutineCatalog.isRight && orderingRoutineSchema.isRight && orderingRoutineName.isRight && referenceType.isRight && dataType.isRight && characterMaximumLength.isRight && characterOctetLength.isRight && characterSetCatalog.isRight && characterSetSchema.isRight && characterSetName.isRight && collationCatalog.isRight && collationSchema.isRight && collationName.isRight && numericPrecision.isRight && numericPrecisionRadix.isRight && numericScale.isRight && datetimePrecision.isRight && intervalType.isRight && intervalPrecision.isRight && sourceDtdIdentifier.isRight && refDtdIdentifier.isRight) + Right(UserDefinedTypesViewRow(userDefinedTypeCatalog = userDefinedTypeCatalog.toOption.get, userDefinedTypeSchema = userDefinedTypeSchema.toOption.get, userDefinedTypeName = userDefinedTypeName.toOption.get, userDefinedTypeCategory = userDefinedTypeCategory.toOption.get, isInstantiable = isInstantiable.toOption.get, isFinal = isFinal.toOption.get, orderingForm = orderingForm.toOption.get, orderingCategory = orderingCategory.toOption.get, orderingRoutineCatalog = orderingRoutineCatalog.toOption.get, orderingRoutineSchema = orderingRoutineSchema.toOption.get, orderingRoutineName = orderingRoutineName.toOption.get, referenceType = referenceType.toOption.get, dataType = dataType.toOption.get, characterMaximumLength = characterMaximumLength.toOption.get, characterOctetLength = characterOctetLength.toOption.get, characterSetCatalog = characterSetCatalog.toOption.get, characterSetSchema = characterSetSchema.toOption.get, characterSetName = characterSetName.toOption.get, collationCatalog = collationCatalog.toOption.get, collationSchema = collationSchema.toOption.get, collationName = collationName.toOption.get, numericPrecision = numericPrecision.toOption.get, numericPrecisionRadix = numericPrecisionRadix.toOption.get, numericScale = numericScale.toOption.get, datetimePrecision = datetimePrecision.toOption.get, intervalType = intervalType.toOption.get, intervalPrecision = intervalPrecision.toOption.get, sourceDtdIdentifier = sourceDtdIdentifier.toOption.get, refDtdIdentifier = refDtdIdentifier.toOption.get)) + else Left(List[Either[String, Any]](userDefinedTypeCatalog, userDefinedTypeSchema, userDefinedTypeName, userDefinedTypeCategory, isInstantiable, isFinal, orderingForm, orderingCategory, orderingRoutineCatalog, orderingRoutineSchema, orderingRoutineName, referenceType, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, sourceDtdIdentifier, refDtdIdentifier).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UserDefinedTypesViewRow] = new JsonEncoder[UserDefinedTypesViewRow] { + override def unsafeEncode(a: UserDefinedTypesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""user_defined_type_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeCatalog, indent, out) + out.write(",") + out.write(""""user_defined_type_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeSchema, indent, out) + out.write(",") + out.write(""""user_defined_type_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeName, indent, out) + out.write(",") + out.write(""""user_defined_type_category":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.userDefinedTypeCategory, indent, out) + out.write(",") + out.write(""""is_instantiable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isInstantiable, indent, out) + out.write(",") + out.write(""""is_final":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isFinal, indent, out) + out.write(",") + out.write(""""ordering_form":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.orderingForm, indent, out) + out.write(",") + out.write(""""ordering_category":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.orderingCategory, indent, out) + out.write(",") + out.write(""""ordering_routine_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.orderingRoutineCatalog, indent, out) + out.write(",") + out.write(""""ordering_routine_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.orderingRoutineSchema, indent, out) + out.write(",") + out.write(""""ordering_routine_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.orderingRoutineName, indent, out) + out.write(",") + out.write(""""reference_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.referenceType, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""character_maximum_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterMaximumLength, indent, out) + out.write(",") + out.write(""""character_octet_length":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.characterOctetLength, indent, out) + out.write(",") + out.write(""""character_set_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetCatalog, indent, out) + out.write(",") + out.write(""""character_set_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetSchema, indent, out) + out.write(",") + out.write(""""character_set_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.characterSetName, indent, out) + out.write(",") + out.write(""""collation_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationCatalog, indent, out) + out.write(",") + out.write(""""collation_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationSchema, indent, out) + out.write(",") + out.write(""""collation_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collationName, indent, out) + out.write(",") + out.write(""""numeric_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecision, indent, out) + out.write(",") + out.write(""""numeric_precision_radix":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericPrecisionRadix, indent, out) + out.write(",") + out.write(""""numeric_scale":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numericScale, indent, out) + out.write(",") + out.write(""""datetime_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.datetimePrecision, indent, out) + out.write(",") + out.write(""""interval_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.intervalType, indent, out) + out.write(",") + out.write(""""interval_precision":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.intervalPrecision, indent, out) + out.write(",") + out.write(""""source_dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sourceDtdIdentifier, indent, out) + out.write(",") + out.write(""""ref_dtd_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.refDtdIdentifier, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewStructure.scala new file mode 100644 index 0000000000..6ee1780d23 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_defined_types/UserDefinedTypesViewStructure.scala @@ -0,0 +1,53 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_defined_types + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UserDefinedTypesViewStructure[Row](val prefix: Option[String], val extract: Row => UserDefinedTypesViewRow, val merge: (Row, UserDefinedTypesViewRow) => Row) + extends Relation[UserDefinedTypesViewFields, UserDefinedTypesViewRow, Row] + with UserDefinedTypesViewFields[Row] { outer => + + override val userDefinedTypeCatalog = new OptField[String, Row](prefix, "user_defined_type_catalog", None, None)(x => extract(x).userDefinedTypeCatalog, (row, value) => merge(row, extract(row).copy(userDefinedTypeCatalog = value))) + override val userDefinedTypeSchema = new OptField[String, Row](prefix, "user_defined_type_schema", None, None)(x => extract(x).userDefinedTypeSchema, (row, value) => merge(row, extract(row).copy(userDefinedTypeSchema = value))) + override val userDefinedTypeName = new OptField[String, Row](prefix, "user_defined_type_name", None, None)(x => extract(x).userDefinedTypeName, (row, value) => merge(row, extract(row).copy(userDefinedTypeName = value))) + override val userDefinedTypeCategory = new OptField[String, Row](prefix, "user_defined_type_category", None, None)(x => extract(x).userDefinedTypeCategory, (row, value) => merge(row, extract(row).copy(userDefinedTypeCategory = value))) + override val isInstantiable = new OptField[/* max 3 chars */ String, Row](prefix, "is_instantiable", None, None)(x => extract(x).isInstantiable, (row, value) => merge(row, extract(row).copy(isInstantiable = value))) + override val isFinal = new OptField[/* max 3 chars */ String, Row](prefix, "is_final", None, None)(x => extract(x).isFinal, (row, value) => merge(row, extract(row).copy(isFinal = value))) + override val orderingForm = new OptField[String, Row](prefix, "ordering_form", None, None)(x => extract(x).orderingForm, (row, value) => merge(row, extract(row).copy(orderingForm = value))) + override val orderingCategory = new OptField[String, Row](prefix, "ordering_category", None, None)(x => extract(x).orderingCategory, (row, value) => merge(row, extract(row).copy(orderingCategory = value))) + override val orderingRoutineCatalog = new OptField[String, Row](prefix, "ordering_routine_catalog", None, None)(x => extract(x).orderingRoutineCatalog, (row, value) => merge(row, extract(row).copy(orderingRoutineCatalog = value))) + override val orderingRoutineSchema = new OptField[String, Row](prefix, "ordering_routine_schema", None, None)(x => extract(x).orderingRoutineSchema, (row, value) => merge(row, extract(row).copy(orderingRoutineSchema = value))) + override val orderingRoutineName = new OptField[String, Row](prefix, "ordering_routine_name", None, None)(x => extract(x).orderingRoutineName, (row, value) => merge(row, extract(row).copy(orderingRoutineName = value))) + override val referenceType = new OptField[String, Row](prefix, "reference_type", None, None)(x => extract(x).referenceType, (row, value) => merge(row, extract(row).copy(referenceType = value))) + override val dataType = new OptField[String, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val characterMaximumLength = new OptField[Int, Row](prefix, "character_maximum_length", None, None)(x => extract(x).characterMaximumLength, (row, value) => merge(row, extract(row).copy(characterMaximumLength = value))) + override val characterOctetLength = new OptField[Int, Row](prefix, "character_octet_length", None, None)(x => extract(x).characterOctetLength, (row, value) => merge(row, extract(row).copy(characterOctetLength = value))) + override val characterSetCatalog = new OptField[String, Row](prefix, "character_set_catalog", None, None)(x => extract(x).characterSetCatalog, (row, value) => merge(row, extract(row).copy(characterSetCatalog = value))) + override val characterSetSchema = new OptField[String, Row](prefix, "character_set_schema", None, None)(x => extract(x).characterSetSchema, (row, value) => merge(row, extract(row).copy(characterSetSchema = value))) + override val characterSetName = new OptField[String, Row](prefix, "character_set_name", None, None)(x => extract(x).characterSetName, (row, value) => merge(row, extract(row).copy(characterSetName = value))) + override val collationCatalog = new OptField[String, Row](prefix, "collation_catalog", None, None)(x => extract(x).collationCatalog, (row, value) => merge(row, extract(row).copy(collationCatalog = value))) + override val collationSchema = new OptField[String, Row](prefix, "collation_schema", None, None)(x => extract(x).collationSchema, (row, value) => merge(row, extract(row).copy(collationSchema = value))) + override val collationName = new OptField[String, Row](prefix, "collation_name", None, None)(x => extract(x).collationName, (row, value) => merge(row, extract(row).copy(collationName = value))) + override val numericPrecision = new OptField[Int, Row](prefix, "numeric_precision", None, None)(x => extract(x).numericPrecision, (row, value) => merge(row, extract(row).copy(numericPrecision = value))) + override val numericPrecisionRadix = new OptField[Int, Row](prefix, "numeric_precision_radix", None, None)(x => extract(x).numericPrecisionRadix, (row, value) => merge(row, extract(row).copy(numericPrecisionRadix = value))) + override val numericScale = new OptField[Int, Row](prefix, "numeric_scale", None, None)(x => extract(x).numericScale, (row, value) => merge(row, extract(row).copy(numericScale = value))) + override val datetimePrecision = new OptField[Int, Row](prefix, "datetime_precision", None, None)(x => extract(x).datetimePrecision, (row, value) => merge(row, extract(row).copy(datetimePrecision = value))) + override val intervalType = new OptField[String, Row](prefix, "interval_type", None, None)(x => extract(x).intervalType, (row, value) => merge(row, extract(row).copy(intervalType = value))) + override val intervalPrecision = new OptField[Int, Row](prefix, "interval_precision", None, None)(x => extract(x).intervalPrecision, (row, value) => merge(row, extract(row).copy(intervalPrecision = value))) + override val sourceDtdIdentifier = new OptField[String, Row](prefix, "source_dtd_identifier", None, None)(x => extract(x).sourceDtdIdentifier, (row, value) => merge(row, extract(row).copy(sourceDtdIdentifier = value))) + override val refDtdIdentifier = new OptField[String, Row](prefix, "ref_dtd_identifier", None, None)(x => extract(x).refDtdIdentifier, (row, value) => merge(row, extract(row).copy(refDtdIdentifier = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](userDefinedTypeCatalog, userDefinedTypeSchema, userDefinedTypeName, userDefinedTypeCategory, isInstantiable, isFinal, orderingForm, orderingCategory, orderingRoutineCatalog, orderingRoutineSchema, orderingRoutineName, referenceType, dataType, characterMaximumLength, characterOctetLength, characterSetCatalog, characterSetSchema, characterSetName, collationCatalog, collationSchema, collationName, numericPrecision, numericPrecisionRadix, numericScale, datetimePrecision, intervalType, intervalPrecision, sourceDtdIdentifier, refDtdIdentifier) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UserDefinedTypesViewRow, merge: (NewRow, UserDefinedTypesViewRow) => NewRow): UserDefinedTypesViewStructure[NewRow] = + new UserDefinedTypesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewFields.scala new file mode 100644 index 0000000000..95a77eec57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mapping_options + +import typo.dsl.SqlExpr.OptField + +trait UserMappingOptionsViewFields[Row] { + val authorizationIdentifier: OptField[/* nullability unknown */ String, Row] + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] + val optionName: OptField[String, Row] + val optionValue: OptField[String, Row] +} +object UserMappingOptionsViewFields extends UserMappingOptionsViewStructure[UserMappingOptionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepo.scala new file mode 100644 index 0000000000..9ca39faf17 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mapping_options + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UserMappingOptionsViewRepo { + def select: SelectBuilder[UserMappingOptionsViewFields, UserMappingOptionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, UserMappingOptionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepoImpl.scala new file mode 100644 index 0000000000..5ea6d330a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mapping_options + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UserMappingOptionsViewRepoImpl extends UserMappingOptionsViewRepo { + override def select: SelectBuilder[UserMappingOptionsViewFields, UserMappingOptionsViewRow] = { + SelectBuilderSql("information_schema.user_mapping_options", UserMappingOptionsViewFields, UserMappingOptionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UserMappingOptionsViewRow] = { + sql"""select "authorization_identifier", "foreign_server_catalog", "foreign_server_name", "option_name", "option_value" from information_schema.user_mapping_options""".query(UserMappingOptionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRow.scala new file mode 100644 index 0000000000..df63bdd2b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewRow.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mapping_options + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UserMappingOptionsViewRow( + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.authorizationIdentifier]] */ + authorizationIdentifier: Option[/* nullability unknown */ String], + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String], + optionName: /* nullability unknown */ Option[String], + optionValue: /* nullability unknown */ Option[String] +) + +object UserMappingOptionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UserMappingOptionsViewRow] = new JdbcDecoder[UserMappingOptionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UserMappingOptionsViewRow) = + columIndex + 4 -> + UserMappingOptionsViewRow( + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + optionName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + optionValue = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UserMappingOptionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionName = jsonObj.get("option_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val optionValue = jsonObj.get("option_value").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (authorizationIdentifier.isRight && foreignServerCatalog.isRight && foreignServerName.isRight && optionName.isRight && optionValue.isRight) + Right(UserMappingOptionsViewRow(authorizationIdentifier = authorizationIdentifier.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get, optionName = optionName.toOption.get, optionValue = optionValue.toOption.get)) + else Left(List[Either[String, Any]](authorizationIdentifier, foreignServerCatalog, foreignServerName, optionName, optionValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UserMappingOptionsViewRow] = new JsonEncoder[UserMappingOptionsViewRow] { + override def unsafeEncode(a: UserMappingOptionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write(",") + out.write(""""option_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionName, indent, out) + out.write(",") + out.write(""""option_value":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.optionValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewStructure.scala new file mode 100644 index 0000000000..74b5b32b82 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mapping_options/UserMappingOptionsViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mapping_options + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UserMappingOptionsViewStructure[Row](val prefix: Option[String], val extract: Row => UserMappingOptionsViewRow, val merge: (Row, UserMappingOptionsViewRow) => Row) + extends Relation[UserMappingOptionsViewFields, UserMappingOptionsViewRow, Row] + with UserMappingOptionsViewFields[Row] { outer => + + override val authorizationIdentifier = new OptField[/* nullability unknown */ String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + override val optionName = new OptField[String, Row](prefix, "option_name", None, None)(x => extract(x).optionName, (row, value) => merge(row, extract(row).copy(optionName = value))) + override val optionValue = new OptField[String, Row](prefix, "option_value", None, None)(x => extract(x).optionValue, (row, value) => merge(row, extract(row).copy(optionValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](authorizationIdentifier, foreignServerCatalog, foreignServerName, optionName, optionValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UserMappingOptionsViewRow, merge: (NewRow, UserMappingOptionsViewRow) => NewRow): UserMappingOptionsViewStructure[NewRow] = + new UserMappingOptionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewFields.scala new file mode 100644 index 0000000000..ee70546179 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewFields.scala @@ -0,0 +1,18 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mappings + +import typo.dsl.SqlExpr.OptField + +trait UserMappingsViewFields[Row] { + val authorizationIdentifier: OptField[/* nullability unknown */ String, Row] + val foreignServerCatalog: OptField[/* nullability unknown */ String, Row] + val foreignServerName: OptField[/* nullability unknown */ String, Row] +} +object UserMappingsViewFields extends UserMappingsViewStructure[UserMappingsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepo.scala new file mode 100644 index 0000000000..509475eab6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mappings + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UserMappingsViewRepo { + def select: SelectBuilder[UserMappingsViewFields, UserMappingsViewRow] + def selectAll: ZStream[ZConnection, Throwable, UserMappingsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepoImpl.scala new file mode 100644 index 0000000000..5625856e1c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mappings + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UserMappingsViewRepoImpl extends UserMappingsViewRepo { + override def select: SelectBuilder[UserMappingsViewFields, UserMappingsViewRow] = { + SelectBuilderSql("information_schema.user_mappings", UserMappingsViewFields, UserMappingsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UserMappingsViewRow] = { + sql"""select "authorization_identifier", "foreign_server_catalog", "foreign_server_name" from information_schema.user_mappings""".query(UserMappingsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRow.scala new file mode 100644 index 0000000000..d9c75ef2a7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mappings + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UserMappingsViewRow( + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.authorizationIdentifier]] */ + authorizationIdentifier: Option[/* nullability unknown */ String], + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.foreignServerCatalog]] */ + foreignServerCatalog: Option[/* nullability unknown */ String], + /** Points to [[`_pg_user_mappings`.PgUserMappingsViewRow.foreignServerName]] */ + foreignServerName: Option[/* nullability unknown */ String] +) + +object UserMappingsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UserMappingsViewRow] = new JdbcDecoder[UserMappingsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UserMappingsViewRow) = + columIndex + 2 -> + UserMappingsViewRow( + authorizationIdentifier = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + foreignServerCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + foreignServerName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UserMappingsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val authorizationIdentifier = jsonObj.get("authorization_identifier").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerCatalog = jsonObj.get("foreign_server_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val foreignServerName = jsonObj.get("foreign_server_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (authorizationIdentifier.isRight && foreignServerCatalog.isRight && foreignServerName.isRight) + Right(UserMappingsViewRow(authorizationIdentifier = authorizationIdentifier.toOption.get, foreignServerCatalog = foreignServerCatalog.toOption.get, foreignServerName = foreignServerName.toOption.get)) + else Left(List[Either[String, Any]](authorizationIdentifier, foreignServerCatalog, foreignServerName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UserMappingsViewRow] = new JsonEncoder[UserMappingsViewRow] { + override def unsafeEncode(a: UserMappingsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""authorization_identifier":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authorizationIdentifier, indent, out) + out.write(",") + out.write(""""foreign_server_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerCatalog, indent, out) + out.write(",") + out.write(""""foreign_server_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.foreignServerName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewStructure.scala new file mode 100644 index 0000000000..b79cdfd963 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/user_mappings/UserMappingsViewStructure.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package user_mappings + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UserMappingsViewStructure[Row](val prefix: Option[String], val extract: Row => UserMappingsViewRow, val merge: (Row, UserMappingsViewRow) => Row) + extends Relation[UserMappingsViewFields, UserMappingsViewRow, Row] + with UserMappingsViewFields[Row] { outer => + + override val authorizationIdentifier = new OptField[/* nullability unknown */ String, Row](prefix, "authorization_identifier", None, None)(x => extract(x).authorizationIdentifier, (row, value) => merge(row, extract(row).copy(authorizationIdentifier = value))) + override val foreignServerCatalog = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_catalog", None, None)(x => extract(x).foreignServerCatalog, (row, value) => merge(row, extract(row).copy(foreignServerCatalog = value))) + override val foreignServerName = new OptField[/* nullability unknown */ String, Row](prefix, "foreign_server_name", None, None)(x => extract(x).foreignServerName, (row, value) => merge(row, extract(row).copy(foreignServerName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](authorizationIdentifier, foreignServerCatalog, foreignServerName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UserMappingsViewRow, merge: (NewRow, UserMappingsViewRow) => NewRow): UserMappingsViewStructure[NewRow] = + new UserMappingsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewFields.scala new file mode 100644 index 0000000000..a8230d5484 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_column_usage + +import typo.dsl.SqlExpr.OptField + +trait ViewColumnUsageViewFields[Row] { + val viewCatalog: OptField[String, Row] + val viewSchema: OptField[String, Row] + val viewName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val columnName: OptField[String, Row] +} +object ViewColumnUsageViewFields extends ViewColumnUsageViewStructure[ViewColumnUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepo.scala new file mode 100644 index 0000000000..f882562448 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_column_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ViewColumnUsageViewRepo { + def select: SelectBuilder[ViewColumnUsageViewFields, ViewColumnUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ViewColumnUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepoImpl.scala new file mode 100644 index 0000000000..e60131ffd4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_column_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ViewColumnUsageViewRepoImpl extends ViewColumnUsageViewRepo { + override def select: SelectBuilder[ViewColumnUsageViewFields, ViewColumnUsageViewRow] = { + SelectBuilderSql("information_schema.view_column_usage", ViewColumnUsageViewFields, ViewColumnUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ViewColumnUsageViewRow] = { + sql"""select "view_catalog", "view_schema", "view_name", "table_catalog", "table_schema", "table_name", "column_name" from information_schema.view_column_usage""".query(ViewColumnUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRow.scala new file mode 100644 index 0000000000..ae6346222e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_column_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ViewColumnUsageViewRow( + viewCatalog: /* nullability unknown */ Option[String], + viewSchema: /* nullability unknown */ Option[String], + viewName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + columnName: /* nullability unknown */ Option[String] +) + +object ViewColumnUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ViewColumnUsageViewRow] = new JdbcDecoder[ViewColumnUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ViewColumnUsageViewRow) = + columIndex + 6 -> + ViewColumnUsageViewRow( + viewCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + viewSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + viewName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + columnName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ViewColumnUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val viewCatalog = jsonObj.get("view_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewSchema = jsonObj.get("view_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewName = jsonObj.get("view_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val columnName = jsonObj.get("column_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (viewCatalog.isRight && viewSchema.isRight && viewName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight && columnName.isRight) + Right(ViewColumnUsageViewRow(viewCatalog = viewCatalog.toOption.get, viewSchema = viewSchema.toOption.get, viewName = viewName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, columnName = columnName.toOption.get)) + else Left(List[Either[String, Any]](viewCatalog, viewSchema, viewName, tableCatalog, tableSchema, tableName, columnName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ViewColumnUsageViewRow] = new JsonEncoder[ViewColumnUsageViewRow] { + override def unsafeEncode(a: ViewColumnUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""view_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewCatalog, indent, out) + out.write(",") + out.write(""""view_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewSchema, indent, out) + out.write(",") + out.write(""""view_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""column_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.columnName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewStructure.scala new file mode 100644 index 0000000000..648d8390ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_column_usage/ViewColumnUsageViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_column_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ViewColumnUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ViewColumnUsageViewRow, val merge: (Row, ViewColumnUsageViewRow) => Row) + extends Relation[ViewColumnUsageViewFields, ViewColumnUsageViewRow, Row] + with ViewColumnUsageViewFields[Row] { outer => + + override val viewCatalog = new OptField[String, Row](prefix, "view_catalog", None, None)(x => extract(x).viewCatalog, (row, value) => merge(row, extract(row).copy(viewCatalog = value))) + override val viewSchema = new OptField[String, Row](prefix, "view_schema", None, None)(x => extract(x).viewSchema, (row, value) => merge(row, extract(row).copy(viewSchema = value))) + override val viewName = new OptField[String, Row](prefix, "view_name", None, None)(x => extract(x).viewName, (row, value) => merge(row, extract(row).copy(viewName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val columnName = new OptField[String, Row](prefix, "column_name", None, None)(x => extract(x).columnName, (row, value) => merge(row, extract(row).copy(columnName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](viewCatalog, viewSchema, viewName, tableCatalog, tableSchema, tableName, columnName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ViewColumnUsageViewRow, merge: (NewRow, ViewColumnUsageViewRow) => NewRow): ViewColumnUsageViewStructure[NewRow] = + new ViewColumnUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewFields.scala new file mode 100644 index 0000000000..e247f3eae8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_routine_usage + +import typo.dsl.SqlExpr.OptField + +trait ViewRoutineUsageViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val specificCatalog: OptField[String, Row] + val specificSchema: OptField[String, Row] + val specificName: OptField[String, Row] +} +object ViewRoutineUsageViewFields extends ViewRoutineUsageViewStructure[ViewRoutineUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepo.scala new file mode 100644 index 0000000000..67fdb81594 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_routine_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ViewRoutineUsageViewRepo { + def select: SelectBuilder[ViewRoutineUsageViewFields, ViewRoutineUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ViewRoutineUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepoImpl.scala new file mode 100644 index 0000000000..beced463f5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_routine_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ViewRoutineUsageViewRepoImpl extends ViewRoutineUsageViewRepo { + override def select: SelectBuilder[ViewRoutineUsageViewFields, ViewRoutineUsageViewRow] = { + SelectBuilderSql("information_schema.view_routine_usage", ViewRoutineUsageViewFields, ViewRoutineUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ViewRoutineUsageViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "specific_catalog", "specific_schema", "specific_name" from information_schema.view_routine_usage""".query(ViewRoutineUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRow.scala new file mode 100644 index 0000000000..4f29811efa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_routine_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ViewRoutineUsageViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + specificCatalog: /* nullability unknown */ Option[String], + specificSchema: /* nullability unknown */ Option[String], + specificName: /* nullability unknown */ Option[String] +) + +object ViewRoutineUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ViewRoutineUsageViewRow] = new JdbcDecoder[ViewRoutineUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ViewRoutineUsageViewRow) = + columIndex + 5 -> + ViewRoutineUsageViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + specificCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + specificSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + specificName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ViewRoutineUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificCatalog = jsonObj.get("specific_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificSchema = jsonObj.get("specific_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val specificName = jsonObj.get("specific_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && specificCatalog.isRight && specificSchema.isRight && specificName.isRight) + Right(ViewRoutineUsageViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, specificCatalog = specificCatalog.toOption.get, specificSchema = specificSchema.toOption.get, specificName = specificName.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, specificCatalog, specificSchema, specificName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ViewRoutineUsageViewRow] = new JsonEncoder[ViewRoutineUsageViewRow] { + override def unsafeEncode(a: ViewRoutineUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""specific_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificCatalog, indent, out) + out.write(",") + out.write(""""specific_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificSchema, indent, out) + out.write(",") + out.write(""""specific_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.specificName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewStructure.scala new file mode 100644 index 0000000000..bdb95727f3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_routine_usage/ViewRoutineUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_routine_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ViewRoutineUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ViewRoutineUsageViewRow, val merge: (Row, ViewRoutineUsageViewRow) => Row) + extends Relation[ViewRoutineUsageViewFields, ViewRoutineUsageViewRow, Row] + with ViewRoutineUsageViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val specificCatalog = new OptField[String, Row](prefix, "specific_catalog", None, None)(x => extract(x).specificCatalog, (row, value) => merge(row, extract(row).copy(specificCatalog = value))) + override val specificSchema = new OptField[String, Row](prefix, "specific_schema", None, None)(x => extract(x).specificSchema, (row, value) => merge(row, extract(row).copy(specificSchema = value))) + override val specificName = new OptField[String, Row](prefix, "specific_name", None, None)(x => extract(x).specificName, (row, value) => merge(row, extract(row).copy(specificName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, specificCatalog, specificSchema, specificName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ViewRoutineUsageViewRow, merge: (NewRow, ViewRoutineUsageViewRow) => NewRow): ViewRoutineUsageViewStructure[NewRow] = + new ViewRoutineUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewFields.scala new file mode 100644 index 0000000000..9999cfff1d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_table_usage + +import typo.dsl.SqlExpr.OptField + +trait ViewTableUsageViewFields[Row] { + val viewCatalog: OptField[String, Row] + val viewSchema: OptField[String, Row] + val viewName: OptField[String, Row] + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] +} +object ViewTableUsageViewFields extends ViewTableUsageViewStructure[ViewTableUsageViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepo.scala new file mode 100644 index 0000000000..82bb30ce38 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_table_usage + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ViewTableUsageViewRepo { + def select: SelectBuilder[ViewTableUsageViewFields, ViewTableUsageViewRow] + def selectAll: ZStream[ZConnection, Throwable, ViewTableUsageViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepoImpl.scala new file mode 100644 index 0000000000..cc7df486a2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_table_usage + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ViewTableUsageViewRepoImpl extends ViewTableUsageViewRepo { + override def select: SelectBuilder[ViewTableUsageViewFields, ViewTableUsageViewRow] = { + SelectBuilderSql("information_schema.view_table_usage", ViewTableUsageViewFields, ViewTableUsageViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ViewTableUsageViewRow] = { + sql"""select "view_catalog", "view_schema", "view_name", "table_catalog", "table_schema", "table_name" from information_schema.view_table_usage""".query(ViewTableUsageViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRow.scala new file mode 100644 index 0000000000..88f94aa279 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_table_usage + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ViewTableUsageViewRow( + viewCatalog: /* nullability unknown */ Option[String], + viewSchema: /* nullability unknown */ Option[String], + viewName: /* nullability unknown */ Option[String], + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String] +) + +object ViewTableUsageViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ViewTableUsageViewRow] = new JdbcDecoder[ViewTableUsageViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ViewTableUsageViewRow) = + columIndex + 5 -> + ViewTableUsageViewRow( + viewCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + viewSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + viewName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ViewTableUsageViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val viewCatalog = jsonObj.get("view_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewSchema = jsonObj.get("view_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewName = jsonObj.get("view_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (viewCatalog.isRight && viewSchema.isRight && viewName.isRight && tableCatalog.isRight && tableSchema.isRight && tableName.isRight) + Right(ViewTableUsageViewRow(viewCatalog = viewCatalog.toOption.get, viewSchema = viewSchema.toOption.get, viewName = viewName.toOption.get, tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get)) + else Left(List[Either[String, Any]](viewCatalog, viewSchema, viewName, tableCatalog, tableSchema, tableName).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ViewTableUsageViewRow] = new JsonEncoder[ViewTableUsageViewRow] { + override def unsafeEncode(a: ViewTableUsageViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""view_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewCatalog, indent, out) + out.write(",") + out.write(""""view_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewSchema, indent, out) + out.write(",") + out.write(""""view_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewName, indent, out) + out.write(",") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewStructure.scala new file mode 100644 index 0000000000..75e8b1d561 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/view_table_usage/ViewTableUsageViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package view_table_usage + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ViewTableUsageViewStructure[Row](val prefix: Option[String], val extract: Row => ViewTableUsageViewRow, val merge: (Row, ViewTableUsageViewRow) => Row) + extends Relation[ViewTableUsageViewFields, ViewTableUsageViewRow, Row] + with ViewTableUsageViewFields[Row] { outer => + + override val viewCatalog = new OptField[String, Row](prefix, "view_catalog", None, None)(x => extract(x).viewCatalog, (row, value) => merge(row, extract(row).copy(viewCatalog = value))) + override val viewSchema = new OptField[String, Row](prefix, "view_schema", None, None)(x => extract(x).viewSchema, (row, value) => merge(row, extract(row).copy(viewSchema = value))) + override val viewName = new OptField[String, Row](prefix, "view_name", None, None)(x => extract(x).viewName, (row, value) => merge(row, extract(row).copy(viewName = value))) + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](viewCatalog, viewSchema, viewName, tableCatalog, tableSchema, tableName) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ViewTableUsageViewRow, merge: (NewRow, ViewTableUsageViewRow) => NewRow): ViewTableUsageViewStructure[NewRow] = + new ViewTableUsageViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewFields.scala new file mode 100644 index 0000000000..6fc8970b7b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package views + +import typo.dsl.SqlExpr.OptField + +trait ViewsViewFields[Row] { + val tableCatalog: OptField[String, Row] + val tableSchema: OptField[String, Row] + val tableName: OptField[String, Row] + val viewDefinition: OptField[String, Row] + val checkOption: OptField[String, Row] + val isUpdatable: OptField[/* max 3 chars */ String, Row] + val isInsertableInto: OptField[/* max 3 chars */ String, Row] + val isTriggerUpdatable: OptField[/* max 3 chars */ String, Row] + val isTriggerDeletable: OptField[/* max 3 chars */ String, Row] + val isTriggerInsertableInto: OptField[/* max 3 chars */ String, Row] +} +object ViewsViewFields extends ViewsViewStructure[ViewsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepo.scala new file mode 100644 index 0000000000..4af9400d8c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package views + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ViewsViewRepo { + def select: SelectBuilder[ViewsViewFields, ViewsViewRow] + def selectAll: ZStream[ZConnection, Throwable, ViewsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepoImpl.scala new file mode 100644 index 0000000000..e7c5def468 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package views + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ViewsViewRepoImpl extends ViewsViewRepo { + override def select: SelectBuilder[ViewsViewFields, ViewsViewRow] = { + SelectBuilderSql("information_schema.views", ViewsViewFields, ViewsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ViewsViewRow] = { + sql"""select "table_catalog", "table_schema", "table_name", "view_definition", "check_option", "is_updatable", "is_insertable_into", "is_trigger_updatable", "is_trigger_deletable", "is_trigger_insertable_into" from information_schema.views""".query(ViewsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRow.scala new file mode 100644 index 0000000000..947a355b0c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package views + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ViewsViewRow( + tableCatalog: /* nullability unknown */ Option[String], + tableSchema: /* nullability unknown */ Option[String], + tableName: /* nullability unknown */ Option[String], + viewDefinition: /* nullability unknown */ Option[String], + checkOption: /* nullability unknown */ Option[String], + isUpdatable: /* nullability unknown */ Option[/* max 3 chars */ String], + isInsertableInto: /* nullability unknown */ Option[/* max 3 chars */ String], + isTriggerUpdatable: /* nullability unknown */ Option[/* max 3 chars */ String], + isTriggerDeletable: /* nullability unknown */ Option[/* max 3 chars */ String], + isTriggerInsertableInto: /* nullability unknown */ Option[/* max 3 chars */ String] +) + +object ViewsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ViewsViewRow] = new JdbcDecoder[ViewsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ViewsViewRow) = + columIndex + 9 -> + ViewsViewRow( + tableCatalog = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tableSchema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + tableName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + viewDefinition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + checkOption = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + isUpdatable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + isInsertableInto = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + isTriggerUpdatable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + isTriggerDeletable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + isTriggerInsertableInto = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ViewsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val tableCatalog = jsonObj.get("table_catalog").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableSchema = jsonObj.get("table_schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tableName = jsonObj.get("table_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewDefinition = jsonObj.get("view_definition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val checkOption = jsonObj.get("check_option").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isUpdatable = jsonObj.get("is_updatable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isInsertableInto = jsonObj.get("is_insertable_into").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isTriggerUpdatable = jsonObj.get("is_trigger_updatable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isTriggerDeletable = jsonObj.get("is_trigger_deletable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isTriggerInsertableInto = jsonObj.get("is_trigger_insertable_into").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (tableCatalog.isRight && tableSchema.isRight && tableName.isRight && viewDefinition.isRight && checkOption.isRight && isUpdatable.isRight && isInsertableInto.isRight && isTriggerUpdatable.isRight && isTriggerDeletable.isRight && isTriggerInsertableInto.isRight) + Right(ViewsViewRow(tableCatalog = tableCatalog.toOption.get, tableSchema = tableSchema.toOption.get, tableName = tableName.toOption.get, viewDefinition = viewDefinition.toOption.get, checkOption = checkOption.toOption.get, isUpdatable = isUpdatable.toOption.get, isInsertableInto = isInsertableInto.toOption.get, isTriggerUpdatable = isTriggerUpdatable.toOption.get, isTriggerDeletable = isTriggerDeletable.toOption.get, isTriggerInsertableInto = isTriggerInsertableInto.toOption.get)) + else Left(List[Either[String, Any]](tableCatalog, tableSchema, tableName, viewDefinition, checkOption, isUpdatable, isInsertableInto, isTriggerUpdatable, isTriggerDeletable, isTriggerInsertableInto).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ViewsViewRow] = new JsonEncoder[ViewsViewRow] { + override def unsafeEncode(a: ViewsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""table_catalog":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableCatalog, indent, out) + out.write(",") + out.write(""""table_schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableSchema, indent, out) + out.write(",") + out.write(""""table_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableName, indent, out) + out.write(",") + out.write(""""view_definition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewDefinition, indent, out) + out.write(",") + out.write(""""check_option":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.checkOption, indent, out) + out.write(",") + out.write(""""is_updatable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isUpdatable, indent, out) + out.write(",") + out.write(""""is_insertable_into":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isInsertableInto, indent, out) + out.write(",") + out.write(""""is_trigger_updatable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isTriggerUpdatable, indent, out) + out.write(",") + out.write(""""is_trigger_deletable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isTriggerDeletable, indent, out) + out.write(",") + out.write(""""is_trigger_insertable_into":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.isTriggerInsertableInto, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewStructure.scala new file mode 100644 index 0000000000..2869478ffd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/information_schema/views/ViewsViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package information_schema +package views + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ViewsViewStructure[Row](val prefix: Option[String], val extract: Row => ViewsViewRow, val merge: (Row, ViewsViewRow) => Row) + extends Relation[ViewsViewFields, ViewsViewRow, Row] + with ViewsViewFields[Row] { outer => + + override val tableCatalog = new OptField[String, Row](prefix, "table_catalog", None, None)(x => extract(x).tableCatalog, (row, value) => merge(row, extract(row).copy(tableCatalog = value))) + override val tableSchema = new OptField[String, Row](prefix, "table_schema", None, None)(x => extract(x).tableSchema, (row, value) => merge(row, extract(row).copy(tableSchema = value))) + override val tableName = new OptField[String, Row](prefix, "table_name", None, None)(x => extract(x).tableName, (row, value) => merge(row, extract(row).copy(tableName = value))) + override val viewDefinition = new OptField[String, Row](prefix, "view_definition", None, None)(x => extract(x).viewDefinition, (row, value) => merge(row, extract(row).copy(viewDefinition = value))) + override val checkOption = new OptField[String, Row](prefix, "check_option", None, None)(x => extract(x).checkOption, (row, value) => merge(row, extract(row).copy(checkOption = value))) + override val isUpdatable = new OptField[/* max 3 chars */ String, Row](prefix, "is_updatable", None, None)(x => extract(x).isUpdatable, (row, value) => merge(row, extract(row).copy(isUpdatable = value))) + override val isInsertableInto = new OptField[/* max 3 chars */ String, Row](prefix, "is_insertable_into", None, None)(x => extract(x).isInsertableInto, (row, value) => merge(row, extract(row).copy(isInsertableInto = value))) + override val isTriggerUpdatable = new OptField[/* max 3 chars */ String, Row](prefix, "is_trigger_updatable", None, None)(x => extract(x).isTriggerUpdatable, (row, value) => merge(row, extract(row).copy(isTriggerUpdatable = value))) + override val isTriggerDeletable = new OptField[/* max 3 chars */ String, Row](prefix, "is_trigger_deletable", None, None)(x => extract(x).isTriggerDeletable, (row, value) => merge(row, extract(row).copy(isTriggerDeletable = value))) + override val isTriggerInsertableInto = new OptField[/* max 3 chars */ String, Row](prefix, "is_trigger_insertable_into", None, None)(x => extract(x).isTriggerInsertableInto, (row, value) => merge(row, extract(row).copy(isTriggerInsertableInto = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](tableCatalog, tableSchema, tableName, viewDefinition, checkOption, isUpdatable, isInsertableInto, isTriggerUpdatable, isTriggerDeletable, isTriggerInsertableInto) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ViewsViewRow, merge: (NewRow, ViewsViewRow) => NewRow): ViewsViewStructure[NewRow] = + new ViewsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/package.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/package.scala new file mode 100644 index 0000000000..0803ca4ec6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/package.scala @@ -0,0 +1,243 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ + + +package object adventureworks { + implicit lazy val BigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] = new zio.jdbc.JdbcDecoder[scala.Array[java.math.BigDecimal]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.math.BigDecimal]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.math.BigDecimal]) { + case (b, x: java.math.BigDecimal) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.math.BigDecimal] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.math.BigDecimal) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.math.BigDecimal). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.math.BigDecimal]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BigDecimalArraySetter) + implicit lazy val BigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.math.BigDecimal]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.math.BigDecimal]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("numeric", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val BooleanArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Boolean]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Boolean]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Boolean]) { + case (b, x: scala.Boolean) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Boolean] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Boolean) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Boolean). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val BooleanArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Boolean]] = zio.jdbc.JdbcEncoder.singleParamEncoder(BooleanArraySetter) + implicit lazy val BooleanArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Boolean]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Boolean]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("bool", v.map(x => boolean2Boolean(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val DoubleArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Double]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Double]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Double]) { + case (b, x: scala.Double) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Double] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Double) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Double). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val DoubleArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Double]] = zio.jdbc.JdbcEncoder.singleParamEncoder(DoubleArraySetter) + implicit lazy val DoubleArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Double]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Double]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float8", v.map(x => double2Double(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val FloatArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Float]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Float]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Float]) { + case (b, x: scala.Float) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Float] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Float) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Float). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val FloatArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Float]] = zio.jdbc.JdbcEncoder.singleParamEncoder(FloatArraySetter) + implicit lazy val FloatArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Float]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Float]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("float4", v.map(x => float2Float(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val IntArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Int]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Int]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Int]) { + case (b, x: scala.Int) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Int] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Int) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Int). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val IntArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Int]] = zio.jdbc.JdbcEncoder.singleParamEncoder(IntArraySetter) + implicit lazy val IntArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Int]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Int]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int4", v.map(x => int2Integer(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val LongArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] = new zio.jdbc.JdbcDecoder[scala.Array[scala.Long]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[scala.Long]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[scala.Long]) { + case (b, x: scala.Long) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[scala.Long] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(scala.Long) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (scala.Long). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val LongArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.Long]] = zio.jdbc.JdbcEncoder.singleParamEncoder(LongArraySetter) + implicit lazy val LongArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.Long]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[scala.Long]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("int8", v.map(x => long2Long(x): scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) + implicit lazy val ScalaBigDecimalArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayDecoder.map(v => if (v eq null) null else v.map(scala.math.BigDecimal.apply)) + implicit lazy val ScalaBigDecimalArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[scala.math.BigDecimal]] = BigDecimalArrayEncoder.contramap(_.map(_.bigDecimal)) + implicit lazy val ScalaBigDecimalArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[scala.math.BigDecimal]] = BigDecimalArraySetter.contramap(_.map(_.bigDecimal)) + implicit lazy val StringArrayDecoder: zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] = new zio.jdbc.JdbcDecoder[scala.Array[java.lang.String]] { + override def unsafeDecode(columIndex: scala.Int, rs: java.sql.ResultSet): (scala.Int, scala.Array[java.lang.String]) = { + val arr = rs.getArray(columIndex) + if (arr eq null) columIndex -> null + else { + columIndex -> + arr + .getArray + .asInstanceOf[Array[Any]] + .foldLeft(Array.newBuilder[java.lang.String]) { + case (b, x: java.lang.String) => b += x + case (b, x: java.lang.Number) => b += x.asInstanceOf[java.lang.String] + case (_, x) => + throw zio.jdbc.JdbcDecoderError( + message = s"Error decoding scala.Array(java.lang.String) from ResultSet", + cause = new IllegalStateException( + s"Retrieved ${x.getClass.getCanonicalName} type from JDBC array, but expected (java.lang.String). Re-check your decoder implementation" + ), + metadata = rs.getMetaData, + row = rs.getRow + ) + } + .result() + } + } + } + implicit lazy val StringArrayEncoder: zio.jdbc.JdbcEncoder[scala.Array[java.lang.String]] = zio.jdbc.JdbcEncoder.singleParamEncoder(StringArraySetter) + implicit lazy val StringArraySetter: zio.jdbc.SqlFragment.Setter[scala.Array[java.lang.String]] = zio.jdbc.SqlFragment.Setter.forSqlType[scala.Array[java.lang.String]]( + (ps, i, v) => { + ps.setArray(i, ps.getConnection.createArrayOf("varchar", v.map(x => x: scala.AnyRef))) + }, + java.sql.Types.ARRAY + ) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewFields.scala new file mode 100644 index 0000000000..cc5665827f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package a + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.stateprovince.StateprovinceId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait AViewFields[Row] { + val id: Field[AddressId, Row] + val addressid: Field[AddressId, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovinceid: Field[StateprovinceId, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val spatiallocation: OptField[TypoBytea, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object AViewFields extends AViewStructure[AViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepo.scala new file mode 100644 index 0000000000..54f8a6361d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package a + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AViewRepo { + def select: SelectBuilder[AViewFields, AViewRow] + def selectAll: ZStream[ZConnection, Throwable, AViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepoImpl.scala new file mode 100644 index 0000000000..909f89e8d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package a + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AViewRepoImpl extends AViewRepo { + override def select: SelectBuilder[AViewFields, AViewRow] = { + SelectBuilderSql("pe.a", AViewFields, AViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AViewRow] = { + sql"""select "id", "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text from pe.a""".query(AViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRow.scala new file mode 100644 index 0000000000..e69e92df28 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewRow.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package a + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.stateprovince.StateprovinceId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AViewRow( + /** Points to [[person.address.AddressRow.addressid]] */ + id: AddressId, + /** Points to [[person.address.AddressRow.addressid]] */ + addressid: AddressId, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.address.AddressRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.address.AddressRow.spatiallocation]] */ + spatiallocation: Option[TypoBytea], + /** Points to [[person.address.AddressRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.address.AddressRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object AViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AViewRow] = new JdbcDecoder[AViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AViewRow) = + columIndex + 9 -> + AViewRow( + id = AddressId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + addressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + spatiallocation = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(AddressId.jsonDecoder)) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val spatiallocation = jsonObj.get("spatiallocation").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && addressid.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovinceid.isRight && postalcode.isRight && spatiallocation.isRight && rowguid.isRight && modifieddate.isRight) + Right(AViewRow(id = id.toOption.get, addressid = addressid.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovinceid = stateprovinceid.toOption.get, postalcode = postalcode.toOption.get, spatiallocation = spatiallocation.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, addressid, addressline1, addressline2, city, stateprovinceid, postalcode, spatiallocation, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AViewRow] = new JsonEncoder[AViewRow] { + override def unsafeEncode(a: AViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + AddressId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""spatiallocation":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.spatiallocation, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewStructure.scala new file mode 100644 index 0000000000..d35821de31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/a/AViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package a + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.stateprovince.StateprovinceId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class AViewStructure[Row](val prefix: Option[String], val extract: Row => AViewRow, val merge: (Row, AViewRow) => Row) + extends Relation[AViewFields, AViewRow, Row] + with AViewFields[Row] { outer => + + override val id = new Field[AddressId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val addressid = new Field[AddressId, Row](prefix, "addressid", None, None)(x => extract(x).addressid, (row, value) => merge(row, extract(row).copy(addressid = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, None)(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val spatiallocation = new OptField[TypoBytea, Row](prefix, "spatiallocation", None, None)(x => extract(x).spatiallocation, (row, value) => merge(row, extract(row).copy(spatiallocation = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, addressid, addressline1, addressline2, city, stateprovinceid, postalcode, spatiallocation, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AViewRow, merge: (NewRow, AViewRow) => NewRow): AViewStructure[NewRow] = + new AViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewFields.scala new file mode 100644 index 0000000000..6e39752a18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package at + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait AtViewFields[Row] { + val id: Field[AddresstypeId, Row] + val addresstypeid: Field[AddresstypeId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object AtViewFields extends AtViewStructure[AtViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepo.scala new file mode 100644 index 0000000000..36425db424 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package at + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AtViewRepo { + def select: SelectBuilder[AtViewFields, AtViewRow] + def selectAll: ZStream[ZConnection, Throwable, AtViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepoImpl.scala new file mode 100644 index 0000000000..8641826804 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package at + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AtViewRepoImpl extends AtViewRepo { + override def select: SelectBuilder[AtViewFields, AtViewRow] = { + SelectBuilderSql("pe.at", AtViewFields, AtViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AtViewRow] = { + sql"""select "id", "addresstypeid", "name", "rowguid", "modifieddate"::text from pe.at""".query(AtViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRow.scala new file mode 100644 index 0000000000..d7a67c0004 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package at + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AtViewRow( + /** Points to [[person.addresstype.AddresstypeRow.addresstypeid]] */ + id: AddresstypeId, + /** Points to [[person.addresstype.AddresstypeRow.addresstypeid]] */ + addresstypeid: AddresstypeId, + /** Points to [[person.addresstype.AddresstypeRow.name]] */ + name: Name, + /** Points to [[person.addresstype.AddresstypeRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.addresstype.AddresstypeRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object AtViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AtViewRow] = new JdbcDecoder[AtViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AtViewRow) = + columIndex + 4 -> + AtViewRow( + id = AddresstypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + addresstypeid = AddresstypeId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AtViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && addresstypeid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(AtViewRow(id = id.toOption.get, addresstypeid = addresstypeid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, addresstypeid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AtViewRow] = new JsonEncoder[AtViewRow] { + override def unsafeEncode(a: AtViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewStructure.scala new file mode 100644 index 0000000000..381f16a972 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/at/AtViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package at + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class AtViewStructure[Row](val prefix: Option[String], val extract: Row => AtViewRow, val merge: (Row, AtViewRow) => Row) + extends Relation[AtViewFields, AtViewRow, Row] + with AtViewFields[Row] { outer => + + override val id = new Field[AddresstypeId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val addresstypeid = new Field[AddresstypeId, Row](prefix, "addresstypeid", None, None)(x => extract(x).addresstypeid, (row, value) => merge(row, extract(row).copy(addresstypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, addresstypeid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AtViewRow, merge: (NewRow, AtViewRow) => NewRow): AtViewStructure[NewRow] = + new AtViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewFields.scala new file mode 100644 index 0000000000..f8bd6c8773 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package be + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field + +trait BeViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BeViewFields extends BeViewStructure[BeViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepo.scala new file mode 100644 index 0000000000..d1f41f3bce --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package be + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BeViewRepo { + def select: SelectBuilder[BeViewFields, BeViewRow] + def selectAll: ZStream[ZConnection, Throwable, BeViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepoImpl.scala new file mode 100644 index 0000000000..b05251e5d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package be + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BeViewRepoImpl extends BeViewRepo { + override def select: SelectBuilder[BeViewFields, BeViewRow] = { + SelectBuilderSql("pe.be", BeViewFields, BeViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BeViewRow] = { + sql"""select "id", "businessentityid", "rowguid", "modifieddate"::text from pe.be""".query(BeViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRow.scala new file mode 100644 index 0000000000..0aef5bf71e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package be + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BeViewRow( + /** Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.businessentity.BusinessentityRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.businessentity.BusinessentityRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object BeViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BeViewRow] = new JdbcDecoder[BeViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BeViewRow) = + columIndex + 3 -> + BeViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BeViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BeViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BeViewRow] = new JsonEncoder[BeViewRow] { + override def unsafeEncode(a: BeViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewStructure.scala new file mode 100644 index 0000000000..ef782f336b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/be/BeViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package be + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class BeViewStructure[Row](val prefix: Option[String], val extract: Row => BeViewRow, val merge: (Row, BeViewRow) => Row) + extends Relation[BeViewFields, BeViewRow, Row] + with BeViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BeViewRow, merge: (NewRow, BeViewRow) => NewRow): BeViewStructure[NewRow] = + new BeViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewFields.scala new file mode 100644 index 0000000000..38e0461608 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bea + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field + +trait BeaViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val addressid: Field[AddressId, Row] + val addresstypeid: Field[AddresstypeId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BeaViewFields extends BeaViewStructure[BeaViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepo.scala new file mode 100644 index 0000000000..a005f1481a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bea + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BeaViewRepo { + def select: SelectBuilder[BeaViewFields, BeaViewRow] + def selectAll: ZStream[ZConnection, Throwable, BeaViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepoImpl.scala new file mode 100644 index 0000000000..a1341dbf5c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bea + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BeaViewRepoImpl extends BeaViewRepo { + override def select: SelectBuilder[BeaViewFields, BeaViewRow] = { + SelectBuilderSql("pe.bea", BeaViewFields, BeaViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BeaViewRow] = { + sql"""select "id", "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text from pe.bea""".query(BeaViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRow.scala new file mode 100644 index 0000000000..e6a400257f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewRow.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bea + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BeaViewRow( + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.addressid]] */ + addressid: AddressId, + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.addresstypeid]] */ + addresstypeid: AddresstypeId, + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.businessentityaddress.BusinessentityaddressRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object BeaViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BeaViewRow] = new JdbcDecoder[BeaViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BeaViewRow) = + columIndex + 5 -> + BeaViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + addressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + addresstypeid = AddresstypeId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BeaViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && addressid.isRight && addresstypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BeaViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, addressid = addressid.toOption.get, addresstypeid = addresstypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, addressid, addresstypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BeaViewRow] = new JsonEncoder[BeaViewRow] { + override def unsafeEncode(a: BeaViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewStructure.scala new file mode 100644 index 0000000000..9939c42684 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bea/BeaViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bea + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class BeaViewStructure[Row](val prefix: Option[String], val extract: Row => BeaViewRow, val merge: (Row, BeaViewRow) => Row) + extends Relation[BeaViewFields, BeaViewRow, Row] + with BeaViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val addressid = new Field[AddressId, Row](prefix, "addressid", None, None)(x => extract(x).addressid, (row, value) => merge(row, extract(row).copy(addressid = value))) + override val addresstypeid = new Field[AddresstypeId, Row](prefix, "addresstypeid", None, None)(x => extract(x).addresstypeid, (row, value) => merge(row, extract(row).copy(addresstypeid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, addressid, addresstypeid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BeaViewRow, merge: (NewRow, BeaViewRow) => NewRow): BeaViewStructure[NewRow] = + new BeaViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewFields.scala new file mode 100644 index 0000000000..5724f5ff7a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bec + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import typo.dsl.SqlExpr.Field + +trait BecViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val personid: Field[BusinessentityId, Row] + val contacttypeid: Field[ContacttypeId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BecViewFields extends BecViewStructure[BecViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepo.scala new file mode 100644 index 0000000000..5c0ec4c534 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bec + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BecViewRepo { + def select: SelectBuilder[BecViewFields, BecViewRow] + def selectAll: ZStream[ZConnection, Throwable, BecViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepoImpl.scala new file mode 100644 index 0000000000..a920635a53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bec + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BecViewRepoImpl extends BecViewRepo { + override def select: SelectBuilder[BecViewFields, BecViewRow] = { + SelectBuilderSql("pe.bec", BecViewFields, BecViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BecViewRow] = { + sql"""select "id", "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text from pe.bec""".query(BecViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRow.scala new file mode 100644 index 0000000000..4ee90ab4e4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewRow.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bec + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BecViewRow( + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.personid]] */ + personid: BusinessentityId, + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.contacttypeid]] */ + contacttypeid: ContacttypeId, + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.businessentitycontact.BusinessentitycontactRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object BecViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BecViewRow] = new JdbcDecoder[BecViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BecViewRow) = + columIndex + 5 -> + BecViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + personid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + contacttypeid = ContacttypeId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BecViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val personid = jsonObj.get("personid").toRight("Missing field 'personid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && personid.isRight && contacttypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BecViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, personid = personid.toOption.get, contacttypeid = contacttypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, personid, contacttypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BecViewRow] = new JsonEncoder[BecViewRow] { + override def unsafeEncode(a: BecViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""personid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewStructure.scala new file mode 100644 index 0000000000..a09467f9c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/bec/BecViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package bec + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class BecViewStructure[Row](val prefix: Option[String], val extract: Row => BecViewRow, val merge: (Row, BecViewRow) => Row) + extends Relation[BecViewFields, BecViewRow, Row] + with BecViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val personid = new Field[BusinessentityId, Row](prefix, "personid", None, None)(x => extract(x).personid, (row, value) => merge(row, extract(row).copy(personid = value))) + override val contacttypeid = new Field[ContacttypeId, Row](prefix, "contacttypeid", None, None)(x => extract(x).contacttypeid, (row, value) => merge(row, extract(row).copy(contacttypeid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, personid, contacttypeid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BecViewRow, merge: (NewRow, BecViewRow) => NewRow): BecViewStructure[NewRow] = + new BecViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewFields.scala new file mode 100644 index 0000000000..71ec6e83a7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait CrViewFields[Row] { + val countryregioncode: Field[CountryregionId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CrViewFields extends CrViewStructure[CrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepo.scala new file mode 100644 index 0000000000..f19ed48ce9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package cr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CrViewRepo { + def select: SelectBuilder[CrViewFields, CrViewRow] + def selectAll: ZStream[ZConnection, Throwable, CrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepoImpl.scala new file mode 100644 index 0000000000..dba3269afc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package cr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CrViewRepoImpl extends CrViewRepo { + override def select: SelectBuilder[CrViewFields, CrViewRow] = { + SelectBuilderSql("pe.cr", CrViewFields, CrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CrViewRow] = { + sql"""select "countryregioncode", "name", "modifieddate"::text from pe.cr""".query(CrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRow.scala new file mode 100644 index 0000000000..1343023d97 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CrViewRow( + /** Points to [[person.countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + name: Name, + /** Points to [[person.countryregion.CountryregionRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CrViewRow] = new JdbcDecoder[CrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CrViewRow) = + columIndex + 2 -> + CrViewRow( + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (countryregioncode.isRight && name.isRight && modifieddate.isRight) + Right(CrViewRow(countryregioncode = countryregioncode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CrViewRow] = new JsonEncoder[CrViewRow] { + override def unsafeEncode(a: CrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewStructure.scala new file mode 100644 index 0000000000..32b8f25325 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/cr/CrViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CrViewStructure[Row](val prefix: Option[String], val extract: Row => CrViewRow, val merge: (Row, CrViewRow) => Row) + extends Relation[CrViewFields, CrViewRow, Row] + with CrViewFields[Row] { outer => + + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](countryregioncode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CrViewRow, merge: (NewRow, CrViewRow) => NewRow): CrViewStructure[NewRow] = + new CrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewFields.scala new file mode 100644 index 0000000000..c00715d06d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package ct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.contacttype.ContacttypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait CtViewFields[Row] { + val id: Field[ContacttypeId, Row] + val contacttypeid: Field[ContacttypeId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CtViewFields extends CtViewStructure[CtViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepo.scala new file mode 100644 index 0000000000..3812b4c30a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package ct + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CtViewRepo { + def select: SelectBuilder[CtViewFields, CtViewRow] + def selectAll: ZStream[ZConnection, Throwable, CtViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepoImpl.scala new file mode 100644 index 0000000000..32f93373ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package ct + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CtViewRepoImpl extends CtViewRepo { + override def select: SelectBuilder[CtViewFields, CtViewRow] = { + SelectBuilderSql("pe.ct", CtViewFields, CtViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CtViewRow] = { + sql"""select "id", "contacttypeid", "name", "modifieddate"::text from pe.ct""".query(CtViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRow.scala new file mode 100644 index 0000000000..113ca21069 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package ct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.contacttype.ContacttypeId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CtViewRow( + /** Points to [[person.contacttype.ContacttypeRow.contacttypeid]] */ + id: ContacttypeId, + /** Points to [[person.contacttype.ContacttypeRow.contacttypeid]] */ + contacttypeid: ContacttypeId, + /** Points to [[person.contacttype.ContacttypeRow.name]] */ + name: Name, + /** Points to [[person.contacttype.ContacttypeRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CtViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CtViewRow] = new JdbcDecoder[CtViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CtViewRow) = + columIndex + 3 -> + CtViewRow( + id = ContacttypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + contacttypeid = ContacttypeId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CtViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && contacttypeid.isRight && name.isRight && modifieddate.isRight) + Right(CtViewRow(id = id.toOption.get, contacttypeid = contacttypeid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, contacttypeid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CtViewRow] = new JsonEncoder[CtViewRow] { + override def unsafeEncode(a: CtViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewStructure.scala new file mode 100644 index 0000000000..a614c2a88f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/ct/CtViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package ct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.contacttype.ContacttypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CtViewStructure[Row](val prefix: Option[String], val extract: Row => CtViewRow, val merge: (Row, CtViewRow) => Row) + extends Relation[CtViewFields, CtViewRow, Row] + with CtViewFields[Row] { outer => + + override val id = new Field[ContacttypeId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val contacttypeid = new Field[ContacttypeId, Row](prefix, "contacttypeid", None, None)(x => extract(x).contacttypeid, (row, value) => merge(row, extract(row).copy(contacttypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, contacttypeid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CtViewRow, merge: (NewRow, CtViewRow) => NewRow): CtViewStructure[NewRow] = + new CtViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewFields.scala new file mode 100644 index 0000000000..8ed9659638 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package e + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait EViewFields[Row] { + val id: Field[Int, Row] + val businessentityid: Field[BusinessentityId, Row] + val emailaddressid: Field[Int, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EViewFields extends EViewStructure[EViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepo.scala new file mode 100644 index 0000000000..60dba511d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package e + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EViewRepo { + def select: SelectBuilder[EViewFields, EViewRow] + def selectAll: ZStream[ZConnection, Throwable, EViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepoImpl.scala new file mode 100644 index 0000000000..60d09292ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package e + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EViewRepoImpl extends EViewRepo { + override def select: SelectBuilder[EViewFields, EViewRow] = { + SelectBuilderSql("pe.e", EViewFields, EViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EViewRow] = { + sql"""select "id", "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text from pe.e""".query(EViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRow.scala new file mode 100644 index 0000000000..90be9c7f97 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package e + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EViewRow( + /** Points to [[person.emailaddress.EmailaddressRow.emailaddressid]] */ + id: Int, + /** Points to [[person.emailaddress.EmailaddressRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.emailaddress.EmailaddressRow.emailaddressid]] */ + emailaddressid: Int, + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.emailaddress.EmailaddressRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.emailaddress.EmailaddressRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object EViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EViewRow] = new JdbcDecoder[EViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EViewRow) = + columIndex + 5 -> + EViewRow( + id = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + emailaddressid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(JsonDecoder.int)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val emailaddressid = jsonObj.get("emailaddressid").toRight("Missing field 'emailaddressid'").flatMap(_.as(JsonDecoder.int)) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && emailaddressid.isRight && emailaddress.isRight && rowguid.isRight && modifieddate.isRight) + Right(EViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, emailaddressid = emailaddressid.toOption.get, emailaddress = emailaddress.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, emailaddressid, emailaddress, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EViewRow] = new JsonEncoder[EViewRow] { + override def unsafeEncode(a: EViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + JsonEncoder.int.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""emailaddressid":""") + JsonEncoder.int.unsafeEncode(a.emailaddressid, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewStructure.scala new file mode 100644 index 0000000000..7003503552 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/e/EViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package e + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EViewStructure[Row](val prefix: Option[String], val extract: Row => EViewRow, val merge: (Row, EViewRow) => Row) + extends Relation[EViewFields, EViewRow, Row] + with EViewFields[Row] { outer => + + 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 businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val emailaddressid = new Field[Int, Row](prefix, "emailaddressid", None, None)(x => extract(x).emailaddressid, (row, value) => merge(row, extract(row).copy(emailaddressid = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, emailaddressid, emailaddress, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EViewRow, merge: (NewRow, EViewRow) => NewRow): EViewStructure[NewRow] = + new EViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewFields.scala new file mode 100644 index 0000000000..8880bac907 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewFields.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val persontype: Field[/* bpchar, max 2 chars */ String, Row] + val namestyle: Field[NameStyle, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val emailpromotion: Field[Int, Row] + val additionalcontactinfo: OptField[TypoXml, Row] + val demographics: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PViewFields extends PViewStructure[PViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepo.scala new file mode 100644 index 0000000000..d6103e2126 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package p + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PViewRepo { + def select: SelectBuilder[PViewFields, PViewRow] + def selectAll: ZStream[ZConnection, Throwable, PViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepoImpl.scala new file mode 100644 index 0000000000..b02223d4b0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package p + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PViewRepoImpl extends PViewRepo { + override def select: SelectBuilder[PViewFields, PViewRow] = { + SelectBuilderSql("pe.p", PViewFields, PViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PViewRow] = { + sql"""select "id", "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text from pe.p""".query(PViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRow.scala new file mode 100644 index 0000000000..15ae4bbb69 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewRow.scala @@ -0,0 +1,142 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PViewRow( + /** Points to [[person.person.PersonRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.persontype]] */ + persontype: /* bpchar, max 2 chars */ String, + /** Points to [[person.person.PersonRow.namestyle]] */ + namestyle: NameStyle, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int, + /** Points to [[person.person.PersonRow.additionalcontactinfo]] */ + additionalcontactinfo: Option[TypoXml], + /** Points to [[person.person.PersonRow.demographics]] */ + demographics: Option[TypoXml], + /** Points to [[person.person.PersonRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.person.PersonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PViewRow] = new JdbcDecoder[PViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PViewRow) = + columIndex + 13 -> + PViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + persontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + namestyle = NameStyle.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 9, rs)._2, + additionalcontactinfo = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + demographics = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val persontype = jsonObj.get("persontype").toRight("Missing field 'persontype'").flatMap(_.as(JsonDecoder.string)) + val namestyle = jsonObj.get("namestyle").toRight("Missing field 'namestyle'").flatMap(_.as(NameStyle.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + val additionalcontactinfo = jsonObj.get("additionalcontactinfo").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && persontype.isRight && namestyle.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && emailpromotion.isRight && additionalcontactinfo.isRight && demographics.isRight && rowguid.isRight && modifieddate.isRight) + Right(PViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, persontype = persontype.toOption.get, namestyle = namestyle.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, emailpromotion = emailpromotion.toOption.get, additionalcontactinfo = additionalcontactinfo.toOption.get, demographics = demographics.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, persontype, namestyle, title, firstname, middlename, lastname, suffix, emailpromotion, additionalcontactinfo, demographics, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PViewRow] = new JsonEncoder[PViewRow] { + override def unsafeEncode(a: PViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""persontype":""") + JsonEncoder.string.unsafeEncode(a.persontype, indent, out) + out.write(",") + out.write(""""namestyle":""") + NameStyle.jsonEncoder.unsafeEncode(a.namestyle, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""additionalcontactinfo":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.additionalcontactinfo, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewStructure.scala new file mode 100644 index 0000000000..29b01d51a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/p/PViewStructure.scala @@ -0,0 +1,46 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PViewStructure[Row](val prefix: Option[String], val extract: Row => PViewRow, val merge: (Row, PViewRow) => Row) + extends Relation[PViewFields, PViewRow, Row] + with PViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val persontype = new Field[/* bpchar, max 2 chars */ String, Row](prefix, "persontype", None, None)(x => extract(x).persontype, (row, value) => merge(row, extract(row).copy(persontype = value))) + override val namestyle = new Field[NameStyle, Row](prefix, "namestyle", None, None)(x => extract(x).namestyle, (row, value) => merge(row, extract(row).copy(namestyle = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + override val additionalcontactinfo = new OptField[TypoXml, Row](prefix, "additionalcontactinfo", None, None)(x => extract(x).additionalcontactinfo, (row, value) => merge(row, extract(row).copy(additionalcontactinfo = value))) + override val demographics = new OptField[TypoXml, Row](prefix, "demographics", None, None)(x => extract(x).demographics, (row, value) => merge(row, extract(row).copy(demographics = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, persontype, namestyle, title, firstname, middlename, lastname, suffix, emailpromotion, additionalcontactinfo, demographics, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PViewRow, merge: (NewRow, PViewRow) => NewRow): PViewStructure[NewRow] = + new PViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewFields.scala new file mode 100644 index 0000000000..4df2b951fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pa + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field + +trait PaViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val passwordhash: Field[/* max 128 chars */ String, Row] + val passwordsalt: Field[/* max 10 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PaViewFields extends PaViewStructure[PaViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepo.scala new file mode 100644 index 0000000000..97d2171c0e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pa + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PaViewRepo { + def select: SelectBuilder[PaViewFields, PaViewRow] + def selectAll: ZStream[ZConnection, Throwable, PaViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepoImpl.scala new file mode 100644 index 0000000000..252a93ee5e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pa + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PaViewRepoImpl extends PaViewRepo { + override def select: SelectBuilder[PaViewFields, PaViewRow] = { + SelectBuilderSql("pe.pa", PaViewFields, PaViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PaViewRow] = { + sql"""select "id", "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text from pe.pa""".query(PaViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRow.scala new file mode 100644 index 0000000000..4bab4dd1dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pa + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PaViewRow( + /** Points to [[person.password.PasswordRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.password.PasswordRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.password.PasswordRow.passwordhash]] */ + passwordhash: /* max 128 chars */ String, + /** Points to [[person.password.PasswordRow.passwordsalt]] */ + passwordsalt: /* max 10 chars */ String, + /** Points to [[person.password.PasswordRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.password.PasswordRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PaViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PaViewRow] = new JdbcDecoder[PaViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PaViewRow) = + columIndex + 5 -> + PaViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + passwordhash = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + passwordsalt = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PaViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val passwordhash = jsonObj.get("passwordhash").toRight("Missing field 'passwordhash'").flatMap(_.as(JsonDecoder.string)) + val passwordsalt = jsonObj.get("passwordsalt").toRight("Missing field 'passwordsalt'").flatMap(_.as(JsonDecoder.string)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && passwordhash.isRight && passwordsalt.isRight && rowguid.isRight && modifieddate.isRight) + Right(PaViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, passwordhash = passwordhash.toOption.get, passwordsalt = passwordsalt.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, passwordhash, passwordsalt, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PaViewRow] = new JsonEncoder[PaViewRow] { + override def unsafeEncode(a: PaViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""passwordhash":""") + JsonEncoder.string.unsafeEncode(a.passwordhash, indent, out) + out.write(",") + out.write(""""passwordsalt":""") + JsonEncoder.string.unsafeEncode(a.passwordsalt, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewStructure.scala new file mode 100644 index 0000000000..77b7c56702 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pa/PaViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pa + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PaViewStructure[Row](val prefix: Option[String], val extract: Row => PaViewRow, val merge: (Row, PaViewRow) => Row) + extends Relation[PaViewFields, PaViewRow, Row] + with PaViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val passwordhash = new Field[/* max 128 chars */ String, Row](prefix, "passwordhash", None, None)(x => extract(x).passwordhash, (row, value) => merge(row, extract(row).copy(passwordhash = value))) + override val passwordsalt = new Field[/* max 10 chars */ String, Row](prefix, "passwordsalt", None, None)(x => extract(x).passwordsalt, (row, value) => merge(row, extract(row).copy(passwordsalt = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, passwordhash, passwordsalt, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PaViewRow, merge: (NewRow, PaViewRow) => NewRow): PaViewStructure[NewRow] = + new PaViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewFields.scala new file mode 100644 index 0000000000..9af94760e7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pnt + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait PntViewFields[Row] { + val id: Field[PhonenumbertypeId, Row] + val phonenumbertypeid: Field[PhonenumbertypeId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PntViewFields extends PntViewStructure[PntViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepo.scala new file mode 100644 index 0000000000..c5a089e0ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pnt + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PntViewRepo { + def select: SelectBuilder[PntViewFields, PntViewRow] + def selectAll: ZStream[ZConnection, Throwable, PntViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepoImpl.scala new file mode 100644 index 0000000000..739cdb45c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pnt + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PntViewRepoImpl extends PntViewRepo { + override def select: SelectBuilder[PntViewFields, PntViewRow] = { + SelectBuilderSql("pe.pnt", PntViewFields, PntViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PntViewRow] = { + sql"""select "id", "phonenumbertypeid", "name", "modifieddate"::text from pe.pnt""".query(PntViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRow.scala new file mode 100644 index 0000000000..e9effae2c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pnt + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PntViewRow( + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.phonenumbertypeid]] */ + id: PhonenumbertypeId, + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.phonenumbertypeid]] */ + phonenumbertypeid: PhonenumbertypeId, + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + name: Name, + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PntViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PntViewRow] = new JdbcDecoder[PntViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PntViewRow) = + columIndex + 3 -> + PntViewRow( + id = PhonenumbertypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + phonenumbertypeid = PhonenumbertypeId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PntViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && phonenumbertypeid.isRight && name.isRight && modifieddate.isRight) + Right(PntViewRow(id = id.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, phonenumbertypeid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PntViewRow] = new JsonEncoder[PntViewRow] { + override def unsafeEncode(a: PntViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewStructure.scala new file mode 100644 index 0000000000..d44f7f510a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pnt/PntViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pnt + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PntViewStructure[Row](val prefix: Option[String], val extract: Row => PntViewRow, val merge: (Row, PntViewRow) => Row) + extends Relation[PntViewFields, PntViewRow, Row] + with PntViewFields[Row] { outer => + + override val id = new Field[PhonenumbertypeId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val phonenumbertypeid = new Field[PhonenumbertypeId, Row](prefix, "phonenumbertypeid", None, None)(x => extract(x).phonenumbertypeid, (row, value) => merge(row, extract(row).copy(phonenumbertypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, phonenumbertypeid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PntViewRow, merge: (NewRow, PntViewRow) => NewRow): PntViewStructure[NewRow] = + new PntViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewFields.scala new file mode 100644 index 0000000000..0b585f248d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import typo.dsl.SqlExpr.Field + +trait PpViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val phonenumber: Field[Phone, Row] + val phonenumbertypeid: Field[PhonenumbertypeId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PpViewFields extends PpViewStructure[PpViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepo.scala new file mode 100644 index 0000000000..6031f55786 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pp + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PpViewRepo { + def select: SelectBuilder[PpViewFields, PpViewRow] + def selectAll: ZStream[ZConnection, Throwable, PpViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepoImpl.scala new file mode 100644 index 0000000000..5de18fc5ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pp + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PpViewRepoImpl extends PpViewRepo { + override def select: SelectBuilder[PpViewFields, PpViewRow] = { + SelectBuilderSql("pe.pp", PpViewFields, PpViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PpViewRow] = { + sql"""select "id", "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text from pe.pp""".query(PpViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRow.scala new file mode 100644 index 0000000000..5d5da86cee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PpViewRow( + /** Points to [[person.personphone.PersonphoneRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[person.personphone.PersonphoneRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Phone, + /** Points to [[person.personphone.PersonphoneRow.phonenumbertypeid]] */ + phonenumbertypeid: PhonenumbertypeId, + /** Points to [[person.personphone.PersonphoneRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PpViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PpViewRow] = new JdbcDecoder[PpViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PpViewRow) = + columIndex + 4 -> + PpViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + phonenumber = Phone.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + phonenumbertypeid = PhonenumbertypeId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PpViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val phonenumber = jsonObj.get("phonenumber").toRight("Missing field 'phonenumber'").flatMap(_.as(Phone.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && phonenumber.isRight && phonenumbertypeid.isRight && modifieddate.isRight) + Right(PpViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, phonenumber, phonenumbertypeid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PpViewRow] = new JsonEncoder[PpViewRow] { + override def unsafeEncode(a: PpViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""phonenumber":""") + Phone.jsonEncoder.unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewStructure.scala new file mode 100644 index 0000000000..e7f3f91a3f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/pp/PpViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package pp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PpViewStructure[Row](val prefix: Option[String], val extract: Row => PpViewRow, val merge: (Row, PpViewRow) => Row) + extends Relation[PpViewFields, PpViewRow, Row] + with PpViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val phonenumber = new Field[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertypeid = new Field[PhonenumbertypeId, Row](prefix, "phonenumbertypeid", None, None)(x => extract(x).phonenumbertypeid, (row, value) => merge(row, extract(row).copy(phonenumbertypeid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, phonenumber, phonenumbertypeid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PpViewRow, merge: (NewRow, PpViewRow) => NewRow): PpViewStructure[NewRow] = + new PpViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewFields.scala new file mode 100644 index 0000000000..5a5f45bc45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field + +trait SpViewFields[Row] { + val id: Field[StateprovinceId, Row] + val stateprovinceid: Field[StateprovinceId, Row] + val stateprovincecode: Field[/* bpchar, max 3 chars */ String, Row] + val countryregioncode: Field[CountryregionId, Row] + val isonlystateprovinceflag: Field[Flag, Row] + val name: Field[Name, Row] + val territoryid: Field[SalesterritoryId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SpViewFields extends SpViewStructure[SpViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepo.scala new file mode 100644 index 0000000000..6dd93ecc93 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package sp + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SpViewRepo { + def select: SelectBuilder[SpViewFields, SpViewRow] + def selectAll: ZStream[ZConnection, Throwable, SpViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepoImpl.scala new file mode 100644 index 0000000000..2193fa93a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package sp + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SpViewRepoImpl extends SpViewRepo { + override def select: SelectBuilder[SpViewFields, SpViewRow] = { + SelectBuilderSql("pe.sp", SpViewFields, SpViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SpViewRow] = { + sql"""select "id", "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text from pe.sp""".query(SpViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRow.scala new file mode 100644 index 0000000000..1f4ef6ee14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewRow.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SpViewRow( + /** Points to [[person.stateprovince.StateprovinceRow.stateprovinceid]] */ + id: StateprovinceId, + /** Points to [[person.stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Points to [[person.stateprovince.StateprovinceRow.stateprovincecode]] */ + stateprovincecode: /* bpchar, max 3 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Points to [[person.stateprovince.StateprovinceRow.isonlystateprovinceflag]] */ + isonlystateprovinceflag: Flag, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + name: Name, + /** Points to [[person.stateprovince.StateprovinceRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Points to [[person.stateprovince.StateprovinceRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.stateprovince.StateprovinceRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SpViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SpViewRow] = new JdbcDecoder[SpViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SpViewRow) = + columIndex + 8 -> + SpViewRow( + id = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + stateprovincecode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + isonlystateprovinceflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SpViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val stateprovincecode = jsonObj.get("stateprovincecode").toRight("Missing field 'stateprovincecode'").flatMap(_.as(JsonDecoder.string)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val isonlystateprovinceflag = jsonObj.get("isonlystateprovinceflag").toRight("Missing field 'isonlystateprovinceflag'").flatMap(_.as(Flag.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && stateprovinceid.isRight && stateprovincecode.isRight && countryregioncode.isRight && isonlystateprovinceflag.isRight && name.isRight && territoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpViewRow(id = id.toOption.get, stateprovinceid = stateprovinceid.toOption.get, stateprovincecode = stateprovincecode.toOption.get, countryregioncode = countryregioncode.toOption.get, isonlystateprovinceflag = isonlystateprovinceflag.toOption.get, name = name.toOption.get, territoryid = territoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, stateprovinceid, stateprovincecode, countryregioncode, isonlystateprovinceflag, name, territoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpViewRow] = new JsonEncoder[SpViewRow] { + override def unsafeEncode(a: SpViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""stateprovincecode":""") + JsonEncoder.string.unsafeEncode(a.stateprovincecode, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""isonlystateprovinceflag":""") + Flag.jsonEncoder.unsafeEncode(a.isonlystateprovinceflag, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewStructure.scala new file mode 100644 index 0000000000..453b934478 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pe/sp/SpViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pe +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SpViewStructure[Row](val prefix: Option[String], val extract: Row => SpViewRow, val merge: (Row, SpViewRow) => Row) + extends Relation[SpViewFields, SpViewRow, Row] + with SpViewFields[Row] { outer => + + override val id = new Field[StateprovinceId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, None)(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val stateprovincecode = new Field[/* bpchar, max 3 chars */ String, Row](prefix, "stateprovincecode", None, None)(x => extract(x).stateprovincecode, (row, value) => merge(row, extract(row).copy(stateprovincecode = value))) + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val isonlystateprovinceflag = new Field[Flag, Row](prefix, "isonlystateprovinceflag", None, None)(x => extract(x).isonlystateprovinceflag, (row, value) => merge(row, extract(row).copy(isonlystateprovinceflag = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val territoryid = new Field[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, stateprovinceid, stateprovincecode, countryregioncode, isonlystateprovinceflag, name, territoryid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SpViewRow, merge: (NewRow, SpViewRow) => NewRow): SpViewStructure[NewRow] = + new SpViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressFields.scala new file mode 100644 index 0000000000..b492204f15 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait AddressFields[Row] { + val addressid: IdField[AddressId, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovinceid: Field[StateprovinceId, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val spatiallocation: OptField[TypoBytea, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object AddressFields extends AddressStructure[AddressRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressId.scala new file mode 100644 index 0000000000..762e0c8736 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +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 `person.address` */ +case class AddressId(value: Int) extends AnyVal +object AddressId { + implicit lazy val arraySetter: Setter[Array[AddressId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[AddressId, Int] = Bijection[AddressId, Int](_.value)(AddressId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[AddressId] = JdbcDecoder.intDecoder.map(AddressId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[AddressId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[AddressId] = JsonDecoder.int.map(AddressId.apply) + implicit lazy val jsonEncoder: JsonEncoder[AddressId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[AddressId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[AddressId] = ParameterMetaData.instance[AddressId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[AddressId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepo.scala new file mode 100644 index 0000000000..5c595566f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AddressRepo { + def delete(addressid: AddressId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[AddressFields, AddressRow] + def insert(unsaved: AddressRow): ZIO[ZConnection, Throwable, AddressRow] + def insert(unsaved: AddressRowUnsaved): ZIO[ZConnection, Throwable, AddressRow] + def select: SelectBuilder[AddressFields, AddressRow] + def selectAll: ZStream[ZConnection, Throwable, AddressRow] + def selectById(addressid: AddressId): ZIO[ZConnection, Throwable, Option[AddressRow]] + def selectByIds(addressids: Array[AddressId]): ZStream[ZConnection, Throwable, AddressRow] + def update(row: AddressRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[AddressFields, AddressRow] + def upsert(unsaved: AddressRow): ZIO[ZConnection, Throwable, UpdateResult[AddressRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoImpl.scala new file mode 100644 index 0000000000..0f39494965 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoImpl.scala @@ -0,0 +1,128 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AddressRepoImpl extends AddressRepo { + override def delete(addressid: AddressId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.address where "addressid" = ${Segment.paramSegment(addressid)(AddressId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[AddressFields, AddressRow] = { + DeleteBuilder("person.address", AddressFields) + } + override def insert(unsaved: AddressRow): ZIO[ZConnection, Throwable, AddressRow] = { + sql"""insert into person.address("addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.addressid)(AddressId.setter)}::int4, ${Segment.paramSegment(unsaved.addressline1)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.addressline2)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.city)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, ${Segment.paramSegment(unsaved.postalcode)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.spatiallocation)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text + """.insertReturning(AddressRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: AddressRowUnsaved): ZIO[ZConnection, Throwable, AddressRow] = { + val fs = List( + Some((sql""""addressline1"""", sql"${Segment.paramSegment(unsaved.addressline1)(Setter.stringSetter)}")), + Some((sql""""addressline2"""", sql"${Segment.paramSegment(unsaved.addressline2)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""city"""", sql"${Segment.paramSegment(unsaved.city)(Setter.stringSetter)}")), + Some((sql""""stateprovinceid"""", sql"${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4")), + Some((sql""""postalcode"""", sql"${Segment.paramSegment(unsaved.postalcode)(Setter.stringSetter)}")), + Some((sql""""spatiallocation"""", sql"${Segment.paramSegment(unsaved.spatiallocation)(Setter.optionParamSetter(TypoBytea.setter))}::bytea")), + unsaved.addressid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""addressid"""", sql"${Segment.paramSegment(value: AddressId)(AddressId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.address default values + returning "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.address($names) values ($values) returning "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text""" + } + q.insertReturning(AddressRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[AddressFields, AddressRow] = { + SelectBuilderSql("person.address", AddressFields, AddressRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AddressRow] = { + sql"""select "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text from person.address""".query(AddressRow.jdbcDecoder).selectStream + } + override def selectById(addressid: AddressId): ZIO[ZConnection, Throwable, Option[AddressRow]] = { + sql"""select "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text from person.address where "addressid" = ${Segment.paramSegment(addressid)(AddressId.setter)}""".query(AddressRow.jdbcDecoder).selectOne + } + override def selectByIds(addressids: Array[AddressId]): ZStream[ZConnection, Throwable, AddressRow] = { + sql"""select "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text from person.address where "addressid" = ANY(${Segment.paramSegment(addressids)(AddressId.arraySetter)})""".query(AddressRow.jdbcDecoder).selectStream + } + override def update(row: AddressRow): ZIO[ZConnection, Throwable, Boolean] = { + val addressid = row.addressid + sql"""update person.address + set "addressline1" = ${Segment.paramSegment(row.addressline1)(Setter.stringSetter)}, + "addressline2" = ${Segment.paramSegment(row.addressline2)(Setter.optionParamSetter(Setter.stringSetter))}, + "city" = ${Segment.paramSegment(row.city)(Setter.stringSetter)}, + "stateprovinceid" = ${Segment.paramSegment(row.stateprovinceid)(StateprovinceId.setter)}::int4, + "postalcode" = ${Segment.paramSegment(row.postalcode)(Setter.stringSetter)}, + "spatiallocation" = ${Segment.paramSegment(row.spatiallocation)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "addressid" = ${Segment.paramSegment(addressid)(AddressId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[AddressFields, AddressRow] = { + UpdateBuilder("person.address", AddressFields, AddressRow.jdbcDecoder) + } + override def upsert(unsaved: AddressRow): ZIO[ZConnection, Throwable, UpdateResult[AddressRow]] = { + sql"""insert into person.address("addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.addressid)(AddressId.setter)}::int4, + ${Segment.paramSegment(unsaved.addressline1)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.addressline2)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.city)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, + ${Segment.paramSegment(unsaved.postalcode)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.spatiallocation)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("addressid") + do update set + "addressline1" = EXCLUDED."addressline1", + "addressline2" = EXCLUDED."addressline2", + "city" = EXCLUDED."city", + "stateprovinceid" = EXCLUDED."stateprovinceid", + "postalcode" = EXCLUDED."postalcode", + "spatiallocation" = EXCLUDED."spatiallocation", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "addressid", "addressline1", "addressline2", "city", "stateprovinceid", "postalcode", "spatiallocation", "rowguid", "modifieddate"::text""".insertReturning(AddressRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoMock.scala new file mode 100644 index 0000000000..f3bcc09dd0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class AddressRepoMock(toRow: Function1[AddressRowUnsaved, AddressRow], + map: scala.collection.mutable.Map[AddressId, AddressRow] = scala.collection.mutable.Map.empty) extends AddressRepo { + override def delete(addressid: AddressId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(addressid).isDefined) + } + override def delete: DeleteBuilder[AddressFields, AddressRow] = { + DeleteBuilderMock(DeleteParams.empty, AddressFields, map) + } + override def insert(unsaved: AddressRow): ZIO[ZConnection, Throwable, AddressRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.addressid)) + sys.error(s"id ${unsaved.addressid} already exists") + else + map.put(unsaved.addressid, unsaved) + + unsaved + } + } + override def insert(unsaved: AddressRowUnsaved): ZIO[ZConnection, Throwable, AddressRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[AddressFields, AddressRow] = { + SelectBuilderMock(AddressFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, AddressRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(addressid: AddressId): ZIO[ZConnection, Throwable, Option[AddressRow]] = { + ZIO.succeed(map.get(addressid)) + } + override def selectByIds(addressids: Array[AddressId]): ZStream[ZConnection, Throwable, AddressRow] = { + ZStream.fromIterable(addressids.flatMap(map.get)) + } + override def update(row: AddressRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.addressid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.addressid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[AddressFields, AddressRow] = { + UpdateBuilderMock(UpdateParams.empty, AddressFields, map) + } + override def upsert(unsaved: AddressRow): ZIO[ZConnection, Throwable, UpdateResult[AddressRow]] = { + ZIO.succeed { + map.put(unsaved.addressid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRow.scala new file mode 100644 index 0000000000..f7ae1b7ed0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRow.scala @@ -0,0 +1,103 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AddressRow( + /** Primary key for Address records. */ + addressid: AddressId, + /** First street address line. */ + addressline1: /* max 60 chars */ String, + /** Second street address line. */ + addressline2: Option[/* max 60 chars */ String], + /** Name of the city. */ + city: /* max 30 chars */ String, + /** Unique identification number for the state or province. Foreign key to StateProvince table. + Points to [[stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Postal code for the street address. */ + postalcode: /* max 15 chars */ String, + /** Latitude and longitude of this address. */ + spatiallocation: Option[TypoBytea], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object AddressRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AddressRow] = new JdbcDecoder[AddressRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AddressRow) = + columIndex + 8 -> + AddressRow( + addressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + spatiallocation = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AddressRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val spatiallocation = jsonObj.get("spatiallocation").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (addressid.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovinceid.isRight && postalcode.isRight && spatiallocation.isRight && rowguid.isRight && modifieddate.isRight) + Right(AddressRow(addressid = addressid.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovinceid = stateprovinceid.toOption.get, postalcode = postalcode.toOption.get, spatiallocation = spatiallocation.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](addressid, addressline1, addressline2, city, stateprovinceid, postalcode, spatiallocation, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AddressRow] = new JsonEncoder[AddressRow] { + override def unsafeEncode(a: AddressRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""spatiallocation":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.spatiallocation, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRowUnsaved.scala new file mode 100644 index 0000000000..b27891480f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressRowUnsaved.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.address` which has not been persisted yet */ +case class AddressRowUnsaved( + /** First street address line. */ + addressline1: /* max 60 chars */ String, + /** Second street address line. */ + addressline2: Option[/* max 60 chars */ String], + /** Name of the city. */ + city: /* max 30 chars */ String, + /** Unique identification number for the state or province. Foreign key to StateProvince table. + Points to [[stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Postal code for the street address. */ + postalcode: /* max 15 chars */ String, + /** Latitude and longitude of this address. */ + spatiallocation: Option[TypoBytea], + /** Default: nextval('person.address_addressid_seq'::regclass) + Primary key for Address records. */ + addressid: Defaulted[AddressId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(addressidDefault: => AddressId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): AddressRow = + AddressRow( + addressline1 = addressline1, + addressline2 = addressline2, + city = city, + stateprovinceid = stateprovinceid, + postalcode = postalcode, + spatiallocation = spatiallocation, + addressid = addressid match { + case Defaulted.UseDefault => addressidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object AddressRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[AddressRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val spatiallocation = jsonObj.get("spatiallocation").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(Defaulted.jsonDecoder(AddressId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (addressline1.isRight && addressline2.isRight && city.isRight && stateprovinceid.isRight && postalcode.isRight && spatiallocation.isRight && addressid.isRight && rowguid.isRight && modifieddate.isRight) + Right(AddressRowUnsaved(addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovinceid = stateprovinceid.toOption.get, postalcode = postalcode.toOption.get, spatiallocation = spatiallocation.toOption.get, addressid = addressid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](addressline1, addressline2, city, stateprovinceid, postalcode, spatiallocation, addressid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AddressRowUnsaved] = new JsonEncoder[AddressRowUnsaved] { + override def unsafeEncode(a: AddressRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""spatiallocation":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.spatiallocation, indent, out) + out.write(",") + out.write(""""addressid":""") + Defaulted.jsonEncoder(AddressId.jsonEncoder).unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressStructure.scala new file mode 100644 index 0000000000..58886fe980 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/address/AddressStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package address + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class AddressStructure[Row](val prefix: Option[String], val extract: Row => AddressRow, val merge: (Row, AddressRow) => Row) + extends Relation[AddressFields, AddressRow, Row] + with AddressFields[Row] { outer => + + override val addressid = new IdField[AddressId, Row](prefix, "addressid", None, Some("int4"))(x => extract(x).addressid, (row, value) => merge(row, extract(row).copy(addressid = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, Some("int4"))(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val spatiallocation = new OptField[TypoBytea, Row](prefix, "spatiallocation", None, Some("bytea"))(x => extract(x).spatiallocation, (row, value) => merge(row, extract(row).copy(spatiallocation = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](addressid, addressline1, addressline2, city, stateprovinceid, postalcode, spatiallocation, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AddressRow, merge: (NewRow, AddressRow) => NewRow): AddressStructure[NewRow] = + new AddressStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeFields.scala new file mode 100644 index 0000000000..3abd412d62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait AddresstypeFields[Row] { + val addresstypeid: IdField[AddresstypeId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object AddresstypeFields extends AddresstypeStructure[AddresstypeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeId.scala new file mode 100644 index 0000000000..db5f664eff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +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 `person.addresstype` */ +case class AddresstypeId(value: Int) extends AnyVal +object AddresstypeId { + implicit lazy val arraySetter: Setter[Array[AddresstypeId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[AddresstypeId, Int] = Bijection[AddresstypeId, Int](_.value)(AddresstypeId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[AddresstypeId] = JdbcDecoder.intDecoder.map(AddresstypeId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[AddresstypeId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[AddresstypeId] = JsonDecoder.int.map(AddresstypeId.apply) + implicit lazy val jsonEncoder: JsonEncoder[AddresstypeId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[AddresstypeId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[AddresstypeId] = ParameterMetaData.instance[AddresstypeId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[AddresstypeId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepo.scala new file mode 100644 index 0000000000..a3044b6003 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait AddresstypeRepo { + def delete(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[AddresstypeFields, AddresstypeRow] + def insert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, AddresstypeRow] + def insert(unsaved: AddresstypeRowUnsaved): ZIO[ZConnection, Throwable, AddresstypeRow] + def select: SelectBuilder[AddresstypeFields, AddresstypeRow] + def selectAll: ZStream[ZConnection, Throwable, AddresstypeRow] + def selectById(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Option[AddresstypeRow]] + def selectByIds(addresstypeids: Array[AddresstypeId]): ZStream[ZConnection, Throwable, AddresstypeRow] + def update(row: AddresstypeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[AddresstypeFields, AddresstypeRow] + def upsert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, UpdateResult[AddresstypeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoImpl.scala new file mode 100644 index 0000000000..fcf9e33c8c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoImpl.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object AddresstypeRepoImpl extends AddresstypeRepo { + override def delete(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.addresstype where "addresstypeid" = ${Segment.paramSegment(addresstypeid)(AddresstypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[AddresstypeFields, AddresstypeRow] = { + DeleteBuilder("person.addresstype", AddresstypeFields) + } + override def insert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, AddresstypeRow] = { + sql"""insert into person.addresstype("addresstypeid", "name", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.addresstypeid)(AddresstypeId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "addresstypeid", "name", "rowguid", "modifieddate"::text + """.insertReturning(AddresstypeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: AddresstypeRowUnsaved): ZIO[ZConnection, Throwable, AddresstypeRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.addresstypeid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""addresstypeid"""", sql"${Segment.paramSegment(value: AddresstypeId)(AddresstypeId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.addresstype default values + returning "addresstypeid", "name", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.addresstype($names) values ($values) returning "addresstypeid", "name", "rowguid", "modifieddate"::text""" + } + q.insertReturning(AddresstypeRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[AddresstypeFields, AddresstypeRow] = { + SelectBuilderSql("person.addresstype", AddresstypeFields, AddresstypeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, AddresstypeRow] = { + sql"""select "addresstypeid", "name", "rowguid", "modifieddate"::text from person.addresstype""".query(AddresstypeRow.jdbcDecoder).selectStream + } + override def selectById(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Option[AddresstypeRow]] = { + sql"""select "addresstypeid", "name", "rowguid", "modifieddate"::text from person.addresstype where "addresstypeid" = ${Segment.paramSegment(addresstypeid)(AddresstypeId.setter)}""".query(AddresstypeRow.jdbcDecoder).selectOne + } + override def selectByIds(addresstypeids: Array[AddresstypeId]): ZStream[ZConnection, Throwable, AddresstypeRow] = { + sql"""select "addresstypeid", "name", "rowguid", "modifieddate"::text from person.addresstype where "addresstypeid" = ANY(${Segment.paramSegment(addresstypeids)(AddresstypeId.arraySetter)})""".query(AddresstypeRow.jdbcDecoder).selectStream + } + override def update(row: AddresstypeRow): ZIO[ZConnection, Throwable, Boolean] = { + val addresstypeid = row.addresstypeid + sql"""update person.addresstype + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "addresstypeid" = ${Segment.paramSegment(addresstypeid)(AddresstypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[AddresstypeFields, AddresstypeRow] = { + UpdateBuilder("person.addresstype", AddresstypeFields, AddresstypeRow.jdbcDecoder) + } + override def upsert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, UpdateResult[AddresstypeRow]] = { + sql"""insert into person.addresstype("addresstypeid", "name", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.addresstypeid)(AddresstypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("addresstypeid") + do update set + "name" = EXCLUDED."name", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "addresstypeid", "name", "rowguid", "modifieddate"::text""".insertReturning(AddresstypeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoMock.scala new file mode 100644 index 0000000000..c19227af85 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class AddresstypeRepoMock(toRow: Function1[AddresstypeRowUnsaved, AddresstypeRow], + map: scala.collection.mutable.Map[AddresstypeId, AddresstypeRow] = scala.collection.mutable.Map.empty) extends AddresstypeRepo { + override def delete(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(addresstypeid).isDefined) + } + override def delete: DeleteBuilder[AddresstypeFields, AddresstypeRow] = { + DeleteBuilderMock(DeleteParams.empty, AddresstypeFields, map) + } + override def insert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, AddresstypeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.addresstypeid)) + sys.error(s"id ${unsaved.addresstypeid} already exists") + else + map.put(unsaved.addresstypeid, unsaved) + + unsaved + } + } + override def insert(unsaved: AddresstypeRowUnsaved): ZIO[ZConnection, Throwable, AddresstypeRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[AddresstypeFields, AddresstypeRow] = { + SelectBuilderMock(AddresstypeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, AddresstypeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(addresstypeid: AddresstypeId): ZIO[ZConnection, Throwable, Option[AddresstypeRow]] = { + ZIO.succeed(map.get(addresstypeid)) + } + override def selectByIds(addresstypeids: Array[AddresstypeId]): ZStream[ZConnection, Throwable, AddresstypeRow] = { + ZStream.fromIterable(addresstypeids.flatMap(map.get)) + } + override def update(row: AddresstypeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.addresstypeid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.addresstypeid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[AddresstypeFields, AddresstypeRow] = { + UpdateBuilderMock(UpdateParams.empty, AddresstypeFields, map) + } + override def upsert(unsaved: AddresstypeRow): ZIO[ZConnection, Throwable, UpdateResult[AddresstypeRow]] = { + ZIO.succeed { + map.put(unsaved.addresstypeid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRow.scala new file mode 100644 index 0000000000..d0371689ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRow.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class AddresstypeRow( + /** Primary key for AddressType records. */ + addresstypeid: AddresstypeId, + /** Address type description. For example, Billing, Home, or Shipping. */ + name: Name, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object AddresstypeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[AddresstypeRow] = new JdbcDecoder[AddresstypeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, AddresstypeRow) = + columIndex + 3 -> + AddresstypeRow( + addresstypeid = AddresstypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[AddresstypeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (addresstypeid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(AddresstypeRow(addresstypeid = addresstypeid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](addresstypeid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AddresstypeRow] = new JsonEncoder[AddresstypeRow] { + override def unsafeEncode(a: AddresstypeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRowUnsaved.scala new file mode 100644 index 0000000000..f171abbdab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeRowUnsaved.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.addresstype` which has not been persisted yet */ +case class AddresstypeRowUnsaved( + /** Address type description. For example, Billing, Home, or Shipping. */ + name: Name, + /** Default: nextval('person.addresstype_addresstypeid_seq'::regclass) + Primary key for AddressType records. */ + addresstypeid: Defaulted[AddresstypeId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(addresstypeidDefault: => AddresstypeId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): AddresstypeRow = + AddresstypeRow( + name = name, + addresstypeid = addresstypeid match { + case Defaulted.UseDefault => addresstypeidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object AddresstypeRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[AddresstypeRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(Defaulted.jsonDecoder(AddresstypeId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && addresstypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(AddresstypeRowUnsaved(name = name.toOption.get, addresstypeid = addresstypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, addresstypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[AddresstypeRowUnsaved] = new JsonEncoder[AddresstypeRowUnsaved] { + override def unsafeEncode(a: AddresstypeRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + Defaulted.jsonEncoder(AddresstypeId.jsonEncoder).unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeStructure.scala new file mode 100644 index 0000000000..26194371da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/addresstype/AddresstypeStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package addresstype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class AddresstypeStructure[Row](val prefix: Option[String], val extract: Row => AddresstypeRow, val merge: (Row, AddresstypeRow) => Row) + extends Relation[AddresstypeFields, AddresstypeRow, Row] + with AddresstypeFields[Row] { outer => + + override val addresstypeid = new IdField[AddresstypeId, Row](prefix, "addresstypeid", None, Some("int4"))(x => extract(x).addresstypeid, (row, value) => merge(row, extract(row).copy(addresstypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](addresstypeid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => AddresstypeRow, merge: (NewRow, AddresstypeRow) => NewRow): AddresstypeStructure[NewRow] = + new AddresstypeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityFields.scala new file mode 100644 index 0000000000..fd3999d9a5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait BusinessentityFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BusinessentityFields extends BusinessentityStructure[BusinessentityRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityId.scala new file mode 100644 index 0000000000..528e080e6a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +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 `person.businessentity` */ +case class BusinessentityId(value: Int) extends AnyVal +object BusinessentityId { + implicit lazy val arraySetter: Setter[Array[BusinessentityId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[BusinessentityId, Int] = Bijection[BusinessentityId, Int](_.value)(BusinessentityId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[BusinessentityId] = JdbcDecoder.intDecoder.map(BusinessentityId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[BusinessentityId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityId] = JsonDecoder.int.map(BusinessentityId.apply) + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[BusinessentityId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[BusinessentityId] = ParameterMetaData.instance[BusinessentityId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[BusinessentityId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepo.scala new file mode 100644 index 0000000000..cc9df3e3d9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BusinessentityRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[BusinessentityFields, BusinessentityRow] + def insert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, BusinessentityRow] + def insert(unsaved: BusinessentityRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityRow] + def select: SelectBuilder[BusinessentityFields, BusinessentityRow] + def selectAll: ZStream[ZConnection, Throwable, BusinessentityRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[BusinessentityRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, BusinessentityRow] + def update(row: BusinessentityRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[BusinessentityFields, BusinessentityRow] + def upsert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoImpl.scala new file mode 100644 index 0000000000..606bc0d3cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoImpl.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BusinessentityRepoImpl extends BusinessentityRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.businessentity where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[BusinessentityFields, BusinessentityRow] = { + DeleteBuilder("person.businessentity", BusinessentityFields) + } + override def insert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, BusinessentityRow] = { + sql"""insert into person.businessentity("businessentityid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "rowguid", "modifieddate"::text + """.insertReturning(BusinessentityRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: BusinessentityRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityRow] = { + val fs = List( + unsaved.businessentityid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""businessentityid"""", sql"${Segment.paramSegment(value: BusinessentityId)(BusinessentityId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.businessentity default values + returning "businessentityid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.businessentity($names) values ($values) returning "businessentityid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(BusinessentityRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[BusinessentityFields, BusinessentityRow] = { + SelectBuilderSql("person.businessentity", BusinessentityFields, BusinessentityRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentityRow] = { + sql"""select "businessentityid", "rowguid", "modifieddate"::text from person.businessentity""".query(BusinessentityRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[BusinessentityRow]] = { + sql"""select "businessentityid", "rowguid", "modifieddate"::text from person.businessentity where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(BusinessentityRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, BusinessentityRow] = { + sql"""select "businessentityid", "rowguid", "modifieddate"::text from person.businessentity where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(BusinessentityRow.jdbcDecoder).selectStream + } + override def update(row: BusinessentityRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update person.businessentity + set "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[BusinessentityFields, BusinessentityRow] = { + UpdateBuilder("person.businessentity", BusinessentityFields, BusinessentityRow.jdbcDecoder) + } + override def upsert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityRow]] = { + sql"""insert into person.businessentity("businessentityid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "rowguid", "modifieddate"::text""".insertReturning(BusinessentityRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoMock.scala new file mode 100644 index 0000000000..40abd526b7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class BusinessentityRepoMock(toRow: Function1[BusinessentityRowUnsaved, BusinessentityRow], + map: scala.collection.mutable.Map[BusinessentityId, BusinessentityRow] = scala.collection.mutable.Map.empty) extends BusinessentityRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[BusinessentityFields, BusinessentityRow] = { + DeleteBuilderMock(DeleteParams.empty, BusinessentityFields, map) + } + override def insert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, BusinessentityRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: BusinessentityRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[BusinessentityFields, BusinessentityRow] = { + SelectBuilderMock(BusinessentityFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentityRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[BusinessentityRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, BusinessentityRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: BusinessentityRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[BusinessentityFields, BusinessentityRow] = { + UpdateBuilderMock(UpdateParams.empty, BusinessentityFields, map) + } + override def upsert(unsaved: BusinessentityRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRow.scala new file mode 100644 index 0000000000..1f9137d980 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BusinessentityRow( + /** Primary key for all customers, vendors, and employees. */ + businessentityid: BusinessentityId, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object BusinessentityRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BusinessentityRow] = new JdbcDecoder[BusinessentityRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BusinessentityRow) = + columIndex + 2 -> + BusinessentityRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentityRow(businessentityid = businessentityid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityRow] = new JsonEncoder[BusinessentityRow] { + override def unsafeEncode(a: BusinessentityRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRowUnsaved.scala new file mode 100644 index 0000000000..796aee9aee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityRowUnsaved.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.businessentity` which has not been persisted yet */ +case class BusinessentityRowUnsaved( + /** Default: nextval('person.businessentity_businessentityid_seq'::regclass) + Primary key for all customers, vendors, and employees. */ + businessentityid: Defaulted[BusinessentityId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(businessentityidDefault: => BusinessentityId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): BusinessentityRow = + BusinessentityRow( + businessentityid = businessentityid match { + case Defaulted.UseDefault => businessentityidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object BusinessentityRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(Defaulted.jsonDecoder(BusinessentityId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentityRowUnsaved(businessentityid = businessentityid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityRowUnsaved] = new JsonEncoder[BusinessentityRowUnsaved] { + override def unsafeEncode(a: BusinessentityRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + Defaulted.jsonEncoder(BusinessentityId.jsonEncoder).unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityStructure.scala new file mode 100644 index 0000000000..d99792e42a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentity/BusinessentityStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentity + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class BusinessentityStructure[Row](val prefix: Option[String], val extract: Row => BusinessentityRow, val merge: (Row, BusinessentityRow) => Row) + extends Relation[BusinessentityFields, BusinessentityRow, Row] + with BusinessentityFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BusinessentityRow, merge: (NewRow, BusinessentityRow) => NewRow): BusinessentityStructure[NewRow] = + new BusinessentityStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressFields.scala new file mode 100644 index 0000000000..69b5da117f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait BusinessentityaddressFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val addressid: IdField[AddressId, Row] + val addresstypeid: IdField[AddresstypeId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BusinessentityaddressFields extends BusinessentityaddressStructure[BusinessentityaddressRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressId.scala new file mode 100644 index 0000000000..8f24f1ae29 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressId.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `person.businessentityaddress` */ +case class BusinessentityaddressId(businessentityid: BusinessentityId, addressid: AddressId, addresstypeid: AddresstypeId) +object BusinessentityaddressId { + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityaddressId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + if (businessentityid.isRight && addressid.isRight && addresstypeid.isRight) + Right(BusinessentityaddressId(businessentityid = businessentityid.toOption.get, addressid = addressid.toOption.get, addresstypeid = addresstypeid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, addressid, addresstypeid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityaddressId] = new JsonEncoder[BusinessentityaddressId] { + override def unsafeEncode(a: BusinessentityaddressId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[BusinessentityaddressId] = Ordering.by(x => (x.businessentityid, x.addressid, x.addresstypeid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepo.scala new file mode 100644 index 0000000000..f926f464e4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BusinessentityaddressRepo { + def delete(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[BusinessentityaddressFields, BusinessentityaddressRow] + def insert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, BusinessentityaddressRow] + def insert(unsaved: BusinessentityaddressRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityaddressRow] + def select: SelectBuilder[BusinessentityaddressFields, BusinessentityaddressRow] + def selectAll: ZStream[ZConnection, Throwable, BusinessentityaddressRow] + def selectById(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Option[BusinessentityaddressRow]] + def update(row: BusinessentityaddressRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[BusinessentityaddressFields, BusinessentityaddressRow] + def upsert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityaddressRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoImpl.scala new file mode 100644 index 0000000000..f99b5f41e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoImpl.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BusinessentityaddressRepoImpl extends BusinessentityaddressRepo { + override def delete(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.businessentityaddress where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "addressid" = ${Segment.paramSegment(compositeId.addressid)(AddressId.setter)} AND "addresstypeid" = ${Segment.paramSegment(compositeId.addresstypeid)(AddresstypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + DeleteBuilder("person.businessentityaddress", BusinessentityaddressFields) + } + override def insert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, BusinessentityaddressRow] = { + sql"""insert into person.businessentityaddress("businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.addressid)(AddressId.setter)}::int4, ${Segment.paramSegment(unsaved.addresstypeid)(AddresstypeId.setter)}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text + """.insertReturning(BusinessentityaddressRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: BusinessentityaddressRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityaddressRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""addressid"""", sql"${Segment.paramSegment(unsaved.addressid)(AddressId.setter)}::int4")), + Some((sql""""addresstypeid"""", sql"${Segment.paramSegment(unsaved.addresstypeid)(AddresstypeId.setter)}::int4")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.businessentityaddress default values + returning "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.businessentityaddress($names) values ($values) returning "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(BusinessentityaddressRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + SelectBuilderSql("person.businessentityaddress", BusinessentityaddressFields, BusinessentityaddressRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentityaddressRow] = { + sql"""select "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text from person.businessentityaddress""".query(BusinessentityaddressRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Option[BusinessentityaddressRow]] = { + sql"""select "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text from person.businessentityaddress where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "addressid" = ${Segment.paramSegment(compositeId.addressid)(AddressId.setter)} AND "addresstypeid" = ${Segment.paramSegment(compositeId.addresstypeid)(AddresstypeId.setter)}""".query(BusinessentityaddressRow.jdbcDecoder).selectOne + } + override def update(row: BusinessentityaddressRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update person.businessentityaddress + set "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "addressid" = ${Segment.paramSegment(compositeId.addressid)(AddressId.setter)} AND "addresstypeid" = ${Segment.paramSegment(compositeId.addresstypeid)(AddresstypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + UpdateBuilder("person.businessentityaddress", BusinessentityaddressFields, BusinessentityaddressRow.jdbcDecoder) + } + override def upsert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityaddressRow]] = { + sql"""insert into person.businessentityaddress("businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.addressid)(AddressId.setter)}::int4, + ${Segment.paramSegment(unsaved.addresstypeid)(AddresstypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "addressid", "addresstypeid") + do update set + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "addressid", "addresstypeid", "rowguid", "modifieddate"::text""".insertReturning(BusinessentityaddressRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoMock.scala new file mode 100644 index 0000000000..d2c8a00ddc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class BusinessentityaddressRepoMock(toRow: Function1[BusinessentityaddressRowUnsaved, BusinessentityaddressRow], + map: scala.collection.mutable.Map[BusinessentityaddressId, BusinessentityaddressRow] = scala.collection.mutable.Map.empty) extends BusinessentityaddressRepo { + override def delete(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + DeleteBuilderMock(DeleteParams.empty, BusinessentityaddressFields, map) + } + override def insert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, BusinessentityaddressRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: BusinessentityaddressRowUnsaved): ZIO[ZConnection, Throwable, BusinessentityaddressRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + SelectBuilderMock(BusinessentityaddressFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentityaddressRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: BusinessentityaddressId): ZIO[ZConnection, Throwable, Option[BusinessentityaddressRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: BusinessentityaddressRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[BusinessentityaddressFields, BusinessentityaddressRow] = { + UpdateBuilderMock(UpdateParams.empty, BusinessentityaddressFields, map) + } + override def upsert(unsaved: BusinessentityaddressRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentityaddressRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRow.scala new file mode 100644 index 0000000000..afa58abc58 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BusinessentityaddressRow( + /** Primary key. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Foreign key to Address.AddressID. + Points to [[address.AddressRow.addressid]] */ + addressid: AddressId, + /** Primary key. Foreign key to AddressType.AddressTypeID. + Points to [[addresstype.AddresstypeRow.addresstypeid]] */ + addresstypeid: AddresstypeId, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: BusinessentityaddressId = BusinessentityaddressId(businessentityid, addressid, addresstypeid) + } + +object BusinessentityaddressRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BusinessentityaddressRow] = new JdbcDecoder[BusinessentityaddressRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BusinessentityaddressRow) = + columIndex + 4 -> + BusinessentityaddressRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + addressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + addresstypeid = AddresstypeId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityaddressRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && addressid.isRight && addresstypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentityaddressRow(businessentityid = businessentityid.toOption.get, addressid = addressid.toOption.get, addresstypeid = addresstypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, addressid, addresstypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityaddressRow] = new JsonEncoder[BusinessentityaddressRow] { + override def unsafeEncode(a: BusinessentityaddressRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRowUnsaved.scala new file mode 100644 index 0000000000..34ca63d346 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressRowUnsaved.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.businessentityaddress` which has not been persisted yet */ +case class BusinessentityaddressRowUnsaved( + /** Primary key. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Foreign key to Address.AddressID. + Points to [[address.AddressRow.addressid]] */ + addressid: AddressId, + /** Primary key. Foreign key to AddressType.AddressTypeID. + Points to [[addresstype.AddresstypeRow.addresstypeid]] */ + addresstypeid: AddresstypeId, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): BusinessentityaddressRow = + BusinessentityaddressRow( + businessentityid = businessentityid, + addressid = addressid, + addresstypeid = addresstypeid, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object BusinessentityaddressRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[BusinessentityaddressRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val addressid = jsonObj.get("addressid").toRight("Missing field 'addressid'").flatMap(_.as(AddressId.jsonDecoder)) + val addresstypeid = jsonObj.get("addresstypeid").toRight("Missing field 'addresstypeid'").flatMap(_.as(AddresstypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && addressid.isRight && addresstypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentityaddressRowUnsaved(businessentityid = businessentityid.toOption.get, addressid = addressid.toOption.get, addresstypeid = addresstypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, addressid, addresstypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentityaddressRowUnsaved] = new JsonEncoder[BusinessentityaddressRowUnsaved] { + override def unsafeEncode(a: BusinessentityaddressRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""addressid":""") + AddressId.jsonEncoder.unsafeEncode(a.addressid, indent, out) + out.write(",") + out.write(""""addresstypeid":""") + AddresstypeId.jsonEncoder.unsafeEncode(a.addresstypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressStructure.scala new file mode 100644 index 0000000000..0b37a0b189 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentityaddress/BusinessentityaddressStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentityaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class BusinessentityaddressStructure[Row](val prefix: Option[String], val extract: Row => BusinessentityaddressRow, val merge: (Row, BusinessentityaddressRow) => Row) + extends Relation[BusinessentityaddressFields, BusinessentityaddressRow, Row] + with BusinessentityaddressFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val addressid = new IdField[AddressId, Row](prefix, "addressid", None, Some("int4"))(x => extract(x).addressid, (row, value) => merge(row, extract(row).copy(addressid = value))) + override val addresstypeid = new IdField[AddresstypeId, Row](prefix, "addresstypeid", None, Some("int4"))(x => extract(x).addresstypeid, (row, value) => merge(row, extract(row).copy(addresstypeid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, addressid, addresstypeid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BusinessentityaddressRow, merge: (NewRow, BusinessentityaddressRow) => NewRow): BusinessentityaddressStructure[NewRow] = + new BusinessentityaddressStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactFields.scala new file mode 100644 index 0000000000..883fa124b2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait BusinessentitycontactFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val personid: IdField[BusinessentityId, Row] + val contacttypeid: IdField[ContacttypeId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BusinessentitycontactFields extends BusinessentitycontactStructure[BusinessentitycontactRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactId.scala new file mode 100644 index 0000000000..a84fcc5a76 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactId.scala @@ -0,0 +1,43 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `person.businessentitycontact` */ +case class BusinessentitycontactId(businessentityid: BusinessentityId, personid: BusinessentityId, contacttypeid: ContacttypeId) +object BusinessentitycontactId { + implicit lazy val jsonDecoder: JsonDecoder[BusinessentitycontactId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val personid = jsonObj.get("personid").toRight("Missing field 'personid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + if (businessentityid.isRight && personid.isRight && contacttypeid.isRight) + Right(BusinessentitycontactId(businessentityid = businessentityid.toOption.get, personid = personid.toOption.get, contacttypeid = contacttypeid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, personid, contacttypeid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentitycontactId] = new JsonEncoder[BusinessentitycontactId] { + override def unsafeEncode(a: BusinessentitycontactId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""personid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[BusinessentitycontactId] = Ordering.by(x => (x.businessentityid, x.personid, x.contacttypeid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepo.scala new file mode 100644 index 0000000000..ae6bf63fcd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BusinessentitycontactRepo { + def delete(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[BusinessentitycontactFields, BusinessentitycontactRow] + def insert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, BusinessentitycontactRow] + def insert(unsaved: BusinessentitycontactRowUnsaved): ZIO[ZConnection, Throwable, BusinessentitycontactRow] + def select: SelectBuilder[BusinessentitycontactFields, BusinessentitycontactRow] + def selectAll: ZStream[ZConnection, Throwable, BusinessentitycontactRow] + def selectById(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Option[BusinessentitycontactRow]] + def update(row: BusinessentitycontactRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[BusinessentitycontactFields, BusinessentitycontactRow] + def upsert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentitycontactRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoImpl.scala new file mode 100644 index 0000000000..b27dda085a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoImpl.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BusinessentitycontactRepoImpl extends BusinessentitycontactRepo { + override def delete(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.businessentitycontact where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "personid" = ${Segment.paramSegment(compositeId.personid)(BusinessentityId.setter)} AND "contacttypeid" = ${Segment.paramSegment(compositeId.contacttypeid)(ContacttypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + DeleteBuilder("person.businessentitycontact", BusinessentitycontactFields) + } + override def insert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, BusinessentitycontactRow] = { + sql"""insert into person.businessentitycontact("businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.personid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.contacttypeid)(ContacttypeId.setter)}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text + """.insertReturning(BusinessentitycontactRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: BusinessentitycontactRowUnsaved): ZIO[ZConnection, Throwable, BusinessentitycontactRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""personid"""", sql"${Segment.paramSegment(unsaved.personid)(BusinessentityId.setter)}::int4")), + Some((sql""""contacttypeid"""", sql"${Segment.paramSegment(unsaved.contacttypeid)(ContacttypeId.setter)}::int4")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.businessentitycontact default values + returning "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.businessentitycontact($names) values ($values) returning "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(BusinessentitycontactRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + SelectBuilderSql("person.businessentitycontact", BusinessentitycontactFields, BusinessentitycontactRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentitycontactRow] = { + sql"""select "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text from person.businessentitycontact""".query(BusinessentitycontactRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Option[BusinessentitycontactRow]] = { + sql"""select "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text from person.businessentitycontact where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "personid" = ${Segment.paramSegment(compositeId.personid)(BusinessentityId.setter)} AND "contacttypeid" = ${Segment.paramSegment(compositeId.contacttypeid)(ContacttypeId.setter)}""".query(BusinessentitycontactRow.jdbcDecoder).selectOne + } + override def update(row: BusinessentitycontactRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update person.businessentitycontact + set "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "personid" = ${Segment.paramSegment(compositeId.personid)(BusinessentityId.setter)} AND "contacttypeid" = ${Segment.paramSegment(compositeId.contacttypeid)(ContacttypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + UpdateBuilder("person.businessentitycontact", BusinessentitycontactFields, BusinessentitycontactRow.jdbcDecoder) + } + override def upsert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentitycontactRow]] = { + sql"""insert into person.businessentitycontact("businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.personid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.contacttypeid)(ContacttypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "personid", "contacttypeid") + do update set + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "personid", "contacttypeid", "rowguid", "modifieddate"::text""".insertReturning(BusinessentitycontactRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoMock.scala new file mode 100644 index 0000000000..ca05e554af --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class BusinessentitycontactRepoMock(toRow: Function1[BusinessentitycontactRowUnsaved, BusinessentitycontactRow], + map: scala.collection.mutable.Map[BusinessentitycontactId, BusinessentitycontactRow] = scala.collection.mutable.Map.empty) extends BusinessentitycontactRepo { + override def delete(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + DeleteBuilderMock(DeleteParams.empty, BusinessentitycontactFields, map) + } + override def insert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, BusinessentitycontactRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: BusinessentitycontactRowUnsaved): ZIO[ZConnection, Throwable, BusinessentitycontactRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + SelectBuilderMock(BusinessentitycontactFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, BusinessentitycontactRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: BusinessentitycontactId): ZIO[ZConnection, Throwable, Option[BusinessentitycontactRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: BusinessentitycontactRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[BusinessentitycontactFields, BusinessentitycontactRow] = { + UpdateBuilderMock(UpdateParams.empty, BusinessentitycontactFields, map) + } + override def upsert(unsaved: BusinessentitycontactRow): ZIO[ZConnection, Throwable, UpdateResult[BusinessentitycontactRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRow.scala new file mode 100644 index 0000000000..925406267e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BusinessentitycontactRow( + /** Primary key. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Foreign key to Person.BusinessEntityID. + Points to [[person.PersonRow.businessentityid]] */ + personid: BusinessentityId, + /** Primary key. Foreign key to ContactType.ContactTypeID. + Points to [[contacttype.ContacttypeRow.contacttypeid]] */ + contacttypeid: ContacttypeId, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: BusinessentitycontactId = BusinessentitycontactId(businessentityid, personid, contacttypeid) + } + +object BusinessentitycontactRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BusinessentitycontactRow] = new JdbcDecoder[BusinessentitycontactRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BusinessentitycontactRow) = + columIndex + 4 -> + BusinessentitycontactRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + personid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + contacttypeid = ContacttypeId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[BusinessentitycontactRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val personid = jsonObj.get("personid").toRight("Missing field 'personid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && personid.isRight && contacttypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentitycontactRow(businessentityid = businessentityid.toOption.get, personid = personid.toOption.get, contacttypeid = contacttypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, personid, contacttypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentitycontactRow] = new JsonEncoder[BusinessentitycontactRow] { + override def unsafeEncode(a: BusinessentitycontactRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""personid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRowUnsaved.scala new file mode 100644 index 0000000000..3ee5d807b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactRowUnsaved.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.businessentitycontact` which has not been persisted yet */ +case class BusinessentitycontactRowUnsaved( + /** Primary key. Foreign key to BusinessEntity.BusinessEntityID. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Foreign key to Person.BusinessEntityID. + Points to [[person.PersonRow.businessentityid]] */ + personid: BusinessentityId, + /** Primary key. Foreign key to ContactType.ContactTypeID. + Points to [[contacttype.ContacttypeRow.contacttypeid]] */ + contacttypeid: ContacttypeId, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): BusinessentitycontactRow = + BusinessentitycontactRow( + businessentityid = businessentityid, + personid = personid, + contacttypeid = contacttypeid, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object BusinessentitycontactRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[BusinessentitycontactRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val personid = jsonObj.get("personid").toRight("Missing field 'personid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && personid.isRight && contacttypeid.isRight && rowguid.isRight && modifieddate.isRight) + Right(BusinessentitycontactRowUnsaved(businessentityid = businessentityid.toOption.get, personid = personid.toOption.get, contacttypeid = contacttypeid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, personid, contacttypeid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BusinessentitycontactRowUnsaved] = new JsonEncoder[BusinessentitycontactRowUnsaved] { + override def unsafeEncode(a: BusinessentitycontactRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""personid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactStructure.scala new file mode 100644 index 0000000000..bd08013e4b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/businessentitycontact/BusinessentitycontactStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package businessentitycontact + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.contacttype.ContacttypeId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class BusinessentitycontactStructure[Row](val prefix: Option[String], val extract: Row => BusinessentitycontactRow, val merge: (Row, BusinessentitycontactRow) => Row) + extends Relation[BusinessentitycontactFields, BusinessentitycontactRow, Row] + with BusinessentitycontactFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val personid = new IdField[BusinessentityId, Row](prefix, "personid", None, Some("int4"))(x => extract(x).personid, (row, value) => merge(row, extract(row).copy(personid = value))) + override val contacttypeid = new IdField[ContacttypeId, Row](prefix, "contacttypeid", None, Some("int4"))(x => extract(x).contacttypeid, (row, value) => merge(row, extract(row).copy(contacttypeid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, personid, contacttypeid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BusinessentitycontactRow, merge: (NewRow, BusinessentitycontactRow) => NewRow): BusinessentitycontactStructure[NewRow] = + new BusinessentitycontactStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeFields.scala new file mode 100644 index 0000000000..13178f020f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ContacttypeFields[Row] { + val contacttypeid: IdField[ContacttypeId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ContacttypeFields extends ContacttypeStructure[ContacttypeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeId.scala new file mode 100644 index 0000000000..bf159142b2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +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 `person.contacttype` */ +case class ContacttypeId(value: Int) extends AnyVal +object ContacttypeId { + implicit lazy val arraySetter: Setter[Array[ContacttypeId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ContacttypeId, Int] = Bijection[ContacttypeId, Int](_.value)(ContacttypeId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ContacttypeId] = JdbcDecoder.intDecoder.map(ContacttypeId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ContacttypeId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ContacttypeId] = JsonDecoder.int.map(ContacttypeId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ContacttypeId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ContacttypeId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ContacttypeId] = ParameterMetaData.instance[ContacttypeId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ContacttypeId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepo.scala new file mode 100644 index 0000000000..ffd53c5b27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ContacttypeRepo { + def delete(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ContacttypeFields, ContacttypeRow] + def insert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, ContacttypeRow] + def insert(unsaved: ContacttypeRowUnsaved): ZIO[ZConnection, Throwable, ContacttypeRow] + def select: SelectBuilder[ContacttypeFields, ContacttypeRow] + def selectAll: ZStream[ZConnection, Throwable, ContacttypeRow] + def selectById(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Option[ContacttypeRow]] + def selectByIds(contacttypeids: Array[ContacttypeId]): ZStream[ZConnection, Throwable, ContacttypeRow] + def update(row: ContacttypeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ContacttypeFields, ContacttypeRow] + def upsert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, UpdateResult[ContacttypeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoImpl.scala new file mode 100644 index 0000000000..8a2879899b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoImpl.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ContacttypeRepoImpl extends ContacttypeRepo { + override def delete(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.contacttype where "contacttypeid" = ${Segment.paramSegment(contacttypeid)(ContacttypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ContacttypeFields, ContacttypeRow] = { + DeleteBuilder("person.contacttype", ContacttypeFields) + } + override def insert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, ContacttypeRow] = { + sql"""insert into person.contacttype("contacttypeid", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.contacttypeid)(ContacttypeId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "contacttypeid", "name", "modifieddate"::text + """.insertReturning(ContacttypeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ContacttypeRowUnsaved): ZIO[ZConnection, Throwable, ContacttypeRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.contacttypeid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""contacttypeid"""", sql"${Segment.paramSegment(value: ContacttypeId)(ContacttypeId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.contacttype default values + returning "contacttypeid", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.contacttype($names) values ($values) returning "contacttypeid", "name", "modifieddate"::text""" + } + q.insertReturning(ContacttypeRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ContacttypeFields, ContacttypeRow] = { + SelectBuilderSql("person.contacttype", ContacttypeFields, ContacttypeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ContacttypeRow] = { + sql"""select "contacttypeid", "name", "modifieddate"::text from person.contacttype""".query(ContacttypeRow.jdbcDecoder).selectStream + } + override def selectById(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Option[ContacttypeRow]] = { + sql"""select "contacttypeid", "name", "modifieddate"::text from person.contacttype where "contacttypeid" = ${Segment.paramSegment(contacttypeid)(ContacttypeId.setter)}""".query(ContacttypeRow.jdbcDecoder).selectOne + } + override def selectByIds(contacttypeids: Array[ContacttypeId]): ZStream[ZConnection, Throwable, ContacttypeRow] = { + sql"""select "contacttypeid", "name", "modifieddate"::text from person.contacttype where "contacttypeid" = ANY(${Segment.paramSegment(contacttypeids)(ContacttypeId.arraySetter)})""".query(ContacttypeRow.jdbcDecoder).selectStream + } + override def update(row: ContacttypeRow): ZIO[ZConnection, Throwable, Boolean] = { + val contacttypeid = row.contacttypeid + sql"""update person.contacttype + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "contacttypeid" = ${Segment.paramSegment(contacttypeid)(ContacttypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ContacttypeFields, ContacttypeRow] = { + UpdateBuilder("person.contacttype", ContacttypeFields, ContacttypeRow.jdbcDecoder) + } + override def upsert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, UpdateResult[ContacttypeRow]] = { + sql"""insert into person.contacttype("contacttypeid", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.contacttypeid)(ContacttypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("contacttypeid") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "contacttypeid", "name", "modifieddate"::text""".insertReturning(ContacttypeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoMock.scala new file mode 100644 index 0000000000..23e8e8d727 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ContacttypeRepoMock(toRow: Function1[ContacttypeRowUnsaved, ContacttypeRow], + map: scala.collection.mutable.Map[ContacttypeId, ContacttypeRow] = scala.collection.mutable.Map.empty) extends ContacttypeRepo { + override def delete(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(contacttypeid).isDefined) + } + override def delete: DeleteBuilder[ContacttypeFields, ContacttypeRow] = { + DeleteBuilderMock(DeleteParams.empty, ContacttypeFields, map) + } + override def insert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, ContacttypeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.contacttypeid)) + sys.error(s"id ${unsaved.contacttypeid} already exists") + else + map.put(unsaved.contacttypeid, unsaved) + + unsaved + } + } + override def insert(unsaved: ContacttypeRowUnsaved): ZIO[ZConnection, Throwable, ContacttypeRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ContacttypeFields, ContacttypeRow] = { + SelectBuilderMock(ContacttypeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ContacttypeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(contacttypeid: ContacttypeId): ZIO[ZConnection, Throwable, Option[ContacttypeRow]] = { + ZIO.succeed(map.get(contacttypeid)) + } + override def selectByIds(contacttypeids: Array[ContacttypeId]): ZStream[ZConnection, Throwable, ContacttypeRow] = { + ZStream.fromIterable(contacttypeids.flatMap(map.get)) + } + override def update(row: ContacttypeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.contacttypeid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.contacttypeid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ContacttypeFields, ContacttypeRow] = { + UpdateBuilderMock(UpdateParams.empty, ContacttypeFields, map) + } + override def upsert(unsaved: ContacttypeRow): ZIO[ZConnection, Throwable, UpdateResult[ContacttypeRow]] = { + ZIO.succeed { + map.put(unsaved.contacttypeid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRow.scala new file mode 100644 index 0000000000..922abfe3b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ContacttypeRow( + /** Primary key for ContactType records. */ + contacttypeid: ContacttypeId, + /** Contact type description. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object ContacttypeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ContacttypeRow] = new JdbcDecoder[ContacttypeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ContacttypeRow) = + columIndex + 2 -> + ContacttypeRow( + contacttypeid = ContacttypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ContacttypeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(ContacttypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (contacttypeid.isRight && name.isRight && modifieddate.isRight) + Right(ContacttypeRow(contacttypeid = contacttypeid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](contacttypeid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ContacttypeRow] = new JsonEncoder[ContacttypeRow] { + override def unsafeEncode(a: ContacttypeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""contacttypeid":""") + ContacttypeId.jsonEncoder.unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRowUnsaved.scala new file mode 100644 index 0000000000..6fa8da1272 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeRowUnsaved.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.contacttype` which has not been persisted yet */ +case class ContacttypeRowUnsaved( + /** Contact type description. */ + name: Name, + /** Default: nextval('person.contacttype_contacttypeid_seq'::regclass) + Primary key for ContactType records. */ + contacttypeid: Defaulted[ContacttypeId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(contacttypeidDefault: => ContacttypeId, modifieddateDefault: => TypoLocalDateTime): ContacttypeRow = + ContacttypeRow( + name = name, + contacttypeid = contacttypeid match { + case Defaulted.UseDefault => contacttypeidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ContacttypeRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ContacttypeRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val contacttypeid = jsonObj.get("contacttypeid").toRight("Missing field 'contacttypeid'").flatMap(_.as(Defaulted.jsonDecoder(ContacttypeId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && contacttypeid.isRight && modifieddate.isRight) + Right(ContacttypeRowUnsaved(name = name.toOption.get, contacttypeid = contacttypeid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, contacttypeid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ContacttypeRowUnsaved] = new JsonEncoder[ContacttypeRowUnsaved] { + override def unsafeEncode(a: ContacttypeRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""contacttypeid":""") + Defaulted.jsonEncoder(ContacttypeId.jsonEncoder).unsafeEncode(a.contacttypeid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeStructure.scala new file mode 100644 index 0000000000..ead8cf9935 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/contacttype/ContacttypeStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package contacttype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ContacttypeStructure[Row](val prefix: Option[String], val extract: Row => ContacttypeRow, val merge: (Row, ContacttypeRow) => Row) + extends Relation[ContacttypeFields, ContacttypeRow, Row] + with ContacttypeFields[Row] { outer => + + override val contacttypeid = new IdField[ContacttypeId, Row](prefix, "contacttypeid", None, Some("int4"))(x => extract(x).contacttypeid, (row, value) => merge(row, extract(row).copy(contacttypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](contacttypeid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ContacttypeRow, merge: (NewRow, ContacttypeRow) => NewRow): ContacttypeStructure[NewRow] = + new ContacttypeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionFields.scala new file mode 100644 index 0000000000..81df8b5160 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CountryregionFields[Row] { + val countryregioncode: IdField[CountryregionId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CountryregionFields extends CountryregionStructure[CountryregionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionId.scala new file mode 100644 index 0000000000..c26346125f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +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 `person.countryregion` */ +case class CountryregionId(value: /* max 3 chars */ String) extends AnyVal +object CountryregionId { + implicit lazy val arraySetter: Setter[Array[CountryregionId]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CountryregionId, /* max 3 chars */ String] = Bijection[CountryregionId, /* max 3 chars */ String](_.value)(CountryregionId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CountryregionId] = JdbcDecoder.stringDecoder.map(CountryregionId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CountryregionId] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CountryregionId] = JsonDecoder.string.map(CountryregionId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CountryregionId] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[CountryregionId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CountryregionId] = ParameterMetaData.instance[CountryregionId](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CountryregionId] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepo.scala new file mode 100644 index 0000000000..9108993421 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CountryregionRepo { + def delete(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CountryregionFields, CountryregionRow] + def insert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, CountryregionRow] + def insert(unsaved: CountryregionRowUnsaved): ZIO[ZConnection, Throwable, CountryregionRow] + def select: SelectBuilder[CountryregionFields, CountryregionRow] + def selectAll: ZStream[ZConnection, Throwable, CountryregionRow] + def selectById(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Option[CountryregionRow]] + def selectByIds(countryregioncodes: Array[CountryregionId]): ZStream[ZConnection, Throwable, CountryregionRow] + def update(row: CountryregionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CountryregionFields, CountryregionRow] + def upsert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoImpl.scala new file mode 100644 index 0000000000..4fd8c5d378 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoImpl.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CountryregionRepoImpl extends CountryregionRepo { + override def delete(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.countryregion where "countryregioncode" = ${Segment.paramSegment(countryregioncode)(CountryregionId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CountryregionFields, CountryregionRow] = { + DeleteBuilder("person.countryregion", CountryregionFields) + } + override def insert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, CountryregionRow] = { + sql"""insert into person.countryregion("countryregioncode", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "countryregioncode", "name", "modifieddate"::text + """.insertReturning(CountryregionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CountryregionRowUnsaved): ZIO[ZConnection, Throwable, CountryregionRow] = { + val fs = List( + Some((sql""""countryregioncode"""", sql"${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.countryregion default values + returning "countryregioncode", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.countryregion($names) values ($values) returning "countryregioncode", "name", "modifieddate"::text""" + } + q.insertReturning(CountryregionRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CountryregionFields, CountryregionRow] = { + SelectBuilderSql("person.countryregion", CountryregionFields, CountryregionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CountryregionRow] = { + sql"""select "countryregioncode", "name", "modifieddate"::text from person.countryregion""".query(CountryregionRow.jdbcDecoder).selectStream + } + override def selectById(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Option[CountryregionRow]] = { + sql"""select "countryregioncode", "name", "modifieddate"::text from person.countryregion where "countryregioncode" = ${Segment.paramSegment(countryregioncode)(CountryregionId.setter)}""".query(CountryregionRow.jdbcDecoder).selectOne + } + override def selectByIds(countryregioncodes: Array[CountryregionId]): ZStream[ZConnection, Throwable, CountryregionRow] = { + sql"""select "countryregioncode", "name", "modifieddate"::text from person.countryregion where "countryregioncode" = ANY(${Segment.paramSegment(countryregioncodes)(CountryregionId.arraySetter)})""".query(CountryregionRow.jdbcDecoder).selectStream + } + override def update(row: CountryregionRow): ZIO[ZConnection, Throwable, Boolean] = { + val countryregioncode = row.countryregioncode + sql"""update person.countryregion + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "countryregioncode" = ${Segment.paramSegment(countryregioncode)(CountryregionId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CountryregionFields, CountryregionRow] = { + UpdateBuilder("person.countryregion", CountryregionFields, CountryregionRow.jdbcDecoder) + } + override def upsert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregionRow]] = { + sql"""insert into person.countryregion("countryregioncode", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("countryregioncode") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "countryregioncode", "name", "modifieddate"::text""".insertReturning(CountryregionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoMock.scala new file mode 100644 index 0000000000..935f7abbd8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CountryregionRepoMock(toRow: Function1[CountryregionRowUnsaved, CountryregionRow], + map: scala.collection.mutable.Map[CountryregionId, CountryregionRow] = scala.collection.mutable.Map.empty) extends CountryregionRepo { + override def delete(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(countryregioncode).isDefined) + } + override def delete: DeleteBuilder[CountryregionFields, CountryregionRow] = { + DeleteBuilderMock(DeleteParams.empty, CountryregionFields, map) + } + override def insert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, CountryregionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.countryregioncode)) + sys.error(s"id ${unsaved.countryregioncode} already exists") + else + map.put(unsaved.countryregioncode, unsaved) + + unsaved + } + } + override def insert(unsaved: CountryregionRowUnsaved): ZIO[ZConnection, Throwable, CountryregionRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CountryregionFields, CountryregionRow] = { + SelectBuilderMock(CountryregionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CountryregionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(countryregioncode: CountryregionId): ZIO[ZConnection, Throwable, Option[CountryregionRow]] = { + ZIO.succeed(map.get(countryregioncode)) + } + override def selectByIds(countryregioncodes: Array[CountryregionId]): ZStream[ZConnection, Throwable, CountryregionRow] = { + ZStream.fromIterable(countryregioncodes.flatMap(map.get)) + } + override def update(row: CountryregionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.countryregioncode) match { + case Some(`row`) => false + case Some(_) => + map.put(row.countryregioncode, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CountryregionFields, CountryregionRow] = { + UpdateBuilderMock(UpdateParams.empty, CountryregionFields, map) + } + override def upsert(unsaved: CountryregionRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregionRow]] = { + ZIO.succeed { + map.put(unsaved.countryregioncode, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRow.scala new file mode 100644 index 0000000000..a7e4429656 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CountryregionRow( + /** ISO standard code for countries and regions. */ + countryregioncode: CountryregionId, + /** Country or region name. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object CountryregionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CountryregionRow] = new JdbcDecoder[CountryregionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CountryregionRow) = + columIndex + 2 -> + CountryregionRow( + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CountryregionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (countryregioncode.isRight && name.isRight && modifieddate.isRight) + Right(CountryregionRow(countryregioncode = countryregioncode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CountryregionRow] = new JsonEncoder[CountryregionRow] { + override def unsafeEncode(a: CountryregionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRowUnsaved.scala new file mode 100644 index 0000000000..68b1da4243 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionRowUnsaved.scala @@ -0,0 +1,60 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.countryregion` which has not been persisted yet */ +case class CountryregionRowUnsaved( + /** ISO standard code for countries and regions. */ + countryregioncode: CountryregionId, + /** Country or region name. */ + name: Name, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): CountryregionRow = + CountryregionRow( + countryregioncode = countryregioncode, + name = name, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CountryregionRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CountryregionRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (countryregioncode.isRight && name.isRight && modifieddate.isRight) + Right(CountryregionRowUnsaved(countryregioncode = countryregioncode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CountryregionRowUnsaved] = new JsonEncoder[CountryregionRowUnsaved] { + override def unsafeEncode(a: CountryregionRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionStructure.scala new file mode 100644 index 0000000000..87d6ccbd31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/countryregion/CountryregionStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package countryregion + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CountryregionStructure[Row](val prefix: Option[String], val extract: Row => CountryregionRow, val merge: (Row, CountryregionRow) => Row) + extends Relation[CountryregionFields, CountryregionRow, Row] + with CountryregionFields[Row] { outer => + + override val countryregioncode = new IdField[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](countryregioncode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CountryregionRow, merge: (NewRow, CountryregionRow) => NewRow): CountryregionStructure[NewRow] = + new CountryregionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressFields.scala new file mode 100644 index 0000000000..70ce831bfd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait EmailaddressFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val emailaddressid: IdField[Int, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object EmailaddressFields extends EmailaddressStructure[EmailaddressRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressId.scala new file mode 100644 index 0000000000..300907e19c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressId.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `person.emailaddress` */ +case class EmailaddressId(businessentityid: BusinessentityId, emailaddressid: Int) +object EmailaddressId { + implicit lazy val jsonDecoder: JsonDecoder[EmailaddressId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val emailaddressid = jsonObj.get("emailaddressid").toRight("Missing field 'emailaddressid'").flatMap(_.as(JsonDecoder.int)) + if (businessentityid.isRight && emailaddressid.isRight) + Right(EmailaddressId(businessentityid = businessentityid.toOption.get, emailaddressid = emailaddressid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, emailaddressid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmailaddressId] = new JsonEncoder[EmailaddressId] { + override def unsafeEncode(a: EmailaddressId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""emailaddressid":""") + JsonEncoder.int.unsafeEncode(a.emailaddressid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[EmailaddressId] = Ordering.by(x => (x.businessentityid, x.emailaddressid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepo.scala new file mode 100644 index 0000000000..d1792dbfa9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait EmailaddressRepo { + def delete(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[EmailaddressFields, EmailaddressRow] + def insert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, EmailaddressRow] + def insert(unsaved: EmailaddressRowUnsaved): ZIO[ZConnection, Throwable, EmailaddressRow] + def select: SelectBuilder[EmailaddressFields, EmailaddressRow] + def selectAll: ZStream[ZConnection, Throwable, EmailaddressRow] + def selectById(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Option[EmailaddressRow]] + def update(row: EmailaddressRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[EmailaddressFields, EmailaddressRow] + def upsert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, UpdateResult[EmailaddressRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoImpl.scala new file mode 100644 index 0000000000..5c053814ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoImpl.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object EmailaddressRepoImpl extends EmailaddressRepo { + override def delete(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.emailaddress where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "emailaddressid" = ${Segment.paramSegment(compositeId.emailaddressid)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[EmailaddressFields, EmailaddressRow] = { + DeleteBuilder("person.emailaddress", EmailaddressFields) + } + override def insert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, EmailaddressRow] = { + sql"""insert into person.emailaddress("businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.emailaddressid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.emailaddress)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text + """.insertReturning(EmailaddressRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: EmailaddressRowUnsaved): ZIO[ZConnection, Throwable, EmailaddressRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""emailaddress"""", sql"${Segment.paramSegment(unsaved.emailaddress)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.emailaddressid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""emailaddressid"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.emailaddress default values + returning "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.emailaddress($names) values ($values) returning "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text""" + } + q.insertReturning(EmailaddressRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[EmailaddressFields, EmailaddressRow] = { + SelectBuilderSql("person.emailaddress", EmailaddressFields, EmailaddressRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, EmailaddressRow] = { + sql"""select "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text from person.emailaddress""".query(EmailaddressRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Option[EmailaddressRow]] = { + sql"""select "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text from person.emailaddress where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "emailaddressid" = ${Segment.paramSegment(compositeId.emailaddressid)(Setter.intSetter)}""".query(EmailaddressRow.jdbcDecoder).selectOne + } + override def update(row: EmailaddressRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update person.emailaddress + set "emailaddress" = ${Segment.paramSegment(row.emailaddress)(Setter.optionParamSetter(Setter.stringSetter))}, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "emailaddressid" = ${Segment.paramSegment(compositeId.emailaddressid)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[EmailaddressFields, EmailaddressRow] = { + UpdateBuilder("person.emailaddress", EmailaddressFields, EmailaddressRow.jdbcDecoder) + } + override def upsert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, UpdateResult[EmailaddressRow]] = { + sql"""insert into person.emailaddress("businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.emailaddressid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.emailaddress)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "emailaddressid") + do update set + "emailaddress" = EXCLUDED."emailaddress", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "emailaddressid", "emailaddress", "rowguid", "modifieddate"::text""".insertReturning(EmailaddressRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoMock.scala new file mode 100644 index 0000000000..61cb43a43c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class EmailaddressRepoMock(toRow: Function1[EmailaddressRowUnsaved, EmailaddressRow], + map: scala.collection.mutable.Map[EmailaddressId, EmailaddressRow] = scala.collection.mutable.Map.empty) extends EmailaddressRepo { + override def delete(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[EmailaddressFields, EmailaddressRow] = { + DeleteBuilderMock(DeleteParams.empty, EmailaddressFields, map) + } + override def insert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, EmailaddressRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: EmailaddressRowUnsaved): ZIO[ZConnection, Throwable, EmailaddressRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[EmailaddressFields, EmailaddressRow] = { + SelectBuilderMock(EmailaddressFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, EmailaddressRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: EmailaddressId): ZIO[ZConnection, Throwable, Option[EmailaddressRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: EmailaddressRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[EmailaddressFields, EmailaddressRow] = { + UpdateBuilderMock(UpdateParams.empty, EmailaddressFields, map) + } + override def upsert(unsaved: EmailaddressRow): ZIO[ZConnection, Throwable, UpdateResult[EmailaddressRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRow.scala new file mode 100644 index 0000000000..98e927404b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class EmailaddressRow( + /** Primary key. Person associated with this email address. Foreign key to Person.BusinessEntityID + Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. ID of this email address. */ + emailaddressid: Int, + /** E-mail address for the person. */ + emailaddress: Option[/* max 50 chars */ String], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: EmailaddressId = EmailaddressId(businessentityid, emailaddressid) + } + +object EmailaddressRow { + implicit lazy val jdbcDecoder: JdbcDecoder[EmailaddressRow] = new JdbcDecoder[EmailaddressRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, EmailaddressRow) = + columIndex + 4 -> + EmailaddressRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + emailaddressid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[EmailaddressRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val emailaddressid = jsonObj.get("emailaddressid").toRight("Missing field 'emailaddressid'").flatMap(_.as(JsonDecoder.int)) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && emailaddressid.isRight && emailaddress.isRight && rowguid.isRight && modifieddate.isRight) + Right(EmailaddressRow(businessentityid = businessentityid.toOption.get, emailaddressid = emailaddressid.toOption.get, emailaddress = emailaddress.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, emailaddressid, emailaddress, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmailaddressRow] = new JsonEncoder[EmailaddressRow] { + override def unsafeEncode(a: EmailaddressRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""emailaddressid":""") + JsonEncoder.int.unsafeEncode(a.emailaddressid, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRowUnsaved.scala new file mode 100644 index 0000000000..c5dbbf495b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressRowUnsaved.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.emailaddress` which has not been persisted yet */ +case class EmailaddressRowUnsaved( + /** Primary key. Person associated with this email address. Foreign key to Person.BusinessEntityID + Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** E-mail address for the person. */ + emailaddress: Option[/* max 50 chars */ String], + /** Default: nextval('person.emailaddress_emailaddressid_seq'::regclass) + Primary key. ID of this email address. */ + emailaddressid: Defaulted[Int] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(emailaddressidDefault: => Int, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): EmailaddressRow = + EmailaddressRow( + businessentityid = businessentityid, + emailaddress = emailaddress, + emailaddressid = emailaddressid match { + case Defaulted.UseDefault => emailaddressidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object EmailaddressRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[EmailaddressRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailaddressid = jsonObj.get("emailaddressid").toRight("Missing field 'emailaddressid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && emailaddress.isRight && emailaddressid.isRight && rowguid.isRight && modifieddate.isRight) + Right(EmailaddressRowUnsaved(businessentityid = businessentityid.toOption.get, emailaddress = emailaddress.toOption.get, emailaddressid = emailaddressid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, emailaddress, emailaddressid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[EmailaddressRowUnsaved] = new JsonEncoder[EmailaddressRowUnsaved] { + override def unsafeEncode(a: EmailaddressRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailaddressid":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.emailaddressid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressStructure.scala new file mode 100644 index 0000000000..55cc11a4b2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/emailaddress/EmailaddressStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package emailaddress + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class EmailaddressStructure[Row](val prefix: Option[String], val extract: Row => EmailaddressRow, val merge: (Row, EmailaddressRow) => Row) + extends Relation[EmailaddressFields, EmailaddressRow, Row] + with EmailaddressFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val emailaddressid = new IdField[Int, Row](prefix, "emailaddressid", None, Some("int4"))(x => extract(x).emailaddressid, (row, value) => merge(row, extract(row).copy(emailaddressid = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, emailaddressid, emailaddress, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => EmailaddressRow, merge: (NewRow, EmailaddressRow) => NewRow): EmailaddressStructure[NewRow] = + new EmailaddressStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordFields.scala new file mode 100644 index 0000000000..2d6eead3de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PasswordFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val passwordhash: Field[/* max 128 chars */ String, Row] + val passwordsalt: Field[/* max 10 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PasswordFields extends PasswordStructure[PasswordRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepo.scala new file mode 100644 index 0000000000..20c539677d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PasswordRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PasswordFields, PasswordRow] + def insert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, PasswordRow] + def insert(unsaved: PasswordRowUnsaved): ZIO[ZConnection, Throwable, PasswordRow] + def select: SelectBuilder[PasswordFields, PasswordRow] + def selectAll: ZStream[ZConnection, Throwable, PasswordRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PasswordRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PasswordRow] + def update(row: PasswordRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PasswordFields, PasswordRow] + def upsert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, UpdateResult[PasswordRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoImpl.scala new file mode 100644 index 0000000000..8ddd6f86a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoImpl.scala @@ -0,0 +1,108 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PasswordRepoImpl extends PasswordRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.password where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PasswordFields, PasswordRow] = { + DeleteBuilder("person.password", PasswordFields) + } + override def insert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, PasswordRow] = { + sql"""insert into person.password("businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.passwordhash)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.passwordsalt)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text + """.insertReturning(PasswordRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PasswordRowUnsaved): ZIO[ZConnection, Throwable, PasswordRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""passwordhash"""", sql"${Segment.paramSegment(unsaved.passwordhash)(Setter.stringSetter)}")), + Some((sql""""passwordsalt"""", sql"${Segment.paramSegment(unsaved.passwordsalt)(Setter.stringSetter)}")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.password default values + returning "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.password($names) values ($values) returning "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text""" + } + q.insertReturning(PasswordRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PasswordFields, PasswordRow] = { + SelectBuilderSql("person.password", PasswordFields, PasswordRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PasswordRow] = { + sql"""select "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text from person.password""".query(PasswordRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PasswordRow]] = { + sql"""select "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text from person.password where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(PasswordRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PasswordRow] = { + sql"""select "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text from person.password where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(PasswordRow.jdbcDecoder).selectStream + } + override def update(row: PasswordRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update person.password + set "passwordhash" = ${Segment.paramSegment(row.passwordhash)(Setter.stringSetter)}, + "passwordsalt" = ${Segment.paramSegment(row.passwordsalt)(Setter.stringSetter)}, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PasswordFields, PasswordRow] = { + UpdateBuilder("person.password", PasswordFields, PasswordRow.jdbcDecoder) + } + override def upsert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, UpdateResult[PasswordRow]] = { + sql"""insert into person.password("businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.passwordhash)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.passwordsalt)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "passwordhash" = EXCLUDED."passwordhash", + "passwordsalt" = EXCLUDED."passwordsalt", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "passwordhash", "passwordsalt", "rowguid", "modifieddate"::text""".insertReturning(PasswordRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoMock.scala new file mode 100644 index 0000000000..8a47d683af --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PasswordRepoMock(toRow: Function1[PasswordRowUnsaved, PasswordRow], + map: scala.collection.mutable.Map[BusinessentityId, PasswordRow] = scala.collection.mutable.Map.empty) extends PasswordRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[PasswordFields, PasswordRow] = { + DeleteBuilderMock(DeleteParams.empty, PasswordFields, map) + } + override def insert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, PasswordRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: PasswordRowUnsaved): ZIO[ZConnection, Throwable, PasswordRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PasswordFields, PasswordRow] = { + SelectBuilderMock(PasswordFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PasswordRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PasswordRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PasswordRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: PasswordRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PasswordFields, PasswordRow] = { + UpdateBuilderMock(UpdateParams.empty, PasswordFields, map) + } + override def upsert(unsaved: PasswordRow): ZIO[ZConnection, Throwable, UpdateResult[PasswordRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRow.scala new file mode 100644 index 0000000000..9ab6022a3b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PasswordRow( + /** Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Password for the e-mail account. */ + passwordhash: /* max 128 chars */ String, + /** Random value concatenated with the password string before the password is hashed. */ + passwordsalt: /* max 10 chars */ String, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object PasswordRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PasswordRow] = new JdbcDecoder[PasswordRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PasswordRow) = + columIndex + 4 -> + PasswordRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + passwordhash = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + passwordsalt = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PasswordRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val passwordhash = jsonObj.get("passwordhash").toRight("Missing field 'passwordhash'").flatMap(_.as(JsonDecoder.string)) + val passwordsalt = jsonObj.get("passwordsalt").toRight("Missing field 'passwordsalt'").flatMap(_.as(JsonDecoder.string)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && passwordhash.isRight && passwordsalt.isRight && rowguid.isRight && modifieddate.isRight) + Right(PasswordRow(businessentityid = businessentityid.toOption.get, passwordhash = passwordhash.toOption.get, passwordsalt = passwordsalt.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, passwordhash, passwordsalt, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PasswordRow] = new JsonEncoder[PasswordRow] { + override def unsafeEncode(a: PasswordRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""passwordhash":""") + JsonEncoder.string.unsafeEncode(a.passwordhash, indent, out) + out.write(",") + out.write(""""passwordsalt":""") + JsonEncoder.string.unsafeEncode(a.passwordsalt, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRowUnsaved.scala new file mode 100644 index 0000000000..72ca606544 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordRowUnsaved.scala @@ -0,0 +1,78 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.password` which has not been persisted yet */ +case class PasswordRowUnsaved( + /** Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Password for the e-mail account. */ + passwordhash: /* max 128 chars */ String, + /** Random value concatenated with the password string before the password is hashed. */ + passwordsalt: /* max 10 chars */ String, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): PasswordRow = + PasswordRow( + businessentityid = businessentityid, + passwordhash = passwordhash, + passwordsalt = passwordsalt, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PasswordRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PasswordRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val passwordhash = jsonObj.get("passwordhash").toRight("Missing field 'passwordhash'").flatMap(_.as(JsonDecoder.string)) + val passwordsalt = jsonObj.get("passwordsalt").toRight("Missing field 'passwordsalt'").flatMap(_.as(JsonDecoder.string)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && passwordhash.isRight && passwordsalt.isRight && rowguid.isRight && modifieddate.isRight) + Right(PasswordRowUnsaved(businessentityid = businessentityid.toOption.get, passwordhash = passwordhash.toOption.get, passwordsalt = passwordsalt.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, passwordhash, passwordsalt, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PasswordRowUnsaved] = new JsonEncoder[PasswordRowUnsaved] { + override def unsafeEncode(a: PasswordRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""passwordhash":""") + JsonEncoder.string.unsafeEncode(a.passwordhash, indent, out) + out.write(",") + out.write(""""passwordsalt":""") + JsonEncoder.string.unsafeEncode(a.passwordsalt, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordStructure.scala new file mode 100644 index 0000000000..60b557bdc7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/password/PasswordStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package password + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PasswordStructure[Row](val prefix: Option[String], val extract: Row => PasswordRow, val merge: (Row, PasswordRow) => Row) + extends Relation[PasswordFields, PasswordRow, Row] + with PasswordFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val passwordhash = new Field[/* max 128 chars */ String, Row](prefix, "passwordhash", None, None)(x => extract(x).passwordhash, (row, value) => merge(row, extract(row).copy(passwordhash = value))) + override val passwordsalt = new Field[/* max 10 chars */ String, Row](prefix, "passwordsalt", None, None)(x => extract(x).passwordsalt, (row, value) => merge(row, extract(row).copy(passwordsalt = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, passwordhash, passwordsalt, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PasswordRow, merge: (NewRow, PasswordRow) => NewRow): PasswordStructure[NewRow] = + new PasswordStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonFields.scala new file mode 100644 index 0000000000..0119c6291d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonFields.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PersonFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val persontype: Field[/* bpchar, max 2 chars */ String, Row] + val namestyle: Field[NameStyle, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val emailpromotion: Field[Int, Row] + val additionalcontactinfo: OptField[TypoXml, Row] + val demographics: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PersonFields extends PersonStructure[PersonRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepo.scala new file mode 100644 index 0000000000..11b15a4b7e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonFields, PersonRow] + def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] + def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] + def select: SelectBuilder[PersonFields, PersonRow] + def selectAll: ZStream[ZConnection, Throwable, PersonRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PersonRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PersonRow] + def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonFields, PersonRow] + def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoImpl.scala new file mode 100644 index 0000000000..a25ad0e92f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoImpl.scala @@ -0,0 +1,150 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRepoImpl extends PersonRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.person where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilder("person.person", PersonFields) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + sql"""insert into person.person("businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.persontype)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.namestyle)(NameStyle.setter)}::bool, ${Segment.paramSegment(unsaved.title)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.firstname)(/* user-picked */ FirstName.setter)}::varchar, ${Segment.paramSegment(unsaved.middlename)(Setter.optionParamSetter(Name.setter))}::varchar, ${Segment.paramSegment(unsaved.lastname)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.suffix)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.emailpromotion)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.additionalcontactinfo)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text + """.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""persontype"""", sql"${Segment.paramSegment(unsaved.persontype)(Setter.stringSetter)}::bpchar")), + Some((sql""""title"""", sql"${Segment.paramSegment(unsaved.title)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""firstname"""", sql"${Segment.paramSegment(unsaved.firstname)(/* user-picked */ FirstName.setter)}::varchar")), + Some((sql""""middlename"""", sql"${Segment.paramSegment(unsaved.middlename)(Setter.optionParamSetter(Name.setter))}::varchar")), + Some((sql""""lastname"""", sql"${Segment.paramSegment(unsaved.lastname)(Name.setter)}::varchar")), + Some((sql""""suffix"""", sql"${Segment.paramSegment(unsaved.suffix)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""additionalcontactinfo"""", sql"${Segment.paramSegment(unsaved.additionalcontactinfo)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + Some((sql""""demographics"""", sql"${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + unsaved.namestyle match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""namestyle"""", sql"${Segment.paramSegment(value: NameStyle)(NameStyle.setter)}::bool")) + }, + unsaved.emailpromotion match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""emailpromotion"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.person default values + returning "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.person($names) values ($values) returning "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text""" + } + q.insertReturning(PersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderSql("person.person", PersonFields, PersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text from person.person""".query(PersonRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + sql"""select "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text from person.person where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(PersonRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PersonRow] = { + sql"""select "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text from person.person where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(PersonRow.jdbcDecoder).selectStream + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update person.person + set "persontype" = ${Segment.paramSegment(row.persontype)(Setter.stringSetter)}::bpchar, + "namestyle" = ${Segment.paramSegment(row.namestyle)(NameStyle.setter)}::bool, + "title" = ${Segment.paramSegment(row.title)(Setter.optionParamSetter(Setter.stringSetter))}, + "firstname" = ${Segment.paramSegment(row.firstname)(/* user-picked */ FirstName.setter)}::varchar, + "middlename" = ${Segment.paramSegment(row.middlename)(Setter.optionParamSetter(Name.setter))}::varchar, + "lastname" = ${Segment.paramSegment(row.lastname)(Name.setter)}::varchar, + "suffix" = ${Segment.paramSegment(row.suffix)(Setter.optionParamSetter(Setter.stringSetter))}, + "emailpromotion" = ${Segment.paramSegment(row.emailpromotion)(Setter.intSetter)}::int4, + "additionalcontactinfo" = ${Segment.paramSegment(row.additionalcontactinfo)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "demographics" = ${Segment.paramSegment(row.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilder("person.person", PersonFields, PersonRow.jdbcDecoder) + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + sql"""insert into person.person("businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.persontype)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.namestyle)(NameStyle.setter)}::bool, + ${Segment.paramSegment(unsaved.title)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.firstname)(/* user-picked */ FirstName.setter)}::varchar, + ${Segment.paramSegment(unsaved.middlename)(Setter.optionParamSetter(Name.setter))}::varchar, + ${Segment.paramSegment(unsaved.lastname)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.suffix)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.emailpromotion)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.additionalcontactinfo)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "persontype" = EXCLUDED."persontype", + "namestyle" = EXCLUDED."namestyle", + "title" = EXCLUDED."title", + "firstname" = EXCLUDED."firstname", + "middlename" = EXCLUDED."middlename", + "lastname" = EXCLUDED."lastname", + "suffix" = EXCLUDED."suffix", + "emailpromotion" = EXCLUDED."emailpromotion", + "additionalcontactinfo" = EXCLUDED."additionalcontactinfo", + "demographics" = EXCLUDED."demographics", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "persontype", "namestyle", "title", "firstname", "middlename", "lastname", "suffix", "emailpromotion", "additionalcontactinfo", "demographics", "rowguid", "modifieddate"::text""".insertReturning(PersonRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoMock.scala new file mode 100644 index 0000000000..3d42477221 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonRepoMock(toRow: Function1[PersonRowUnsaved, PersonRow], + map: scala.collection.mutable.Map[BusinessentityId, PersonRow] = scala.collection.mutable.Map.empty) extends PersonRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[PersonFields, PersonRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonFields, map) + } + override def insert(unsaved: PersonRow): ZIO[ZConnection, Throwable, PersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonRowUnsaved): ZIO[ZConnection, Throwable, PersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonFields, PersonRow] = { + SelectBuilderMock(PersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[PersonRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, PersonRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: PersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonFields, PersonRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonFields, map) + } + override def upsert(unsaved: PersonRow): ZIO[ZConnection, Throwable, UpdateResult[PersonRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRow.scala new file mode 100644 index 0000000000..e1fb42fa58 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRow.scala @@ -0,0 +1,136 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRow( + /** Primary key for Person records. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary type of person: SC = Store Contact, IN = Individual (retail) customer, SP = Sales person, EM = Employee (non-sales), VC = Vendor contact, GC = General contact + Constraint CK_Person_PersonType affecting columns "persontype": (((persontype IS NULL) OR (upper((persontype)::text) = ANY (ARRAY['SC'::text, 'VC'::text, 'IN'::text, 'EM'::text, 'SP'::text, 'GC'::text])))) */ + persontype: /* bpchar, max 2 chars */ String, + /** 0 = The data in FirstName and LastName are stored in western style (first name, last name) order. 1 = Eastern style (last name, first name) order. */ + namestyle: NameStyle, + /** A courtesy title. For example, Mr. or Ms. */ + title: Option[/* max 8 chars */ String], + /** First name of the person. */ + firstname: /* user-picked */ FirstName, + /** Middle name or middle initial of the person. */ + middlename: Option[Name], + /** Last name of the person. */ + lastname: Name, + /** Surname suffix. For example, Sr. or Jr. */ + suffix: Option[/* max 10 chars */ String], + /** 0 = Contact does not wish to receive e-mail promotions, 1 = Contact does wish to receive e-mail promotions from AdventureWorks, 2 = Contact does wish to receive e-mail promotions from AdventureWorks and selected partners. + Constraint CK_Person_EmailPromotion affecting columns "emailpromotion": (((emailpromotion >= 0) AND (emailpromotion <= 2))) */ + emailpromotion: Int, + /** Additional contact information about the person stored in xml format. */ + additionalcontactinfo: Option[TypoXml], + /** Personal information such as hobbies, and income collected from online shoppers. Used for sales analysis. */ + demographics: Option[TypoXml], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object PersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRow] = new JdbcDecoder[PersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRow) = + columIndex + 12 -> + PersonRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + persontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + namestyle = NameStyle.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 8, rs)._2, + additionalcontactinfo = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + demographics = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val persontype = jsonObj.get("persontype").toRight("Missing field 'persontype'").flatMap(_.as(JsonDecoder.string)) + val namestyle = jsonObj.get("namestyle").toRight("Missing field 'namestyle'").flatMap(_.as(NameStyle.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + val additionalcontactinfo = jsonObj.get("additionalcontactinfo").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && persontype.isRight && namestyle.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && emailpromotion.isRight && additionalcontactinfo.isRight && demographics.isRight && rowguid.isRight && modifieddate.isRight) + Right(PersonRow(businessentityid = businessentityid.toOption.get, persontype = persontype.toOption.get, namestyle = namestyle.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, emailpromotion = emailpromotion.toOption.get, additionalcontactinfo = additionalcontactinfo.toOption.get, demographics = demographics.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, persontype, namestyle, title, firstname, middlename, lastname, suffix, emailpromotion, additionalcontactinfo, demographics, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRow] = new JsonEncoder[PersonRow] { + override def unsafeEncode(a: PersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""persontype":""") + JsonEncoder.string.unsafeEncode(a.persontype, indent, out) + out.write(",") + out.write(""""namestyle":""") + NameStyle.jsonEncoder.unsafeEncode(a.namestyle, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""additionalcontactinfo":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.additionalcontactinfo, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRowUnsaved.scala new file mode 100644 index 0000000000..8027695cbb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonRowUnsaved.scala @@ -0,0 +1,149 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.person` which has not been persisted yet */ +case class PersonRowUnsaved( + /** Primary key for Person records. + Points to [[businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary type of person: SC = Store Contact, IN = Individual (retail) customer, SP = Sales person, EM = Employee (non-sales), VC = Vendor contact, GC = General contact + Constraint CK_Person_PersonType affecting columns "persontype": (((persontype IS NULL) OR (upper((persontype)::text) = ANY (ARRAY['SC'::text, 'VC'::text, 'IN'::text, 'EM'::text, 'SP'::text, 'GC'::text])))) */ + persontype: /* bpchar, max 2 chars */ String, + /** A courtesy title. For example, Mr. or Ms. */ + title: Option[/* max 8 chars */ String], + /** First name of the person. */ + firstname: /* user-picked */ FirstName, + /** Middle name or middle initial of the person. */ + middlename: Option[Name], + /** Last name of the person. */ + lastname: Name, + /** Surname suffix. For example, Sr. or Jr. */ + suffix: Option[/* max 10 chars */ String], + /** Additional contact information about the person stored in xml format. */ + additionalcontactinfo: Option[TypoXml], + /** Personal information such as hobbies, and income collected from online shoppers. Used for sales analysis. */ + demographics: Option[TypoXml], + /** Default: false + 0 = The data in FirstName and LastName are stored in western style (first name, last name) order. 1 = Eastern style (last name, first name) order. */ + namestyle: Defaulted[NameStyle] = Defaulted.UseDefault, + /** Default: 0 + 0 = Contact does not wish to receive e-mail promotions, 1 = Contact does wish to receive e-mail promotions from AdventureWorks, 2 = Contact does wish to receive e-mail promotions from AdventureWorks and selected partners. + Constraint CK_Person_EmailPromotion affecting columns "emailpromotion": (((emailpromotion >= 0) AND (emailpromotion <= 2))) */ + emailpromotion: Defaulted[Int] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(namestyleDefault: => NameStyle, emailpromotionDefault: => Int, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): PersonRow = + PersonRow( + businessentityid = businessentityid, + persontype = persontype, + title = title, + firstname = firstname, + middlename = middlename, + lastname = lastname, + suffix = suffix, + additionalcontactinfo = additionalcontactinfo, + demographics = demographics, + namestyle = namestyle match { + case Defaulted.UseDefault => namestyleDefault + case Defaulted.Provided(value) => value + }, + emailpromotion = emailpromotion match { + case Defaulted.UseDefault => emailpromotionDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val persontype = jsonObj.get("persontype").toRight("Missing field 'persontype'").flatMap(_.as(JsonDecoder.string)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val additionalcontactinfo = jsonObj.get("additionalcontactinfo").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val namestyle = jsonObj.get("namestyle").toRight("Missing field 'namestyle'").flatMap(_.as(Defaulted.jsonDecoder(NameStyle.jsonDecoder))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && persontype.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && additionalcontactinfo.isRight && demographics.isRight && namestyle.isRight && emailpromotion.isRight && rowguid.isRight && modifieddate.isRight) + Right(PersonRowUnsaved(businessentityid = businessentityid.toOption.get, persontype = persontype.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, additionalcontactinfo = additionalcontactinfo.toOption.get, demographics = demographics.toOption.get, namestyle = namestyle.toOption.get, emailpromotion = emailpromotion.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, persontype, title, firstname, middlename, lastname, suffix, additionalcontactinfo, demographics, namestyle, emailpromotion, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowUnsaved] = new JsonEncoder[PersonRowUnsaved] { + override def unsafeEncode(a: PersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""persontype":""") + JsonEncoder.string.unsafeEncode(a.persontype, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""additionalcontactinfo":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.additionalcontactinfo, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""namestyle":""") + Defaulted.jsonEncoder(NameStyle.jsonEncoder).unsafeEncode(a.namestyle, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonStructure.scala new file mode 100644 index 0000000000..123311e8d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/person/PersonStructure.scala @@ -0,0 +1,46 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package person + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PersonStructure[Row](val prefix: Option[String], val extract: Row => PersonRow, val merge: (Row, PersonRow) => Row) + extends Relation[PersonFields, PersonRow, Row] + with PersonFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val persontype = new Field[/* bpchar, max 2 chars */ String, Row](prefix, "persontype", None, Some("bpchar"))(x => extract(x).persontype, (row, value) => merge(row, extract(row).copy(persontype = value))) + override val namestyle = new Field[NameStyle, Row](prefix, "namestyle", None, Some("bool"))(x => extract(x).namestyle, (row, value) => merge(row, extract(row).copy(namestyle = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, Some("varchar"))(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, Some("varchar"))(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, Some("varchar"))(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, Some("int4"))(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + override val additionalcontactinfo = new OptField[TypoXml, Row](prefix, "additionalcontactinfo", None, Some("xml"))(x => extract(x).additionalcontactinfo, (row, value) => merge(row, extract(row).copy(additionalcontactinfo = value))) + override val demographics = new OptField[TypoXml, Row](prefix, "demographics", None, Some("xml"))(x => extract(x).demographics, (row, value) => merge(row, extract(row).copy(demographics = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, persontype, namestyle, title, firstname, middlename, lastname, suffix, emailpromotion, additionalcontactinfo, demographics, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonRow, merge: (NewRow, PersonRow) => NewRow): PersonStructure[NewRow] = + new PersonStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneFields.scala new file mode 100644 index 0000000000..f297954278 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PersonphoneFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val phonenumber: IdField[Phone, Row] + val phonenumbertypeid: IdField[PhonenumbertypeId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PersonphoneFields extends PersonphoneStructure[PersonphoneRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneId.scala new file mode 100644 index 0000000000..934cd43021 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneId.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `person.personphone` */ +case class PersonphoneId(businessentityid: BusinessentityId, phonenumber: Phone, phonenumbertypeid: PhonenumbertypeId) +object PersonphoneId { + implicit lazy val jsonDecoder: JsonDecoder[PersonphoneId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val phonenumber = jsonObj.get("phonenumber").toRight("Missing field 'phonenumber'").flatMap(_.as(Phone.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + if (businessentityid.isRight && phonenumber.isRight && phonenumbertypeid.isRight) + Right(PersonphoneId(businessentityid = businessentityid.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, phonenumber, phonenumbertypeid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonphoneId] = new JsonEncoder[PersonphoneId] { + override def unsafeEncode(a: PersonphoneId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""phonenumber":""") + Phone.jsonEncoder.unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PersonphoneId] = Ordering.by(x => (x.businessentityid, x.phonenumber, x.phonenumbertypeid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepo.scala new file mode 100644 index 0000000000..292f5ce53d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonphoneRepo { + def delete(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersonphoneFields, PersonphoneRow] + def insert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, PersonphoneRow] + def insert(unsaved: PersonphoneRowUnsaved): ZIO[ZConnection, Throwable, PersonphoneRow] + def select: SelectBuilder[PersonphoneFields, PersonphoneRow] + def selectAll: ZStream[ZConnection, Throwable, PersonphoneRow] + def selectById(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Option[PersonphoneRow]] + def update(row: PersonphoneRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersonphoneFields, PersonphoneRow] + def upsert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, UpdateResult[PersonphoneRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoImpl.scala new file mode 100644 index 0000000000..7e935b8d09 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonphoneRepoImpl extends PersonphoneRepo { + override def delete(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.personphone where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "phonenumber" = ${Segment.paramSegment(compositeId.phonenumber)(Phone.setter)} AND "phonenumbertypeid" = ${Segment.paramSegment(compositeId.phonenumbertypeid)(PhonenumbertypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersonphoneFields, PersonphoneRow] = { + DeleteBuilder("person.personphone", PersonphoneFields) + } + override def insert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, PersonphoneRow] = { + sql"""insert into person.personphone("businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.phonenumber)(Phone.setter)}::varchar, ${Segment.paramSegment(unsaved.phonenumbertypeid)(PhonenumbertypeId.setter)}::int4, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text + """.insertReturning(PersonphoneRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersonphoneRowUnsaved): ZIO[ZConnection, Throwable, PersonphoneRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""phonenumber"""", sql"${Segment.paramSegment(unsaved.phonenumber)(Phone.setter)}::varchar")), + Some((sql""""phonenumbertypeid"""", sql"${Segment.paramSegment(unsaved.phonenumbertypeid)(PhonenumbertypeId.setter)}::int4")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.personphone default values + returning "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.personphone($names) values ($values) returning "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text""" + } + q.insertReturning(PersonphoneRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersonphoneFields, PersonphoneRow] = { + SelectBuilderSql("person.personphone", PersonphoneFields, PersonphoneRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonphoneRow] = { + sql"""select "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text from person.personphone""".query(PersonphoneRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Option[PersonphoneRow]] = { + sql"""select "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text from person.personphone where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "phonenumber" = ${Segment.paramSegment(compositeId.phonenumber)(Phone.setter)} AND "phonenumbertypeid" = ${Segment.paramSegment(compositeId.phonenumbertypeid)(PhonenumbertypeId.setter)}""".query(PersonphoneRow.jdbcDecoder).selectOne + } + override def update(row: PersonphoneRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update person.personphone + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "phonenumber" = ${Segment.paramSegment(compositeId.phonenumber)(Phone.setter)} AND "phonenumbertypeid" = ${Segment.paramSegment(compositeId.phonenumbertypeid)(PhonenumbertypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersonphoneFields, PersonphoneRow] = { + UpdateBuilder("person.personphone", PersonphoneFields, PersonphoneRow.jdbcDecoder) + } + override def upsert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, UpdateResult[PersonphoneRow]] = { + sql"""insert into person.personphone("businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.phonenumber)(Phone.setter)}::varchar, + ${Segment.paramSegment(unsaved.phonenumbertypeid)(PhonenumbertypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "phonenumber", "phonenumbertypeid") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "phonenumber", "phonenumbertypeid", "modifieddate"::text""".insertReturning(PersonphoneRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoMock.scala new file mode 100644 index 0000000000..78be4459d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersonphoneRepoMock(toRow: Function1[PersonphoneRowUnsaved, PersonphoneRow], + map: scala.collection.mutable.Map[PersonphoneId, PersonphoneRow] = scala.collection.mutable.Map.empty) extends PersonphoneRepo { + override def delete(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PersonphoneFields, PersonphoneRow] = { + DeleteBuilderMock(DeleteParams.empty, PersonphoneFields, map) + } + override def insert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, PersonphoneRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: PersonphoneRowUnsaved): ZIO[ZConnection, Throwable, PersonphoneRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersonphoneFields, PersonphoneRow] = { + SelectBuilderMock(PersonphoneFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersonphoneRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PersonphoneId): ZIO[ZConnection, Throwable, Option[PersonphoneRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PersonphoneRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersonphoneFields, PersonphoneRow] = { + UpdateBuilderMock(UpdateParams.empty, PersonphoneFields, map) + } + override def upsert(unsaved: PersonphoneRow): ZIO[ZConnection, Throwable, UpdateResult[PersonphoneRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRow.scala new file mode 100644 index 0000000000..26ae8caaaf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRow.scala @@ -0,0 +1,72 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonphoneRow( + /** Business entity identification number. Foreign key to Person.BusinessEntityID. + Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Telephone number identification number. */ + phonenumber: Phone, + /** Kind of phone number. Foreign key to PhoneNumberType.PhoneNumberTypeID. + Points to [[phonenumbertype.PhonenumbertypeRow.phonenumbertypeid]] */ + phonenumbertypeid: PhonenumbertypeId, + modifieddate: TypoLocalDateTime +){ + val compositeId: PersonphoneId = PersonphoneId(businessentityid, phonenumber, phonenumbertypeid) + } + +object PersonphoneRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonphoneRow] = new JdbcDecoder[PersonphoneRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonphoneRow) = + columIndex + 3 -> + PersonphoneRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + phonenumber = Phone.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + phonenumbertypeid = PhonenumbertypeId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonphoneRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val phonenumber = jsonObj.get("phonenumber").toRight("Missing field 'phonenumber'").flatMap(_.as(Phone.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && phonenumber.isRight && phonenumbertypeid.isRight && modifieddate.isRight) + Right(PersonphoneRow(businessentityid = businessentityid.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, phonenumber, phonenumbertypeid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonphoneRow] = new JsonEncoder[PersonphoneRow] { + override def unsafeEncode(a: PersonphoneRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""phonenumber":""") + Phone.jsonEncoder.unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRowUnsaved.scala new file mode 100644 index 0000000000..9e934a4d62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneRowUnsaved.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.personphone` which has not been persisted yet */ +case class PersonphoneRowUnsaved( + /** Business entity identification number. Foreign key to Person.BusinessEntityID. + Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Telephone number identification number. */ + phonenumber: Phone, + /** Kind of phone number. Foreign key to PhoneNumberType.PhoneNumberTypeID. + Points to [[phonenumbertype.PhonenumbertypeRow.phonenumbertypeid]] */ + phonenumbertypeid: PhonenumbertypeId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): PersonphoneRow = + PersonphoneRow( + businessentityid = businessentityid, + phonenumber = phonenumber, + phonenumbertypeid = phonenumbertypeid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersonphoneRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersonphoneRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val phonenumber = jsonObj.get("phonenumber").toRight("Missing field 'phonenumber'").flatMap(_.as(Phone.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && phonenumber.isRight && phonenumbertypeid.isRight && modifieddate.isRight) + Right(PersonphoneRowUnsaved(businessentityid = businessentityid.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, phonenumber, phonenumbertypeid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonphoneRowUnsaved] = new JsonEncoder[PersonphoneRowUnsaved] { + override def unsafeEncode(a: PersonphoneRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""phonenumber":""") + Phone.jsonEncoder.unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneStructure.scala new file mode 100644 index 0000000000..bc16c6660c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/personphone/PersonphoneStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package personphone + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.public.Phone +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PersonphoneStructure[Row](val prefix: Option[String], val extract: Row => PersonphoneRow, val merge: (Row, PersonphoneRow) => Row) + extends Relation[PersonphoneFields, PersonphoneRow, Row] + with PersonphoneFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val phonenumber = new IdField[Phone, Row](prefix, "phonenumber", None, Some("varchar"))(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertypeid = new IdField[PhonenumbertypeId, Row](prefix, "phonenumbertypeid", None, Some("int4"))(x => extract(x).phonenumbertypeid, (row, value) => merge(row, extract(row).copy(phonenumbertypeid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, phonenumber, phonenumbertypeid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersonphoneRow, merge: (NewRow, PersonphoneRow) => NewRow): PersonphoneStructure[NewRow] = + new PersonphoneStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeFields.scala new file mode 100644 index 0000000000..498a3475ef --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PhonenumbertypeFields[Row] { + val phonenumbertypeid: IdField[PhonenumbertypeId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PhonenumbertypeFields extends PhonenumbertypeStructure[PhonenumbertypeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeId.scala new file mode 100644 index 0000000000..f0ad92a576 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +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 `person.phonenumbertype` */ +case class PhonenumbertypeId(value: Int) extends AnyVal +object PhonenumbertypeId { + implicit lazy val arraySetter: Setter[Array[PhonenumbertypeId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PhonenumbertypeId, Int] = Bijection[PhonenumbertypeId, Int](_.value)(PhonenumbertypeId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PhonenumbertypeId] = JdbcDecoder.intDecoder.map(PhonenumbertypeId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PhonenumbertypeId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PhonenumbertypeId] = JsonDecoder.int.map(PhonenumbertypeId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PhonenumbertypeId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[PhonenumbertypeId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PhonenumbertypeId] = ParameterMetaData.instance[PhonenumbertypeId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PhonenumbertypeId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepo.scala new file mode 100644 index 0000000000..38f36a92a0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PhonenumbertypeRepo { + def delete(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PhonenumbertypeFields, PhonenumbertypeRow] + def insert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, PhonenumbertypeRow] + def insert(unsaved: PhonenumbertypeRowUnsaved): ZIO[ZConnection, Throwable, PhonenumbertypeRow] + def select: SelectBuilder[PhonenumbertypeFields, PhonenumbertypeRow] + def selectAll: ZStream[ZConnection, Throwable, PhonenumbertypeRow] + def selectById(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Option[PhonenumbertypeRow]] + def selectByIds(phonenumbertypeids: Array[PhonenumbertypeId]): ZStream[ZConnection, Throwable, PhonenumbertypeRow] + def update(row: PhonenumbertypeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PhonenumbertypeFields, PhonenumbertypeRow] + def upsert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, UpdateResult[PhonenumbertypeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoImpl.scala new file mode 100644 index 0000000000..f9c2250813 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoImpl.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PhonenumbertypeRepoImpl extends PhonenumbertypeRepo { + override def delete(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.phonenumbertype where "phonenumbertypeid" = ${Segment.paramSegment(phonenumbertypeid)(PhonenumbertypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + DeleteBuilder("person.phonenumbertype", PhonenumbertypeFields) + } + override def insert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, PhonenumbertypeRow] = { + sql"""insert into person.phonenumbertype("phonenumbertypeid", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.phonenumbertypeid)(PhonenumbertypeId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "phonenumbertypeid", "name", "modifieddate"::text + """.insertReturning(PhonenumbertypeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PhonenumbertypeRowUnsaved): ZIO[ZConnection, Throwable, PhonenumbertypeRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.phonenumbertypeid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""phonenumbertypeid"""", sql"${Segment.paramSegment(value: PhonenumbertypeId)(PhonenumbertypeId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.phonenumbertype default values + returning "phonenumbertypeid", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.phonenumbertype($names) values ($values) returning "phonenumbertypeid", "name", "modifieddate"::text""" + } + q.insertReturning(PhonenumbertypeRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + SelectBuilderSql("person.phonenumbertype", PhonenumbertypeFields, PhonenumbertypeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PhonenumbertypeRow] = { + sql"""select "phonenumbertypeid", "name", "modifieddate"::text from person.phonenumbertype""".query(PhonenumbertypeRow.jdbcDecoder).selectStream + } + override def selectById(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Option[PhonenumbertypeRow]] = { + sql"""select "phonenumbertypeid", "name", "modifieddate"::text from person.phonenumbertype where "phonenumbertypeid" = ${Segment.paramSegment(phonenumbertypeid)(PhonenumbertypeId.setter)}""".query(PhonenumbertypeRow.jdbcDecoder).selectOne + } + override def selectByIds(phonenumbertypeids: Array[PhonenumbertypeId]): ZStream[ZConnection, Throwable, PhonenumbertypeRow] = { + sql"""select "phonenumbertypeid", "name", "modifieddate"::text from person.phonenumbertype where "phonenumbertypeid" = ANY(${Segment.paramSegment(phonenumbertypeids)(PhonenumbertypeId.arraySetter)})""".query(PhonenumbertypeRow.jdbcDecoder).selectStream + } + override def update(row: PhonenumbertypeRow): ZIO[ZConnection, Throwable, Boolean] = { + val phonenumbertypeid = row.phonenumbertypeid + sql"""update person.phonenumbertype + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "phonenumbertypeid" = ${Segment.paramSegment(phonenumbertypeid)(PhonenumbertypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + UpdateBuilder("person.phonenumbertype", PhonenumbertypeFields, PhonenumbertypeRow.jdbcDecoder) + } + override def upsert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, UpdateResult[PhonenumbertypeRow]] = { + sql"""insert into person.phonenumbertype("phonenumbertypeid", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.phonenumbertypeid)(PhonenumbertypeId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("phonenumbertypeid") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "phonenumbertypeid", "name", "modifieddate"::text""".insertReturning(PhonenumbertypeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoMock.scala new file mode 100644 index 0000000000..2f9653671d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PhonenumbertypeRepoMock(toRow: Function1[PhonenumbertypeRowUnsaved, PhonenumbertypeRow], + map: scala.collection.mutable.Map[PhonenumbertypeId, PhonenumbertypeRow] = scala.collection.mutable.Map.empty) extends PhonenumbertypeRepo { + override def delete(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(phonenumbertypeid).isDefined) + } + override def delete: DeleteBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + DeleteBuilderMock(DeleteParams.empty, PhonenumbertypeFields, map) + } + override def insert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, PhonenumbertypeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.phonenumbertypeid)) + sys.error(s"id ${unsaved.phonenumbertypeid} already exists") + else + map.put(unsaved.phonenumbertypeid, unsaved) + + unsaved + } + } + override def insert(unsaved: PhonenumbertypeRowUnsaved): ZIO[ZConnection, Throwable, PhonenumbertypeRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + SelectBuilderMock(PhonenumbertypeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PhonenumbertypeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(phonenumbertypeid: PhonenumbertypeId): ZIO[ZConnection, Throwable, Option[PhonenumbertypeRow]] = { + ZIO.succeed(map.get(phonenumbertypeid)) + } + override def selectByIds(phonenumbertypeids: Array[PhonenumbertypeId]): ZStream[ZConnection, Throwable, PhonenumbertypeRow] = { + ZStream.fromIterable(phonenumbertypeids.flatMap(map.get)) + } + override def update(row: PhonenumbertypeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.phonenumbertypeid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.phonenumbertypeid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PhonenumbertypeFields, PhonenumbertypeRow] = { + UpdateBuilderMock(UpdateParams.empty, PhonenumbertypeFields, map) + } + override def upsert(unsaved: PhonenumbertypeRow): ZIO[ZConnection, Throwable, UpdateResult[PhonenumbertypeRow]] = { + ZIO.succeed { + map.put(unsaved.phonenumbertypeid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRow.scala new file mode 100644 index 0000000000..09fd1eef1a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PhonenumbertypeRow( + /** Primary key for telephone number type records. */ + phonenumbertypeid: PhonenumbertypeId, + /** Name of the telephone number type */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object PhonenumbertypeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PhonenumbertypeRow] = new JdbcDecoder[PhonenumbertypeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PhonenumbertypeRow) = + columIndex + 2 -> + PhonenumbertypeRow( + phonenumbertypeid = PhonenumbertypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PhonenumbertypeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(PhonenumbertypeId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (phonenumbertypeid.isRight && name.isRight && modifieddate.isRight) + Right(PhonenumbertypeRow(phonenumbertypeid = phonenumbertypeid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](phonenumbertypeid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PhonenumbertypeRow] = new JsonEncoder[PhonenumbertypeRow] { + override def unsafeEncode(a: PhonenumbertypeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""phonenumbertypeid":""") + PhonenumbertypeId.jsonEncoder.unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRowUnsaved.scala new file mode 100644 index 0000000000..7a0930893d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeRowUnsaved.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.phonenumbertype` which has not been persisted yet */ +case class PhonenumbertypeRowUnsaved( + /** Name of the telephone number type */ + name: Name, + /** Default: nextval('person.phonenumbertype_phonenumbertypeid_seq'::regclass) + Primary key for telephone number type records. */ + phonenumbertypeid: Defaulted[PhonenumbertypeId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(phonenumbertypeidDefault: => PhonenumbertypeId, modifieddateDefault: => TypoLocalDateTime): PhonenumbertypeRow = + PhonenumbertypeRow( + name = name, + phonenumbertypeid = phonenumbertypeid match { + case Defaulted.UseDefault => phonenumbertypeidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PhonenumbertypeRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PhonenumbertypeRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val phonenumbertypeid = jsonObj.get("phonenumbertypeid").toRight("Missing field 'phonenumbertypeid'").flatMap(_.as(Defaulted.jsonDecoder(PhonenumbertypeId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && phonenumbertypeid.isRight && modifieddate.isRight) + Right(PhonenumbertypeRowUnsaved(name = name.toOption.get, phonenumbertypeid = phonenumbertypeid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, phonenumbertypeid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PhonenumbertypeRowUnsaved] = new JsonEncoder[PhonenumbertypeRowUnsaved] { + override def unsafeEncode(a: PhonenumbertypeRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""phonenumbertypeid":""") + Defaulted.jsonEncoder(PhonenumbertypeId.jsonEncoder).unsafeEncode(a.phonenumbertypeid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeStructure.scala new file mode 100644 index 0000000000..d97624344a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/phonenumbertype/PhonenumbertypeStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package phonenumbertype + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PhonenumbertypeStructure[Row](val prefix: Option[String], val extract: Row => PhonenumbertypeRow, val merge: (Row, PhonenumbertypeRow) => Row) + extends Relation[PhonenumbertypeFields, PhonenumbertypeRow, Row] + with PhonenumbertypeFields[Row] { outer => + + override val phonenumbertypeid = new IdField[PhonenumbertypeId, Row](prefix, "phonenumbertypeid", None, Some("int4"))(x => extract(x).phonenumbertypeid, (row, value) => merge(row, extract(row).copy(phonenumbertypeid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](phonenumbertypeid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PhonenumbertypeRow, merge: (NewRow, PhonenumbertypeRow) => NewRow): PhonenumbertypeStructure[NewRow] = + new PhonenumbertypeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceFields.scala new file mode 100644 index 0000000000..e08e645ce9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait StateprovinceFields[Row] { + val stateprovinceid: IdField[StateprovinceId, Row] + val stateprovincecode: Field[/* bpchar, max 3 chars */ String, Row] + val countryregioncode: Field[CountryregionId, Row] + val isonlystateprovinceflag: Field[Flag, Row] + val name: Field[Name, Row] + val territoryid: Field[SalesterritoryId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object StateprovinceFields extends StateprovinceStructure[StateprovinceRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceId.scala new file mode 100644 index 0000000000..a996270aad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +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 `person.stateprovince` */ +case class StateprovinceId(value: Int) extends AnyVal +object StateprovinceId { + implicit lazy val arraySetter: Setter[Array[StateprovinceId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[StateprovinceId, Int] = Bijection[StateprovinceId, Int](_.value)(StateprovinceId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[StateprovinceId] = JdbcDecoder.intDecoder.map(StateprovinceId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[StateprovinceId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[StateprovinceId] = JsonDecoder.int.map(StateprovinceId.apply) + implicit lazy val jsonEncoder: JsonEncoder[StateprovinceId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[StateprovinceId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[StateprovinceId] = ParameterMetaData.instance[StateprovinceId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[StateprovinceId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepo.scala new file mode 100644 index 0000000000..4e0cfbb003 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait StateprovinceRepo { + def delete(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[StateprovinceFields, StateprovinceRow] + def insert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, StateprovinceRow] + def insert(unsaved: StateprovinceRowUnsaved): ZIO[ZConnection, Throwable, StateprovinceRow] + def select: SelectBuilder[StateprovinceFields, StateprovinceRow] + def selectAll: ZStream[ZConnection, Throwable, StateprovinceRow] + def selectById(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Option[StateprovinceRow]] + def selectByIds(stateprovinceids: Array[StateprovinceId]): ZStream[ZConnection, Throwable, StateprovinceRow] + def update(row: StateprovinceRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[StateprovinceFields, StateprovinceRow] + def upsert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, UpdateResult[StateprovinceRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoImpl.scala new file mode 100644 index 0000000000..3da1df782f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoImpl.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object StateprovinceRepoImpl extends StateprovinceRepo { + override def delete(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from person.stateprovince where "stateprovinceid" = ${Segment.paramSegment(stateprovinceid)(StateprovinceId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[StateprovinceFields, StateprovinceRow] = { + DeleteBuilder("person.stateprovince", StateprovinceFields) + } + override def insert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, StateprovinceRow] = { + sql"""insert into person.stateprovince("stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, ${Segment.paramSegment(unsaved.stateprovincecode)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, ${Segment.paramSegment(unsaved.isonlystateprovinceflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text + """.insertReturning(StateprovinceRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: StateprovinceRowUnsaved): ZIO[ZConnection, Throwable, StateprovinceRow] = { + val fs = List( + Some((sql""""stateprovincecode"""", sql"${Segment.paramSegment(unsaved.stateprovincecode)(Setter.stringSetter)}::bpchar")), + Some((sql""""countryregioncode"""", sql"${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""territoryid"""", sql"${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4")), + unsaved.stateprovinceid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""stateprovinceid"""", sql"${Segment.paramSegment(value: StateprovinceId)(StateprovinceId.setter)}::int4")) + }, + unsaved.isonlystateprovinceflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""isonlystateprovinceflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into person.stateprovince default values + returning "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into person.stateprovince($names) values ($values) returning "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(StateprovinceRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[StateprovinceFields, StateprovinceRow] = { + SelectBuilderSql("person.stateprovince", StateprovinceFields, StateprovinceRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, StateprovinceRow] = { + sql"""select "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text from person.stateprovince""".query(StateprovinceRow.jdbcDecoder).selectStream + } + override def selectById(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Option[StateprovinceRow]] = { + sql"""select "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text from person.stateprovince where "stateprovinceid" = ${Segment.paramSegment(stateprovinceid)(StateprovinceId.setter)}""".query(StateprovinceRow.jdbcDecoder).selectOne + } + override def selectByIds(stateprovinceids: Array[StateprovinceId]): ZStream[ZConnection, Throwable, StateprovinceRow] = { + sql"""select "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text from person.stateprovince where "stateprovinceid" = ANY(${Segment.paramSegment(stateprovinceids)(StateprovinceId.arraySetter)})""".query(StateprovinceRow.jdbcDecoder).selectStream + } + override def update(row: StateprovinceRow): ZIO[ZConnection, Throwable, Boolean] = { + val stateprovinceid = row.stateprovinceid + sql"""update person.stateprovince + set "stateprovincecode" = ${Segment.paramSegment(row.stateprovincecode)(Setter.stringSetter)}::bpchar, + "countryregioncode" = ${Segment.paramSegment(row.countryregioncode)(CountryregionId.setter)}, + "isonlystateprovinceflag" = ${Segment.paramSegment(row.isonlystateprovinceflag)(Flag.setter)}::bool, + "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "territoryid" = ${Segment.paramSegment(row.territoryid)(SalesterritoryId.setter)}::int4, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "stateprovinceid" = ${Segment.paramSegment(stateprovinceid)(StateprovinceId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[StateprovinceFields, StateprovinceRow] = { + UpdateBuilder("person.stateprovince", StateprovinceFields, StateprovinceRow.jdbcDecoder) + } + override def upsert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, UpdateResult[StateprovinceRow]] = { + sql"""insert into person.stateprovince("stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, + ${Segment.paramSegment(unsaved.stateprovincecode)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, + ${Segment.paramSegment(unsaved.isonlystateprovinceflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("stateprovinceid") + do update set + "stateprovincecode" = EXCLUDED."stateprovincecode", + "countryregioncode" = EXCLUDED."countryregioncode", + "isonlystateprovinceflag" = EXCLUDED."isonlystateprovinceflag", + "name" = EXCLUDED."name", + "territoryid" = EXCLUDED."territoryid", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "stateprovinceid", "stateprovincecode", "countryregioncode", "isonlystateprovinceflag", "name", "territoryid", "rowguid", "modifieddate"::text""".insertReturning(StateprovinceRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoMock.scala new file mode 100644 index 0000000000..e2510d754d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class StateprovinceRepoMock(toRow: Function1[StateprovinceRowUnsaved, StateprovinceRow], + map: scala.collection.mutable.Map[StateprovinceId, StateprovinceRow] = scala.collection.mutable.Map.empty) extends StateprovinceRepo { + override def delete(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(stateprovinceid).isDefined) + } + override def delete: DeleteBuilder[StateprovinceFields, StateprovinceRow] = { + DeleteBuilderMock(DeleteParams.empty, StateprovinceFields, map) + } + override def insert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, StateprovinceRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.stateprovinceid)) + sys.error(s"id ${unsaved.stateprovinceid} already exists") + else + map.put(unsaved.stateprovinceid, unsaved) + + unsaved + } + } + override def insert(unsaved: StateprovinceRowUnsaved): ZIO[ZConnection, Throwable, StateprovinceRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[StateprovinceFields, StateprovinceRow] = { + SelectBuilderMock(StateprovinceFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, StateprovinceRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(stateprovinceid: StateprovinceId): ZIO[ZConnection, Throwable, Option[StateprovinceRow]] = { + ZIO.succeed(map.get(stateprovinceid)) + } + override def selectByIds(stateprovinceids: Array[StateprovinceId]): ZStream[ZConnection, Throwable, StateprovinceRow] = { + ZStream.fromIterable(stateprovinceids.flatMap(map.get)) + } + override def update(row: StateprovinceRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.stateprovinceid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.stateprovinceid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[StateprovinceFields, StateprovinceRow] = { + UpdateBuilderMock(UpdateParams.empty, StateprovinceFields, map) + } + override def upsert(unsaved: StateprovinceRow): ZIO[ZConnection, Throwable, UpdateResult[StateprovinceRow]] = { + ZIO.succeed { + map.put(unsaved.stateprovinceid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRow.scala new file mode 100644 index 0000000000..b66425ac0b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRow.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class StateprovinceRow( + /** Primary key for StateProvince records. */ + stateprovinceid: StateprovinceId, + /** ISO standard state or province code. */ + stateprovincecode: /* bpchar, max 3 chars */ String, + /** ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. + Points to [[countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** 0 = StateProvinceCode exists. 1 = StateProvinceCode unavailable, using CountryRegionCode. */ + isonlystateprovinceflag: Flag, + /** State or province description. */ + name: Name, + /** ID of the territory in which the state or province is located. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[sales.salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: SalesterritoryId, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object StateprovinceRow { + implicit lazy val jdbcDecoder: JdbcDecoder[StateprovinceRow] = new JdbcDecoder[StateprovinceRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, StateprovinceRow) = + columIndex + 7 -> + StateprovinceRow( + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stateprovincecode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + isonlystateprovinceflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[StateprovinceRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val stateprovincecode = jsonObj.get("stateprovincecode").toRight("Missing field 'stateprovincecode'").flatMap(_.as(JsonDecoder.string)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val isonlystateprovinceflag = jsonObj.get("isonlystateprovinceflag").toRight("Missing field 'isonlystateprovinceflag'").flatMap(_.as(Flag.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (stateprovinceid.isRight && stateprovincecode.isRight && countryregioncode.isRight && isonlystateprovinceflag.isRight && name.isRight && territoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(StateprovinceRow(stateprovinceid = stateprovinceid.toOption.get, stateprovincecode = stateprovincecode.toOption.get, countryregioncode = countryregioncode.toOption.get, isonlystateprovinceflag = isonlystateprovinceflag.toOption.get, name = name.toOption.get, territoryid = territoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](stateprovinceid, stateprovincecode, countryregioncode, isonlystateprovinceflag, name, territoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[StateprovinceRow] = new JsonEncoder[StateprovinceRow] { + override def unsafeEncode(a: StateprovinceRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""stateprovincecode":""") + JsonEncoder.string.unsafeEncode(a.stateprovincecode, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""isonlystateprovinceflag":""") + Flag.jsonEncoder.unsafeEncode(a.isonlystateprovinceflag, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRowUnsaved.scala new file mode 100644 index 0000000000..a42c899150 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceRowUnsaved.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `person.stateprovince` which has not been persisted yet */ +case class StateprovinceRowUnsaved( + /** ISO standard state or province code. */ + stateprovincecode: /* bpchar, max 3 chars */ String, + /** ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. + Points to [[countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** State or province description. */ + name: Name, + /** ID of the territory in which the state or province is located. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[sales.salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Default: nextval('person.stateprovince_stateprovinceid_seq'::regclass) + Primary key for StateProvince records. */ + stateprovinceid: Defaulted[StateprovinceId] = Defaulted.UseDefault, + /** Default: true + 0 = StateProvinceCode exists. 1 = StateProvinceCode unavailable, using CountryRegionCode. */ + isonlystateprovinceflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(stateprovinceidDefault: => StateprovinceId, isonlystateprovinceflagDefault: => Flag, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): StateprovinceRow = + StateprovinceRow( + stateprovincecode = stateprovincecode, + countryregioncode = countryregioncode, + name = name, + territoryid = territoryid, + stateprovinceid = stateprovinceid match { + case Defaulted.UseDefault => stateprovinceidDefault + case Defaulted.Provided(value) => value + }, + isonlystateprovinceflag = isonlystateprovinceflag match { + case Defaulted.UseDefault => isonlystateprovinceflagDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object StateprovinceRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[StateprovinceRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val stateprovincecode = jsonObj.get("stateprovincecode").toRight("Missing field 'stateprovincecode'").flatMap(_.as(JsonDecoder.string)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(Defaulted.jsonDecoder(StateprovinceId.jsonDecoder))) + val isonlystateprovinceflag = jsonObj.get("isonlystateprovinceflag").toRight("Missing field 'isonlystateprovinceflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (stateprovincecode.isRight && countryregioncode.isRight && name.isRight && territoryid.isRight && stateprovinceid.isRight && isonlystateprovinceflag.isRight && rowguid.isRight && modifieddate.isRight) + Right(StateprovinceRowUnsaved(stateprovincecode = stateprovincecode.toOption.get, countryregioncode = countryregioncode.toOption.get, name = name.toOption.get, territoryid = territoryid.toOption.get, stateprovinceid = stateprovinceid.toOption.get, isonlystateprovinceflag = isonlystateprovinceflag.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](stateprovincecode, countryregioncode, name, territoryid, stateprovinceid, isonlystateprovinceflag, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[StateprovinceRowUnsaved] = new JsonEncoder[StateprovinceRowUnsaved] { + override def unsafeEncode(a: StateprovinceRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""stateprovincecode":""") + JsonEncoder.string.unsafeEncode(a.stateprovincecode, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + Defaulted.jsonEncoder(StateprovinceId.jsonEncoder).unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""isonlystateprovinceflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.isonlystateprovinceflag, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceStructure.scala new file mode 100644 index 0000000000..269d64f176 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/stateprovince/StateprovinceStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package stateprovince + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class StateprovinceStructure[Row](val prefix: Option[String], val extract: Row => StateprovinceRow, val merge: (Row, StateprovinceRow) => Row) + extends Relation[StateprovinceFields, StateprovinceRow, Row] + with StateprovinceFields[Row] { outer => + + override val stateprovinceid = new IdField[StateprovinceId, Row](prefix, "stateprovinceid", None, Some("int4"))(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val stateprovincecode = new Field[/* bpchar, max 3 chars */ String, Row](prefix, "stateprovincecode", None, Some("bpchar"))(x => extract(x).stateprovincecode, (row, value) => merge(row, extract(row).copy(stateprovincecode = value))) + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val isonlystateprovinceflag = new Field[Flag, Row](prefix, "isonlystateprovinceflag", None, Some("bool"))(x => extract(x).isonlystateprovinceflag, (row, value) => merge(row, extract(row).copy(isonlystateprovinceflag = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val territoryid = new Field[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](stateprovinceid, stateprovincecode, countryregioncode, isonlystateprovinceflag, name, territoryid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => StateprovinceRow, merge: (NewRow, StateprovinceRow) => NewRow): StateprovinceStructure[NewRow] = + new StateprovinceStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewFields.scala new file mode 100644 index 0000000000..c138112fbb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewFields.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vadditionalcontactinfo + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VadditionalcontactinfoViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val telephonenumber: OptField[TypoXml, Row] + val telephonespecialinstructions: OptField[String, Row] + val street: OptField[TypoXml, Row] + val city: OptField[TypoXml, Row] + val stateprovince: OptField[TypoXml, Row] + val postalcode: OptField[TypoXml, Row] + val countryregion: OptField[TypoXml, Row] + val homeaddressspecialinstructions: OptField[TypoXml, Row] + val emailaddress: OptField[TypoXml, Row] + val emailspecialinstructions: OptField[String, Row] + val emailtelephonenumber: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VadditionalcontactinfoViewFields extends VadditionalcontactinfoViewStructure[VadditionalcontactinfoViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepo.scala new file mode 100644 index 0000000000..74e774af44 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vadditionalcontactinfo + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VadditionalcontactinfoViewRepo { + def select: SelectBuilder[VadditionalcontactinfoViewFields, VadditionalcontactinfoViewRow] + def selectAll: ZStream[ZConnection, Throwable, VadditionalcontactinfoViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepoImpl.scala new file mode 100644 index 0000000000..28f34639a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vadditionalcontactinfo + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VadditionalcontactinfoViewRepoImpl extends VadditionalcontactinfoViewRepo { + override def select: SelectBuilder[VadditionalcontactinfoViewFields, VadditionalcontactinfoViewRow] = { + SelectBuilderSql("person.vadditionalcontactinfo", VadditionalcontactinfoViewFields, VadditionalcontactinfoViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VadditionalcontactinfoViewRow] = { + sql"""select "businessentityid", "firstname", "middlename", "lastname", "telephonenumber", "telephonespecialinstructions", "street", "city", "stateprovince", "postalcode", "countryregion", "homeaddressspecialinstructions", "emailaddress", "emailspecialinstructions", "emailtelephonenumber", "rowguid", "modifieddate"::text from person.vadditionalcontactinfo""".query(VadditionalcontactinfoViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRow.scala new file mode 100644 index 0000000000..3dec873329 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewRow.scala @@ -0,0 +1,151 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vadditionalcontactinfo + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VadditionalcontactinfoViewRow( + /** Points to [[person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.PersonRow.lastname]] */ + lastname: Name, + telephonenumber: /* nullability unknown */ Option[TypoXml], + telephonespecialinstructions: /* nullability unknown */ Option[String], + street: /* nullability unknown */ Option[TypoXml], + city: /* nullability unknown */ Option[TypoXml], + stateprovince: /* nullability unknown */ Option[TypoXml], + postalcode: /* nullability unknown */ Option[TypoXml], + countryregion: /* nullability unknown */ Option[TypoXml], + homeaddressspecialinstructions: /* nullability unknown */ Option[TypoXml], + emailaddress: /* nullability unknown */ Option[TypoXml], + emailspecialinstructions: /* nullability unknown */ Option[String], + emailtelephonenumber: /* nullability unknown */ Option[TypoXml], + /** Points to [[person.PersonRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[person.PersonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object VadditionalcontactinfoViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VadditionalcontactinfoViewRow] = new JdbcDecoder[VadditionalcontactinfoViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VadditionalcontactinfoViewRow) = + columIndex + 16 -> + VadditionalcontactinfoViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + telephonenumber = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + telephonespecialinstructions = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + street = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + city = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + stateprovince = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + postalcode = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + countryregion = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + homeaddressspecialinstructions = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + emailspecialinstructions = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + emailtelephonenumber = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 14, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VadditionalcontactinfoViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val telephonenumber = jsonObj.get("telephonenumber").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val telephonespecialinstructions = jsonObj.get("telephonespecialinstructions").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val street = jsonObj.get("street").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val city = jsonObj.get("city").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val stateprovince = jsonObj.get("stateprovince").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val postalcode = jsonObj.get("postalcode").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val countryregion = jsonObj.get("countryregion").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val homeaddressspecialinstructions = jsonObj.get("homeaddressspecialinstructions").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val emailspecialinstructions = jsonObj.get("emailspecialinstructions").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailtelephonenumber = jsonObj.get("emailtelephonenumber").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && firstname.isRight && middlename.isRight && lastname.isRight && telephonenumber.isRight && telephonespecialinstructions.isRight && street.isRight && city.isRight && stateprovince.isRight && postalcode.isRight && countryregion.isRight && homeaddressspecialinstructions.isRight && emailaddress.isRight && emailspecialinstructions.isRight && emailtelephonenumber.isRight && rowguid.isRight && modifieddate.isRight) + Right(VadditionalcontactinfoViewRow(businessentityid = businessentityid.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, telephonenumber = telephonenumber.toOption.get, telephonespecialinstructions = telephonespecialinstructions.toOption.get, street = street.toOption.get, city = city.toOption.get, stateprovince = stateprovince.toOption.get, postalcode = postalcode.toOption.get, countryregion = countryregion.toOption.get, homeaddressspecialinstructions = homeaddressspecialinstructions.toOption.get, emailaddress = emailaddress.toOption.get, emailspecialinstructions = emailspecialinstructions.toOption.get, emailtelephonenumber = emailtelephonenumber.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, firstname, middlename, lastname, telephonenumber, telephonespecialinstructions, street, city, stateprovince, postalcode, countryregion, homeaddressspecialinstructions, emailaddress, emailspecialinstructions, emailtelephonenumber, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VadditionalcontactinfoViewRow] = new JsonEncoder[VadditionalcontactinfoViewRow] { + override def unsafeEncode(a: VadditionalcontactinfoViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""telephonenumber":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.telephonenumber, indent, out) + out.write(",") + out.write(""""telephonespecialinstructions":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.telephonespecialinstructions, indent, out) + out.write(",") + out.write(""""street":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.street, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovince":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.stateprovince, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregion":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.countryregion, indent, out) + out.write(",") + out.write(""""homeaddressspecialinstructions":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.homeaddressspecialinstructions, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailspecialinstructions":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailspecialinstructions, indent, out) + out.write(",") + out.write(""""emailtelephonenumber":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.emailtelephonenumber, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewStructure.scala new file mode 100644 index 0000000000..41f1bb48d2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vadditionalcontactinfo/VadditionalcontactinfoViewStructure.scala @@ -0,0 +1,48 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vadditionalcontactinfo + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VadditionalcontactinfoViewStructure[Row](val prefix: Option[String], val extract: Row => VadditionalcontactinfoViewRow, val merge: (Row, VadditionalcontactinfoViewRow) => Row) + extends Relation[VadditionalcontactinfoViewFields, VadditionalcontactinfoViewRow, Row] + with VadditionalcontactinfoViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val telephonenumber = new OptField[TypoXml, Row](prefix, "telephonenumber", None, None)(x => extract(x).telephonenumber, (row, value) => merge(row, extract(row).copy(telephonenumber = value))) + override val telephonespecialinstructions = new OptField[String, Row](prefix, "telephonespecialinstructions", None, None)(x => extract(x).telephonespecialinstructions, (row, value) => merge(row, extract(row).copy(telephonespecialinstructions = value))) + override val street = new OptField[TypoXml, Row](prefix, "street", None, None)(x => extract(x).street, (row, value) => merge(row, extract(row).copy(street = value))) + override val city = new OptField[TypoXml, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovince = new OptField[TypoXml, Row](prefix, "stateprovince", None, None)(x => extract(x).stateprovince, (row, value) => merge(row, extract(row).copy(stateprovince = value))) + override val postalcode = new OptField[TypoXml, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregion = new OptField[TypoXml, Row](prefix, "countryregion", None, None)(x => extract(x).countryregion, (row, value) => merge(row, extract(row).copy(countryregion = value))) + override val homeaddressspecialinstructions = new OptField[TypoXml, Row](prefix, "homeaddressspecialinstructions", None, None)(x => extract(x).homeaddressspecialinstructions, (row, value) => merge(row, extract(row).copy(homeaddressspecialinstructions = value))) + override val emailaddress = new OptField[TypoXml, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailspecialinstructions = new OptField[String, Row](prefix, "emailspecialinstructions", None, None)(x => extract(x).emailspecialinstructions, (row, value) => merge(row, extract(row).copy(emailspecialinstructions = value))) + override val emailtelephonenumber = new OptField[TypoXml, Row](prefix, "emailtelephonenumber", None, None)(x => extract(x).emailtelephonenumber, (row, value) => merge(row, extract(row).copy(emailtelephonenumber = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, firstname, middlename, lastname, telephonenumber, telephonespecialinstructions, street, city, stateprovince, postalcode, countryregion, homeaddressspecialinstructions, emailaddress, emailspecialinstructions, emailtelephonenumber, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VadditionalcontactinfoViewRow, merge: (NewRow, VadditionalcontactinfoViewRow) => NewRow): VadditionalcontactinfoViewStructure[NewRow] = + new VadditionalcontactinfoViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVFields.scala new file mode 100644 index 0000000000..0f86db826d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vstateprovincecountryregion + +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field + +trait VstateprovincecountryregionMVFields[Row] { + val stateprovinceid: Field[StateprovinceId, Row] + val stateprovincecode: Field[/* bpchar, max 3 chars */ String, Row] + val isonlystateprovinceflag: Field[Flag, Row] + val stateprovincename: Field[Name, Row] + val territoryid: Field[SalesterritoryId, Row] + val countryregioncode: Field[CountryregionId, Row] + val countryregionname: Field[Name, Row] +} +object VstateprovincecountryregionMVFields extends VstateprovincecountryregionMVStructure[VstateprovincecountryregionMVRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepo.scala new file mode 100644 index 0000000000..d725effbfa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vstateprovincecountryregion + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VstateprovincecountryregionMVRepo { + def select: SelectBuilder[VstateprovincecountryregionMVFields, VstateprovincecountryregionMVRow] + def selectAll: ZStream[ZConnection, Throwable, VstateprovincecountryregionMVRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepoImpl.scala new file mode 100644 index 0000000000..474eb10755 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vstateprovincecountryregion + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VstateprovincecountryregionMVRepoImpl extends VstateprovincecountryregionMVRepo { + override def select: SelectBuilder[VstateprovincecountryregionMVFields, VstateprovincecountryregionMVRow] = { + SelectBuilderSql("person.vstateprovincecountryregion", VstateprovincecountryregionMVFields, VstateprovincecountryregionMVRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VstateprovincecountryregionMVRow] = { + sql"""select "stateprovinceid", "stateprovincecode", "isonlystateprovinceflag", "stateprovincename", "territoryid", "countryregioncode", "countryregionname" from person.vstateprovincecountryregion""".query(VstateprovincecountryregionMVRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRow.scala new file mode 100644 index 0000000000..644f79dc28 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vstateprovincecountryregion + +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VstateprovincecountryregionMVRow( + /** Points to [[stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Points to [[stateprovince.StateprovinceRow.stateprovincecode]] */ + stateprovincecode: /* bpchar, max 3 chars */ String, + /** Points to [[stateprovince.StateprovinceRow.isonlystateprovinceflag]] */ + isonlystateprovinceflag: Flag, + /** Points to [[stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[stateprovince.StateprovinceRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Points to [[countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Points to [[countryregion.CountryregionRow.name]] */ + countryregionname: Name +) + +object VstateprovincecountryregionMVRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VstateprovincecountryregionMVRow] = new JdbcDecoder[VstateprovincecountryregionMVRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VstateprovincecountryregionMVRow) = + columIndex + 6 -> + VstateprovincecountryregionMVRow( + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stateprovincecode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + isonlystateprovinceflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VstateprovincecountryregionMVRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val stateprovincecode = jsonObj.get("stateprovincecode").toRight("Missing field 'stateprovincecode'").flatMap(_.as(JsonDecoder.string)) + val isonlystateprovinceflag = jsonObj.get("isonlystateprovinceflag").toRight("Missing field 'isonlystateprovinceflag'").flatMap(_.as(Flag.jsonDecoder)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + if (stateprovinceid.isRight && stateprovincecode.isRight && isonlystateprovinceflag.isRight && stateprovincename.isRight && territoryid.isRight && countryregioncode.isRight && countryregionname.isRight) + Right(VstateprovincecountryregionMVRow(stateprovinceid = stateprovinceid.toOption.get, stateprovincecode = stateprovincecode.toOption.get, isonlystateprovinceflag = isonlystateprovinceflag.toOption.get, stateprovincename = stateprovincename.toOption.get, territoryid = territoryid.toOption.get, countryregioncode = countryregioncode.toOption.get, countryregionname = countryregionname.toOption.get)) + else Left(List[Either[String, Any]](stateprovinceid, stateprovincecode, isonlystateprovinceflag, stateprovincename, territoryid, countryregioncode, countryregionname).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VstateprovincecountryregionMVRow] = new JsonEncoder[VstateprovincecountryregionMVRow] { + override def unsafeEncode(a: VstateprovincecountryregionMVRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""stateprovincecode":""") + JsonEncoder.string.unsafeEncode(a.stateprovincecode, indent, out) + out.write(",") + out.write(""""isonlystateprovinceflag":""") + Flag.jsonEncoder.unsafeEncode(a.isonlystateprovinceflag, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVStructure.scala new file mode 100644 index 0000000000..13c82bdeb1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person/vstateprovincecountryregion/VstateprovincecountryregionMVStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person +package vstateprovincecountryregion + +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Flag +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class VstateprovincecountryregionMVStructure[Row](val prefix: Option[String], val extract: Row => VstateprovincecountryregionMVRow, val merge: (Row, VstateprovincecountryregionMVRow) => Row) + extends Relation[VstateprovincecountryregionMVFields, VstateprovincecountryregionMVRow, Row] + with VstateprovincecountryregionMVFields[Row] { outer => + + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, None)(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val stateprovincecode = new Field[/* bpchar, max 3 chars */ String, Row](prefix, "stateprovincecode", None, None)(x => extract(x).stateprovincecode, (row, value) => merge(row, extract(row).copy(stateprovincecode = value))) + override val isonlystateprovinceflag = new Field[Flag, Row](prefix, "isonlystateprovinceflag", None, None)(x => extract(x).isonlystateprovinceflag, (row, value) => merge(row, extract(row).copy(isonlystateprovinceflag = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val territoryid = new Field[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](stateprovinceid, stateprovincecode, isonlystateprovinceflag, stateprovincename, territoryid, countryregioncode, countryregionname) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VstateprovincecountryregionMVRow, merge: (NewRow, VstateprovincecountryregionMVRow) => NewRow): VstateprovincecountryregionMVStructure[NewRow] = + new VstateprovincecountryregionMVStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepo.scala new file mode 100644 index 0000000000..216ae046bc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepo.scala @@ -0,0 +1,16 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_detail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonDetailSqlRepo { + def apply(businessentityid: /* user-picked */ BusinessentityId, modifiedAfter: TypoLocalDateTime): ZStream[ZConnection, Throwable, PersonDetailSqlRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepoImpl.scala new file mode 100644 index 0000000000..a01a98f3ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRepoImpl.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_detail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonDetailSqlRepoImpl extends PersonDetailSqlRepo { + override def apply(businessentityid: /* user-picked */ BusinessentityId, modifiedAfter: TypoLocalDateTime): ZStream[ZConnection, Throwable, PersonDetailSqlRow] = { + val sql = + sql"""SELECT s.businessentityid, + p.title, + p.firstname, + p.middlename, + p.lastname, + e.jobtitle, + a.addressline1, + a.city, + a.postalcode, + a.rowguid as "rowguid:java.lang.String!" + FROM sales.salesperson s + JOIN humanresources.employee e ON e.businessentityid = s.businessentityid + JOIN person.person p ON p.businessentityid = s.businessentityid + JOIN person.businessentityaddress bea ON bea.businessentityid = s.businessentityid + LEFT JOIN person.address a ON a.addressid = bea.addressid + where s.businessentityid = ${Segment.paramSegment(businessentityid)(/* user-picked */ BusinessentityId.setter)}::int4 + and p.modifieddate > ${Segment.paramSegment(modifiedAfter)(TypoLocalDateTime.setter)}::timestamp""" + sql.query(PersonDetailSqlRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRow.scala new file mode 100644 index 0000000000..63ada32ddd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_detail/PersonDetailSqlRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_detail + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonDetailSqlRow( + /** Points to [[sales.salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[humanresources.employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: Option[/* max 30 chars */ String], + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: Option[/* max 15 chars */ String], + /** Points to [[person.address.AddressRow.rowguid]] */ + rowguid: /* user-picked */ String +) + +object PersonDetailSqlRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonDetailSqlRow] = new JdbcDecoder[PersonDetailSqlRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonDetailSqlRow) = + columIndex + 9 -> + PersonDetailSqlRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + addressline1 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + city = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + postalcode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + rowguid = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonDetailSqlRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val addressline1 = jsonObj.get("addressline1").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val postalcode = jsonObj.get("postalcode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(JsonDecoder.string)) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && jobtitle.isRight && addressline1.isRight && city.isRight && postalcode.isRight && rowguid.isRight) + Right(PersonDetailSqlRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, jobtitle = jobtitle.toOption.get, addressline1 = addressline1.toOption.get, city = city.toOption.get, postalcode = postalcode.toOption.get, rowguid = rowguid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, jobtitle, addressline1, city, postalcode, rowguid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonDetailSqlRow] = new JsonEncoder[PersonDetailSqlRow] { + override def unsafeEncode(a: PersonDetailSqlRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""rowguid":""") + JsonEncoder.string.unsafeEncode(a.rowguid, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepo.scala new file mode 100644 index 0000000000..a03c6075c6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepo.scala @@ -0,0 +1,14 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_dynamic + +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonDynamicSqlRepo { + def apply(firstName: Option[String]): ZStream[ZConnection, Throwable, PersonDynamicSqlRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepoImpl.scala new file mode 100644 index 0000000000..6c7da7ed26 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRepoImpl.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_dynamic + +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonDynamicSqlRepoImpl extends PersonDynamicSqlRepo { + override def apply(firstName: Option[String]): ZStream[ZConnection, Throwable, PersonDynamicSqlRow] = { + val sql = + sql"""SELECT p.title, p.firstname, p.middlename, p.lastname + FROM person.person p + WHERE ${Segment.paramSegment(firstName)(Setter.optionParamSetter(Setter.stringSetter))}::text IS NULL OR p.firstname = ${Segment.paramSegment(firstName)(Setter.optionParamSetter(Setter.stringSetter))} + """ + sql.query(PersonDynamicSqlRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRow.scala new file mode 100644 index 0000000000..a3c80e0249 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_dynamic/PersonDynamicSqlRow.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_dynamic + +import adventureworks.public.Name +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonDynamicSqlRow( + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name +) + +object PersonDynamicSqlRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonDynamicSqlRow] = new JdbcDecoder[PersonDynamicSqlRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonDynamicSqlRow) = + columIndex + 3 -> + PersonDynamicSqlRow( + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonDynamicSqlRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + if (title.isRight && firstname.isRight && middlename.isRight && lastname.isRight) + Right(PersonDynamicSqlRow(title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get)) + else Left(List[Either[String, Any]](title, firstname, middlename, lastname).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonDynamicSqlRow] = new JsonEncoder[PersonDynamicSqlRow] { + override def unsafeEncode(a: PersonDynamicSqlRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepo.scala new file mode 100644 index 0000000000..e8d824f6fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepo.scala @@ -0,0 +1,14 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_row_join + +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersonRowJoinSqlRepo { + def apply(): ZStream[ZConnection, Throwable, PersonRowJoinSqlRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepoImpl.scala new file mode 100644 index 0000000000..06a1b46473 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_row_join + +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersonRowJoinSqlRepoImpl extends PersonRowJoinSqlRepo { + override def apply(): ZStream[ZConnection, Throwable, PersonRowJoinSqlRow] = { + val sql = + sql"""SELECT s.businessentityid, + (select array_agg(ROW(a.emailaddress, a.rowguid)) from person.emailaddress a where a.businessentityid = s.businessentityid) as email, + (select ARRAY[ROW(a.emailaddress, a.rowguid)] from person.emailaddress a where a.businessentityid = s.businessentityid) as emails + FROM sales.salesperson s + """ + sql.query(PersonRowJoinSqlRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRow.scala new file mode 100644 index 0000000000..8398d4a5bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/person_row_join/PersonRowJoinSqlRow.scala @@ -0,0 +1,57 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package person_row_join + +import adventureworks.customtypes.TypoRecord +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersonRowJoinSqlRow( + /** Points to [[sales.salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + email: /* nullability unknown */ Option[Array[TypoRecord]], + emails: /* nullability unknown */ Option[Array[TypoRecord]] +) + +object PersonRowJoinSqlRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersonRowJoinSqlRow] = new JdbcDecoder[PersonRowJoinSqlRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersonRowJoinSqlRow) = + columIndex + 2 -> + PersonRowJoinSqlRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + email = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoRecord]]).unsafeDecode(columIndex + 1, rs)._2, + emails = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoRecord]]).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersonRowJoinSqlRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val email = jsonObj.get("email").fold[Either[String, Option[Array[TypoRecord]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoRecord](TypoRecord.jsonDecoder, implicitly)))) + val emails = jsonObj.get("emails").fold[Either[String, Option[Array[TypoRecord]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoRecord](TypoRecord.jsonDecoder, implicitly)))) + if (businessentityid.isRight && email.isRight && emails.isRight) + Right(PersonRowJoinSqlRow(businessentityid = businessentityid.toOption.get, email = email.toOption.get, emails = emails.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, email, emails).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersonRowJoinSqlRow] = new JsonEncoder[PersonRowJoinSqlRow] { + override def unsafeEncode(a: PersonRowJoinSqlRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""email":""") + JsonEncoder.option(JsonEncoder.array[TypoRecord](TypoRecord.jsonEncoder, implicitly)).unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""emails":""") + JsonEncoder.option(JsonEncoder.array[TypoRecord](TypoRecord.jsonEncoder, implicitly)).unsafeEncode(a.emails, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateFields.scala new file mode 100644 index 0000000000..80eff61d3b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateFields.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgAggregateFields[Row] { + val aggfnoid: IdField[PgAggregateId, Row] + val aggkind: Field[String, Row] + val aggnumdirectargs: Field[TypoShort, Row] + val aggtransfn: Field[TypoRegproc, Row] + val aggfinalfn: Field[TypoRegproc, Row] + val aggcombinefn: Field[TypoRegproc, Row] + val aggserialfn: Field[TypoRegproc, Row] + val aggdeserialfn: Field[TypoRegproc, Row] + val aggmtransfn: Field[TypoRegproc, Row] + val aggminvtransfn: Field[TypoRegproc, Row] + val aggmfinalfn: Field[TypoRegproc, Row] + val aggfinalextra: Field[Boolean, Row] + val aggmfinalextra: Field[Boolean, Row] + val aggfinalmodify: Field[String, Row] + val aggmfinalmodify: Field[String, Row] + val aggsortop: Field[/* oid */ Long, Row] + val aggtranstype: Field[/* oid */ Long, Row] + val aggtransspace: Field[Int, Row] + val aggmtranstype: Field[/* oid */ Long, Row] + val aggmtransspace: Field[Int, Row] + val agginitval: OptField[String, Row] + val aggminitval: OptField[String, Row] +} +object PgAggregateFields extends PgAggregateStructure[PgAggregateRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateId.scala new file mode 100644 index 0000000000..87e0fe6c95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateId.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import adventureworks.customtypes.TypoRegproc +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 `pg_catalog.pg_aggregate` */ +case class PgAggregateId(value: TypoRegproc) extends AnyVal +object PgAggregateId { + implicit lazy val arraySetter: Setter[Array[PgAggregateId]] = TypoRegproc.arraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAggregateId, TypoRegproc] = Bijection[PgAggregateId, TypoRegproc](_.value)(PgAggregateId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAggregateId] = TypoRegproc.jdbcDecoder.map(PgAggregateId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAggregateId] = TypoRegproc.jdbcEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAggregateId] = TypoRegproc.jsonDecoder.map(PgAggregateId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAggregateId] = TypoRegproc.jsonEncoder.contramap(_.value) + implicit def ordering(implicit O0: Ordering[TypoRegproc]): Ordering[PgAggregateId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAggregateId] = ParameterMetaData.instance[PgAggregateId](TypoRegproc.parameterMetadata.sqlType, TypoRegproc.parameterMetadata.jdbcType) + implicit lazy val setter: Setter[PgAggregateId] = TypoRegproc.setter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepo.scala new file mode 100644 index 0000000000..35e5c392b2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAggregateRepo { + def delete(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAggregateFields, PgAggregateRow] + def insert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, PgAggregateRow] + def select: SelectBuilder[PgAggregateFields, PgAggregateRow] + def selectAll: ZStream[ZConnection, Throwable, PgAggregateRow] + def selectById(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Option[PgAggregateRow]] + def selectByIds(aggfnoids: Array[PgAggregateId]): ZStream[ZConnection, Throwable, PgAggregateRow] + def update(row: PgAggregateRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAggregateFields, PgAggregateRow] + def upsert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, UpdateResult[PgAggregateRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoImpl.scala new file mode 100644 index 0000000000..e17138d047 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoImpl.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAggregateRepoImpl extends PgAggregateRepo { + override def delete(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_aggregate where "aggfnoid" = ${Segment.paramSegment(aggfnoid)(PgAggregateId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAggregateFields, PgAggregateRow] = { + DeleteBuilder("pg_catalog.pg_aggregate", PgAggregateFields) + } + override def insert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, PgAggregateRow] = { + sql"""insert into pg_catalog.pg_aggregate("aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval") + values (${Segment.paramSegment(unsaved.aggfnoid)(PgAggregateId.setter)}::regproc, ${Segment.paramSegment(unsaved.aggkind)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.aggnumdirectargs)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.aggtransfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggfinalfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggcombinefn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggserialfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggdeserialfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggmtransfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggminvtransfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggmfinalfn)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.aggfinalextra)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.aggmfinalextra)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.aggfinalmodify)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.aggmfinalmodify)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.aggsortop)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.aggtranstype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.aggtransspace)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.aggmtranstype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.aggmtransspace)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.agginitval)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.aggminitval)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval" + """.insertReturning(PgAggregateRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAggregateFields, PgAggregateRow] = { + SelectBuilderSql("pg_catalog.pg_aggregate", PgAggregateFields, PgAggregateRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAggregateRow] = { + sql"""select "aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval" from pg_catalog.pg_aggregate""".query(PgAggregateRow.jdbcDecoder).selectStream + } + override def selectById(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Option[PgAggregateRow]] = { + sql"""select "aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval" from pg_catalog.pg_aggregate where "aggfnoid" = ${Segment.paramSegment(aggfnoid)(PgAggregateId.setter)}""".query(PgAggregateRow.jdbcDecoder).selectOne + } + override def selectByIds(aggfnoids: Array[PgAggregateId]): ZStream[ZConnection, Throwable, PgAggregateRow] = { + sql"""select "aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval" from pg_catalog.pg_aggregate where "aggfnoid" = ANY(${Segment.paramSegment(aggfnoids)(PgAggregateId.arraySetter)})""".query(PgAggregateRow.jdbcDecoder).selectStream + } + override def update(row: PgAggregateRow): ZIO[ZConnection, Throwable, Boolean] = { + val aggfnoid = row.aggfnoid + sql"""update pg_catalog.pg_aggregate + set "aggkind" = ${Segment.paramSegment(row.aggkind)(Setter.stringSetter)}::char, + "aggnumdirectargs" = ${Segment.paramSegment(row.aggnumdirectargs)(TypoShort.setter)}::int2, + "aggtransfn" = ${Segment.paramSegment(row.aggtransfn)(TypoRegproc.setter)}::regproc, + "aggfinalfn" = ${Segment.paramSegment(row.aggfinalfn)(TypoRegproc.setter)}::regproc, + "aggcombinefn" = ${Segment.paramSegment(row.aggcombinefn)(TypoRegproc.setter)}::regproc, + "aggserialfn" = ${Segment.paramSegment(row.aggserialfn)(TypoRegproc.setter)}::regproc, + "aggdeserialfn" = ${Segment.paramSegment(row.aggdeserialfn)(TypoRegproc.setter)}::regproc, + "aggmtransfn" = ${Segment.paramSegment(row.aggmtransfn)(TypoRegproc.setter)}::regproc, + "aggminvtransfn" = ${Segment.paramSegment(row.aggminvtransfn)(TypoRegproc.setter)}::regproc, + "aggmfinalfn" = ${Segment.paramSegment(row.aggmfinalfn)(TypoRegproc.setter)}::regproc, + "aggfinalextra" = ${Segment.paramSegment(row.aggfinalextra)(Setter.booleanSetter)}, + "aggmfinalextra" = ${Segment.paramSegment(row.aggmfinalextra)(Setter.booleanSetter)}, + "aggfinalmodify" = ${Segment.paramSegment(row.aggfinalmodify)(Setter.stringSetter)}::char, + "aggmfinalmodify" = ${Segment.paramSegment(row.aggmfinalmodify)(Setter.stringSetter)}::char, + "aggsortop" = ${Segment.paramSegment(row.aggsortop)(Setter.longSetter)}::oid, + "aggtranstype" = ${Segment.paramSegment(row.aggtranstype)(Setter.longSetter)}::oid, + "aggtransspace" = ${Segment.paramSegment(row.aggtransspace)(Setter.intSetter)}::int4, + "aggmtranstype" = ${Segment.paramSegment(row.aggmtranstype)(Setter.longSetter)}::oid, + "aggmtransspace" = ${Segment.paramSegment(row.aggmtransspace)(Setter.intSetter)}::int4, + "agginitval" = ${Segment.paramSegment(row.agginitval)(Setter.optionParamSetter(Setter.stringSetter))}, + "aggminitval" = ${Segment.paramSegment(row.aggminitval)(Setter.optionParamSetter(Setter.stringSetter))} + where "aggfnoid" = ${Segment.paramSegment(aggfnoid)(PgAggregateId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAggregateFields, PgAggregateRow] = { + UpdateBuilder("pg_catalog.pg_aggregate", PgAggregateFields, PgAggregateRow.jdbcDecoder) + } + override def upsert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, UpdateResult[PgAggregateRow]] = { + sql"""insert into pg_catalog.pg_aggregate("aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval") + values ( + ${Segment.paramSegment(unsaved.aggfnoid)(PgAggregateId.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggkind)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.aggnumdirectargs)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.aggtransfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggfinalfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggcombinefn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggserialfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggdeserialfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggmtransfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggminvtransfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggmfinalfn)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.aggfinalextra)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.aggmfinalextra)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.aggfinalmodify)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.aggmfinalmodify)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.aggsortop)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.aggtranstype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.aggtransspace)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.aggmtranstype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.aggmtransspace)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.agginitval)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.aggminitval)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("aggfnoid") + do update set + "aggkind" = EXCLUDED."aggkind", + "aggnumdirectargs" = EXCLUDED."aggnumdirectargs", + "aggtransfn" = EXCLUDED."aggtransfn", + "aggfinalfn" = EXCLUDED."aggfinalfn", + "aggcombinefn" = EXCLUDED."aggcombinefn", + "aggserialfn" = EXCLUDED."aggserialfn", + "aggdeserialfn" = EXCLUDED."aggdeserialfn", + "aggmtransfn" = EXCLUDED."aggmtransfn", + "aggminvtransfn" = EXCLUDED."aggminvtransfn", + "aggmfinalfn" = EXCLUDED."aggmfinalfn", + "aggfinalextra" = EXCLUDED."aggfinalextra", + "aggmfinalextra" = EXCLUDED."aggmfinalextra", + "aggfinalmodify" = EXCLUDED."aggfinalmodify", + "aggmfinalmodify" = EXCLUDED."aggmfinalmodify", + "aggsortop" = EXCLUDED."aggsortop", + "aggtranstype" = EXCLUDED."aggtranstype", + "aggtransspace" = EXCLUDED."aggtransspace", + "aggmtranstype" = EXCLUDED."aggmtranstype", + "aggmtransspace" = EXCLUDED."aggmtransspace", + "agginitval" = EXCLUDED."agginitval", + "aggminitval" = EXCLUDED."aggminitval" + returning "aggfnoid", "aggkind", "aggnumdirectargs", "aggtransfn", "aggfinalfn", "aggcombinefn", "aggserialfn", "aggdeserialfn", "aggmtransfn", "aggminvtransfn", "aggmfinalfn", "aggfinalextra", "aggmfinalextra", "aggfinalmodify", "aggmfinalmodify", "aggsortop", "aggtranstype", "aggtransspace", "aggmtranstype", "aggmtransspace", "agginitval", "aggminitval"""".insertReturning(PgAggregateRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoMock.scala new file mode 100644 index 0000000000..83a40d1aca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAggregateRepoMock(map: scala.collection.mutable.Map[PgAggregateId, PgAggregateRow] = scala.collection.mutable.Map.empty) extends PgAggregateRepo { + override def delete(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(aggfnoid).isDefined) + } + override def delete: DeleteBuilder[PgAggregateFields, PgAggregateRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAggregateFields, map) + } + override def insert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, PgAggregateRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.aggfnoid)) + sys.error(s"id ${unsaved.aggfnoid} already exists") + else + map.put(unsaved.aggfnoid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAggregateFields, PgAggregateRow] = { + SelectBuilderMock(PgAggregateFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAggregateRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(aggfnoid: PgAggregateId): ZIO[ZConnection, Throwable, Option[PgAggregateRow]] = { + ZIO.succeed(map.get(aggfnoid)) + } + override def selectByIds(aggfnoids: Array[PgAggregateId]): ZStream[ZConnection, Throwable, PgAggregateRow] = { + ZStream.fromIterable(aggfnoids.flatMap(map.get)) + } + override def update(row: PgAggregateRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.aggfnoid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.aggfnoid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAggregateFields, PgAggregateRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAggregateFields, map) + } + override def upsert(unsaved: PgAggregateRow): ZIO[ZConnection, Throwable, UpdateResult[PgAggregateRow]] = { + ZIO.succeed { + map.put(unsaved.aggfnoid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRow.scala new file mode 100644 index 0000000000..c12d168a28 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateRow.scala @@ -0,0 +1,171 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAggregateRow( + aggfnoid: PgAggregateId, + aggkind: String, + aggnumdirectargs: TypoShort, + aggtransfn: TypoRegproc, + aggfinalfn: TypoRegproc, + aggcombinefn: TypoRegproc, + aggserialfn: TypoRegproc, + aggdeserialfn: TypoRegproc, + aggmtransfn: TypoRegproc, + aggminvtransfn: TypoRegproc, + aggmfinalfn: TypoRegproc, + aggfinalextra: Boolean, + aggmfinalextra: Boolean, + aggfinalmodify: String, + aggmfinalmodify: String, + aggsortop: /* oid */ Long, + aggtranstype: /* oid */ Long, + aggtransspace: Int, + aggmtranstype: /* oid */ Long, + aggmtransspace: Int, + agginitval: Option[String], + aggminitval: Option[String] +) + +object PgAggregateRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAggregateRow] = new JdbcDecoder[PgAggregateRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAggregateRow) = + columIndex + 21 -> + PgAggregateRow( + aggfnoid = PgAggregateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + aggkind = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + aggnumdirectargs = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + aggtransfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + aggfinalfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + aggcombinefn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + aggserialfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + aggdeserialfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + aggmtransfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + aggminvtransfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + aggmfinalfn = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + aggfinalextra = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 11, rs)._2, + aggmfinalextra = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 12, rs)._2, + aggfinalmodify = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 13, rs)._2, + aggmfinalmodify = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 14, rs)._2, + aggsortop = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 15, rs)._2, + aggtranstype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 16, rs)._2, + aggtransspace = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 17, rs)._2, + aggmtranstype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 18, rs)._2, + aggmtransspace = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 19, rs)._2, + agginitval = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + aggminitval = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAggregateRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val aggfnoid = jsonObj.get("aggfnoid").toRight("Missing field 'aggfnoid'").flatMap(_.as(PgAggregateId.jsonDecoder)) + val aggkind = jsonObj.get("aggkind").toRight("Missing field 'aggkind'").flatMap(_.as(JsonDecoder.string)) + val aggnumdirectargs = jsonObj.get("aggnumdirectargs").toRight("Missing field 'aggnumdirectargs'").flatMap(_.as(TypoShort.jsonDecoder)) + val aggtransfn = jsonObj.get("aggtransfn").toRight("Missing field 'aggtransfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggfinalfn = jsonObj.get("aggfinalfn").toRight("Missing field 'aggfinalfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggcombinefn = jsonObj.get("aggcombinefn").toRight("Missing field 'aggcombinefn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggserialfn = jsonObj.get("aggserialfn").toRight("Missing field 'aggserialfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggdeserialfn = jsonObj.get("aggdeserialfn").toRight("Missing field 'aggdeserialfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggmtransfn = jsonObj.get("aggmtransfn").toRight("Missing field 'aggmtransfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggminvtransfn = jsonObj.get("aggminvtransfn").toRight("Missing field 'aggminvtransfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggmfinalfn = jsonObj.get("aggmfinalfn").toRight("Missing field 'aggmfinalfn'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val aggfinalextra = jsonObj.get("aggfinalextra").toRight("Missing field 'aggfinalextra'").flatMap(_.as(JsonDecoder.boolean)) + val aggmfinalextra = jsonObj.get("aggmfinalextra").toRight("Missing field 'aggmfinalextra'").flatMap(_.as(JsonDecoder.boolean)) + val aggfinalmodify = jsonObj.get("aggfinalmodify").toRight("Missing field 'aggfinalmodify'").flatMap(_.as(JsonDecoder.string)) + val aggmfinalmodify = jsonObj.get("aggmfinalmodify").toRight("Missing field 'aggmfinalmodify'").flatMap(_.as(JsonDecoder.string)) + val aggsortop = jsonObj.get("aggsortop").toRight("Missing field 'aggsortop'").flatMap(_.as(JsonDecoder.long)) + val aggtranstype = jsonObj.get("aggtranstype").toRight("Missing field 'aggtranstype'").flatMap(_.as(JsonDecoder.long)) + val aggtransspace = jsonObj.get("aggtransspace").toRight("Missing field 'aggtransspace'").flatMap(_.as(JsonDecoder.int)) + val aggmtranstype = jsonObj.get("aggmtranstype").toRight("Missing field 'aggmtranstype'").flatMap(_.as(JsonDecoder.long)) + val aggmtransspace = jsonObj.get("aggmtransspace").toRight("Missing field 'aggmtransspace'").flatMap(_.as(JsonDecoder.int)) + val agginitval = jsonObj.get("agginitval").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val aggminitval = jsonObj.get("aggminitval").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (aggfnoid.isRight && aggkind.isRight && aggnumdirectargs.isRight && aggtransfn.isRight && aggfinalfn.isRight && aggcombinefn.isRight && aggserialfn.isRight && aggdeserialfn.isRight && aggmtransfn.isRight && aggminvtransfn.isRight && aggmfinalfn.isRight && aggfinalextra.isRight && aggmfinalextra.isRight && aggfinalmodify.isRight && aggmfinalmodify.isRight && aggsortop.isRight && aggtranstype.isRight && aggtransspace.isRight && aggmtranstype.isRight && aggmtransspace.isRight && agginitval.isRight && aggminitval.isRight) + Right(PgAggregateRow(aggfnoid = aggfnoid.toOption.get, aggkind = aggkind.toOption.get, aggnumdirectargs = aggnumdirectargs.toOption.get, aggtransfn = aggtransfn.toOption.get, aggfinalfn = aggfinalfn.toOption.get, aggcombinefn = aggcombinefn.toOption.get, aggserialfn = aggserialfn.toOption.get, aggdeserialfn = aggdeserialfn.toOption.get, aggmtransfn = aggmtransfn.toOption.get, aggminvtransfn = aggminvtransfn.toOption.get, aggmfinalfn = aggmfinalfn.toOption.get, aggfinalextra = aggfinalextra.toOption.get, aggmfinalextra = aggmfinalextra.toOption.get, aggfinalmodify = aggfinalmodify.toOption.get, aggmfinalmodify = aggmfinalmodify.toOption.get, aggsortop = aggsortop.toOption.get, aggtranstype = aggtranstype.toOption.get, aggtransspace = aggtransspace.toOption.get, aggmtranstype = aggmtranstype.toOption.get, aggmtransspace = aggmtransspace.toOption.get, agginitval = agginitval.toOption.get, aggminitval = aggminitval.toOption.get)) + else Left(List[Either[String, Any]](aggfnoid, aggkind, aggnumdirectargs, aggtransfn, aggfinalfn, aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, aggminvtransfn, aggmfinalfn, aggfinalextra, aggmfinalextra, aggfinalmodify, aggmfinalmodify, aggsortop, aggtranstype, aggtransspace, aggmtranstype, aggmtransspace, agginitval, aggminitval).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAggregateRow] = new JsonEncoder[PgAggregateRow] { + override def unsafeEncode(a: PgAggregateRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""aggfnoid":""") + PgAggregateId.jsonEncoder.unsafeEncode(a.aggfnoid, indent, out) + out.write(",") + out.write(""""aggkind":""") + JsonEncoder.string.unsafeEncode(a.aggkind, indent, out) + out.write(",") + out.write(""""aggnumdirectargs":""") + TypoShort.jsonEncoder.unsafeEncode(a.aggnumdirectargs, indent, out) + out.write(",") + out.write(""""aggtransfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggtransfn, indent, out) + out.write(",") + out.write(""""aggfinalfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggfinalfn, indent, out) + out.write(",") + out.write(""""aggcombinefn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggcombinefn, indent, out) + out.write(",") + out.write(""""aggserialfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggserialfn, indent, out) + out.write(",") + out.write(""""aggdeserialfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggdeserialfn, indent, out) + out.write(",") + out.write(""""aggmtransfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggmtransfn, indent, out) + out.write(",") + out.write(""""aggminvtransfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggminvtransfn, indent, out) + out.write(",") + out.write(""""aggmfinalfn":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.aggmfinalfn, indent, out) + out.write(",") + out.write(""""aggfinalextra":""") + JsonEncoder.boolean.unsafeEncode(a.aggfinalextra, indent, out) + out.write(",") + out.write(""""aggmfinalextra":""") + JsonEncoder.boolean.unsafeEncode(a.aggmfinalextra, indent, out) + out.write(",") + out.write(""""aggfinalmodify":""") + JsonEncoder.string.unsafeEncode(a.aggfinalmodify, indent, out) + out.write(",") + out.write(""""aggmfinalmodify":""") + JsonEncoder.string.unsafeEncode(a.aggmfinalmodify, indent, out) + out.write(",") + out.write(""""aggsortop":""") + JsonEncoder.long.unsafeEncode(a.aggsortop, indent, out) + out.write(",") + out.write(""""aggtranstype":""") + JsonEncoder.long.unsafeEncode(a.aggtranstype, indent, out) + out.write(",") + out.write(""""aggtransspace":""") + JsonEncoder.int.unsafeEncode(a.aggtransspace, indent, out) + out.write(",") + out.write(""""aggmtranstype":""") + JsonEncoder.long.unsafeEncode(a.aggmtranstype, indent, out) + out.write(",") + out.write(""""aggmtransspace":""") + JsonEncoder.int.unsafeEncode(a.aggmtransspace, indent, out) + out.write(",") + out.write(""""agginitval":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.agginitval, indent, out) + out.write(",") + out.write(""""aggminitval":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.aggminitval, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateStructure.scala new file mode 100644 index 0000000000..c515c3f0f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_aggregate/PgAggregateStructure.scala @@ -0,0 +1,50 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_aggregate + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgAggregateStructure[Row](val prefix: Option[String], val extract: Row => PgAggregateRow, val merge: (Row, PgAggregateRow) => Row) + extends Relation[PgAggregateFields, PgAggregateRow, Row] + with PgAggregateFields[Row] { outer => + + override val aggfnoid = new IdField[PgAggregateId, Row](prefix, "aggfnoid", None, Some("regproc"))(x => extract(x).aggfnoid, (row, value) => merge(row, extract(row).copy(aggfnoid = value))) + override val aggkind = new Field[String, Row](prefix, "aggkind", None, Some("char"))(x => extract(x).aggkind, (row, value) => merge(row, extract(row).copy(aggkind = value))) + override val aggnumdirectargs = new Field[TypoShort, Row](prefix, "aggnumdirectargs", None, Some("int2"))(x => extract(x).aggnumdirectargs, (row, value) => merge(row, extract(row).copy(aggnumdirectargs = value))) + override val aggtransfn = new Field[TypoRegproc, Row](prefix, "aggtransfn", None, Some("regproc"))(x => extract(x).aggtransfn, (row, value) => merge(row, extract(row).copy(aggtransfn = value))) + override val aggfinalfn = new Field[TypoRegproc, Row](prefix, "aggfinalfn", None, Some("regproc"))(x => extract(x).aggfinalfn, (row, value) => merge(row, extract(row).copy(aggfinalfn = value))) + override val aggcombinefn = new Field[TypoRegproc, Row](prefix, "aggcombinefn", None, Some("regproc"))(x => extract(x).aggcombinefn, (row, value) => merge(row, extract(row).copy(aggcombinefn = value))) + override val aggserialfn = new Field[TypoRegproc, Row](prefix, "aggserialfn", None, Some("regproc"))(x => extract(x).aggserialfn, (row, value) => merge(row, extract(row).copy(aggserialfn = value))) + override val aggdeserialfn = new Field[TypoRegproc, Row](prefix, "aggdeserialfn", None, Some("regproc"))(x => extract(x).aggdeserialfn, (row, value) => merge(row, extract(row).copy(aggdeserialfn = value))) + override val aggmtransfn = new Field[TypoRegproc, Row](prefix, "aggmtransfn", None, Some("regproc"))(x => extract(x).aggmtransfn, (row, value) => merge(row, extract(row).copy(aggmtransfn = value))) + override val aggminvtransfn = new Field[TypoRegproc, Row](prefix, "aggminvtransfn", None, Some("regproc"))(x => extract(x).aggminvtransfn, (row, value) => merge(row, extract(row).copy(aggminvtransfn = value))) + override val aggmfinalfn = new Field[TypoRegproc, Row](prefix, "aggmfinalfn", None, Some("regproc"))(x => extract(x).aggmfinalfn, (row, value) => merge(row, extract(row).copy(aggmfinalfn = value))) + override val aggfinalextra = new Field[Boolean, Row](prefix, "aggfinalextra", None, None)(x => extract(x).aggfinalextra, (row, value) => merge(row, extract(row).copy(aggfinalextra = value))) + override val aggmfinalextra = new Field[Boolean, Row](prefix, "aggmfinalextra", None, None)(x => extract(x).aggmfinalextra, (row, value) => merge(row, extract(row).copy(aggmfinalextra = value))) + override val aggfinalmodify = new Field[String, Row](prefix, "aggfinalmodify", None, Some("char"))(x => extract(x).aggfinalmodify, (row, value) => merge(row, extract(row).copy(aggfinalmodify = value))) + override val aggmfinalmodify = new Field[String, Row](prefix, "aggmfinalmodify", None, Some("char"))(x => extract(x).aggmfinalmodify, (row, value) => merge(row, extract(row).copy(aggmfinalmodify = value))) + override val aggsortop = new Field[/* oid */ Long, Row](prefix, "aggsortop", None, Some("oid"))(x => extract(x).aggsortop, (row, value) => merge(row, extract(row).copy(aggsortop = value))) + override val aggtranstype = new Field[/* oid */ Long, Row](prefix, "aggtranstype", None, Some("oid"))(x => extract(x).aggtranstype, (row, value) => merge(row, extract(row).copy(aggtranstype = value))) + override val aggtransspace = new Field[Int, Row](prefix, "aggtransspace", None, Some("int4"))(x => extract(x).aggtransspace, (row, value) => merge(row, extract(row).copy(aggtransspace = value))) + override val aggmtranstype = new Field[/* oid */ Long, Row](prefix, "aggmtranstype", None, Some("oid"))(x => extract(x).aggmtranstype, (row, value) => merge(row, extract(row).copy(aggmtranstype = value))) + override val aggmtransspace = new Field[Int, Row](prefix, "aggmtransspace", None, Some("int4"))(x => extract(x).aggmtransspace, (row, value) => merge(row, extract(row).copy(aggmtransspace = value))) + override val agginitval = new OptField[String, Row](prefix, "agginitval", None, None)(x => extract(x).agginitval, (row, value) => merge(row, extract(row).copy(agginitval = value))) + override val aggminitval = new OptField[String, Row](prefix, "aggminitval", None, None)(x => extract(x).aggminitval, (row, value) => merge(row, extract(row).copy(aggminitval = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](aggfnoid, aggkind, aggnumdirectargs, aggtransfn, aggfinalfn, aggcombinefn, aggserialfn, aggdeserialfn, aggmtransfn, aggminvtransfn, aggmfinalfn, aggfinalextra, aggmfinalextra, aggfinalmodify, aggmfinalmodify, aggsortop, aggtranstype, aggtransspace, aggmtranstype, aggmtransspace, agginitval, aggminitval) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAggregateRow, merge: (NewRow, PgAggregateRow) => NewRow): PgAggregateStructure[NewRow] = + new PgAggregateStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmFields.scala new file mode 100644 index 0000000000..050868413b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgAmFields[Row] { + val oid: IdField[PgAmId, Row] + val amname: Field[String, Row] + val amhandler: Field[TypoRegproc, Row] + val amtype: Field[String, Row] +} +object PgAmFields extends PgAmStructure[PgAmRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmId.scala new file mode 100644 index 0000000000..8969eec42f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +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 `pg_catalog.pg_am` */ +case class PgAmId(value: /* oid */ Long) extends AnyVal +object PgAmId { + implicit lazy val arraySetter: Setter[Array[PgAmId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAmId, /* oid */ Long] = Bijection[PgAmId, /* oid */ Long](_.value)(PgAmId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmId] = JdbcDecoder.longDecoder.map(PgAmId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAmId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAmId] = JsonDecoder.long.map(PgAmId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAmId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgAmId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAmId] = ParameterMetaData.instance[PgAmId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgAmId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepo.scala new file mode 100644 index 0000000000..6a10852769 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAmRepo { + def delete(oid: PgAmId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAmFields, PgAmRow] + def insert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, PgAmRow] + def select: SelectBuilder[PgAmFields, PgAmRow] + def selectAll: ZStream[ZConnection, Throwable, PgAmRow] + def selectById(oid: PgAmId): ZIO[ZConnection, Throwable, Option[PgAmRow]] + def selectByIds(oids: Array[PgAmId]): ZStream[ZConnection, Throwable, PgAmRow] + def selectByUnique(amname: String): ZIO[ZConnection, Throwable, Option[PgAmRow]] + def update(row: PgAmRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAmFields, PgAmRow] + def upsert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoImpl.scala new file mode 100644 index 0000000000..9e44a641fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoImpl.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAmRepoImpl extends PgAmRepo { + override def delete(oid: PgAmId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_am where "oid" = ${Segment.paramSegment(oid)(PgAmId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAmFields, PgAmRow] = { + DeleteBuilder("pg_catalog.pg_am", PgAmFields) + } + override def insert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, PgAmRow] = { + sql"""insert into pg_catalog.pg_am("oid", "amname", "amhandler", "amtype") + values (${Segment.paramSegment(unsaved.oid)(PgAmId.setter)}::oid, ${Segment.paramSegment(unsaved.amname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.amhandler)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.amtype)(Setter.stringSetter)}::char) + returning "oid", "amname", "amhandler", "amtype" + """.insertReturning(PgAmRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAmFields, PgAmRow] = { + SelectBuilderSql("pg_catalog.pg_am", PgAmFields, PgAmRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmRow] = { + sql"""select "oid", "amname", "amhandler", "amtype" from pg_catalog.pg_am""".query(PgAmRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgAmId): ZIO[ZConnection, Throwable, Option[PgAmRow]] = { + sql"""select "oid", "amname", "amhandler", "amtype" from pg_catalog.pg_am where "oid" = ${Segment.paramSegment(oid)(PgAmId.setter)}""".query(PgAmRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgAmId]): ZStream[ZConnection, Throwable, PgAmRow] = { + sql"""select "oid", "amname", "amhandler", "amtype" from pg_catalog.pg_am where "oid" = ANY(${Segment.paramSegment(oids)(PgAmId.arraySetter)})""".query(PgAmRow.jdbcDecoder).selectStream + } + override def selectByUnique(amname: String): ZIO[ZConnection, Throwable, Option[PgAmRow]] = { + sql"""select "amname" + from pg_catalog.pg_am + where "amname" = ${Segment.paramSegment(amname)(Setter.stringSetter)} + """.query(PgAmRow.jdbcDecoder).selectOne + } + override def update(row: PgAmRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_am + set "amname" = ${Segment.paramSegment(row.amname)(Setter.stringSetter)}::name, + "amhandler" = ${Segment.paramSegment(row.amhandler)(TypoRegproc.setter)}::regproc, + "amtype" = ${Segment.paramSegment(row.amtype)(Setter.stringSetter)}::char + where "oid" = ${Segment.paramSegment(oid)(PgAmId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAmFields, PgAmRow] = { + UpdateBuilder("pg_catalog.pg_am", PgAmFields, PgAmRow.jdbcDecoder) + } + override def upsert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmRow]] = { + sql"""insert into pg_catalog.pg_am("oid", "amname", "amhandler", "amtype") + values ( + ${Segment.paramSegment(unsaved.oid)(PgAmId.setter)}::oid, + ${Segment.paramSegment(unsaved.amname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.amhandler)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.amtype)(Setter.stringSetter)}::char + ) + on conflict ("oid") + do update set + "amname" = EXCLUDED."amname", + "amhandler" = EXCLUDED."amhandler", + "amtype" = EXCLUDED."amtype" + returning "oid", "amname", "amhandler", "amtype"""".insertReturning(PgAmRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoMock.scala new file mode 100644 index 0000000000..fe6c9ee47a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAmRepoMock(map: scala.collection.mutable.Map[PgAmId, PgAmRow] = scala.collection.mutable.Map.empty) extends PgAmRepo { + override def delete(oid: PgAmId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgAmFields, PgAmRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAmFields, map) + } + override def insert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, PgAmRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAmFields, PgAmRow] = { + SelectBuilderMock(PgAmFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgAmId): ZIO[ZConnection, Throwable, Option[PgAmRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgAmId]): ZStream[ZConnection, Throwable, PgAmRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(amname: String): ZIO[ZConnection, Throwable, Option[PgAmRow]] = { + ZIO.succeed(map.values.find(v => amname == v.amname)) + } + override def update(row: PgAmRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAmFields, PgAmRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAmFields, map) + } + override def upsert(unsaved: PgAmRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRow.scala new file mode 100644 index 0000000000..f6050b49ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmRow.scala @@ -0,0 +1,62 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAmRow( + oid: PgAmId, + amname: String, + amhandler: TypoRegproc, + amtype: String +) + +object PgAmRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmRow] = new JdbcDecoder[PgAmRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAmRow) = + columIndex + 3 -> + PgAmRow( + oid = PgAmId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + amname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + amhandler = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + amtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAmRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAmId.jsonDecoder)) + val amname = jsonObj.get("amname").toRight("Missing field 'amname'").flatMap(_.as(JsonDecoder.string)) + val amhandler = jsonObj.get("amhandler").toRight("Missing field 'amhandler'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val amtype = jsonObj.get("amtype").toRight("Missing field 'amtype'").flatMap(_.as(JsonDecoder.string)) + if (oid.isRight && amname.isRight && amhandler.isRight && amtype.isRight) + Right(PgAmRow(oid = oid.toOption.get, amname = amname.toOption.get, amhandler = amhandler.toOption.get, amtype = amtype.toOption.get)) + else Left(List[Either[String, Any]](oid, amname, amhandler, amtype).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAmRow] = new JsonEncoder[PgAmRow] { + override def unsafeEncode(a: PgAmRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgAmId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""amname":""") + JsonEncoder.string.unsafeEncode(a.amname, indent, out) + out.write(",") + out.write(""""amhandler":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.amhandler, indent, out) + out.write(",") + out.write(""""amtype":""") + JsonEncoder.string.unsafeEncode(a.amtype, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmStructure.scala new file mode 100644 index 0000000000..15da084e4f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_am/PgAmStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_am + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgAmStructure[Row](val prefix: Option[String], val extract: Row => PgAmRow, val merge: (Row, PgAmRow) => Row) + extends Relation[PgAmFields, PgAmRow, Row] + with PgAmFields[Row] { outer => + + override val oid = new IdField[PgAmId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val amname = new Field[String, Row](prefix, "amname", None, Some("name"))(x => extract(x).amname, (row, value) => merge(row, extract(row).copy(amname = value))) + override val amhandler = new Field[TypoRegproc, Row](prefix, "amhandler", None, Some("regproc"))(x => extract(x).amhandler, (row, value) => merge(row, extract(row).copy(amhandler = value))) + override val amtype = new Field[String, Row](prefix, "amtype", None, Some("char"))(x => extract(x).amtype, (row, value) => merge(row, extract(row).copy(amtype = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, amname, amhandler, amtype) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAmRow, merge: (NewRow, PgAmRow) => NewRow): PgAmStructure[NewRow] = + new PgAmStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopFields.scala new file mode 100644 index 0000000000..09dd2cf774 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgAmopFields[Row] { + val oid: IdField[PgAmopId, Row] + val amopfamily: Field[/* oid */ Long, Row] + val amoplefttype: Field[/* oid */ Long, Row] + val amoprighttype: Field[/* oid */ Long, Row] + val amopstrategy: Field[TypoShort, Row] + val amoppurpose: Field[String, Row] + val amopopr: Field[/* oid */ Long, Row] + val amopmethod: Field[/* oid */ Long, Row] + val amopsortfamily: Field[/* oid */ Long, Row] +} +object PgAmopFields extends PgAmopStructure[PgAmopRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopId.scala new file mode 100644 index 0000000000..c44fc6d8bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +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 `pg_catalog.pg_amop` */ +case class PgAmopId(value: /* oid */ Long) extends AnyVal +object PgAmopId { + implicit lazy val arraySetter: Setter[Array[PgAmopId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAmopId, /* oid */ Long] = Bijection[PgAmopId, /* oid */ Long](_.value)(PgAmopId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmopId] = JdbcDecoder.longDecoder.map(PgAmopId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAmopId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAmopId] = JsonDecoder.long.map(PgAmopId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAmopId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgAmopId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAmopId] = ParameterMetaData.instance[PgAmopId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgAmopId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepo.scala new file mode 100644 index 0000000000..8dcba6e86f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepo.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAmopRepo { + def delete(oid: PgAmopId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAmopFields, PgAmopRow] + def insert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, PgAmopRow] + def select: SelectBuilder[PgAmopFields, PgAmopRow] + def selectAll: ZStream[ZConnection, Throwable, PgAmopRow] + def selectById(oid: PgAmopId): ZIO[ZConnection, Throwable, Option[PgAmopRow]] + def selectByIds(oids: Array[PgAmopId]): ZStream[ZConnection, Throwable, PgAmopRow] + def selectByUnique(amopfamily: /* oid */ Long, amoplefttype: /* oid */ Long, amoprighttype: /* oid */ Long, amopstrategy: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmopRow]] + def selectByUnique(amopopr: /* oid */ Long, amoppurpose: String, amopfamily: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAmopRow]] + def update(row: PgAmopRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAmopFields, PgAmopRow] + def upsert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmopRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoImpl.scala new file mode 100644 index 0000000000..81f7a4f1bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoImpl.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAmopRepoImpl extends PgAmopRepo { + override def delete(oid: PgAmopId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_amop where "oid" = ${Segment.paramSegment(oid)(PgAmopId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAmopFields, PgAmopRow] = { + DeleteBuilder("pg_catalog.pg_amop", PgAmopFields) + } + override def insert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, PgAmopRow] = { + sql"""insert into pg_catalog.pg_amop("oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily") + values (${Segment.paramSegment(unsaved.oid)(PgAmopId.setter)}::oid, ${Segment.paramSegment(unsaved.amopfamily)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amoplefttype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amoprighttype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amopstrategy)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.amoppurpose)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.amopopr)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amopmethod)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amopsortfamily)(Setter.longSetter)}::oid) + returning "oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily" + """.insertReturning(PgAmopRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAmopFields, PgAmopRow] = { + SelectBuilderSql("pg_catalog.pg_amop", PgAmopFields, PgAmopRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmopRow] = { + sql"""select "oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily" from pg_catalog.pg_amop""".query(PgAmopRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgAmopId): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + sql"""select "oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily" from pg_catalog.pg_amop where "oid" = ${Segment.paramSegment(oid)(PgAmopId.setter)}""".query(PgAmopRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgAmopId]): ZStream[ZConnection, Throwable, PgAmopRow] = { + sql"""select "oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily" from pg_catalog.pg_amop where "oid" = ANY(${Segment.paramSegment(oids)(PgAmopId.arraySetter)})""".query(PgAmopRow.jdbcDecoder).selectStream + } + override def selectByUnique(amopfamily: /* oid */ Long, amoplefttype: /* oid */ Long, amoprighttype: /* oid */ Long, amopstrategy: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + sql"""select "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy" + from pg_catalog.pg_amop + where "amopfamily" = ${Segment.paramSegment(amopfamily)(Setter.longSetter)} AND "amoplefttype" = ${Segment.paramSegment(amoplefttype)(Setter.longSetter)} AND "amoprighttype" = ${Segment.paramSegment(amoprighttype)(Setter.longSetter)} AND "amopstrategy" = ${Segment.paramSegment(amopstrategy)(TypoShort.setter)} + """.query(PgAmopRow.jdbcDecoder).selectOne + } + override def selectByUnique(amopopr: /* oid */ Long, amoppurpose: String, amopfamily: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + sql"""select "amopopr", "amoppurpose", "amopfamily" + from pg_catalog.pg_amop + where "amopopr" = ${Segment.paramSegment(amopopr)(Setter.longSetter)} AND "amoppurpose" = ${Segment.paramSegment(amoppurpose)(Setter.stringSetter)} AND "amopfamily" = ${Segment.paramSegment(amopfamily)(Setter.longSetter)} + """.query(PgAmopRow.jdbcDecoder).selectOne + } + override def update(row: PgAmopRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_amop + set "amopfamily" = ${Segment.paramSegment(row.amopfamily)(Setter.longSetter)}::oid, + "amoplefttype" = ${Segment.paramSegment(row.amoplefttype)(Setter.longSetter)}::oid, + "amoprighttype" = ${Segment.paramSegment(row.amoprighttype)(Setter.longSetter)}::oid, + "amopstrategy" = ${Segment.paramSegment(row.amopstrategy)(TypoShort.setter)}::int2, + "amoppurpose" = ${Segment.paramSegment(row.amoppurpose)(Setter.stringSetter)}::char, + "amopopr" = ${Segment.paramSegment(row.amopopr)(Setter.longSetter)}::oid, + "amopmethod" = ${Segment.paramSegment(row.amopmethod)(Setter.longSetter)}::oid, + "amopsortfamily" = ${Segment.paramSegment(row.amopsortfamily)(Setter.longSetter)}::oid + where "oid" = ${Segment.paramSegment(oid)(PgAmopId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAmopFields, PgAmopRow] = { + UpdateBuilder("pg_catalog.pg_amop", PgAmopFields, PgAmopRow.jdbcDecoder) + } + override def upsert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmopRow]] = { + sql"""insert into pg_catalog.pg_amop("oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily") + values ( + ${Segment.paramSegment(unsaved.oid)(PgAmopId.setter)}::oid, + ${Segment.paramSegment(unsaved.amopfamily)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amoplefttype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amoprighttype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amopstrategy)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.amoppurpose)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.amopopr)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amopmethod)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amopsortfamily)(Setter.longSetter)}::oid + ) + on conflict ("oid") + do update set + "amopfamily" = EXCLUDED."amopfamily", + "amoplefttype" = EXCLUDED."amoplefttype", + "amoprighttype" = EXCLUDED."amoprighttype", + "amopstrategy" = EXCLUDED."amopstrategy", + "amoppurpose" = EXCLUDED."amoppurpose", + "amopopr" = EXCLUDED."amopopr", + "amopmethod" = EXCLUDED."amopmethod", + "amopsortfamily" = EXCLUDED."amopsortfamily" + returning "oid", "amopfamily", "amoplefttype", "amoprighttype", "amopstrategy", "amoppurpose", "amopopr", "amopmethod", "amopsortfamily"""".insertReturning(PgAmopRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoMock.scala new file mode 100644 index 0000000000..837cc0a667 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRepoMock.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAmopRepoMock(map: scala.collection.mutable.Map[PgAmopId, PgAmopRow] = scala.collection.mutable.Map.empty) extends PgAmopRepo { + override def delete(oid: PgAmopId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgAmopFields, PgAmopRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAmopFields, map) + } + override def insert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, PgAmopRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAmopFields, PgAmopRow] = { + SelectBuilderMock(PgAmopFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmopRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgAmopId): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgAmopId]): ZStream[ZConnection, Throwable, PgAmopRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(amopfamily: /* oid */ Long, amoplefttype: /* oid */ Long, amoprighttype: /* oid */ Long, amopstrategy: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + ZIO.succeed(map.values.find(v => amopfamily == v.amopfamily && amoplefttype == v.amoplefttype && amoprighttype == v.amoprighttype && amopstrategy == v.amopstrategy)) + } + override def selectByUnique(amopopr: /* oid */ Long, amoppurpose: String, amopfamily: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAmopRow]] = { + ZIO.succeed(map.values.find(v => amopopr == v.amopopr && amoppurpose == v.amoppurpose && amopfamily == v.amopfamily)) + } + override def update(row: PgAmopRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAmopFields, PgAmopRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAmopFields, map) + } + override def upsert(unsaved: PgAmopRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmopRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRow.scala new file mode 100644 index 0000000000..4b77b5db8c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopRow.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAmopRow( + oid: PgAmopId, + amopfamily: /* oid */ Long, + amoplefttype: /* oid */ Long, + amoprighttype: /* oid */ Long, + amopstrategy: TypoShort, + amoppurpose: String, + amopopr: /* oid */ Long, + amopmethod: /* oid */ Long, + amopsortfamily: /* oid */ Long +) + +object PgAmopRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmopRow] = new JdbcDecoder[PgAmopRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAmopRow) = + columIndex + 8 -> + PgAmopRow( + oid = PgAmopId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + amopfamily = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + amoplefttype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + amoprighttype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + amopstrategy = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + amoppurpose = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + amopopr = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + amopmethod = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + amopsortfamily = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAmopRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAmopId.jsonDecoder)) + val amopfamily = jsonObj.get("amopfamily").toRight("Missing field 'amopfamily'").flatMap(_.as(JsonDecoder.long)) + val amoplefttype = jsonObj.get("amoplefttype").toRight("Missing field 'amoplefttype'").flatMap(_.as(JsonDecoder.long)) + val amoprighttype = jsonObj.get("amoprighttype").toRight("Missing field 'amoprighttype'").flatMap(_.as(JsonDecoder.long)) + val amopstrategy = jsonObj.get("amopstrategy").toRight("Missing field 'amopstrategy'").flatMap(_.as(TypoShort.jsonDecoder)) + val amoppurpose = jsonObj.get("amoppurpose").toRight("Missing field 'amoppurpose'").flatMap(_.as(JsonDecoder.string)) + val amopopr = jsonObj.get("amopopr").toRight("Missing field 'amopopr'").flatMap(_.as(JsonDecoder.long)) + val amopmethod = jsonObj.get("amopmethod").toRight("Missing field 'amopmethod'").flatMap(_.as(JsonDecoder.long)) + val amopsortfamily = jsonObj.get("amopsortfamily").toRight("Missing field 'amopsortfamily'").flatMap(_.as(JsonDecoder.long)) + if (oid.isRight && amopfamily.isRight && amoplefttype.isRight && amoprighttype.isRight && amopstrategy.isRight && amoppurpose.isRight && amopopr.isRight && amopmethod.isRight && amopsortfamily.isRight) + Right(PgAmopRow(oid = oid.toOption.get, amopfamily = amopfamily.toOption.get, amoplefttype = amoplefttype.toOption.get, amoprighttype = amoprighttype.toOption.get, amopstrategy = amopstrategy.toOption.get, amoppurpose = amoppurpose.toOption.get, amopopr = amopopr.toOption.get, amopmethod = amopmethod.toOption.get, amopsortfamily = amopsortfamily.toOption.get)) + else Left(List[Either[String, Any]](oid, amopfamily, amoplefttype, amoprighttype, amopstrategy, amoppurpose, amopopr, amopmethod, amopsortfamily).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAmopRow] = new JsonEncoder[PgAmopRow] { + override def unsafeEncode(a: PgAmopRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgAmopId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""amopfamily":""") + JsonEncoder.long.unsafeEncode(a.amopfamily, indent, out) + out.write(",") + out.write(""""amoplefttype":""") + JsonEncoder.long.unsafeEncode(a.amoplefttype, indent, out) + out.write(",") + out.write(""""amoprighttype":""") + JsonEncoder.long.unsafeEncode(a.amoprighttype, indent, out) + out.write(",") + out.write(""""amopstrategy":""") + TypoShort.jsonEncoder.unsafeEncode(a.amopstrategy, indent, out) + out.write(",") + out.write(""""amoppurpose":""") + JsonEncoder.string.unsafeEncode(a.amoppurpose, indent, out) + out.write(",") + out.write(""""amopopr":""") + JsonEncoder.long.unsafeEncode(a.amopopr, indent, out) + out.write(",") + out.write(""""amopmethod":""") + JsonEncoder.long.unsafeEncode(a.amopmethod, indent, out) + out.write(",") + out.write(""""amopsortfamily":""") + JsonEncoder.long.unsafeEncode(a.amopsortfamily, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopStructure.scala new file mode 100644 index 0000000000..8a6104bc5d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amop/PgAmopStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amop + +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgAmopStructure[Row](val prefix: Option[String], val extract: Row => PgAmopRow, val merge: (Row, PgAmopRow) => Row) + extends Relation[PgAmopFields, PgAmopRow, Row] + with PgAmopFields[Row] { outer => + + override val oid = new IdField[PgAmopId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val amopfamily = new Field[/* oid */ Long, Row](prefix, "amopfamily", None, Some("oid"))(x => extract(x).amopfamily, (row, value) => merge(row, extract(row).copy(amopfamily = value))) + override val amoplefttype = new Field[/* oid */ Long, Row](prefix, "amoplefttype", None, Some("oid"))(x => extract(x).amoplefttype, (row, value) => merge(row, extract(row).copy(amoplefttype = value))) + override val amoprighttype = new Field[/* oid */ Long, Row](prefix, "amoprighttype", None, Some("oid"))(x => extract(x).amoprighttype, (row, value) => merge(row, extract(row).copy(amoprighttype = value))) + override val amopstrategy = new Field[TypoShort, Row](prefix, "amopstrategy", None, Some("int2"))(x => extract(x).amopstrategy, (row, value) => merge(row, extract(row).copy(amopstrategy = value))) + override val amoppurpose = new Field[String, Row](prefix, "amoppurpose", None, Some("char"))(x => extract(x).amoppurpose, (row, value) => merge(row, extract(row).copy(amoppurpose = value))) + override val amopopr = new Field[/* oid */ Long, Row](prefix, "amopopr", None, Some("oid"))(x => extract(x).amopopr, (row, value) => merge(row, extract(row).copy(amopopr = value))) + override val amopmethod = new Field[/* oid */ Long, Row](prefix, "amopmethod", None, Some("oid"))(x => extract(x).amopmethod, (row, value) => merge(row, extract(row).copy(amopmethod = value))) + override val amopsortfamily = new Field[/* oid */ Long, Row](prefix, "amopsortfamily", None, Some("oid"))(x => extract(x).amopsortfamily, (row, value) => merge(row, extract(row).copy(amopsortfamily = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, amopfamily, amoplefttype, amoprighttype, amopstrategy, amoppurpose, amopopr, amopmethod, amopsortfamily) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAmopRow, merge: (NewRow, PgAmopRow) => NewRow): PgAmopStructure[NewRow] = + new PgAmopStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocFields.scala new file mode 100644 index 0000000000..9c0dd649d9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgAmprocFields[Row] { + val oid: IdField[PgAmprocId, Row] + val amprocfamily: Field[/* oid */ Long, Row] + val amproclefttype: Field[/* oid */ Long, Row] + val amprocrighttype: Field[/* oid */ Long, Row] + val amprocnum: Field[TypoShort, Row] + val amproc: Field[TypoRegproc, Row] +} +object PgAmprocFields extends PgAmprocStructure[PgAmprocRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocId.scala new file mode 100644 index 0000000000..1c059450e8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +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 `pg_catalog.pg_amproc` */ +case class PgAmprocId(value: /* oid */ Long) extends AnyVal +object PgAmprocId { + implicit lazy val arraySetter: Setter[Array[PgAmprocId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAmprocId, /* oid */ Long] = Bijection[PgAmprocId, /* oid */ Long](_.value)(PgAmprocId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmprocId] = JdbcDecoder.longDecoder.map(PgAmprocId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAmprocId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAmprocId] = JsonDecoder.long.map(PgAmprocId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAmprocId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgAmprocId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAmprocId] = ParameterMetaData.instance[PgAmprocId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgAmprocId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepo.scala new file mode 100644 index 0000000000..d7336818b3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAmprocRepo { + def delete(oid: PgAmprocId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAmprocFields, PgAmprocRow] + def insert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, PgAmprocRow] + def select: SelectBuilder[PgAmprocFields, PgAmprocRow] + def selectAll: ZStream[ZConnection, Throwable, PgAmprocRow] + def selectById(oid: PgAmprocId): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] + def selectByIds(oids: Array[PgAmprocId]): ZStream[ZConnection, Throwable, PgAmprocRow] + def selectByUnique(amprocfamily: /* oid */ Long, amproclefttype: /* oid */ Long, amprocrighttype: /* oid */ Long, amprocnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] + def update(row: PgAmprocRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAmprocFields, PgAmprocRow] + def upsert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmprocRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoImpl.scala new file mode 100644 index 0000000000..7d5af9f8f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoImpl.scala @@ -0,0 +1,87 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAmprocRepoImpl extends PgAmprocRepo { + override def delete(oid: PgAmprocId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_amproc where "oid" = ${Segment.paramSegment(oid)(PgAmprocId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAmprocFields, PgAmprocRow] = { + DeleteBuilder("pg_catalog.pg_amproc", PgAmprocFields) + } + override def insert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, PgAmprocRow] = { + sql"""insert into pg_catalog.pg_amproc("oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc") + values (${Segment.paramSegment(unsaved.oid)(PgAmprocId.setter)}::oid, ${Segment.paramSegment(unsaved.amprocfamily)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amproclefttype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amprocrighttype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.amprocnum)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.amproc)(TypoRegproc.setter)}::regproc) + returning "oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc" + """.insertReturning(PgAmprocRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAmprocFields, PgAmprocRow] = { + SelectBuilderSql("pg_catalog.pg_amproc", PgAmprocFields, PgAmprocRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmprocRow] = { + sql"""select "oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc" from pg_catalog.pg_amproc""".query(PgAmprocRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgAmprocId): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] = { + sql"""select "oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc" from pg_catalog.pg_amproc where "oid" = ${Segment.paramSegment(oid)(PgAmprocId.setter)}""".query(PgAmprocRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgAmprocId]): ZStream[ZConnection, Throwable, PgAmprocRow] = { + sql"""select "oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc" from pg_catalog.pg_amproc where "oid" = ANY(${Segment.paramSegment(oids)(PgAmprocId.arraySetter)})""".query(PgAmprocRow.jdbcDecoder).selectStream + } + override def selectByUnique(amprocfamily: /* oid */ Long, amproclefttype: /* oid */ Long, amprocrighttype: /* oid */ Long, amprocnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] = { + sql"""select "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum" + from pg_catalog.pg_amproc + where "amprocfamily" = ${Segment.paramSegment(amprocfamily)(Setter.longSetter)} AND "amproclefttype" = ${Segment.paramSegment(amproclefttype)(Setter.longSetter)} AND "amprocrighttype" = ${Segment.paramSegment(amprocrighttype)(Setter.longSetter)} AND "amprocnum" = ${Segment.paramSegment(amprocnum)(TypoShort.setter)} + """.query(PgAmprocRow.jdbcDecoder).selectOne + } + override def update(row: PgAmprocRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_amproc + set "amprocfamily" = ${Segment.paramSegment(row.amprocfamily)(Setter.longSetter)}::oid, + "amproclefttype" = ${Segment.paramSegment(row.amproclefttype)(Setter.longSetter)}::oid, + "amprocrighttype" = ${Segment.paramSegment(row.amprocrighttype)(Setter.longSetter)}::oid, + "amprocnum" = ${Segment.paramSegment(row.amprocnum)(TypoShort.setter)}::int2, + "amproc" = ${Segment.paramSegment(row.amproc)(TypoRegproc.setter)}::regproc + where "oid" = ${Segment.paramSegment(oid)(PgAmprocId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAmprocFields, PgAmprocRow] = { + UpdateBuilder("pg_catalog.pg_amproc", PgAmprocFields, PgAmprocRow.jdbcDecoder) + } + override def upsert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmprocRow]] = { + sql"""insert into pg_catalog.pg_amproc("oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc") + values ( + ${Segment.paramSegment(unsaved.oid)(PgAmprocId.setter)}::oid, + ${Segment.paramSegment(unsaved.amprocfamily)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amproclefttype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amprocrighttype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.amprocnum)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.amproc)(TypoRegproc.setter)}::regproc + ) + on conflict ("oid") + do update set + "amprocfamily" = EXCLUDED."amprocfamily", + "amproclefttype" = EXCLUDED."amproclefttype", + "amprocrighttype" = EXCLUDED."amprocrighttype", + "amprocnum" = EXCLUDED."amprocnum", + "amproc" = EXCLUDED."amproc" + returning "oid", "amprocfamily", "amproclefttype", "amprocrighttype", "amprocnum", "amproc"""".insertReturning(PgAmprocRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoMock.scala new file mode 100644 index 0000000000..fd8c27fdf4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoShort +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAmprocRepoMock(map: scala.collection.mutable.Map[PgAmprocId, PgAmprocRow] = scala.collection.mutable.Map.empty) extends PgAmprocRepo { + override def delete(oid: PgAmprocId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgAmprocFields, PgAmprocRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAmprocFields, map) + } + override def insert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, PgAmprocRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAmprocFields, PgAmprocRow] = { + SelectBuilderMock(PgAmprocFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAmprocRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgAmprocId): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgAmprocId]): ZStream[ZConnection, Throwable, PgAmprocRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(amprocfamily: /* oid */ Long, amproclefttype: /* oid */ Long, amprocrighttype: /* oid */ Long, amprocnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAmprocRow]] = { + ZIO.succeed(map.values.find(v => amprocfamily == v.amprocfamily && amproclefttype == v.amproclefttype && amprocrighttype == v.amprocrighttype && amprocnum == v.amprocnum)) + } + override def update(row: PgAmprocRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAmprocFields, PgAmprocRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAmprocFields, map) + } + override def upsert(unsaved: PgAmprocRow): ZIO[ZConnection, Throwable, UpdateResult[PgAmprocRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRow.scala new file mode 100644 index 0000000000..146e1d065e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAmprocRow( + oid: PgAmprocId, + amprocfamily: /* oid */ Long, + amproclefttype: /* oid */ Long, + amprocrighttype: /* oid */ Long, + amprocnum: TypoShort, + amproc: TypoRegproc +) + +object PgAmprocRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAmprocRow] = new JdbcDecoder[PgAmprocRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAmprocRow) = + columIndex + 5 -> + PgAmprocRow( + oid = PgAmprocId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + amprocfamily = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + amproclefttype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + amprocrighttype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + amprocnum = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + amproc = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAmprocRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAmprocId.jsonDecoder)) + val amprocfamily = jsonObj.get("amprocfamily").toRight("Missing field 'amprocfamily'").flatMap(_.as(JsonDecoder.long)) + val amproclefttype = jsonObj.get("amproclefttype").toRight("Missing field 'amproclefttype'").flatMap(_.as(JsonDecoder.long)) + val amprocrighttype = jsonObj.get("amprocrighttype").toRight("Missing field 'amprocrighttype'").flatMap(_.as(JsonDecoder.long)) + val amprocnum = jsonObj.get("amprocnum").toRight("Missing field 'amprocnum'").flatMap(_.as(TypoShort.jsonDecoder)) + val amproc = jsonObj.get("amproc").toRight("Missing field 'amproc'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (oid.isRight && amprocfamily.isRight && amproclefttype.isRight && amprocrighttype.isRight && amprocnum.isRight && amproc.isRight) + Right(PgAmprocRow(oid = oid.toOption.get, amprocfamily = amprocfamily.toOption.get, amproclefttype = amproclefttype.toOption.get, amprocrighttype = amprocrighttype.toOption.get, amprocnum = amprocnum.toOption.get, amproc = amproc.toOption.get)) + else Left(List[Either[String, Any]](oid, amprocfamily, amproclefttype, amprocrighttype, amprocnum, amproc).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAmprocRow] = new JsonEncoder[PgAmprocRow] { + override def unsafeEncode(a: PgAmprocRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgAmprocId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""amprocfamily":""") + JsonEncoder.long.unsafeEncode(a.amprocfamily, indent, out) + out.write(",") + out.write(""""amproclefttype":""") + JsonEncoder.long.unsafeEncode(a.amproclefttype, indent, out) + out.write(",") + out.write(""""amprocrighttype":""") + JsonEncoder.long.unsafeEncode(a.amprocrighttype, indent, out) + out.write(",") + out.write(""""amprocnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.amprocnum, indent, out) + out.write(",") + out.write(""""amproc":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.amproc, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocStructure.scala new file mode 100644 index 0000000000..0fe6fec4b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_amproc/PgAmprocStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_amproc + +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgAmprocStructure[Row](val prefix: Option[String], val extract: Row => PgAmprocRow, val merge: (Row, PgAmprocRow) => Row) + extends Relation[PgAmprocFields, PgAmprocRow, Row] + with PgAmprocFields[Row] { outer => + + override val oid = new IdField[PgAmprocId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val amprocfamily = new Field[/* oid */ Long, Row](prefix, "amprocfamily", None, Some("oid"))(x => extract(x).amprocfamily, (row, value) => merge(row, extract(row).copy(amprocfamily = value))) + override val amproclefttype = new Field[/* oid */ Long, Row](prefix, "amproclefttype", None, Some("oid"))(x => extract(x).amproclefttype, (row, value) => merge(row, extract(row).copy(amproclefttype = value))) + override val amprocrighttype = new Field[/* oid */ Long, Row](prefix, "amprocrighttype", None, Some("oid"))(x => extract(x).amprocrighttype, (row, value) => merge(row, extract(row).copy(amprocrighttype = value))) + override val amprocnum = new Field[TypoShort, Row](prefix, "amprocnum", None, Some("int2"))(x => extract(x).amprocnum, (row, value) => merge(row, extract(row).copy(amprocnum = value))) + override val amproc = new Field[TypoRegproc, Row](prefix, "amproc", None, Some("regproc"))(x => extract(x).amproc, (row, value) => merge(row, extract(row).copy(amproc = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, amprocfamily, amproclefttype, amprocrighttype, amprocnum, amproc) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAmprocRow, merge: (NewRow, PgAmprocRow) => NewRow): PgAmprocStructure[NewRow] = + new PgAmprocStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefFields.scala new file mode 100644 index 0000000000..4d810e775a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgAttrdefFields[Row] { + val oid: IdField[PgAttrdefId, Row] + val adrelid: Field[/* oid */ Long, Row] + val adnum: Field[TypoShort, Row] + val adbin: Field[TypoPgNodeTree, Row] +} +object PgAttrdefFields extends PgAttrdefStructure[PgAttrdefRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefId.scala new file mode 100644 index 0000000000..3c1861b502 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +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 `pg_catalog.pg_attrdef` */ +case class PgAttrdefId(value: /* oid */ Long) extends AnyVal +object PgAttrdefId { + implicit lazy val arraySetter: Setter[Array[PgAttrdefId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAttrdefId, /* oid */ Long] = Bijection[PgAttrdefId, /* oid */ Long](_.value)(PgAttrdefId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAttrdefId] = JdbcDecoder.longDecoder.map(PgAttrdefId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAttrdefId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAttrdefId] = JsonDecoder.long.map(PgAttrdefId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAttrdefId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgAttrdefId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAttrdefId] = ParameterMetaData.instance[PgAttrdefId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgAttrdefId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepo.scala new file mode 100644 index 0000000000..5aa2fd30dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAttrdefRepo { + def delete(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAttrdefFields, PgAttrdefRow] + def insert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, PgAttrdefRow] + def select: SelectBuilder[PgAttrdefFields, PgAttrdefRow] + def selectAll: ZStream[ZConnection, Throwable, PgAttrdefRow] + def selectById(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] + def selectByIds(oids: Array[PgAttrdefId]): ZStream[ZConnection, Throwable, PgAttrdefRow] + def selectByUnique(adrelid: /* oid */ Long, adnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] + def update(row: PgAttrdefRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAttrdefFields, PgAttrdefRow] + def upsert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttrdefRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoImpl.scala new file mode 100644 index 0000000000..ea0a92557a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoImpl.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAttrdefRepoImpl extends PgAttrdefRepo { + override def delete(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_attrdef where "oid" = ${Segment.paramSegment(oid)(PgAttrdefId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAttrdefFields, PgAttrdefRow] = { + DeleteBuilder("pg_catalog.pg_attrdef", PgAttrdefFields) + } + override def insert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, PgAttrdefRow] = { + sql"""insert into pg_catalog.pg_attrdef("oid", "adrelid", "adnum", "adbin") + values (${Segment.paramSegment(unsaved.oid)(PgAttrdefId.setter)}::oid, ${Segment.paramSegment(unsaved.adrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.adnum)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.adbin)(TypoPgNodeTree.setter)}::pg_node_tree) + returning "oid", "adrelid", "adnum", "adbin" + """.insertReturning(PgAttrdefRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAttrdefFields, PgAttrdefRow] = { + SelectBuilderSql("pg_catalog.pg_attrdef", PgAttrdefFields, PgAttrdefRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAttrdefRow] = { + sql"""select "oid", "adrelid", "adnum", "adbin" from pg_catalog.pg_attrdef""".query(PgAttrdefRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] = { + sql"""select "oid", "adrelid", "adnum", "adbin" from pg_catalog.pg_attrdef where "oid" = ${Segment.paramSegment(oid)(PgAttrdefId.setter)}""".query(PgAttrdefRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgAttrdefId]): ZStream[ZConnection, Throwable, PgAttrdefRow] = { + sql"""select "oid", "adrelid", "adnum", "adbin" from pg_catalog.pg_attrdef where "oid" = ANY(${Segment.paramSegment(oids)(PgAttrdefId.arraySetter)})""".query(PgAttrdefRow.jdbcDecoder).selectStream + } + override def selectByUnique(adrelid: /* oid */ Long, adnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] = { + sql"""select "adrelid", "adnum" + from pg_catalog.pg_attrdef + where "adrelid" = ${Segment.paramSegment(adrelid)(Setter.longSetter)} AND "adnum" = ${Segment.paramSegment(adnum)(TypoShort.setter)} + """.query(PgAttrdefRow.jdbcDecoder).selectOne + } + override def update(row: PgAttrdefRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_attrdef + set "adrelid" = ${Segment.paramSegment(row.adrelid)(Setter.longSetter)}::oid, + "adnum" = ${Segment.paramSegment(row.adnum)(TypoShort.setter)}::int2, + "adbin" = ${Segment.paramSegment(row.adbin)(TypoPgNodeTree.setter)}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgAttrdefId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAttrdefFields, PgAttrdefRow] = { + UpdateBuilder("pg_catalog.pg_attrdef", PgAttrdefFields, PgAttrdefRow.jdbcDecoder) + } + override def upsert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttrdefRow]] = { + sql"""insert into pg_catalog.pg_attrdef("oid", "adrelid", "adnum", "adbin") + values ( + ${Segment.paramSegment(unsaved.oid)(PgAttrdefId.setter)}::oid, + ${Segment.paramSegment(unsaved.adrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.adnum)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.adbin)(TypoPgNodeTree.setter)}::pg_node_tree + ) + on conflict ("oid") + do update set + "adrelid" = EXCLUDED."adrelid", + "adnum" = EXCLUDED."adnum", + "adbin" = EXCLUDED."adbin" + returning "oid", "adrelid", "adnum", "adbin"""".insertReturning(PgAttrdefRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoMock.scala new file mode 100644 index 0000000000..9a6bb74a57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoShort +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAttrdefRepoMock(map: scala.collection.mutable.Map[PgAttrdefId, PgAttrdefRow] = scala.collection.mutable.Map.empty) extends PgAttrdefRepo { + override def delete(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgAttrdefFields, PgAttrdefRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAttrdefFields, map) + } + override def insert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, PgAttrdefRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAttrdefFields, PgAttrdefRow] = { + SelectBuilderMock(PgAttrdefFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAttrdefRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgAttrdefId): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgAttrdefId]): ZStream[ZConnection, Throwable, PgAttrdefRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(adrelid: /* oid */ Long, adnum: TypoShort): ZIO[ZConnection, Throwable, Option[PgAttrdefRow]] = { + ZIO.succeed(map.values.find(v => adrelid == v.adrelid && adnum == v.adnum)) + } + override def update(row: PgAttrdefRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAttrdefFields, PgAttrdefRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAttrdefFields, map) + } + override def upsert(unsaved: PgAttrdefRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttrdefRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRow.scala new file mode 100644 index 0000000000..2d1abde399 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAttrdefRow( + oid: PgAttrdefId, + adrelid: /* oid */ Long, + adnum: TypoShort, + adbin: TypoPgNodeTree +) + +object PgAttrdefRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAttrdefRow] = new JdbcDecoder[PgAttrdefRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAttrdefRow) = + columIndex + 3 -> + PgAttrdefRow( + oid = PgAttrdefId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + adrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + adnum = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + adbin = TypoPgNodeTree.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAttrdefRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAttrdefId.jsonDecoder)) + val adrelid = jsonObj.get("adrelid").toRight("Missing field 'adrelid'").flatMap(_.as(JsonDecoder.long)) + val adnum = jsonObj.get("adnum").toRight("Missing field 'adnum'").flatMap(_.as(TypoShort.jsonDecoder)) + val adbin = jsonObj.get("adbin").toRight("Missing field 'adbin'").flatMap(_.as(TypoPgNodeTree.jsonDecoder)) + if (oid.isRight && adrelid.isRight && adnum.isRight && adbin.isRight) + Right(PgAttrdefRow(oid = oid.toOption.get, adrelid = adrelid.toOption.get, adnum = adnum.toOption.get, adbin = adbin.toOption.get)) + else Left(List[Either[String, Any]](oid, adrelid, adnum, adbin).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAttrdefRow] = new JsonEncoder[PgAttrdefRow] { + override def unsafeEncode(a: PgAttrdefRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgAttrdefId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""adrelid":""") + JsonEncoder.long.unsafeEncode(a.adrelid, indent, out) + out.write(",") + out.write(""""adnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.adnum, indent, out) + out.write(",") + out.write(""""adbin":""") + TypoPgNodeTree.jsonEncoder.unsafeEncode(a.adbin, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefStructure.scala new file mode 100644 index 0000000000..223f10a020 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attrdef/PgAttrdefStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attrdef + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgAttrdefStructure[Row](val prefix: Option[String], val extract: Row => PgAttrdefRow, val merge: (Row, PgAttrdefRow) => Row) + extends Relation[PgAttrdefFields, PgAttrdefRow, Row] + with PgAttrdefFields[Row] { outer => + + override val oid = new IdField[PgAttrdefId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val adrelid = new Field[/* oid */ Long, Row](prefix, "adrelid", None, Some("oid"))(x => extract(x).adrelid, (row, value) => merge(row, extract(row).copy(adrelid = value))) + override val adnum = new Field[TypoShort, Row](prefix, "adnum", None, Some("int2"))(x => extract(x).adnum, (row, value) => merge(row, extract(row).copy(adnum = value))) + override val adbin = new Field[TypoPgNodeTree, Row](prefix, "adbin", None, Some("pg_node_tree"))(x => extract(x).adbin, (row, value) => merge(row, extract(row).copy(adbin = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, adrelid, adnum, adbin) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAttrdefRow, merge: (NewRow, PgAttrdefRow) => NewRow): PgAttrdefStructure[NewRow] = + new PgAttrdefStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeFields.scala new file mode 100644 index 0000000000..a60123628c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeFields.scala @@ -0,0 +1,46 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgAttributeFields[Row] { + val attrelid: IdField[/* oid */ Long, Row] + val attname: Field[String, Row] + val atttypid: Field[/* oid */ Long, Row] + val attstattarget: Field[Int, Row] + val attlen: Field[TypoShort, Row] + val attnum: IdField[TypoShort, Row] + val attndims: Field[Int, Row] + val attcacheoff: Field[Int, Row] + val atttypmod: Field[Int, Row] + val attbyval: Field[Boolean, Row] + val attalign: Field[String, Row] + val attstorage: Field[String, Row] + val attcompression: Field[String, Row] + val attnotnull: Field[Boolean, Row] + val atthasdef: Field[Boolean, Row] + val atthasmissing: Field[Boolean, Row] + val attidentity: Field[String, Row] + val attgenerated: Field[String, Row] + val attisdropped: Field[Boolean, Row] + val attislocal: Field[Boolean, Row] + val attinhcount: Field[Int, Row] + val attcollation: Field[/* oid */ Long, Row] + val attacl: OptField[Array[TypoAclItem], Row] + val attoptions: OptField[Array[String], Row] + val attfdwoptions: OptField[Array[String], Row] + val attmissingval: OptField[TypoAnyArray, Row] +} +object PgAttributeFields extends PgAttributeStructure[PgAttributeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeId.scala new file mode 100644 index 0000000000..12b5d08752 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeId.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import adventureworks.customtypes.TypoShort +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_attribute` */ +case class PgAttributeId(attrelid: /* oid */ Long, attnum: TypoShort) +object PgAttributeId { + implicit lazy val jsonDecoder: JsonDecoder[PgAttributeId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val attrelid = jsonObj.get("attrelid").toRight("Missing field 'attrelid'").flatMap(_.as(JsonDecoder.long)) + val attnum = jsonObj.get("attnum").toRight("Missing field 'attnum'").flatMap(_.as(TypoShort.jsonDecoder)) + if (attrelid.isRight && attnum.isRight) + Right(PgAttributeId(attrelid = attrelid.toOption.get, attnum = attnum.toOption.get)) + else Left(List[Either[String, Any]](attrelid, attnum).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAttributeId] = new JsonEncoder[PgAttributeId] { + override def unsafeEncode(a: PgAttributeId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""attrelid":""") + JsonEncoder.long.unsafeEncode(a.attrelid, indent, out) + out.write(",") + out.write(""""attnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.attnum, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoShort]): Ordering[PgAttributeId] = Ordering.by(x => (x.attrelid, x.attnum)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepo.scala new file mode 100644 index 0000000000..d3b9823344 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAttributeRepo { + def delete(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAttributeFields, PgAttributeRow] + def insert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, PgAttributeRow] + def select: SelectBuilder[PgAttributeFields, PgAttributeRow] + def selectAll: ZStream[ZConnection, Throwable, PgAttributeRow] + def selectById(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] + def selectByUnique(attrelid: /* oid */ Long, attname: String): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] + def update(row: PgAttributeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAttributeFields, PgAttributeRow] + def upsert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttributeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoImpl.scala new file mode 100644 index 0000000000..50f019f80b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoImpl.scala @@ -0,0 +1,143 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAttributeRepoImpl extends PgAttributeRepo { + override def delete(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_attribute where "attrelid" = ${Segment.paramSegment(compositeId.attrelid)(Setter.longSetter)} AND "attnum" = ${Segment.paramSegment(compositeId.attnum)(TypoShort.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAttributeFields, PgAttributeRow] = { + DeleteBuilder("pg_catalog.pg_attribute", PgAttributeFields) + } + override def insert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, PgAttributeRow] = { + sql"""insert into pg_catalog.pg_attribute("attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval") + values (${Segment.paramSegment(unsaved.attrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.attname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.atttypid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.attstattarget)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.attlen)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.attnum)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.attndims)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.attcacheoff)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.atttypmod)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.attbyval)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.attalign)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.attstorage)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.attcompression)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.attnotnull)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.atthasdef)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.atthasmissing)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.attidentity)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.attgenerated)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.attisdropped)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.attislocal)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.attinhcount)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.attcollation)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.attacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, ${Segment.paramSegment(unsaved.attoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.attfdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.attmissingval)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray) + returning "attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval" + """.insertReturning(PgAttributeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAttributeFields, PgAttributeRow] = { + SelectBuilderSql("pg_catalog.pg_attribute", PgAttributeFields, PgAttributeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAttributeRow] = { + sql"""select "attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval" from pg_catalog.pg_attribute""".query(PgAttributeRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] = { + sql"""select "attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval" from pg_catalog.pg_attribute where "attrelid" = ${Segment.paramSegment(compositeId.attrelid)(Setter.longSetter)} AND "attnum" = ${Segment.paramSegment(compositeId.attnum)(TypoShort.setter)}""".query(PgAttributeRow.jdbcDecoder).selectOne + } + override def selectByUnique(attrelid: /* oid */ Long, attname: String): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] = { + sql"""select "attrelid", "attname" + from pg_catalog.pg_attribute + where "attrelid" = ${Segment.paramSegment(attrelid)(Setter.longSetter)} AND "attname" = ${Segment.paramSegment(attname)(Setter.stringSetter)} + """.query(PgAttributeRow.jdbcDecoder).selectOne + } + override def update(row: PgAttributeRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_attribute + set "attname" = ${Segment.paramSegment(row.attname)(Setter.stringSetter)}::name, + "atttypid" = ${Segment.paramSegment(row.atttypid)(Setter.longSetter)}::oid, + "attstattarget" = ${Segment.paramSegment(row.attstattarget)(Setter.intSetter)}::int4, + "attlen" = ${Segment.paramSegment(row.attlen)(TypoShort.setter)}::int2, + "attndims" = ${Segment.paramSegment(row.attndims)(Setter.intSetter)}::int4, + "attcacheoff" = ${Segment.paramSegment(row.attcacheoff)(Setter.intSetter)}::int4, + "atttypmod" = ${Segment.paramSegment(row.atttypmod)(Setter.intSetter)}::int4, + "attbyval" = ${Segment.paramSegment(row.attbyval)(Setter.booleanSetter)}, + "attalign" = ${Segment.paramSegment(row.attalign)(Setter.stringSetter)}::char, + "attstorage" = ${Segment.paramSegment(row.attstorage)(Setter.stringSetter)}::char, + "attcompression" = ${Segment.paramSegment(row.attcompression)(Setter.stringSetter)}::char, + "attnotnull" = ${Segment.paramSegment(row.attnotnull)(Setter.booleanSetter)}, + "atthasdef" = ${Segment.paramSegment(row.atthasdef)(Setter.booleanSetter)}, + "atthasmissing" = ${Segment.paramSegment(row.atthasmissing)(Setter.booleanSetter)}, + "attidentity" = ${Segment.paramSegment(row.attidentity)(Setter.stringSetter)}::char, + "attgenerated" = ${Segment.paramSegment(row.attgenerated)(Setter.stringSetter)}::char, + "attisdropped" = ${Segment.paramSegment(row.attisdropped)(Setter.booleanSetter)}, + "attislocal" = ${Segment.paramSegment(row.attislocal)(Setter.booleanSetter)}, + "attinhcount" = ${Segment.paramSegment(row.attinhcount)(Setter.intSetter)}::int4, + "attcollation" = ${Segment.paramSegment(row.attcollation)(Setter.longSetter)}::oid, + "attacl" = ${Segment.paramSegment(row.attacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + "attoptions" = ${Segment.paramSegment(row.attoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + "attfdwoptions" = ${Segment.paramSegment(row.attfdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + "attmissingval" = ${Segment.paramSegment(row.attmissingval)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray + where "attrelid" = ${Segment.paramSegment(compositeId.attrelid)(Setter.longSetter)} AND "attnum" = ${Segment.paramSegment(compositeId.attnum)(TypoShort.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAttributeFields, PgAttributeRow] = { + UpdateBuilder("pg_catalog.pg_attribute", PgAttributeFields, PgAttributeRow.jdbcDecoder) + } + override def upsert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttributeRow]] = { + sql"""insert into pg_catalog.pg_attribute("attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval") + values ( + ${Segment.paramSegment(unsaved.attrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.attname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.atttypid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.attstattarget)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.attlen)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.attnum)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.attndims)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.attcacheoff)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.atttypmod)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.attbyval)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.attalign)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.attstorage)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.attcompression)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.attnotnull)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.atthasdef)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.atthasmissing)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.attidentity)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.attgenerated)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.attisdropped)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.attislocal)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.attinhcount)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.attcollation)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.attacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + ${Segment.paramSegment(unsaved.attoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + ${Segment.paramSegment(unsaved.attfdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + ${Segment.paramSegment(unsaved.attmissingval)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray + ) + on conflict ("attrelid", "attnum") + do update set + "attname" = EXCLUDED."attname", + "atttypid" = EXCLUDED."atttypid", + "attstattarget" = EXCLUDED."attstattarget", + "attlen" = EXCLUDED."attlen", + "attndims" = EXCLUDED."attndims", + "attcacheoff" = EXCLUDED."attcacheoff", + "atttypmod" = EXCLUDED."atttypmod", + "attbyval" = EXCLUDED."attbyval", + "attalign" = EXCLUDED."attalign", + "attstorage" = EXCLUDED."attstorage", + "attcompression" = EXCLUDED."attcompression", + "attnotnull" = EXCLUDED."attnotnull", + "atthasdef" = EXCLUDED."atthasdef", + "atthasmissing" = EXCLUDED."atthasmissing", + "attidentity" = EXCLUDED."attidentity", + "attgenerated" = EXCLUDED."attgenerated", + "attisdropped" = EXCLUDED."attisdropped", + "attislocal" = EXCLUDED."attislocal", + "attinhcount" = EXCLUDED."attinhcount", + "attcollation" = EXCLUDED."attcollation", + "attacl" = EXCLUDED."attacl", + "attoptions" = EXCLUDED."attoptions", + "attfdwoptions" = EXCLUDED."attfdwoptions", + "attmissingval" = EXCLUDED."attmissingval" + returning "attrelid", "attname", "atttypid", "attstattarget", "attlen", "attnum", "attndims", "attcacheoff", "atttypmod", "attbyval", "attalign", "attstorage", "attcompression", "attnotnull", "atthasdef", "atthasmissing", "attidentity", "attgenerated", "attisdropped", "attislocal", "attinhcount", "attcollation", "attacl", "attoptions", "attfdwoptions", "attmissingval"""".insertReturning(PgAttributeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoMock.scala new file mode 100644 index 0000000000..46bdf1e760 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAttributeRepoMock(map: scala.collection.mutable.Map[PgAttributeId, PgAttributeRow] = scala.collection.mutable.Map.empty) extends PgAttributeRepo { + override def delete(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgAttributeFields, PgAttributeRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAttributeFields, map) + } + override def insert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, PgAttributeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAttributeFields, PgAttributeRow] = { + SelectBuilderMock(PgAttributeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAttributeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgAttributeId): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def selectByUnique(attrelid: /* oid */ Long, attname: String): ZIO[ZConnection, Throwable, Option[PgAttributeRow]] = { + ZIO.succeed(map.values.find(v => attrelid == v.attrelid && attname == v.attname)) + } + override def update(row: PgAttributeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAttributeFields, PgAttributeRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAttributeFields, map) + } + override def upsert(unsaved: PgAttributeRow): ZIO[ZConnection, Throwable, UpdateResult[PgAttributeRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRow.scala new file mode 100644 index 0000000000..461060cb7e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeRow.scala @@ -0,0 +1,198 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAttributeRow( + attrelid: /* oid */ Long, + attname: String, + atttypid: /* oid */ Long, + attstattarget: Int, + attlen: TypoShort, + attnum: TypoShort, + attndims: Int, + attcacheoff: Int, + atttypmod: Int, + attbyval: Boolean, + attalign: String, + attstorage: String, + attcompression: String, + attnotnull: Boolean, + atthasdef: Boolean, + atthasmissing: Boolean, + attidentity: String, + attgenerated: String, + attisdropped: Boolean, + attislocal: Boolean, + attinhcount: Int, + attcollation: /* oid */ Long, + attacl: Option[Array[TypoAclItem]], + attoptions: Option[Array[String]], + attfdwoptions: Option[Array[String]], + attmissingval: Option[TypoAnyArray] +){ + val compositeId: PgAttributeId = PgAttributeId(attrelid, attnum) + } + +object PgAttributeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAttributeRow] = new JdbcDecoder[PgAttributeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAttributeRow) = + columIndex + 25 -> + PgAttributeRow( + attrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + attname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + atttypid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + attstattarget = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + attlen = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + attnum = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + attndims = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + attcacheoff = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + atttypmod = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 8, rs)._2, + attbyval = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 9, rs)._2, + attalign = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 10, rs)._2, + attstorage = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 11, rs)._2, + attcompression = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 12, rs)._2, + attnotnull = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 13, rs)._2, + atthasdef = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 14, rs)._2, + atthasmissing = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 15, rs)._2, + attidentity = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 16, rs)._2, + attgenerated = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 17, rs)._2, + attisdropped = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 18, rs)._2, + attislocal = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 19, rs)._2, + attinhcount = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 20, rs)._2, + attcollation = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 21, rs)._2, + attacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 22, rs)._2, + attoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 23, rs)._2, + attfdwoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 24, rs)._2, + attmissingval = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 25, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAttributeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val attrelid = jsonObj.get("attrelid").toRight("Missing field 'attrelid'").flatMap(_.as(JsonDecoder.long)) + val attname = jsonObj.get("attname").toRight("Missing field 'attname'").flatMap(_.as(JsonDecoder.string)) + val atttypid = jsonObj.get("atttypid").toRight("Missing field 'atttypid'").flatMap(_.as(JsonDecoder.long)) + val attstattarget = jsonObj.get("attstattarget").toRight("Missing field 'attstattarget'").flatMap(_.as(JsonDecoder.int)) + val attlen = jsonObj.get("attlen").toRight("Missing field 'attlen'").flatMap(_.as(TypoShort.jsonDecoder)) + val attnum = jsonObj.get("attnum").toRight("Missing field 'attnum'").flatMap(_.as(TypoShort.jsonDecoder)) + val attndims = jsonObj.get("attndims").toRight("Missing field 'attndims'").flatMap(_.as(JsonDecoder.int)) + val attcacheoff = jsonObj.get("attcacheoff").toRight("Missing field 'attcacheoff'").flatMap(_.as(JsonDecoder.int)) + val atttypmod = jsonObj.get("atttypmod").toRight("Missing field 'atttypmod'").flatMap(_.as(JsonDecoder.int)) + val attbyval = jsonObj.get("attbyval").toRight("Missing field 'attbyval'").flatMap(_.as(JsonDecoder.boolean)) + val attalign = jsonObj.get("attalign").toRight("Missing field 'attalign'").flatMap(_.as(JsonDecoder.string)) + val attstorage = jsonObj.get("attstorage").toRight("Missing field 'attstorage'").flatMap(_.as(JsonDecoder.string)) + val attcompression = jsonObj.get("attcompression").toRight("Missing field 'attcompression'").flatMap(_.as(JsonDecoder.string)) + val attnotnull = jsonObj.get("attnotnull").toRight("Missing field 'attnotnull'").flatMap(_.as(JsonDecoder.boolean)) + val atthasdef = jsonObj.get("atthasdef").toRight("Missing field 'atthasdef'").flatMap(_.as(JsonDecoder.boolean)) + val atthasmissing = jsonObj.get("atthasmissing").toRight("Missing field 'atthasmissing'").flatMap(_.as(JsonDecoder.boolean)) + val attidentity = jsonObj.get("attidentity").toRight("Missing field 'attidentity'").flatMap(_.as(JsonDecoder.string)) + val attgenerated = jsonObj.get("attgenerated").toRight("Missing field 'attgenerated'").flatMap(_.as(JsonDecoder.string)) + val attisdropped = jsonObj.get("attisdropped").toRight("Missing field 'attisdropped'").flatMap(_.as(JsonDecoder.boolean)) + val attislocal = jsonObj.get("attislocal").toRight("Missing field 'attislocal'").flatMap(_.as(JsonDecoder.boolean)) + val attinhcount = jsonObj.get("attinhcount").toRight("Missing field 'attinhcount'").flatMap(_.as(JsonDecoder.int)) + val attcollation = jsonObj.get("attcollation").toRight("Missing field 'attcollation'").flatMap(_.as(JsonDecoder.long)) + val attacl = jsonObj.get("attacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + val attoptions = jsonObj.get("attoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val attfdwoptions = jsonObj.get("attfdwoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val attmissingval = jsonObj.get("attmissingval").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + if (attrelid.isRight && attname.isRight && atttypid.isRight && attstattarget.isRight && attlen.isRight && attnum.isRight && attndims.isRight && attcacheoff.isRight && atttypmod.isRight && attbyval.isRight && attalign.isRight && attstorage.isRight && attcompression.isRight && attnotnull.isRight && atthasdef.isRight && atthasmissing.isRight && attidentity.isRight && attgenerated.isRight && attisdropped.isRight && attislocal.isRight && attinhcount.isRight && attcollation.isRight && attacl.isRight && attoptions.isRight && attfdwoptions.isRight && attmissingval.isRight) + Right(PgAttributeRow(attrelid = attrelid.toOption.get, attname = attname.toOption.get, atttypid = atttypid.toOption.get, attstattarget = attstattarget.toOption.get, attlen = attlen.toOption.get, attnum = attnum.toOption.get, attndims = attndims.toOption.get, attcacheoff = attcacheoff.toOption.get, atttypmod = atttypmod.toOption.get, attbyval = attbyval.toOption.get, attalign = attalign.toOption.get, attstorage = attstorage.toOption.get, attcompression = attcompression.toOption.get, attnotnull = attnotnull.toOption.get, atthasdef = atthasdef.toOption.get, atthasmissing = atthasmissing.toOption.get, attidentity = attidentity.toOption.get, attgenerated = attgenerated.toOption.get, attisdropped = attisdropped.toOption.get, attislocal = attislocal.toOption.get, attinhcount = attinhcount.toOption.get, attcollation = attcollation.toOption.get, attacl = attacl.toOption.get, attoptions = attoptions.toOption.get, attfdwoptions = attfdwoptions.toOption.get, attmissingval = attmissingval.toOption.get)) + else Left(List[Either[String, Any]](attrelid, attname, atttypid, attstattarget, attlen, attnum, attndims, attcacheoff, atttypmod, attbyval, attalign, attstorage, attcompression, attnotnull, atthasdef, atthasmissing, attidentity, attgenerated, attisdropped, attislocal, attinhcount, attcollation, attacl, attoptions, attfdwoptions, attmissingval).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAttributeRow] = new JsonEncoder[PgAttributeRow] { + override def unsafeEncode(a: PgAttributeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""attrelid":""") + JsonEncoder.long.unsafeEncode(a.attrelid, indent, out) + out.write(",") + out.write(""""attname":""") + JsonEncoder.string.unsafeEncode(a.attname, indent, out) + out.write(",") + out.write(""""atttypid":""") + JsonEncoder.long.unsafeEncode(a.atttypid, indent, out) + out.write(",") + out.write(""""attstattarget":""") + JsonEncoder.int.unsafeEncode(a.attstattarget, indent, out) + out.write(",") + out.write(""""attlen":""") + TypoShort.jsonEncoder.unsafeEncode(a.attlen, indent, out) + out.write(",") + out.write(""""attnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.attnum, indent, out) + out.write(",") + out.write(""""attndims":""") + JsonEncoder.int.unsafeEncode(a.attndims, indent, out) + out.write(",") + out.write(""""attcacheoff":""") + JsonEncoder.int.unsafeEncode(a.attcacheoff, indent, out) + out.write(",") + out.write(""""atttypmod":""") + JsonEncoder.int.unsafeEncode(a.atttypmod, indent, out) + out.write(",") + out.write(""""attbyval":""") + JsonEncoder.boolean.unsafeEncode(a.attbyval, indent, out) + out.write(",") + out.write(""""attalign":""") + JsonEncoder.string.unsafeEncode(a.attalign, indent, out) + out.write(",") + out.write(""""attstorage":""") + JsonEncoder.string.unsafeEncode(a.attstorage, indent, out) + out.write(",") + out.write(""""attcompression":""") + JsonEncoder.string.unsafeEncode(a.attcompression, indent, out) + out.write(",") + out.write(""""attnotnull":""") + JsonEncoder.boolean.unsafeEncode(a.attnotnull, indent, out) + out.write(",") + out.write(""""atthasdef":""") + JsonEncoder.boolean.unsafeEncode(a.atthasdef, indent, out) + out.write(",") + out.write(""""atthasmissing":""") + JsonEncoder.boolean.unsafeEncode(a.atthasmissing, indent, out) + out.write(",") + out.write(""""attidentity":""") + JsonEncoder.string.unsafeEncode(a.attidentity, indent, out) + out.write(",") + out.write(""""attgenerated":""") + JsonEncoder.string.unsafeEncode(a.attgenerated, indent, out) + out.write(",") + out.write(""""attisdropped":""") + JsonEncoder.boolean.unsafeEncode(a.attisdropped, indent, out) + out.write(",") + out.write(""""attislocal":""") + JsonEncoder.boolean.unsafeEncode(a.attislocal, indent, out) + out.write(",") + out.write(""""attinhcount":""") + JsonEncoder.int.unsafeEncode(a.attinhcount, indent, out) + out.write(",") + out.write(""""attcollation":""") + JsonEncoder.long.unsafeEncode(a.attcollation, indent, out) + out.write(",") + out.write(""""attacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.attacl, indent, out) + out.write(",") + out.write(""""attoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.attoptions, indent, out) + out.write(",") + out.write(""""attfdwoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.attfdwoptions, indent, out) + out.write(",") + out.write(""""attmissingval":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.attmissingval, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeStructure.scala new file mode 100644 index 0000000000..4bb2970f2e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_attribute/PgAttributeStructure.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_attribute + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgAttributeStructure[Row](val prefix: Option[String], val extract: Row => PgAttributeRow, val merge: (Row, PgAttributeRow) => Row) + extends Relation[PgAttributeFields, PgAttributeRow, Row] + with PgAttributeFields[Row] { outer => + + override val attrelid = new IdField[/* oid */ Long, Row](prefix, "attrelid", None, Some("oid"))(x => extract(x).attrelid, (row, value) => merge(row, extract(row).copy(attrelid = value))) + override val attname = new Field[String, Row](prefix, "attname", None, Some("name"))(x => extract(x).attname, (row, value) => merge(row, extract(row).copy(attname = value))) + override val atttypid = new Field[/* oid */ Long, Row](prefix, "atttypid", None, Some("oid"))(x => extract(x).atttypid, (row, value) => merge(row, extract(row).copy(atttypid = value))) + override val attstattarget = new Field[Int, Row](prefix, "attstattarget", None, Some("int4"))(x => extract(x).attstattarget, (row, value) => merge(row, extract(row).copy(attstattarget = value))) + override val attlen = new Field[TypoShort, Row](prefix, "attlen", None, Some("int2"))(x => extract(x).attlen, (row, value) => merge(row, extract(row).copy(attlen = value))) + override val attnum = new IdField[TypoShort, Row](prefix, "attnum", None, Some("int2"))(x => extract(x).attnum, (row, value) => merge(row, extract(row).copy(attnum = value))) + override val attndims = new Field[Int, Row](prefix, "attndims", None, Some("int4"))(x => extract(x).attndims, (row, value) => merge(row, extract(row).copy(attndims = value))) + override val attcacheoff = new Field[Int, Row](prefix, "attcacheoff", None, Some("int4"))(x => extract(x).attcacheoff, (row, value) => merge(row, extract(row).copy(attcacheoff = value))) + override val atttypmod = new Field[Int, Row](prefix, "atttypmod", None, Some("int4"))(x => extract(x).atttypmod, (row, value) => merge(row, extract(row).copy(atttypmod = value))) + override val attbyval = new Field[Boolean, Row](prefix, "attbyval", None, None)(x => extract(x).attbyval, (row, value) => merge(row, extract(row).copy(attbyval = value))) + override val attalign = new Field[String, Row](prefix, "attalign", None, Some("char"))(x => extract(x).attalign, (row, value) => merge(row, extract(row).copy(attalign = value))) + override val attstorage = new Field[String, Row](prefix, "attstorage", None, Some("char"))(x => extract(x).attstorage, (row, value) => merge(row, extract(row).copy(attstorage = value))) + override val attcompression = new Field[String, Row](prefix, "attcompression", None, Some("char"))(x => extract(x).attcompression, (row, value) => merge(row, extract(row).copy(attcompression = value))) + override val attnotnull = new Field[Boolean, Row](prefix, "attnotnull", None, None)(x => extract(x).attnotnull, (row, value) => merge(row, extract(row).copy(attnotnull = value))) + override val atthasdef = new Field[Boolean, Row](prefix, "atthasdef", None, None)(x => extract(x).atthasdef, (row, value) => merge(row, extract(row).copy(atthasdef = value))) + override val atthasmissing = new Field[Boolean, Row](prefix, "atthasmissing", None, None)(x => extract(x).atthasmissing, (row, value) => merge(row, extract(row).copy(atthasmissing = value))) + override val attidentity = new Field[String, Row](prefix, "attidentity", None, Some("char"))(x => extract(x).attidentity, (row, value) => merge(row, extract(row).copy(attidentity = value))) + override val attgenerated = new Field[String, Row](prefix, "attgenerated", None, Some("char"))(x => extract(x).attgenerated, (row, value) => merge(row, extract(row).copy(attgenerated = value))) + override val attisdropped = new Field[Boolean, Row](prefix, "attisdropped", None, None)(x => extract(x).attisdropped, (row, value) => merge(row, extract(row).copy(attisdropped = value))) + override val attislocal = new Field[Boolean, Row](prefix, "attislocal", None, None)(x => extract(x).attislocal, (row, value) => merge(row, extract(row).copy(attislocal = value))) + override val attinhcount = new Field[Int, Row](prefix, "attinhcount", None, Some("int4"))(x => extract(x).attinhcount, (row, value) => merge(row, extract(row).copy(attinhcount = value))) + override val attcollation = new Field[/* oid */ Long, Row](prefix, "attcollation", None, Some("oid"))(x => extract(x).attcollation, (row, value) => merge(row, extract(row).copy(attcollation = value))) + override val attacl = new OptField[Array[TypoAclItem], Row](prefix, "attacl", None, Some("_aclitem"))(x => extract(x).attacl, (row, value) => merge(row, extract(row).copy(attacl = value))) + override val attoptions = new OptField[Array[String], Row](prefix, "attoptions", None, Some("_text"))(x => extract(x).attoptions, (row, value) => merge(row, extract(row).copy(attoptions = value))) + override val attfdwoptions = new OptField[Array[String], Row](prefix, "attfdwoptions", None, Some("_text"))(x => extract(x).attfdwoptions, (row, value) => merge(row, extract(row).copy(attfdwoptions = value))) + override val attmissingval = new OptField[TypoAnyArray, Row](prefix, "attmissingval", None, Some("anyarray"))(x => extract(x).attmissingval, (row, value) => merge(row, extract(row).copy(attmissingval = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](attrelid, attname, atttypid, attstattarget, attlen, attnum, attndims, attcacheoff, atttypmod, attbyval, attalign, attstorage, attcompression, attnotnull, atthasdef, atthasmissing, attidentity, attgenerated, attisdropped, attislocal, attinhcount, attcollation, attacl, attoptions, attfdwoptions, attmissingval) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAttributeRow, merge: (NewRow, PgAttributeRow) => NewRow): PgAttributeStructure[NewRow] = + new PgAttributeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersFields.scala new file mode 100644 index 0000000000..e4d687e940 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgAuthMembersFields[Row] { + val roleid: IdField[/* oid */ Long, Row] + val member: IdField[/* oid */ Long, Row] + val grantor: Field[/* oid */ Long, Row] + val adminOption: Field[Boolean, Row] +} +object PgAuthMembersFields extends PgAuthMembersStructure[PgAuthMembersRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersId.scala new file mode 100644 index 0000000000..75d782bc9a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_auth_members` */ +case class PgAuthMembersId(roleid: /* oid */ Long, member: /* oid */ Long) +object PgAuthMembersId { + implicit lazy val jsonDecoder: JsonDecoder[PgAuthMembersId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val roleid = jsonObj.get("roleid").toRight("Missing field 'roleid'").flatMap(_.as(JsonDecoder.long)) + val member = jsonObj.get("member").toRight("Missing field 'member'").flatMap(_.as(JsonDecoder.long)) + if (roleid.isRight && member.isRight) + Right(PgAuthMembersId(roleid = roleid.toOption.get, member = member.toOption.get)) + else Left(List[Either[String, Any]](roleid, member).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAuthMembersId] = new JsonEncoder[PgAuthMembersId] { + override def unsafeEncode(a: PgAuthMembersId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""roleid":""") + JsonEncoder.long.unsafeEncode(a.roleid, indent, out) + out.write(",") + out.write(""""member":""") + JsonEncoder.long.unsafeEncode(a.member, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgAuthMembersId] = Ordering.by(x => (x.roleid, x.member)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepo.scala new file mode 100644 index 0000000000..48edc1be62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAuthMembersRepo { + def delete(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAuthMembersFields, PgAuthMembersRow] + def insert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, PgAuthMembersRow] + def select: SelectBuilder[PgAuthMembersFields, PgAuthMembersRow] + def selectAll: ZStream[ZConnection, Throwable, PgAuthMembersRow] + def selectById(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] + def selectByUnique(member: /* oid */ Long, roleid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] + def update(row: PgAuthMembersRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAuthMembersFields, PgAuthMembersRow] + def upsert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthMembersRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoImpl.scala new file mode 100644 index 0000000000..94fe097acf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoImpl.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAuthMembersRepoImpl extends PgAuthMembersRepo { + override def delete(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_auth_members where "roleid" = ${Segment.paramSegment(compositeId.roleid)(Setter.longSetter)} AND "member" = ${Segment.paramSegment(compositeId.member)(Setter.longSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + DeleteBuilder("pg_catalog.pg_auth_members", PgAuthMembersFields) + } + override def insert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, PgAuthMembersRow] = { + sql"""insert into pg_catalog.pg_auth_members("roleid", "member", "grantor", "admin_option") + values (${Segment.paramSegment(unsaved.roleid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.member)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.grantor)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.adminOption)(Setter.booleanSetter)}) + returning "roleid", "member", "grantor", "admin_option" + """.insertReturning(PgAuthMembersRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + SelectBuilderSql("pg_catalog.pg_auth_members", PgAuthMembersFields, PgAuthMembersRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAuthMembersRow] = { + sql"""select "roleid", "member", "grantor", "admin_option" from pg_catalog.pg_auth_members""".query(PgAuthMembersRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] = { + sql"""select "roleid", "member", "grantor", "admin_option" from pg_catalog.pg_auth_members where "roleid" = ${Segment.paramSegment(compositeId.roleid)(Setter.longSetter)} AND "member" = ${Segment.paramSegment(compositeId.member)(Setter.longSetter)}""".query(PgAuthMembersRow.jdbcDecoder).selectOne + } + override def selectByUnique(member: /* oid */ Long, roleid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] = { + sql"""select "member", "roleid" + from pg_catalog.pg_auth_members + where "member" = ${Segment.paramSegment(member)(Setter.longSetter)} AND "roleid" = ${Segment.paramSegment(roleid)(Setter.longSetter)} + """.query(PgAuthMembersRow.jdbcDecoder).selectOne + } + override def update(row: PgAuthMembersRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_auth_members + set "grantor" = ${Segment.paramSegment(row.grantor)(Setter.longSetter)}::oid, + "admin_option" = ${Segment.paramSegment(row.adminOption)(Setter.booleanSetter)} + where "roleid" = ${Segment.paramSegment(compositeId.roleid)(Setter.longSetter)} AND "member" = ${Segment.paramSegment(compositeId.member)(Setter.longSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + UpdateBuilder("pg_catalog.pg_auth_members", PgAuthMembersFields, PgAuthMembersRow.jdbcDecoder) + } + override def upsert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthMembersRow]] = { + sql"""insert into pg_catalog.pg_auth_members("roleid", "member", "grantor", "admin_option") + values ( + ${Segment.paramSegment(unsaved.roleid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.member)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.grantor)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.adminOption)(Setter.booleanSetter)} + ) + on conflict ("roleid", "member") + do update set + "grantor" = EXCLUDED."grantor", + "admin_option" = EXCLUDED."admin_option" + returning "roleid", "member", "grantor", "admin_option"""".insertReturning(PgAuthMembersRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoMock.scala new file mode 100644 index 0000000000..6d9b6648d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAuthMembersRepoMock(map: scala.collection.mutable.Map[PgAuthMembersId, PgAuthMembersRow] = scala.collection.mutable.Map.empty) extends PgAuthMembersRepo { + override def delete(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAuthMembersFields, map) + } + override def insert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, PgAuthMembersRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + SelectBuilderMock(PgAuthMembersFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAuthMembersRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgAuthMembersId): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def selectByUnique(member: /* oid */ Long, roleid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgAuthMembersRow]] = { + ZIO.succeed(map.values.find(v => member == v.member && roleid == v.roleid)) + } + override def update(row: PgAuthMembersRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAuthMembersFields, PgAuthMembersRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAuthMembersFields, map) + } + override def upsert(unsaved: PgAuthMembersRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthMembersRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRow.scala new file mode 100644 index 0000000000..2decf71c29 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAuthMembersRow( + roleid: /* oid */ Long, + member: /* oid */ Long, + grantor: /* oid */ Long, + adminOption: Boolean +){ + val compositeId: PgAuthMembersId = PgAuthMembersId(roleid, member) + } + +object PgAuthMembersRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAuthMembersRow] = new JdbcDecoder[PgAuthMembersRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAuthMembersRow) = + columIndex + 3 -> + PgAuthMembersRow( + roleid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + member = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + grantor = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + adminOption = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAuthMembersRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val roleid = jsonObj.get("roleid").toRight("Missing field 'roleid'").flatMap(_.as(JsonDecoder.long)) + val member = jsonObj.get("member").toRight("Missing field 'member'").flatMap(_.as(JsonDecoder.long)) + val grantor = jsonObj.get("grantor").toRight("Missing field 'grantor'").flatMap(_.as(JsonDecoder.long)) + val adminOption = jsonObj.get("admin_option").toRight("Missing field 'admin_option'").flatMap(_.as(JsonDecoder.boolean)) + if (roleid.isRight && member.isRight && grantor.isRight && adminOption.isRight) + Right(PgAuthMembersRow(roleid = roleid.toOption.get, member = member.toOption.get, grantor = grantor.toOption.get, adminOption = adminOption.toOption.get)) + else Left(List[Either[String, Any]](roleid, member, grantor, adminOption).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAuthMembersRow] = new JsonEncoder[PgAuthMembersRow] { + override def unsafeEncode(a: PgAuthMembersRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""roleid":""") + JsonEncoder.long.unsafeEncode(a.roleid, indent, out) + out.write(",") + out.write(""""member":""") + JsonEncoder.long.unsafeEncode(a.member, indent, out) + out.write(",") + out.write(""""grantor":""") + JsonEncoder.long.unsafeEncode(a.grantor, indent, out) + out.write(",") + out.write(""""admin_option":""") + JsonEncoder.boolean.unsafeEncode(a.adminOption, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersStructure.scala new file mode 100644 index 0000000000..06229d43c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_auth_members/PgAuthMembersStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_auth_members + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgAuthMembersStructure[Row](val prefix: Option[String], val extract: Row => PgAuthMembersRow, val merge: (Row, PgAuthMembersRow) => Row) + extends Relation[PgAuthMembersFields, PgAuthMembersRow, Row] + with PgAuthMembersFields[Row] { outer => + + override val roleid = new IdField[/* oid */ Long, Row](prefix, "roleid", None, Some("oid"))(x => extract(x).roleid, (row, value) => merge(row, extract(row).copy(roleid = value))) + override val member = new IdField[/* oid */ Long, Row](prefix, "member", None, Some("oid"))(x => extract(x).member, (row, value) => merge(row, extract(row).copy(member = value))) + override val grantor = new Field[/* oid */ Long, Row](prefix, "grantor", None, Some("oid"))(x => extract(x).grantor, (row, value) => merge(row, extract(row).copy(grantor = value))) + override val adminOption = new Field[Boolean, Row](prefix, "admin_option", None, None)(x => extract(x).adminOption, (row, value) => merge(row, extract(row).copy(adminOption = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](roleid, member, grantor, adminOption) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAuthMembersRow, merge: (NewRow, PgAuthMembersRow) => NewRow): PgAuthMembersStructure[NewRow] = + new PgAuthMembersStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidFields.scala new file mode 100644 index 0000000000..69905125ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgAuthidFields[Row] { + val oid: IdField[PgAuthidId, Row] + val rolname: Field[String, Row] + val rolsuper: Field[Boolean, Row] + val rolinherit: Field[Boolean, Row] + val rolcreaterole: Field[Boolean, Row] + val rolcreatedb: Field[Boolean, Row] + val rolcanlogin: Field[Boolean, Row] + val rolreplication: Field[Boolean, Row] + val rolbypassrls: Field[Boolean, Row] + val rolconnlimit: Field[Int, Row] + val rolpassword: OptField[String, Row] + val rolvaliduntil: OptField[TypoInstant, Row] +} +object PgAuthidFields extends PgAuthidStructure[PgAuthidRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidId.scala new file mode 100644 index 0000000000..8028e38d23 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +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 `pg_catalog.pg_authid` */ +case class PgAuthidId(value: /* oid */ Long) extends AnyVal +object PgAuthidId { + implicit lazy val arraySetter: Setter[Array[PgAuthidId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgAuthidId, /* oid */ Long] = Bijection[PgAuthidId, /* oid */ Long](_.value)(PgAuthidId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgAuthidId] = JdbcDecoder.longDecoder.map(PgAuthidId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgAuthidId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgAuthidId] = JsonDecoder.long.map(PgAuthidId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgAuthidId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgAuthidId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgAuthidId] = ParameterMetaData.instance[PgAuthidId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgAuthidId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepo.scala new file mode 100644 index 0000000000..1e2e7cbd96 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAuthidRepo { + def delete(oid: PgAuthidId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgAuthidFields, PgAuthidRow] + def insert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, PgAuthidRow] + def select: SelectBuilder[PgAuthidFields, PgAuthidRow] + def selectAll: ZStream[ZConnection, Throwable, PgAuthidRow] + def selectById(oid: PgAuthidId): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] + def selectByIds(oids: Array[PgAuthidId]): ZStream[ZConnection, Throwable, PgAuthidRow] + def selectByUnique(rolname: String): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] + def update(row: PgAuthidRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgAuthidFields, PgAuthidRow] + def upsert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthidRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoImpl.scala new file mode 100644 index 0000000000..77760463d8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoImpl.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import adventureworks.customtypes.TypoInstant +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAuthidRepoImpl extends PgAuthidRepo { + override def delete(oid: PgAuthidId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_authid where "oid" = ${Segment.paramSegment(oid)(PgAuthidId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgAuthidFields, PgAuthidRow] = { + DeleteBuilder("pg_catalog.pg_authid", PgAuthidFields) + } + override def insert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, PgAuthidRow] = { + sql"""insert into pg_catalog.pg_authid("oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil") + values (${Segment.paramSegment(unsaved.oid)(PgAuthidId.setter)}::oid, ${Segment.paramSegment(unsaved.rolname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.rolsuper)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolinherit)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolcreaterole)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolcreatedb)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolcanlogin)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolreplication)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolbypassrls)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.rolconnlimit)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.rolpassword)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.rolvaliduntil)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz) + returning "oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil"::text + """.insertReturning(PgAuthidRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgAuthidFields, PgAuthidRow] = { + SelectBuilderSql("pg_catalog.pg_authid", PgAuthidFields, PgAuthidRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAuthidRow] = { + sql"""select "oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil"::text from pg_catalog.pg_authid""".query(PgAuthidRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgAuthidId): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] = { + sql"""select "oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil"::text from pg_catalog.pg_authid where "oid" = ${Segment.paramSegment(oid)(PgAuthidId.setter)}""".query(PgAuthidRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgAuthidId]): ZStream[ZConnection, Throwable, PgAuthidRow] = { + sql"""select "oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil"::text from pg_catalog.pg_authid where "oid" = ANY(${Segment.paramSegment(oids)(PgAuthidId.arraySetter)})""".query(PgAuthidRow.jdbcDecoder).selectStream + } + override def selectByUnique(rolname: String): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] = { + sql"""select "rolname" + from pg_catalog.pg_authid + where "rolname" = ${Segment.paramSegment(rolname)(Setter.stringSetter)} + """.query(PgAuthidRow.jdbcDecoder).selectOne + } + override def update(row: PgAuthidRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_authid + set "rolname" = ${Segment.paramSegment(row.rolname)(Setter.stringSetter)}::name, + "rolsuper" = ${Segment.paramSegment(row.rolsuper)(Setter.booleanSetter)}, + "rolinherit" = ${Segment.paramSegment(row.rolinherit)(Setter.booleanSetter)}, + "rolcreaterole" = ${Segment.paramSegment(row.rolcreaterole)(Setter.booleanSetter)}, + "rolcreatedb" = ${Segment.paramSegment(row.rolcreatedb)(Setter.booleanSetter)}, + "rolcanlogin" = ${Segment.paramSegment(row.rolcanlogin)(Setter.booleanSetter)}, + "rolreplication" = ${Segment.paramSegment(row.rolreplication)(Setter.booleanSetter)}, + "rolbypassrls" = ${Segment.paramSegment(row.rolbypassrls)(Setter.booleanSetter)}, + "rolconnlimit" = ${Segment.paramSegment(row.rolconnlimit)(Setter.intSetter)}::int4, + "rolpassword" = ${Segment.paramSegment(row.rolpassword)(Setter.optionParamSetter(Setter.stringSetter))}, + "rolvaliduntil" = ${Segment.paramSegment(row.rolvaliduntil)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz + where "oid" = ${Segment.paramSegment(oid)(PgAuthidId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgAuthidFields, PgAuthidRow] = { + UpdateBuilder("pg_catalog.pg_authid", PgAuthidFields, PgAuthidRow.jdbcDecoder) + } + override def upsert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthidRow]] = { + sql"""insert into pg_catalog.pg_authid("oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil") + values ( + ${Segment.paramSegment(unsaved.oid)(PgAuthidId.setter)}::oid, + ${Segment.paramSegment(unsaved.rolname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.rolsuper)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolinherit)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolcreaterole)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolcreatedb)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolcanlogin)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolreplication)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolbypassrls)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.rolconnlimit)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.rolpassword)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.rolvaliduntil)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz + ) + on conflict ("oid") + do update set + "rolname" = EXCLUDED."rolname", + "rolsuper" = EXCLUDED."rolsuper", + "rolinherit" = EXCLUDED."rolinherit", + "rolcreaterole" = EXCLUDED."rolcreaterole", + "rolcreatedb" = EXCLUDED."rolcreatedb", + "rolcanlogin" = EXCLUDED."rolcanlogin", + "rolreplication" = EXCLUDED."rolreplication", + "rolbypassrls" = EXCLUDED."rolbypassrls", + "rolconnlimit" = EXCLUDED."rolconnlimit", + "rolpassword" = EXCLUDED."rolpassword", + "rolvaliduntil" = EXCLUDED."rolvaliduntil" + returning "oid", "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolbypassrls", "rolconnlimit", "rolpassword", "rolvaliduntil"::text""".insertReturning(PgAuthidRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoMock.scala new file mode 100644 index 0000000000..90c4217176 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgAuthidRepoMock(map: scala.collection.mutable.Map[PgAuthidId, PgAuthidRow] = scala.collection.mutable.Map.empty) extends PgAuthidRepo { + override def delete(oid: PgAuthidId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgAuthidFields, PgAuthidRow] = { + DeleteBuilderMock(DeleteParams.empty, PgAuthidFields, map) + } + override def insert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, PgAuthidRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgAuthidFields, PgAuthidRow] = { + SelectBuilderMock(PgAuthidFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAuthidRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgAuthidId): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgAuthidId]): ZStream[ZConnection, Throwable, PgAuthidRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(rolname: String): ZIO[ZConnection, Throwable, Option[PgAuthidRow]] = { + ZIO.succeed(map.values.find(v => rolname == v.rolname)) + } + override def update(row: PgAuthidRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgAuthidFields, PgAuthidRow] = { + UpdateBuilderMock(UpdateParams.empty, PgAuthidFields, map) + } + override def upsert(unsaved: PgAuthidRow): ZIO[ZConnection, Throwable, UpdateResult[PgAuthidRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRow.scala new file mode 100644 index 0000000000..6785ec924c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidRow.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAuthidRow( + oid: PgAuthidId, + rolname: String, + rolsuper: Boolean, + rolinherit: Boolean, + rolcreaterole: Boolean, + rolcreatedb: Boolean, + rolcanlogin: Boolean, + rolreplication: Boolean, + rolbypassrls: Boolean, + rolconnlimit: Int, + rolpassword: Option[String], + rolvaliduntil: Option[TypoInstant] +) + +object PgAuthidRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAuthidRow] = new JdbcDecoder[PgAuthidRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAuthidRow) = + columIndex + 11 -> + PgAuthidRow( + oid = PgAuthidId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + rolname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + rolsuper = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 2, rs)._2, + rolinherit = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + rolcreaterole = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + rolcreatedb = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + rolcanlogin = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + rolreplication = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + rolbypassrls = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 8, rs)._2, + rolconnlimit = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 9, rs)._2, + rolpassword = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + rolvaliduntil = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAuthidRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAuthidId.jsonDecoder)) + val rolname = jsonObj.get("rolname").toRight("Missing field 'rolname'").flatMap(_.as(JsonDecoder.string)) + val rolsuper = jsonObj.get("rolsuper").toRight("Missing field 'rolsuper'").flatMap(_.as(JsonDecoder.boolean)) + val rolinherit = jsonObj.get("rolinherit").toRight("Missing field 'rolinherit'").flatMap(_.as(JsonDecoder.boolean)) + val rolcreaterole = jsonObj.get("rolcreaterole").toRight("Missing field 'rolcreaterole'").flatMap(_.as(JsonDecoder.boolean)) + val rolcreatedb = jsonObj.get("rolcreatedb").toRight("Missing field 'rolcreatedb'").flatMap(_.as(JsonDecoder.boolean)) + val rolcanlogin = jsonObj.get("rolcanlogin").toRight("Missing field 'rolcanlogin'").flatMap(_.as(JsonDecoder.boolean)) + val rolreplication = jsonObj.get("rolreplication").toRight("Missing field 'rolreplication'").flatMap(_.as(JsonDecoder.boolean)) + val rolbypassrls = jsonObj.get("rolbypassrls").toRight("Missing field 'rolbypassrls'").flatMap(_.as(JsonDecoder.boolean)) + val rolconnlimit = jsonObj.get("rolconnlimit").toRight("Missing field 'rolconnlimit'").flatMap(_.as(JsonDecoder.int)) + val rolpassword = jsonObj.get("rolpassword").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rolvaliduntil = jsonObj.get("rolvaliduntil").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (oid.isRight && rolname.isRight && rolsuper.isRight && rolinherit.isRight && rolcreaterole.isRight && rolcreatedb.isRight && rolcanlogin.isRight && rolreplication.isRight && rolbypassrls.isRight && rolconnlimit.isRight && rolpassword.isRight && rolvaliduntil.isRight) + Right(PgAuthidRow(oid = oid.toOption.get, rolname = rolname.toOption.get, rolsuper = rolsuper.toOption.get, rolinherit = rolinherit.toOption.get, rolcreaterole = rolcreaterole.toOption.get, rolcreatedb = rolcreatedb.toOption.get, rolcanlogin = rolcanlogin.toOption.get, rolreplication = rolreplication.toOption.get, rolbypassrls = rolbypassrls.toOption.get, rolconnlimit = rolconnlimit.toOption.get, rolpassword = rolpassword.toOption.get, rolvaliduntil = rolvaliduntil.toOption.get)) + else Left(List[Either[String, Any]](oid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAuthidRow] = new JsonEncoder[PgAuthidRow] { + override def unsafeEncode(a: PgAuthidRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgAuthidId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""rolname":""") + JsonEncoder.string.unsafeEncode(a.rolname, indent, out) + out.write(",") + out.write(""""rolsuper":""") + JsonEncoder.boolean.unsafeEncode(a.rolsuper, indent, out) + out.write(",") + out.write(""""rolinherit":""") + JsonEncoder.boolean.unsafeEncode(a.rolinherit, indent, out) + out.write(",") + out.write(""""rolcreaterole":""") + JsonEncoder.boolean.unsafeEncode(a.rolcreaterole, indent, out) + out.write(",") + out.write(""""rolcreatedb":""") + JsonEncoder.boolean.unsafeEncode(a.rolcreatedb, indent, out) + out.write(",") + out.write(""""rolcanlogin":""") + JsonEncoder.boolean.unsafeEncode(a.rolcanlogin, indent, out) + out.write(",") + out.write(""""rolreplication":""") + JsonEncoder.boolean.unsafeEncode(a.rolreplication, indent, out) + out.write(",") + out.write(""""rolbypassrls":""") + JsonEncoder.boolean.unsafeEncode(a.rolbypassrls, indent, out) + out.write(",") + out.write(""""rolconnlimit":""") + JsonEncoder.int.unsafeEncode(a.rolconnlimit, indent, out) + out.write(",") + out.write(""""rolpassword":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.rolpassword, indent, out) + out.write(",") + out.write(""""rolvaliduntil":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.rolvaliduntil, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidStructure.scala new file mode 100644 index 0000000000..58ca3d20c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_authid/PgAuthidStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_authid + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgAuthidStructure[Row](val prefix: Option[String], val extract: Row => PgAuthidRow, val merge: (Row, PgAuthidRow) => Row) + extends Relation[PgAuthidFields, PgAuthidRow, Row] + with PgAuthidFields[Row] { outer => + + override val oid = new IdField[PgAuthidId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val rolname = new Field[String, Row](prefix, "rolname", None, Some("name"))(x => extract(x).rolname, (row, value) => merge(row, extract(row).copy(rolname = value))) + override val rolsuper = new Field[Boolean, Row](prefix, "rolsuper", None, None)(x => extract(x).rolsuper, (row, value) => merge(row, extract(row).copy(rolsuper = value))) + override val rolinherit = new Field[Boolean, Row](prefix, "rolinherit", None, None)(x => extract(x).rolinherit, (row, value) => merge(row, extract(row).copy(rolinherit = value))) + override val rolcreaterole = new Field[Boolean, Row](prefix, "rolcreaterole", None, None)(x => extract(x).rolcreaterole, (row, value) => merge(row, extract(row).copy(rolcreaterole = value))) + override val rolcreatedb = new Field[Boolean, Row](prefix, "rolcreatedb", None, None)(x => extract(x).rolcreatedb, (row, value) => merge(row, extract(row).copy(rolcreatedb = value))) + override val rolcanlogin = new Field[Boolean, Row](prefix, "rolcanlogin", None, None)(x => extract(x).rolcanlogin, (row, value) => merge(row, extract(row).copy(rolcanlogin = value))) + override val rolreplication = new Field[Boolean, Row](prefix, "rolreplication", None, None)(x => extract(x).rolreplication, (row, value) => merge(row, extract(row).copy(rolreplication = value))) + override val rolbypassrls = new Field[Boolean, Row](prefix, "rolbypassrls", None, None)(x => extract(x).rolbypassrls, (row, value) => merge(row, extract(row).copy(rolbypassrls = value))) + override val rolconnlimit = new Field[Int, Row](prefix, "rolconnlimit", None, Some("int4"))(x => extract(x).rolconnlimit, (row, value) => merge(row, extract(row).copy(rolconnlimit = value))) + override val rolpassword = new OptField[String, Row](prefix, "rolpassword", None, None)(x => extract(x).rolpassword, (row, value) => merge(row, extract(row).copy(rolpassword = value))) + override val rolvaliduntil = new OptField[TypoInstant, Row](prefix, "rolvaliduntil", Some("text"), Some("timestamptz"))(x => extract(x).rolvaliduntil, (row, value) => merge(row, extract(row).copy(rolvaliduntil = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolbypassrls, rolconnlimit, rolpassword, rolvaliduntil) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAuthidRow, merge: (NewRow, PgAuthidRow) => NewRow): PgAuthidStructure[NewRow] = + new PgAuthidStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewFields.scala new file mode 100644 index 0000000000..eaaa1ca073 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extension_versions + +import typo.dsl.SqlExpr.OptField + +trait PgAvailableExtensionVersionsViewFields[Row] { + val name: OptField[String, Row] + val version: OptField[String, Row] + val installed: OptField[Boolean, Row] + val superuser: OptField[Boolean, Row] + val trusted: OptField[Boolean, Row] + val relocatable: OptField[Boolean, Row] + val schema: OptField[String, Row] + val requires: OptField[Array[String], Row] + val comment: OptField[String, Row] +} +object PgAvailableExtensionVersionsViewFields extends PgAvailableExtensionVersionsViewStructure[PgAvailableExtensionVersionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepo.scala new file mode 100644 index 0000000000..f7ff61be6a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extension_versions + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAvailableExtensionVersionsViewRepo { + def select: SelectBuilder[PgAvailableExtensionVersionsViewFields, PgAvailableExtensionVersionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgAvailableExtensionVersionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepoImpl.scala new file mode 100644 index 0000000000..b99ffd4ef4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extension_versions + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAvailableExtensionVersionsViewRepoImpl extends PgAvailableExtensionVersionsViewRepo { + override def select: SelectBuilder[PgAvailableExtensionVersionsViewFields, PgAvailableExtensionVersionsViewRow] = { + SelectBuilderSql("pg_catalog.pg_available_extension_versions", PgAvailableExtensionVersionsViewFields, PgAvailableExtensionVersionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAvailableExtensionVersionsViewRow] = { + sql"""select "name", "version", "installed", "superuser", "trusted", "relocatable", "schema", "requires", "comment" from pg_catalog.pg_available_extension_versions""".query(PgAvailableExtensionVersionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRow.scala new file mode 100644 index 0000000000..d31eca6f2b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extension_versions + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAvailableExtensionVersionsViewRow( + name: /* nullability unknown */ Option[String], + version: /* nullability unknown */ Option[String], + installed: /* nullability unknown */ Option[Boolean], + superuser: /* nullability unknown */ Option[Boolean], + trusted: /* nullability unknown */ Option[Boolean], + relocatable: /* nullability unknown */ Option[Boolean], + schema: /* nullability unknown */ Option[String], + requires: /* nullability unknown */ Option[Array[String]], + comment: /* nullability unknown */ Option[String] +) + +object PgAvailableExtensionVersionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAvailableExtensionVersionsViewRow] = new JdbcDecoder[PgAvailableExtensionVersionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAvailableExtensionVersionsViewRow) = + columIndex + 8 -> + PgAvailableExtensionVersionsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + version = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + installed = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 2, rs)._2, + superuser = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 3, rs)._2, + trusted = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 4, rs)._2, + relocatable = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 5, rs)._2, + schema = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + requires = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 7, rs)._2, + comment = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAvailableExtensionVersionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val version = jsonObj.get("version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val installed = jsonObj.get("installed").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val superuser = jsonObj.get("superuser").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val trusted = jsonObj.get("trusted").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val relocatable = jsonObj.get("relocatable").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val schema = jsonObj.get("schema").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val requires = jsonObj.get("requires").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val comment = jsonObj.get("comment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (name.isRight && version.isRight && installed.isRight && superuser.isRight && trusted.isRight && relocatable.isRight && schema.isRight && requires.isRight && comment.isRight) + Right(PgAvailableExtensionVersionsViewRow(name = name.toOption.get, version = version.toOption.get, installed = installed.toOption.get, superuser = superuser.toOption.get, trusted = trusted.toOption.get, relocatable = relocatable.toOption.get, schema = schema.toOption.get, requires = requires.toOption.get, comment = comment.toOption.get)) + else Left(List[Either[String, Any]](name, version, installed, superuser, trusted, relocatable, schema, requires, comment).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAvailableExtensionVersionsViewRow] = new JsonEncoder[PgAvailableExtensionVersionsViewRow] { + override def unsafeEncode(a: PgAvailableExtensionVersionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.version, indent, out) + out.write(",") + out.write(""""installed":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.installed, indent, out) + out.write(",") + out.write(""""superuser":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.superuser, indent, out) + out.write(",") + out.write(""""trusted":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.trusted, indent, out) + out.write(",") + out.write(""""relocatable":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.relocatable, indent, out) + out.write(",") + out.write(""""schema":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schema, indent, out) + out.write(",") + out.write(""""requires":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.requires, indent, out) + out.write(",") + out.write(""""comment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comment, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewStructure.scala new file mode 100644 index 0000000000..71c251d5fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extension_versions/PgAvailableExtensionVersionsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extension_versions + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgAvailableExtensionVersionsViewStructure[Row](val prefix: Option[String], val extract: Row => PgAvailableExtensionVersionsViewRow, val merge: (Row, PgAvailableExtensionVersionsViewRow) => Row) + extends Relation[PgAvailableExtensionVersionsViewFields, PgAvailableExtensionVersionsViewRow, Row] + with PgAvailableExtensionVersionsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val version = new OptField[String, Row](prefix, "version", None, None)(x => extract(x).version, (row, value) => merge(row, extract(row).copy(version = value))) + override val installed = new OptField[Boolean, Row](prefix, "installed", None, None)(x => extract(x).installed, (row, value) => merge(row, extract(row).copy(installed = value))) + override val superuser = new OptField[Boolean, Row](prefix, "superuser", None, None)(x => extract(x).superuser, (row, value) => merge(row, extract(row).copy(superuser = value))) + override val trusted = new OptField[Boolean, Row](prefix, "trusted", None, None)(x => extract(x).trusted, (row, value) => merge(row, extract(row).copy(trusted = value))) + override val relocatable = new OptField[Boolean, Row](prefix, "relocatable", None, None)(x => extract(x).relocatable, (row, value) => merge(row, extract(row).copy(relocatable = value))) + override val schema = new OptField[String, Row](prefix, "schema", None, None)(x => extract(x).schema, (row, value) => merge(row, extract(row).copy(schema = value))) + override val requires = new OptField[Array[String], Row](prefix, "requires", None, None)(x => extract(x).requires, (row, value) => merge(row, extract(row).copy(requires = value))) + override val comment = new OptField[String, Row](prefix, "comment", None, None)(x => extract(x).comment, (row, value) => merge(row, extract(row).copy(comment = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, version, installed, superuser, trusted, relocatable, schema, requires, comment) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAvailableExtensionVersionsViewRow, merge: (NewRow, PgAvailableExtensionVersionsViewRow) => NewRow): PgAvailableExtensionVersionsViewStructure[NewRow] = + new PgAvailableExtensionVersionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewFields.scala new file mode 100644 index 0000000000..fa22f3ac7c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extensions + +import typo.dsl.SqlExpr.OptField + +trait PgAvailableExtensionsViewFields[Row] { + val name: OptField[String, Row] + val defaultVersion: OptField[String, Row] + val installedVersion: OptField[String, Row] + val comment: OptField[String, Row] +} +object PgAvailableExtensionsViewFields extends PgAvailableExtensionsViewStructure[PgAvailableExtensionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepo.scala new file mode 100644 index 0000000000..d0c8e19014 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extensions + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgAvailableExtensionsViewRepo { + def select: SelectBuilder[PgAvailableExtensionsViewFields, PgAvailableExtensionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgAvailableExtensionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepoImpl.scala new file mode 100644 index 0000000000..8de86641e6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extensions + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgAvailableExtensionsViewRepoImpl extends PgAvailableExtensionsViewRepo { + override def select: SelectBuilder[PgAvailableExtensionsViewFields, PgAvailableExtensionsViewRow] = { + SelectBuilderSql("pg_catalog.pg_available_extensions", PgAvailableExtensionsViewFields, PgAvailableExtensionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgAvailableExtensionsViewRow] = { + sql"""select "name", "default_version", "installed_version", "comment" from pg_catalog.pg_available_extensions""".query(PgAvailableExtensionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRow.scala new file mode 100644 index 0000000000..f06eef4867 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewRow.scala @@ -0,0 +1,62 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extensions + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgAvailableExtensionsViewRow( + name: /* nullability unknown */ Option[String], + defaultVersion: /* nullability unknown */ Option[String], + /** Points to [[pg_extension.PgExtensionRow.extversion]] */ + installedVersion: Option[String], + comment: /* nullability unknown */ Option[String] +) + +object PgAvailableExtensionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgAvailableExtensionsViewRow] = new JdbcDecoder[PgAvailableExtensionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgAvailableExtensionsViewRow) = + columIndex + 3 -> + PgAvailableExtensionsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + defaultVersion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + installedVersion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + comment = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgAvailableExtensionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val defaultVersion = jsonObj.get("default_version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val installedVersion = jsonObj.get("installed_version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val comment = jsonObj.get("comment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (name.isRight && defaultVersion.isRight && installedVersion.isRight && comment.isRight) + Right(PgAvailableExtensionsViewRow(name = name.toOption.get, defaultVersion = defaultVersion.toOption.get, installedVersion = installedVersion.toOption.get, comment = comment.toOption.get)) + else Left(List[Either[String, Any]](name, defaultVersion, installedVersion, comment).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgAvailableExtensionsViewRow] = new JsonEncoder[PgAvailableExtensionsViewRow] { + override def unsafeEncode(a: PgAvailableExtensionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""default_version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.defaultVersion, indent, out) + out.write(",") + out.write(""""installed_version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.installedVersion, indent, out) + out.write(",") + out.write(""""comment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comment, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewStructure.scala new file mode 100644 index 0000000000..bdbd064393 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_available_extensions/PgAvailableExtensionsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_available_extensions + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgAvailableExtensionsViewStructure[Row](val prefix: Option[String], val extract: Row => PgAvailableExtensionsViewRow, val merge: (Row, PgAvailableExtensionsViewRow) => Row) + extends Relation[PgAvailableExtensionsViewFields, PgAvailableExtensionsViewRow, Row] + with PgAvailableExtensionsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val defaultVersion = new OptField[String, Row](prefix, "default_version", None, None)(x => extract(x).defaultVersion, (row, value) => merge(row, extract(row).copy(defaultVersion = value))) + override val installedVersion = new OptField[String, Row](prefix, "installed_version", None, None)(x => extract(x).installedVersion, (row, value) => merge(row, extract(row).copy(installedVersion = value))) + override val comment = new OptField[String, Row](prefix, "comment", None, None)(x => extract(x).comment, (row, value) => merge(row, extract(row).copy(comment = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, defaultVersion, installedVersion, comment) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgAvailableExtensionsViewRow, merge: (NewRow, PgAvailableExtensionsViewRow) => NewRow): PgAvailableExtensionsViewStructure[NewRow] = + new PgAvailableExtensionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewFields.scala new file mode 100644 index 0000000000..8ffffbfc3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_backend_memory_contexts + +import typo.dsl.SqlExpr.OptField + +trait PgBackendMemoryContextsViewFields[Row] { + val name: OptField[String, Row] + val ident: OptField[String, Row] + val parent: OptField[String, Row] + val level: OptField[Int, Row] + val totalBytes: OptField[Long, Row] + val totalNblocks: OptField[Long, Row] + val freeBytes: OptField[Long, Row] + val freeChunks: OptField[Long, Row] + val usedBytes: OptField[Long, Row] +} +object PgBackendMemoryContextsViewFields extends PgBackendMemoryContextsViewStructure[PgBackendMemoryContextsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepo.scala new file mode 100644 index 0000000000..f68870a8cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_backend_memory_contexts + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgBackendMemoryContextsViewRepo { + def select: SelectBuilder[PgBackendMemoryContextsViewFields, PgBackendMemoryContextsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgBackendMemoryContextsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepoImpl.scala new file mode 100644 index 0000000000..85000669d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_backend_memory_contexts + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgBackendMemoryContextsViewRepoImpl extends PgBackendMemoryContextsViewRepo { + override def select: SelectBuilder[PgBackendMemoryContextsViewFields, PgBackendMemoryContextsViewRow] = { + SelectBuilderSql("pg_catalog.pg_backend_memory_contexts", PgBackendMemoryContextsViewFields, PgBackendMemoryContextsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgBackendMemoryContextsViewRow] = { + sql"""select "name", "ident", "parent", "level", "total_bytes", "total_nblocks", "free_bytes", "free_chunks", "used_bytes" from pg_catalog.pg_backend_memory_contexts""".query(PgBackendMemoryContextsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRow.scala new file mode 100644 index 0000000000..c26771b85b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_backend_memory_contexts + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgBackendMemoryContextsViewRow( + name: /* nullability unknown */ Option[String], + ident: /* nullability unknown */ Option[String], + parent: /* nullability unknown */ Option[String], + level: /* nullability unknown */ Option[Int], + totalBytes: /* nullability unknown */ Option[Long], + totalNblocks: /* nullability unknown */ Option[Long], + freeBytes: /* nullability unknown */ Option[Long], + freeChunks: /* nullability unknown */ Option[Long], + usedBytes: /* nullability unknown */ Option[Long] +) + +object PgBackendMemoryContextsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgBackendMemoryContextsViewRow] = new JdbcDecoder[PgBackendMemoryContextsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgBackendMemoryContextsViewRow) = + columIndex + 8 -> + PgBackendMemoryContextsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + ident = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + parent = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + level = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + totalBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + totalNblocks = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + freeBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + freeChunks = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + usedBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgBackendMemoryContextsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val ident = jsonObj.get("ident").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val parent = jsonObj.get("parent").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val level = jsonObj.get("level").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val totalBytes = jsonObj.get("total_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val totalNblocks = jsonObj.get("total_nblocks").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val freeBytes = jsonObj.get("free_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val freeChunks = jsonObj.get("free_chunks").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val usedBytes = jsonObj.get("used_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (name.isRight && ident.isRight && parent.isRight && level.isRight && totalBytes.isRight && totalNblocks.isRight && freeBytes.isRight && freeChunks.isRight && usedBytes.isRight) + Right(PgBackendMemoryContextsViewRow(name = name.toOption.get, ident = ident.toOption.get, parent = parent.toOption.get, level = level.toOption.get, totalBytes = totalBytes.toOption.get, totalNblocks = totalNblocks.toOption.get, freeBytes = freeBytes.toOption.get, freeChunks = freeChunks.toOption.get, usedBytes = usedBytes.toOption.get)) + else Left(List[Either[String, Any]](name, ident, parent, level, totalBytes, totalNblocks, freeBytes, freeChunks, usedBytes).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgBackendMemoryContextsViewRow] = new JsonEncoder[PgBackendMemoryContextsViewRow] { + override def unsafeEncode(a: PgBackendMemoryContextsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""ident":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.ident, indent, out) + out.write(",") + out.write(""""parent":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.parent, indent, out) + out.write(",") + out.write(""""level":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.level, indent, out) + out.write(",") + out.write(""""total_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.totalBytes, indent, out) + out.write(",") + out.write(""""total_nblocks":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.totalNblocks, indent, out) + out.write(",") + out.write(""""free_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.freeBytes, indent, out) + out.write(",") + out.write(""""free_chunks":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.freeChunks, indent, out) + out.write(",") + out.write(""""used_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.usedBytes, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewStructure.scala new file mode 100644 index 0000000000..3812224788 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_backend_memory_contexts/PgBackendMemoryContextsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_backend_memory_contexts + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgBackendMemoryContextsViewStructure[Row](val prefix: Option[String], val extract: Row => PgBackendMemoryContextsViewRow, val merge: (Row, PgBackendMemoryContextsViewRow) => Row) + extends Relation[PgBackendMemoryContextsViewFields, PgBackendMemoryContextsViewRow, Row] + with PgBackendMemoryContextsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val ident = new OptField[String, Row](prefix, "ident", None, None)(x => extract(x).ident, (row, value) => merge(row, extract(row).copy(ident = value))) + override val parent = new OptField[String, Row](prefix, "parent", None, None)(x => extract(x).parent, (row, value) => merge(row, extract(row).copy(parent = value))) + override val level = new OptField[Int, Row](prefix, "level", None, None)(x => extract(x).level, (row, value) => merge(row, extract(row).copy(level = value))) + override val totalBytes = new OptField[Long, Row](prefix, "total_bytes", None, None)(x => extract(x).totalBytes, (row, value) => merge(row, extract(row).copy(totalBytes = value))) + override val totalNblocks = new OptField[Long, Row](prefix, "total_nblocks", None, None)(x => extract(x).totalNblocks, (row, value) => merge(row, extract(row).copy(totalNblocks = value))) + override val freeBytes = new OptField[Long, Row](prefix, "free_bytes", None, None)(x => extract(x).freeBytes, (row, value) => merge(row, extract(row).copy(freeBytes = value))) + override val freeChunks = new OptField[Long, Row](prefix, "free_chunks", None, None)(x => extract(x).freeChunks, (row, value) => merge(row, extract(row).copy(freeChunks = value))) + override val usedBytes = new OptField[Long, Row](prefix, "used_bytes", None, None)(x => extract(x).usedBytes, (row, value) => merge(row, extract(row).copy(usedBytes = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, ident, parent, level, totalBytes, totalNblocks, freeBytes, freeChunks, usedBytes) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgBackendMemoryContextsViewRow, merge: (NewRow, PgBackendMemoryContextsViewRow) => NewRow): PgBackendMemoryContextsViewStructure[NewRow] = + new PgBackendMemoryContextsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastFields.scala new file mode 100644 index 0000000000..28f36a933c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgCastFields[Row] { + val oid: IdField[PgCastId, Row] + val castsource: Field[/* oid */ Long, Row] + val casttarget: Field[/* oid */ Long, Row] + val castfunc: Field[/* oid */ Long, Row] + val castcontext: Field[String, Row] + val castmethod: Field[String, Row] +} +object PgCastFields extends PgCastStructure[PgCastRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastId.scala new file mode 100644 index 0000000000..63ebbc31cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +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 `pg_catalog.pg_cast` */ +case class PgCastId(value: /* oid */ Long) extends AnyVal +object PgCastId { + implicit lazy val arraySetter: Setter[Array[PgCastId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgCastId, /* oid */ Long] = Bijection[PgCastId, /* oid */ Long](_.value)(PgCastId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgCastId] = JdbcDecoder.longDecoder.map(PgCastId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgCastId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgCastId] = JsonDecoder.long.map(PgCastId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgCastId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgCastId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgCastId] = ParameterMetaData.instance[PgCastId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgCastId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepo.scala new file mode 100644 index 0000000000..02cad834c5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgCastRepo { + def delete(oid: PgCastId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgCastFields, PgCastRow] + def insert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, PgCastRow] + def select: SelectBuilder[PgCastFields, PgCastRow] + def selectAll: ZStream[ZConnection, Throwable, PgCastRow] + def selectById(oid: PgCastId): ZIO[ZConnection, Throwable, Option[PgCastRow]] + def selectByIds(oids: Array[PgCastId]): ZStream[ZConnection, Throwable, PgCastRow] + def selectByUnique(castsource: /* oid */ Long, casttarget: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCastRow]] + def update(row: PgCastRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgCastFields, PgCastRow] + def upsert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, UpdateResult[PgCastRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoImpl.scala new file mode 100644 index 0000000000..0314ce8fb5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoImpl.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgCastRepoImpl extends PgCastRepo { + override def delete(oid: PgCastId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_cast where "oid" = ${Segment.paramSegment(oid)(PgCastId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgCastFields, PgCastRow] = { + DeleteBuilder("pg_catalog.pg_cast", PgCastFields) + } + override def insert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, PgCastRow] = { + sql"""insert into pg_catalog.pg_cast("oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod") + values (${Segment.paramSegment(unsaved.oid)(PgCastId.setter)}::oid, ${Segment.paramSegment(unsaved.castsource)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.casttarget)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.castfunc)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.castcontext)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.castmethod)(Setter.stringSetter)}::char) + returning "oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod" + """.insertReturning(PgCastRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgCastFields, PgCastRow] = { + SelectBuilderSql("pg_catalog.pg_cast", PgCastFields, PgCastRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgCastRow] = { + sql"""select "oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod" from pg_catalog.pg_cast""".query(PgCastRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgCastId): ZIO[ZConnection, Throwable, Option[PgCastRow]] = { + sql"""select "oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod" from pg_catalog.pg_cast where "oid" = ${Segment.paramSegment(oid)(PgCastId.setter)}""".query(PgCastRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgCastId]): ZStream[ZConnection, Throwable, PgCastRow] = { + sql"""select "oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod" from pg_catalog.pg_cast where "oid" = ANY(${Segment.paramSegment(oids)(PgCastId.arraySetter)})""".query(PgCastRow.jdbcDecoder).selectStream + } + override def selectByUnique(castsource: /* oid */ Long, casttarget: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCastRow]] = { + sql"""select "castsource", "casttarget" + from pg_catalog.pg_cast + where "castsource" = ${Segment.paramSegment(castsource)(Setter.longSetter)} AND "casttarget" = ${Segment.paramSegment(casttarget)(Setter.longSetter)} + """.query(PgCastRow.jdbcDecoder).selectOne + } + override def update(row: PgCastRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_cast + set "castsource" = ${Segment.paramSegment(row.castsource)(Setter.longSetter)}::oid, + "casttarget" = ${Segment.paramSegment(row.casttarget)(Setter.longSetter)}::oid, + "castfunc" = ${Segment.paramSegment(row.castfunc)(Setter.longSetter)}::oid, + "castcontext" = ${Segment.paramSegment(row.castcontext)(Setter.stringSetter)}::char, + "castmethod" = ${Segment.paramSegment(row.castmethod)(Setter.stringSetter)}::char + where "oid" = ${Segment.paramSegment(oid)(PgCastId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgCastFields, PgCastRow] = { + UpdateBuilder("pg_catalog.pg_cast", PgCastFields, PgCastRow.jdbcDecoder) + } + override def upsert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, UpdateResult[PgCastRow]] = { + sql"""insert into pg_catalog.pg_cast("oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod") + values ( + ${Segment.paramSegment(unsaved.oid)(PgCastId.setter)}::oid, + ${Segment.paramSegment(unsaved.castsource)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.casttarget)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.castfunc)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.castcontext)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.castmethod)(Setter.stringSetter)}::char + ) + on conflict ("oid") + do update set + "castsource" = EXCLUDED."castsource", + "casttarget" = EXCLUDED."casttarget", + "castfunc" = EXCLUDED."castfunc", + "castcontext" = EXCLUDED."castcontext", + "castmethod" = EXCLUDED."castmethod" + returning "oid", "castsource", "casttarget", "castfunc", "castcontext", "castmethod"""".insertReturning(PgCastRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoMock.scala new file mode 100644 index 0000000000..7c230cd525 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgCastRepoMock(map: scala.collection.mutable.Map[PgCastId, PgCastRow] = scala.collection.mutable.Map.empty) extends PgCastRepo { + override def delete(oid: PgCastId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgCastFields, PgCastRow] = { + DeleteBuilderMock(DeleteParams.empty, PgCastFields, map) + } + override def insert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, PgCastRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgCastFields, PgCastRow] = { + SelectBuilderMock(PgCastFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgCastRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgCastId): ZIO[ZConnection, Throwable, Option[PgCastRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgCastId]): ZStream[ZConnection, Throwable, PgCastRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(castsource: /* oid */ Long, casttarget: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCastRow]] = { + ZIO.succeed(map.values.find(v => castsource == v.castsource && casttarget == v.casttarget)) + } + override def update(row: PgCastRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgCastFields, PgCastRow] = { + UpdateBuilderMock(UpdateParams.empty, PgCastFields, map) + } + override def upsert(unsaved: PgCastRow): ZIO[ZConnection, Throwable, UpdateResult[PgCastRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRow.scala new file mode 100644 index 0000000000..b7f9480259 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgCastRow( + oid: PgCastId, + castsource: /* oid */ Long, + casttarget: /* oid */ Long, + castfunc: /* oid */ Long, + castcontext: String, + castmethod: String +) + +object PgCastRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgCastRow] = new JdbcDecoder[PgCastRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgCastRow) = + columIndex + 5 -> + PgCastRow( + oid = PgCastId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + castsource = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + casttarget = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + castfunc = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + castcontext = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + castmethod = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgCastRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgCastId.jsonDecoder)) + val castsource = jsonObj.get("castsource").toRight("Missing field 'castsource'").flatMap(_.as(JsonDecoder.long)) + val casttarget = jsonObj.get("casttarget").toRight("Missing field 'casttarget'").flatMap(_.as(JsonDecoder.long)) + val castfunc = jsonObj.get("castfunc").toRight("Missing field 'castfunc'").flatMap(_.as(JsonDecoder.long)) + val castcontext = jsonObj.get("castcontext").toRight("Missing field 'castcontext'").flatMap(_.as(JsonDecoder.string)) + val castmethod = jsonObj.get("castmethod").toRight("Missing field 'castmethod'").flatMap(_.as(JsonDecoder.string)) + if (oid.isRight && castsource.isRight && casttarget.isRight && castfunc.isRight && castcontext.isRight && castmethod.isRight) + Right(PgCastRow(oid = oid.toOption.get, castsource = castsource.toOption.get, casttarget = casttarget.toOption.get, castfunc = castfunc.toOption.get, castcontext = castcontext.toOption.get, castmethod = castmethod.toOption.get)) + else Left(List[Either[String, Any]](oid, castsource, casttarget, castfunc, castcontext, castmethod).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgCastRow] = new JsonEncoder[PgCastRow] { + override def unsafeEncode(a: PgCastRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgCastId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""castsource":""") + JsonEncoder.long.unsafeEncode(a.castsource, indent, out) + out.write(",") + out.write(""""casttarget":""") + JsonEncoder.long.unsafeEncode(a.casttarget, indent, out) + out.write(",") + out.write(""""castfunc":""") + JsonEncoder.long.unsafeEncode(a.castfunc, indent, out) + out.write(",") + out.write(""""castcontext":""") + JsonEncoder.string.unsafeEncode(a.castcontext, indent, out) + out.write(",") + out.write(""""castmethod":""") + JsonEncoder.string.unsafeEncode(a.castmethod, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastStructure.scala new file mode 100644 index 0000000000..ee4ce4ac7f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cast/PgCastStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cast + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgCastStructure[Row](val prefix: Option[String], val extract: Row => PgCastRow, val merge: (Row, PgCastRow) => Row) + extends Relation[PgCastFields, PgCastRow, Row] + with PgCastFields[Row] { outer => + + override val oid = new IdField[PgCastId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val castsource = new Field[/* oid */ Long, Row](prefix, "castsource", None, Some("oid"))(x => extract(x).castsource, (row, value) => merge(row, extract(row).copy(castsource = value))) + override val casttarget = new Field[/* oid */ Long, Row](prefix, "casttarget", None, Some("oid"))(x => extract(x).casttarget, (row, value) => merge(row, extract(row).copy(casttarget = value))) + override val castfunc = new Field[/* oid */ Long, Row](prefix, "castfunc", None, Some("oid"))(x => extract(x).castfunc, (row, value) => merge(row, extract(row).copy(castfunc = value))) + override val castcontext = new Field[String, Row](prefix, "castcontext", None, Some("char"))(x => extract(x).castcontext, (row, value) => merge(row, extract(row).copy(castcontext = value))) + override val castmethod = new Field[String, Row](prefix, "castmethod", None, Some("char"))(x => extract(x).castmethod, (row, value) => merge(row, extract(row).copy(castmethod = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, castsource, casttarget, castfunc, castcontext, castmethod) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgCastRow, merge: (NewRow, PgCastRow) => NewRow): PgCastStructure[NewRow] = + new PgCastStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassFields.scala new file mode 100644 index 0000000000..fb4c392c34 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassFields.scala @@ -0,0 +1,54 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgClassFields[Row] { + val oid: IdField[PgClassId, Row] + val relname: Field[String, Row] + val relnamespace: Field[/* oid */ Long, Row] + val reltype: Field[/* oid */ Long, Row] + val reloftype: Field[/* oid */ Long, Row] + val relowner: Field[/* oid */ Long, Row] + val relam: Field[/* oid */ Long, Row] + val relfilenode: Field[/* oid */ Long, Row] + val reltablespace: Field[/* oid */ Long, Row] + val relpages: Field[Int, Row] + val reltuples: Field[Float, Row] + val relallvisible: Field[Int, Row] + val reltoastrelid: Field[/* oid */ Long, Row] + val relhasindex: Field[Boolean, Row] + val relisshared: Field[Boolean, Row] + val relpersistence: Field[String, Row] + val relkind: Field[String, Row] + val relnatts: Field[TypoShort, Row] + val relchecks: Field[TypoShort, Row] + val relhasrules: Field[Boolean, Row] + val relhastriggers: Field[Boolean, Row] + val relhassubclass: Field[Boolean, Row] + val relrowsecurity: Field[Boolean, Row] + val relforcerowsecurity: Field[Boolean, Row] + val relispopulated: Field[Boolean, Row] + val relreplident: Field[String, Row] + val relispartition: Field[Boolean, Row] + val relrewrite: Field[/* oid */ Long, Row] + val relfrozenxid: Field[TypoXid, Row] + val relminmxid: Field[TypoXid, Row] + val relacl: OptField[Array[TypoAclItem], Row] + val reloptions: OptField[Array[String], Row] + val relpartbound: OptField[TypoPgNodeTree, Row] +} +object PgClassFields extends PgClassStructure[PgClassRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassId.scala new file mode 100644 index 0000000000..f78b4ab5d2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +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 `pg_catalog.pg_class` */ +case class PgClassId(value: /* oid */ Long) extends AnyVal +object PgClassId { + implicit lazy val arraySetter: Setter[Array[PgClassId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgClassId, /* oid */ Long] = Bijection[PgClassId, /* oid */ Long](_.value)(PgClassId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgClassId] = JdbcDecoder.longDecoder.map(PgClassId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgClassId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgClassId] = JsonDecoder.long.map(PgClassId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgClassId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgClassId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgClassId] = ParameterMetaData.instance[PgClassId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgClassId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepo.scala new file mode 100644 index 0000000000..61335fa865 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgClassRepo { + def delete(oid: PgClassId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgClassFields, PgClassRow] + def insert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, PgClassRow] + def select: SelectBuilder[PgClassFields, PgClassRow] + def selectAll: ZStream[ZConnection, Throwable, PgClassRow] + def selectById(oid: PgClassId): ZIO[ZConnection, Throwable, Option[PgClassRow]] + def selectByIds(oids: Array[PgClassId]): ZStream[ZConnection, Throwable, PgClassRow] + def selectByUnique(relname: String, relnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgClassRow]] + def update(row: PgClassRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgClassFields, PgClassRow] + def upsert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, UpdateResult[PgClassRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoImpl.scala new file mode 100644 index 0000000000..1713317939 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoImpl.scala @@ -0,0 +1,170 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgClassRepoImpl extends PgClassRepo { + override def delete(oid: PgClassId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_class where "oid" = ${Segment.paramSegment(oid)(PgClassId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgClassFields, PgClassRow] = { + DeleteBuilder("pg_catalog.pg_class", PgClassFields) + } + override def insert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, PgClassRow] = { + sql"""insert into pg_catalog.pg_class("oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound") + values (${Segment.paramSegment(unsaved.oid)(PgClassId.setter)}::oid, ${Segment.paramSegment(unsaved.relname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.relnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.reltype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.reloftype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relam)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relfilenode)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.reltablespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relpages)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.reltuples)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.relallvisible)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.reltoastrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relhasindex)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relisshared)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relpersistence)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.relkind)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.relnatts)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.relchecks)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.relhasrules)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relhastriggers)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relhassubclass)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relrowsecurity)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relforcerowsecurity)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relispopulated)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relreplident)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.relispartition)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.relrewrite)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.relfrozenxid)(TypoXid.setter)}::xid, ${Segment.paramSegment(unsaved.relminmxid)(TypoXid.setter)}::xid, ${Segment.paramSegment(unsaved.relacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, ${Segment.paramSegment(unsaved.reloptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.relpartbound)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound" + """.insertReturning(PgClassRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgClassFields, PgClassRow] = { + SelectBuilderSql("pg_catalog.pg_class", PgClassFields, PgClassRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgClassRow] = { + sql"""select "oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound" from pg_catalog.pg_class""".query(PgClassRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgClassId): ZIO[ZConnection, Throwable, Option[PgClassRow]] = { + sql"""select "oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound" from pg_catalog.pg_class where "oid" = ${Segment.paramSegment(oid)(PgClassId.setter)}""".query(PgClassRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgClassId]): ZStream[ZConnection, Throwable, PgClassRow] = { + sql"""select "oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound" from pg_catalog.pg_class where "oid" = ANY(${Segment.paramSegment(oids)(PgClassId.arraySetter)})""".query(PgClassRow.jdbcDecoder).selectStream + } + override def selectByUnique(relname: String, relnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgClassRow]] = { + sql"""select "relname", "relnamespace" + from pg_catalog.pg_class + where "relname" = ${Segment.paramSegment(relname)(Setter.stringSetter)} AND "relnamespace" = ${Segment.paramSegment(relnamespace)(Setter.longSetter)} + """.query(PgClassRow.jdbcDecoder).selectOne + } + override def update(row: PgClassRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_class + set "relname" = ${Segment.paramSegment(row.relname)(Setter.stringSetter)}::name, + "relnamespace" = ${Segment.paramSegment(row.relnamespace)(Setter.longSetter)}::oid, + "reltype" = ${Segment.paramSegment(row.reltype)(Setter.longSetter)}::oid, + "reloftype" = ${Segment.paramSegment(row.reloftype)(Setter.longSetter)}::oid, + "relowner" = ${Segment.paramSegment(row.relowner)(Setter.longSetter)}::oid, + "relam" = ${Segment.paramSegment(row.relam)(Setter.longSetter)}::oid, + "relfilenode" = ${Segment.paramSegment(row.relfilenode)(Setter.longSetter)}::oid, + "reltablespace" = ${Segment.paramSegment(row.reltablespace)(Setter.longSetter)}::oid, + "relpages" = ${Segment.paramSegment(row.relpages)(Setter.intSetter)}::int4, + "reltuples" = ${Segment.paramSegment(row.reltuples)(Setter.floatSetter)}::float4, + "relallvisible" = ${Segment.paramSegment(row.relallvisible)(Setter.intSetter)}::int4, + "reltoastrelid" = ${Segment.paramSegment(row.reltoastrelid)(Setter.longSetter)}::oid, + "relhasindex" = ${Segment.paramSegment(row.relhasindex)(Setter.booleanSetter)}, + "relisshared" = ${Segment.paramSegment(row.relisshared)(Setter.booleanSetter)}, + "relpersistence" = ${Segment.paramSegment(row.relpersistence)(Setter.stringSetter)}::char, + "relkind" = ${Segment.paramSegment(row.relkind)(Setter.stringSetter)}::char, + "relnatts" = ${Segment.paramSegment(row.relnatts)(TypoShort.setter)}::int2, + "relchecks" = ${Segment.paramSegment(row.relchecks)(TypoShort.setter)}::int2, + "relhasrules" = ${Segment.paramSegment(row.relhasrules)(Setter.booleanSetter)}, + "relhastriggers" = ${Segment.paramSegment(row.relhastriggers)(Setter.booleanSetter)}, + "relhassubclass" = ${Segment.paramSegment(row.relhassubclass)(Setter.booleanSetter)}, + "relrowsecurity" = ${Segment.paramSegment(row.relrowsecurity)(Setter.booleanSetter)}, + "relforcerowsecurity" = ${Segment.paramSegment(row.relforcerowsecurity)(Setter.booleanSetter)}, + "relispopulated" = ${Segment.paramSegment(row.relispopulated)(Setter.booleanSetter)}, + "relreplident" = ${Segment.paramSegment(row.relreplident)(Setter.stringSetter)}::char, + "relispartition" = ${Segment.paramSegment(row.relispartition)(Setter.booleanSetter)}, + "relrewrite" = ${Segment.paramSegment(row.relrewrite)(Setter.longSetter)}::oid, + "relfrozenxid" = ${Segment.paramSegment(row.relfrozenxid)(TypoXid.setter)}::xid, + "relminmxid" = ${Segment.paramSegment(row.relminmxid)(TypoXid.setter)}::xid, + "relacl" = ${Segment.paramSegment(row.relacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + "reloptions" = ${Segment.paramSegment(row.reloptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + "relpartbound" = ${Segment.paramSegment(row.relpartbound)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgClassId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgClassFields, PgClassRow] = { + UpdateBuilder("pg_catalog.pg_class", PgClassFields, PgClassRow.jdbcDecoder) + } + override def upsert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, UpdateResult[PgClassRow]] = { + sql"""insert into pg_catalog.pg_class("oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound") + values ( + ${Segment.paramSegment(unsaved.oid)(PgClassId.setter)}::oid, + ${Segment.paramSegment(unsaved.relname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.relnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.reltype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.reloftype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relam)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relfilenode)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.reltablespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relpages)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.reltuples)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.relallvisible)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.reltoastrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relhasindex)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relisshared)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relpersistence)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.relkind)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.relnatts)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.relchecks)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.relhasrules)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relhastriggers)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relhassubclass)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relrowsecurity)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relforcerowsecurity)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relispopulated)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relreplident)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.relispartition)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.relrewrite)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.relfrozenxid)(TypoXid.setter)}::xid, + ${Segment.paramSegment(unsaved.relminmxid)(TypoXid.setter)}::xid, + ${Segment.paramSegment(unsaved.relacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + ${Segment.paramSegment(unsaved.reloptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + ${Segment.paramSegment(unsaved.relpartbound)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("oid") + do update set + "relname" = EXCLUDED."relname", + "relnamespace" = EXCLUDED."relnamespace", + "reltype" = EXCLUDED."reltype", + "reloftype" = EXCLUDED."reloftype", + "relowner" = EXCLUDED."relowner", + "relam" = EXCLUDED."relam", + "relfilenode" = EXCLUDED."relfilenode", + "reltablespace" = EXCLUDED."reltablespace", + "relpages" = EXCLUDED."relpages", + "reltuples" = EXCLUDED."reltuples", + "relallvisible" = EXCLUDED."relallvisible", + "reltoastrelid" = EXCLUDED."reltoastrelid", + "relhasindex" = EXCLUDED."relhasindex", + "relisshared" = EXCLUDED."relisshared", + "relpersistence" = EXCLUDED."relpersistence", + "relkind" = EXCLUDED."relkind", + "relnatts" = EXCLUDED."relnatts", + "relchecks" = EXCLUDED."relchecks", + "relhasrules" = EXCLUDED."relhasrules", + "relhastriggers" = EXCLUDED."relhastriggers", + "relhassubclass" = EXCLUDED."relhassubclass", + "relrowsecurity" = EXCLUDED."relrowsecurity", + "relforcerowsecurity" = EXCLUDED."relforcerowsecurity", + "relispopulated" = EXCLUDED."relispopulated", + "relreplident" = EXCLUDED."relreplident", + "relispartition" = EXCLUDED."relispartition", + "relrewrite" = EXCLUDED."relrewrite", + "relfrozenxid" = EXCLUDED."relfrozenxid", + "relminmxid" = EXCLUDED."relminmxid", + "relacl" = EXCLUDED."relacl", + "reloptions" = EXCLUDED."reloptions", + "relpartbound" = EXCLUDED."relpartbound" + returning "oid", "relname", "relnamespace", "reltype", "reloftype", "relowner", "relam", "relfilenode", "reltablespace", "relpages", "reltuples", "relallvisible", "reltoastrelid", "relhasindex", "relisshared", "relpersistence", "relkind", "relnatts", "relchecks", "relhasrules", "relhastriggers", "relhassubclass", "relrowsecurity", "relforcerowsecurity", "relispopulated", "relreplident", "relispartition", "relrewrite", "relfrozenxid", "relminmxid", "relacl", "reloptions", "relpartbound"""".insertReturning(PgClassRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoMock.scala new file mode 100644 index 0000000000..a67a93e335 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgClassRepoMock(map: scala.collection.mutable.Map[PgClassId, PgClassRow] = scala.collection.mutable.Map.empty) extends PgClassRepo { + override def delete(oid: PgClassId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgClassFields, PgClassRow] = { + DeleteBuilderMock(DeleteParams.empty, PgClassFields, map) + } + override def insert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, PgClassRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgClassFields, PgClassRow] = { + SelectBuilderMock(PgClassFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgClassRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgClassId): ZIO[ZConnection, Throwable, Option[PgClassRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgClassId]): ZStream[ZConnection, Throwable, PgClassRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(relname: String, relnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgClassRow]] = { + ZIO.succeed(map.values.find(v => relname == v.relname && relnamespace == v.relnamespace)) + } + override def update(row: PgClassRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgClassFields, PgClassRow] = { + UpdateBuilderMock(UpdateParams.empty, PgClassFields, map) + } + override def upsert(unsaved: PgClassRow): ZIO[ZConnection, Throwable, UpdateResult[PgClassRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRow.scala new file mode 100644 index 0000000000..19cd25d45a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassRow.scala @@ -0,0 +1,239 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgClassRow( + oid: PgClassId, + relname: String, + relnamespace: /* oid */ Long, + reltype: /* oid */ Long, + reloftype: /* oid */ Long, + relowner: /* oid */ Long, + relam: /* oid */ Long, + relfilenode: /* oid */ Long, + reltablespace: /* oid */ Long, + relpages: Int, + reltuples: Float, + relallvisible: Int, + reltoastrelid: /* oid */ Long, + relhasindex: Boolean, + relisshared: Boolean, + relpersistence: String, + relkind: String, + relnatts: TypoShort, + relchecks: TypoShort, + relhasrules: Boolean, + relhastriggers: Boolean, + relhassubclass: Boolean, + relrowsecurity: Boolean, + relforcerowsecurity: Boolean, + relispopulated: Boolean, + relreplident: String, + relispartition: Boolean, + relrewrite: /* oid */ Long, + relfrozenxid: TypoXid, + relminmxid: TypoXid, + relacl: Option[Array[TypoAclItem]], + reloptions: Option[Array[String]], + relpartbound: Option[TypoPgNodeTree] +) + +object PgClassRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgClassRow] = new JdbcDecoder[PgClassRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgClassRow) = + columIndex + 32 -> + PgClassRow( + oid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + relnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + reltype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + reloftype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + relowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + relam = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + relfilenode = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + reltablespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2, + relpages = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 9, rs)._2, + reltuples = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 10, rs)._2, + relallvisible = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 11, rs)._2, + reltoastrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 12, rs)._2, + relhasindex = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 13, rs)._2, + relisshared = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 14, rs)._2, + relpersistence = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 15, rs)._2, + relkind = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 16, rs)._2, + relnatts = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 17, rs)._2, + relchecks = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 18, rs)._2, + relhasrules = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 19, rs)._2, + relhastriggers = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 20, rs)._2, + relhassubclass = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 21, rs)._2, + relrowsecurity = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 22, rs)._2, + relforcerowsecurity = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 23, rs)._2, + relispopulated = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 24, rs)._2, + relreplident = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 25, rs)._2, + relispartition = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 26, rs)._2, + relrewrite = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 27, rs)._2, + relfrozenxid = TypoXid.jdbcDecoder.unsafeDecode(columIndex + 28, rs)._2, + relminmxid = TypoXid.jdbcDecoder.unsafeDecode(columIndex + 29, rs)._2, + relacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 30, rs)._2, + reloptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 31, rs)._2, + relpartbound = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 32, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgClassRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgClassId.jsonDecoder)) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val relnamespace = jsonObj.get("relnamespace").toRight("Missing field 'relnamespace'").flatMap(_.as(JsonDecoder.long)) + val reltype = jsonObj.get("reltype").toRight("Missing field 'reltype'").flatMap(_.as(JsonDecoder.long)) + val reloftype = jsonObj.get("reloftype").toRight("Missing field 'reloftype'").flatMap(_.as(JsonDecoder.long)) + val relowner = jsonObj.get("relowner").toRight("Missing field 'relowner'").flatMap(_.as(JsonDecoder.long)) + val relam = jsonObj.get("relam").toRight("Missing field 'relam'").flatMap(_.as(JsonDecoder.long)) + val relfilenode = jsonObj.get("relfilenode").toRight("Missing field 'relfilenode'").flatMap(_.as(JsonDecoder.long)) + val reltablespace = jsonObj.get("reltablespace").toRight("Missing field 'reltablespace'").flatMap(_.as(JsonDecoder.long)) + val relpages = jsonObj.get("relpages").toRight("Missing field 'relpages'").flatMap(_.as(JsonDecoder.int)) + val reltuples = jsonObj.get("reltuples").toRight("Missing field 'reltuples'").flatMap(_.as(JsonDecoder.float)) + val relallvisible = jsonObj.get("relallvisible").toRight("Missing field 'relallvisible'").flatMap(_.as(JsonDecoder.int)) + val reltoastrelid = jsonObj.get("reltoastrelid").toRight("Missing field 'reltoastrelid'").flatMap(_.as(JsonDecoder.long)) + val relhasindex = jsonObj.get("relhasindex").toRight("Missing field 'relhasindex'").flatMap(_.as(JsonDecoder.boolean)) + val relisshared = jsonObj.get("relisshared").toRight("Missing field 'relisshared'").flatMap(_.as(JsonDecoder.boolean)) + val relpersistence = jsonObj.get("relpersistence").toRight("Missing field 'relpersistence'").flatMap(_.as(JsonDecoder.string)) + val relkind = jsonObj.get("relkind").toRight("Missing field 'relkind'").flatMap(_.as(JsonDecoder.string)) + val relnatts = jsonObj.get("relnatts").toRight("Missing field 'relnatts'").flatMap(_.as(TypoShort.jsonDecoder)) + val relchecks = jsonObj.get("relchecks").toRight("Missing field 'relchecks'").flatMap(_.as(TypoShort.jsonDecoder)) + val relhasrules = jsonObj.get("relhasrules").toRight("Missing field 'relhasrules'").flatMap(_.as(JsonDecoder.boolean)) + val relhastriggers = jsonObj.get("relhastriggers").toRight("Missing field 'relhastriggers'").flatMap(_.as(JsonDecoder.boolean)) + val relhassubclass = jsonObj.get("relhassubclass").toRight("Missing field 'relhassubclass'").flatMap(_.as(JsonDecoder.boolean)) + val relrowsecurity = jsonObj.get("relrowsecurity").toRight("Missing field 'relrowsecurity'").flatMap(_.as(JsonDecoder.boolean)) + val relforcerowsecurity = jsonObj.get("relforcerowsecurity").toRight("Missing field 'relforcerowsecurity'").flatMap(_.as(JsonDecoder.boolean)) + val relispopulated = jsonObj.get("relispopulated").toRight("Missing field 'relispopulated'").flatMap(_.as(JsonDecoder.boolean)) + val relreplident = jsonObj.get("relreplident").toRight("Missing field 'relreplident'").flatMap(_.as(JsonDecoder.string)) + val relispartition = jsonObj.get("relispartition").toRight("Missing field 'relispartition'").flatMap(_.as(JsonDecoder.boolean)) + val relrewrite = jsonObj.get("relrewrite").toRight("Missing field 'relrewrite'").flatMap(_.as(JsonDecoder.long)) + val relfrozenxid = jsonObj.get("relfrozenxid").toRight("Missing field 'relfrozenxid'").flatMap(_.as(TypoXid.jsonDecoder)) + val relminmxid = jsonObj.get("relminmxid").toRight("Missing field 'relminmxid'").flatMap(_.as(TypoXid.jsonDecoder)) + val relacl = jsonObj.get("relacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + val reloptions = jsonObj.get("reloptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val relpartbound = jsonObj.get("relpartbound").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (oid.isRight && relname.isRight && relnamespace.isRight && reltype.isRight && reloftype.isRight && relowner.isRight && relam.isRight && relfilenode.isRight && reltablespace.isRight && relpages.isRight && reltuples.isRight && relallvisible.isRight && reltoastrelid.isRight && relhasindex.isRight && relisshared.isRight && relpersistence.isRight && relkind.isRight && relnatts.isRight && relchecks.isRight && relhasrules.isRight && relhastriggers.isRight && relhassubclass.isRight && relrowsecurity.isRight && relforcerowsecurity.isRight && relispopulated.isRight && relreplident.isRight && relispartition.isRight && relrewrite.isRight && relfrozenxid.isRight && relminmxid.isRight && relacl.isRight && reloptions.isRight && relpartbound.isRight) + Right(PgClassRow(oid = oid.toOption.get, relname = relname.toOption.get, relnamespace = relnamespace.toOption.get, reltype = reltype.toOption.get, reloftype = reloftype.toOption.get, relowner = relowner.toOption.get, relam = relam.toOption.get, relfilenode = relfilenode.toOption.get, reltablespace = reltablespace.toOption.get, relpages = relpages.toOption.get, reltuples = reltuples.toOption.get, relallvisible = relallvisible.toOption.get, reltoastrelid = reltoastrelid.toOption.get, relhasindex = relhasindex.toOption.get, relisshared = relisshared.toOption.get, relpersistence = relpersistence.toOption.get, relkind = relkind.toOption.get, relnatts = relnatts.toOption.get, relchecks = relchecks.toOption.get, relhasrules = relhasrules.toOption.get, relhastriggers = relhastriggers.toOption.get, relhassubclass = relhassubclass.toOption.get, relrowsecurity = relrowsecurity.toOption.get, relforcerowsecurity = relforcerowsecurity.toOption.get, relispopulated = relispopulated.toOption.get, relreplident = relreplident.toOption.get, relispartition = relispartition.toOption.get, relrewrite = relrewrite.toOption.get, relfrozenxid = relfrozenxid.toOption.get, relminmxid = relminmxid.toOption.get, relacl = relacl.toOption.get, reloptions = reloptions.toOption.get, relpartbound = relpartbound.toOption.get)) + else Left(List[Either[String, Any]](oid, relname, relnamespace, reltype, reloftype, relowner, relam, relfilenode, reltablespace, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence, relkind, relnatts, relchecks, relhasrules, relhastriggers, relhassubclass, relrowsecurity, relforcerowsecurity, relispopulated, relreplident, relispartition, relrewrite, relfrozenxid, relminmxid, relacl, reloptions, relpartbound).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgClassRow] = new JsonEncoder[PgClassRow] { + override def unsafeEncode(a: PgClassRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgClassId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""relnamespace":""") + JsonEncoder.long.unsafeEncode(a.relnamespace, indent, out) + out.write(",") + out.write(""""reltype":""") + JsonEncoder.long.unsafeEncode(a.reltype, indent, out) + out.write(",") + out.write(""""reloftype":""") + JsonEncoder.long.unsafeEncode(a.reloftype, indent, out) + out.write(",") + out.write(""""relowner":""") + JsonEncoder.long.unsafeEncode(a.relowner, indent, out) + out.write(",") + out.write(""""relam":""") + JsonEncoder.long.unsafeEncode(a.relam, indent, out) + out.write(",") + out.write(""""relfilenode":""") + JsonEncoder.long.unsafeEncode(a.relfilenode, indent, out) + out.write(",") + out.write(""""reltablespace":""") + JsonEncoder.long.unsafeEncode(a.reltablespace, indent, out) + out.write(",") + out.write(""""relpages":""") + JsonEncoder.int.unsafeEncode(a.relpages, indent, out) + out.write(",") + out.write(""""reltuples":""") + JsonEncoder.float.unsafeEncode(a.reltuples, indent, out) + out.write(",") + out.write(""""relallvisible":""") + JsonEncoder.int.unsafeEncode(a.relallvisible, indent, out) + out.write(",") + out.write(""""reltoastrelid":""") + JsonEncoder.long.unsafeEncode(a.reltoastrelid, indent, out) + out.write(",") + out.write(""""relhasindex":""") + JsonEncoder.boolean.unsafeEncode(a.relhasindex, indent, out) + out.write(",") + out.write(""""relisshared":""") + JsonEncoder.boolean.unsafeEncode(a.relisshared, indent, out) + out.write(",") + out.write(""""relpersistence":""") + JsonEncoder.string.unsafeEncode(a.relpersistence, indent, out) + out.write(",") + out.write(""""relkind":""") + JsonEncoder.string.unsafeEncode(a.relkind, indent, out) + out.write(",") + out.write(""""relnatts":""") + TypoShort.jsonEncoder.unsafeEncode(a.relnatts, indent, out) + out.write(",") + out.write(""""relchecks":""") + TypoShort.jsonEncoder.unsafeEncode(a.relchecks, indent, out) + out.write(",") + out.write(""""relhasrules":""") + JsonEncoder.boolean.unsafeEncode(a.relhasrules, indent, out) + out.write(",") + out.write(""""relhastriggers":""") + JsonEncoder.boolean.unsafeEncode(a.relhastriggers, indent, out) + out.write(",") + out.write(""""relhassubclass":""") + JsonEncoder.boolean.unsafeEncode(a.relhassubclass, indent, out) + out.write(",") + out.write(""""relrowsecurity":""") + JsonEncoder.boolean.unsafeEncode(a.relrowsecurity, indent, out) + out.write(",") + out.write(""""relforcerowsecurity":""") + JsonEncoder.boolean.unsafeEncode(a.relforcerowsecurity, indent, out) + out.write(",") + out.write(""""relispopulated":""") + JsonEncoder.boolean.unsafeEncode(a.relispopulated, indent, out) + out.write(",") + out.write(""""relreplident":""") + JsonEncoder.string.unsafeEncode(a.relreplident, indent, out) + out.write(",") + out.write(""""relispartition":""") + JsonEncoder.boolean.unsafeEncode(a.relispartition, indent, out) + out.write(",") + out.write(""""relrewrite":""") + JsonEncoder.long.unsafeEncode(a.relrewrite, indent, out) + out.write(",") + out.write(""""relfrozenxid":""") + TypoXid.jsonEncoder.unsafeEncode(a.relfrozenxid, indent, out) + out.write(",") + out.write(""""relminmxid":""") + TypoXid.jsonEncoder.unsafeEncode(a.relminmxid, indent, out) + out.write(",") + out.write(""""relacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.relacl, indent, out) + out.write(",") + out.write(""""reloptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.reloptions, indent, out) + out.write(",") + out.write(""""relpartbound":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.relpartbound, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassStructure.scala new file mode 100644 index 0000000000..f2d9c8b49d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_class/PgClassStructure.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_class + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgClassStructure[Row](val prefix: Option[String], val extract: Row => PgClassRow, val merge: (Row, PgClassRow) => Row) + extends Relation[PgClassFields, PgClassRow, Row] + with PgClassFields[Row] { outer => + + override val oid = new IdField[PgClassId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val relname = new Field[String, Row](prefix, "relname", None, Some("name"))(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val relnamespace = new Field[/* oid */ Long, Row](prefix, "relnamespace", None, Some("oid"))(x => extract(x).relnamespace, (row, value) => merge(row, extract(row).copy(relnamespace = value))) + override val reltype = new Field[/* oid */ Long, Row](prefix, "reltype", None, Some("oid"))(x => extract(x).reltype, (row, value) => merge(row, extract(row).copy(reltype = value))) + override val reloftype = new Field[/* oid */ Long, Row](prefix, "reloftype", None, Some("oid"))(x => extract(x).reloftype, (row, value) => merge(row, extract(row).copy(reloftype = value))) + override val relowner = new Field[/* oid */ Long, Row](prefix, "relowner", None, Some("oid"))(x => extract(x).relowner, (row, value) => merge(row, extract(row).copy(relowner = value))) + override val relam = new Field[/* oid */ Long, Row](prefix, "relam", None, Some("oid"))(x => extract(x).relam, (row, value) => merge(row, extract(row).copy(relam = value))) + override val relfilenode = new Field[/* oid */ Long, Row](prefix, "relfilenode", None, Some("oid"))(x => extract(x).relfilenode, (row, value) => merge(row, extract(row).copy(relfilenode = value))) + override val reltablespace = new Field[/* oid */ Long, Row](prefix, "reltablespace", None, Some("oid"))(x => extract(x).reltablespace, (row, value) => merge(row, extract(row).copy(reltablespace = value))) + override val relpages = new Field[Int, Row](prefix, "relpages", None, Some("int4"))(x => extract(x).relpages, (row, value) => merge(row, extract(row).copy(relpages = value))) + override val reltuples = new Field[Float, Row](prefix, "reltuples", None, Some("float4"))(x => extract(x).reltuples, (row, value) => merge(row, extract(row).copy(reltuples = value))) + override val relallvisible = new Field[Int, Row](prefix, "relallvisible", None, Some("int4"))(x => extract(x).relallvisible, (row, value) => merge(row, extract(row).copy(relallvisible = value))) + override val reltoastrelid = new Field[/* oid */ Long, Row](prefix, "reltoastrelid", None, Some("oid"))(x => extract(x).reltoastrelid, (row, value) => merge(row, extract(row).copy(reltoastrelid = value))) + override val relhasindex = new Field[Boolean, Row](prefix, "relhasindex", None, None)(x => extract(x).relhasindex, (row, value) => merge(row, extract(row).copy(relhasindex = value))) + override val relisshared = new Field[Boolean, Row](prefix, "relisshared", None, None)(x => extract(x).relisshared, (row, value) => merge(row, extract(row).copy(relisshared = value))) + override val relpersistence = new Field[String, Row](prefix, "relpersistence", None, Some("char"))(x => extract(x).relpersistence, (row, value) => merge(row, extract(row).copy(relpersistence = value))) + override val relkind = new Field[String, Row](prefix, "relkind", None, Some("char"))(x => extract(x).relkind, (row, value) => merge(row, extract(row).copy(relkind = value))) + override val relnatts = new Field[TypoShort, Row](prefix, "relnatts", None, Some("int2"))(x => extract(x).relnatts, (row, value) => merge(row, extract(row).copy(relnatts = value))) + override val relchecks = new Field[TypoShort, Row](prefix, "relchecks", None, Some("int2"))(x => extract(x).relchecks, (row, value) => merge(row, extract(row).copy(relchecks = value))) + override val relhasrules = new Field[Boolean, Row](prefix, "relhasrules", None, None)(x => extract(x).relhasrules, (row, value) => merge(row, extract(row).copy(relhasrules = value))) + override val relhastriggers = new Field[Boolean, Row](prefix, "relhastriggers", None, None)(x => extract(x).relhastriggers, (row, value) => merge(row, extract(row).copy(relhastriggers = value))) + override val relhassubclass = new Field[Boolean, Row](prefix, "relhassubclass", None, None)(x => extract(x).relhassubclass, (row, value) => merge(row, extract(row).copy(relhassubclass = value))) + override val relrowsecurity = new Field[Boolean, Row](prefix, "relrowsecurity", None, None)(x => extract(x).relrowsecurity, (row, value) => merge(row, extract(row).copy(relrowsecurity = value))) + override val relforcerowsecurity = new Field[Boolean, Row](prefix, "relforcerowsecurity", None, None)(x => extract(x).relforcerowsecurity, (row, value) => merge(row, extract(row).copy(relforcerowsecurity = value))) + override val relispopulated = new Field[Boolean, Row](prefix, "relispopulated", None, None)(x => extract(x).relispopulated, (row, value) => merge(row, extract(row).copy(relispopulated = value))) + override val relreplident = new Field[String, Row](prefix, "relreplident", None, Some("char"))(x => extract(x).relreplident, (row, value) => merge(row, extract(row).copy(relreplident = value))) + override val relispartition = new Field[Boolean, Row](prefix, "relispartition", None, None)(x => extract(x).relispartition, (row, value) => merge(row, extract(row).copy(relispartition = value))) + override val relrewrite = new Field[/* oid */ Long, Row](prefix, "relrewrite", None, Some("oid"))(x => extract(x).relrewrite, (row, value) => merge(row, extract(row).copy(relrewrite = value))) + override val relfrozenxid = new Field[TypoXid, Row](prefix, "relfrozenxid", None, Some("xid"))(x => extract(x).relfrozenxid, (row, value) => merge(row, extract(row).copy(relfrozenxid = value))) + override val relminmxid = new Field[TypoXid, Row](prefix, "relminmxid", None, Some("xid"))(x => extract(x).relminmxid, (row, value) => merge(row, extract(row).copy(relminmxid = value))) + override val relacl = new OptField[Array[TypoAclItem], Row](prefix, "relacl", None, Some("_aclitem"))(x => extract(x).relacl, (row, value) => merge(row, extract(row).copy(relacl = value))) + override val reloptions = new OptField[Array[String], Row](prefix, "reloptions", None, Some("_text"))(x => extract(x).reloptions, (row, value) => merge(row, extract(row).copy(reloptions = value))) + override val relpartbound = new OptField[TypoPgNodeTree, Row](prefix, "relpartbound", None, Some("pg_node_tree"))(x => extract(x).relpartbound, (row, value) => merge(row, extract(row).copy(relpartbound = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, relname, relnamespace, reltype, reloftype, relowner, relam, relfilenode, reltablespace, relpages, reltuples, relallvisible, reltoastrelid, relhasindex, relisshared, relpersistence, relkind, relnatts, relchecks, relhasrules, relhastriggers, relhassubclass, relrowsecurity, relforcerowsecurity, relispopulated, relreplident, relispartition, relrewrite, relfrozenxid, relminmxid, relacl, reloptions, relpartbound) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgClassRow, merge: (NewRow, PgClassRow) => NewRow): PgClassStructure[NewRow] = + new PgClassStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationFields.scala new file mode 100644 index 0000000000..8940de9495 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgCollationFields[Row] { + val oid: IdField[PgCollationId, Row] + val collname: Field[String, Row] + val collnamespace: Field[/* oid */ Long, Row] + val collowner: Field[/* oid */ Long, Row] + val collprovider: Field[String, Row] + val collisdeterministic: Field[Boolean, Row] + val collencoding: Field[Int, Row] + val collcollate: Field[String, Row] + val collctype: Field[String, Row] + val collversion: OptField[String, Row] +} +object PgCollationFields extends PgCollationStructure[PgCollationRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationId.scala new file mode 100644 index 0000000000..887c3fa103 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +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 `pg_catalog.pg_collation` */ +case class PgCollationId(value: /* oid */ Long) extends AnyVal +object PgCollationId { + implicit lazy val arraySetter: Setter[Array[PgCollationId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgCollationId, /* oid */ Long] = Bijection[PgCollationId, /* oid */ Long](_.value)(PgCollationId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgCollationId] = JdbcDecoder.longDecoder.map(PgCollationId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgCollationId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgCollationId] = JsonDecoder.long.map(PgCollationId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgCollationId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgCollationId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgCollationId] = ParameterMetaData.instance[PgCollationId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgCollationId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepo.scala new file mode 100644 index 0000000000..c3ac8154be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgCollationRepo { + def delete(oid: PgCollationId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgCollationFields, PgCollationRow] + def insert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, PgCollationRow] + def select: SelectBuilder[PgCollationFields, PgCollationRow] + def selectAll: ZStream[ZConnection, Throwable, PgCollationRow] + def selectById(oid: PgCollationId): ZIO[ZConnection, Throwable, Option[PgCollationRow]] + def selectByIds(oids: Array[PgCollationId]): ZStream[ZConnection, Throwable, PgCollationRow] + def selectByUnique(collname: String, collencoding: Int, collnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCollationRow]] + def update(row: PgCollationRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgCollationFields, PgCollationRow] + def upsert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, UpdateResult[PgCollationRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoImpl.scala new file mode 100644 index 0000000000..571f649242 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoImpl.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgCollationRepoImpl extends PgCollationRepo { + override def delete(oid: PgCollationId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_collation where "oid" = ${Segment.paramSegment(oid)(PgCollationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgCollationFields, PgCollationRow] = { + DeleteBuilder("pg_catalog.pg_collation", PgCollationFields) + } + override def insert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, PgCollationRow] = { + sql"""insert into pg_catalog.pg_collation("oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion") + values (${Segment.paramSegment(unsaved.oid)(PgCollationId.setter)}::oid, ${Segment.paramSegment(unsaved.collname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.collnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.collowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.collprovider)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.collisdeterministic)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.collencoding)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.collcollate)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.collctype)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.collversion)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion" + """.insertReturning(PgCollationRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgCollationFields, PgCollationRow] = { + SelectBuilderSql("pg_catalog.pg_collation", PgCollationFields, PgCollationRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgCollationRow] = { + sql"""select "oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion" from pg_catalog.pg_collation""".query(PgCollationRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgCollationId): ZIO[ZConnection, Throwable, Option[PgCollationRow]] = { + sql"""select "oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion" from pg_catalog.pg_collation where "oid" = ${Segment.paramSegment(oid)(PgCollationId.setter)}""".query(PgCollationRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgCollationId]): ZStream[ZConnection, Throwable, PgCollationRow] = { + sql"""select "oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion" from pg_catalog.pg_collation where "oid" = ANY(${Segment.paramSegment(oids)(PgCollationId.arraySetter)})""".query(PgCollationRow.jdbcDecoder).selectStream + } + override def selectByUnique(collname: String, collencoding: Int, collnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCollationRow]] = { + sql"""select "collname", "collencoding", "collnamespace" + from pg_catalog.pg_collation + where "collname" = ${Segment.paramSegment(collname)(Setter.stringSetter)} AND "collencoding" = ${Segment.paramSegment(collencoding)(Setter.intSetter)} AND "collnamespace" = ${Segment.paramSegment(collnamespace)(Setter.longSetter)} + """.query(PgCollationRow.jdbcDecoder).selectOne + } + override def update(row: PgCollationRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_collation + set "collname" = ${Segment.paramSegment(row.collname)(Setter.stringSetter)}::name, + "collnamespace" = ${Segment.paramSegment(row.collnamespace)(Setter.longSetter)}::oid, + "collowner" = ${Segment.paramSegment(row.collowner)(Setter.longSetter)}::oid, + "collprovider" = ${Segment.paramSegment(row.collprovider)(Setter.stringSetter)}::char, + "collisdeterministic" = ${Segment.paramSegment(row.collisdeterministic)(Setter.booleanSetter)}, + "collencoding" = ${Segment.paramSegment(row.collencoding)(Setter.intSetter)}::int4, + "collcollate" = ${Segment.paramSegment(row.collcollate)(Setter.stringSetter)}::name, + "collctype" = ${Segment.paramSegment(row.collctype)(Setter.stringSetter)}::name, + "collversion" = ${Segment.paramSegment(row.collversion)(Setter.optionParamSetter(Setter.stringSetter))} + where "oid" = ${Segment.paramSegment(oid)(PgCollationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgCollationFields, PgCollationRow] = { + UpdateBuilder("pg_catalog.pg_collation", PgCollationFields, PgCollationRow.jdbcDecoder) + } + override def upsert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, UpdateResult[PgCollationRow]] = { + sql"""insert into pg_catalog.pg_collation("oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion") + values ( + ${Segment.paramSegment(unsaved.oid)(PgCollationId.setter)}::oid, + ${Segment.paramSegment(unsaved.collname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.collnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.collowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.collprovider)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.collisdeterministic)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.collencoding)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.collcollate)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.collctype)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.collversion)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("oid") + do update set + "collname" = EXCLUDED."collname", + "collnamespace" = EXCLUDED."collnamespace", + "collowner" = EXCLUDED."collowner", + "collprovider" = EXCLUDED."collprovider", + "collisdeterministic" = EXCLUDED."collisdeterministic", + "collencoding" = EXCLUDED."collencoding", + "collcollate" = EXCLUDED."collcollate", + "collctype" = EXCLUDED."collctype", + "collversion" = EXCLUDED."collversion" + returning "oid", "collname", "collnamespace", "collowner", "collprovider", "collisdeterministic", "collencoding", "collcollate", "collctype", "collversion"""".insertReturning(PgCollationRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoMock.scala new file mode 100644 index 0000000000..df113c7785 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgCollationRepoMock(map: scala.collection.mutable.Map[PgCollationId, PgCollationRow] = scala.collection.mutable.Map.empty) extends PgCollationRepo { + override def delete(oid: PgCollationId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgCollationFields, PgCollationRow] = { + DeleteBuilderMock(DeleteParams.empty, PgCollationFields, map) + } + override def insert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, PgCollationRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgCollationFields, PgCollationRow] = { + SelectBuilderMock(PgCollationFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgCollationRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgCollationId): ZIO[ZConnection, Throwable, Option[PgCollationRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgCollationId]): ZStream[ZConnection, Throwable, PgCollationRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(collname: String, collencoding: Int, collnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgCollationRow]] = { + ZIO.succeed(map.values.find(v => collname == v.collname && collencoding == v.collencoding && collnamespace == v.collnamespace)) + } + override def update(row: PgCollationRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgCollationFields, PgCollationRow] = { + UpdateBuilderMock(UpdateParams.empty, PgCollationFields, map) + } + override def upsert(unsaved: PgCollationRow): ZIO[ZConnection, Throwable, UpdateResult[PgCollationRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRow.scala new file mode 100644 index 0000000000..f3154829a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgCollationRow( + oid: PgCollationId, + collname: String, + collnamespace: /* oid */ Long, + collowner: /* oid */ Long, + collprovider: String, + collisdeterministic: Boolean, + collencoding: Int, + collcollate: String, + collctype: String, + collversion: Option[String] +) + +object PgCollationRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgCollationRow] = new JdbcDecoder[PgCollationRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgCollationRow) = + columIndex + 9 -> + PgCollationRow( + oid = PgCollationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + collname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + collnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + collowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + collprovider = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + collisdeterministic = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + collencoding = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + collcollate = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + collctype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 8, rs)._2, + collversion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgCollationRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgCollationId.jsonDecoder)) + val collname = jsonObj.get("collname").toRight("Missing field 'collname'").flatMap(_.as(JsonDecoder.string)) + val collnamespace = jsonObj.get("collnamespace").toRight("Missing field 'collnamespace'").flatMap(_.as(JsonDecoder.long)) + val collowner = jsonObj.get("collowner").toRight("Missing field 'collowner'").flatMap(_.as(JsonDecoder.long)) + val collprovider = jsonObj.get("collprovider").toRight("Missing field 'collprovider'").flatMap(_.as(JsonDecoder.string)) + val collisdeterministic = jsonObj.get("collisdeterministic").toRight("Missing field 'collisdeterministic'").flatMap(_.as(JsonDecoder.boolean)) + val collencoding = jsonObj.get("collencoding").toRight("Missing field 'collencoding'").flatMap(_.as(JsonDecoder.int)) + val collcollate = jsonObj.get("collcollate").toRight("Missing field 'collcollate'").flatMap(_.as(JsonDecoder.string)) + val collctype = jsonObj.get("collctype").toRight("Missing field 'collctype'").flatMap(_.as(JsonDecoder.string)) + val collversion = jsonObj.get("collversion").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && collname.isRight && collnamespace.isRight && collowner.isRight && collprovider.isRight && collisdeterministic.isRight && collencoding.isRight && collcollate.isRight && collctype.isRight && collversion.isRight) + Right(PgCollationRow(oid = oid.toOption.get, collname = collname.toOption.get, collnamespace = collnamespace.toOption.get, collowner = collowner.toOption.get, collprovider = collprovider.toOption.get, collisdeterministic = collisdeterministic.toOption.get, collencoding = collencoding.toOption.get, collcollate = collcollate.toOption.get, collctype = collctype.toOption.get, collversion = collversion.toOption.get)) + else Left(List[Either[String, Any]](oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype, collversion).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgCollationRow] = new JsonEncoder[PgCollationRow] { + override def unsafeEncode(a: PgCollationRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgCollationId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""collname":""") + JsonEncoder.string.unsafeEncode(a.collname, indent, out) + out.write(",") + out.write(""""collnamespace":""") + JsonEncoder.long.unsafeEncode(a.collnamespace, indent, out) + out.write(",") + out.write(""""collowner":""") + JsonEncoder.long.unsafeEncode(a.collowner, indent, out) + out.write(",") + out.write(""""collprovider":""") + JsonEncoder.string.unsafeEncode(a.collprovider, indent, out) + out.write(",") + out.write(""""collisdeterministic":""") + JsonEncoder.boolean.unsafeEncode(a.collisdeterministic, indent, out) + out.write(",") + out.write(""""collencoding":""") + JsonEncoder.int.unsafeEncode(a.collencoding, indent, out) + out.write(",") + out.write(""""collcollate":""") + JsonEncoder.string.unsafeEncode(a.collcollate, indent, out) + out.write(",") + out.write(""""collctype":""") + JsonEncoder.string.unsafeEncode(a.collctype, indent, out) + out.write(",") + out.write(""""collversion":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.collversion, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationStructure.scala new file mode 100644 index 0000000000..00b407a429 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_collation/PgCollationStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_collation + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgCollationStructure[Row](val prefix: Option[String], val extract: Row => PgCollationRow, val merge: (Row, PgCollationRow) => Row) + extends Relation[PgCollationFields, PgCollationRow, Row] + with PgCollationFields[Row] { outer => + + override val oid = new IdField[PgCollationId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val collname = new Field[String, Row](prefix, "collname", None, Some("name"))(x => extract(x).collname, (row, value) => merge(row, extract(row).copy(collname = value))) + override val collnamespace = new Field[/* oid */ Long, Row](prefix, "collnamespace", None, Some("oid"))(x => extract(x).collnamespace, (row, value) => merge(row, extract(row).copy(collnamespace = value))) + override val collowner = new Field[/* oid */ Long, Row](prefix, "collowner", None, Some("oid"))(x => extract(x).collowner, (row, value) => merge(row, extract(row).copy(collowner = value))) + override val collprovider = new Field[String, Row](prefix, "collprovider", None, Some("char"))(x => extract(x).collprovider, (row, value) => merge(row, extract(row).copy(collprovider = value))) + override val collisdeterministic = new Field[Boolean, Row](prefix, "collisdeterministic", None, None)(x => extract(x).collisdeterministic, (row, value) => merge(row, extract(row).copy(collisdeterministic = value))) + override val collencoding = new Field[Int, Row](prefix, "collencoding", None, Some("int4"))(x => extract(x).collencoding, (row, value) => merge(row, extract(row).copy(collencoding = value))) + override val collcollate = new Field[String, Row](prefix, "collcollate", None, Some("name"))(x => extract(x).collcollate, (row, value) => merge(row, extract(row).copy(collcollate = value))) + override val collctype = new Field[String, Row](prefix, "collctype", None, Some("name"))(x => extract(x).collctype, (row, value) => merge(row, extract(row).copy(collctype = value))) + override val collversion = new OptField[String, Row](prefix, "collversion", None, None)(x => extract(x).collversion, (row, value) => merge(row, extract(row).copy(collversion = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, collname, collnamespace, collowner, collprovider, collisdeterministic, collencoding, collcollate, collctype, collversion) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgCollationRow, merge: (NewRow, PgCollationRow) => NewRow): PgCollationStructure[NewRow] = + new PgCollationStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewFields.scala new file mode 100644 index 0000000000..578138a80c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewFields.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_config + +import typo.dsl.SqlExpr.OptField + +trait PgConfigViewFields[Row] { + val name: OptField[String, Row] + val setting: OptField[String, Row] +} +object PgConfigViewFields extends PgConfigViewStructure[PgConfigViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepo.scala new file mode 100644 index 0000000000..c8abe693da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_config + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgConfigViewRepo { + def select: SelectBuilder[PgConfigViewFields, PgConfigViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgConfigViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepoImpl.scala new file mode 100644 index 0000000000..40ee9fafe0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_config + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgConfigViewRepoImpl extends PgConfigViewRepo { + override def select: SelectBuilder[PgConfigViewFields, PgConfigViewRow] = { + SelectBuilderSql("pg_catalog.pg_config", PgConfigViewFields, PgConfigViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgConfigViewRow] = { + sql"""select "name", "setting" from pg_catalog.pg_config""".query(PgConfigViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRow.scala new file mode 100644 index 0000000000..f4e05adc9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewRow.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_config + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgConfigViewRow( + name: /* nullability unknown */ Option[String], + setting: /* nullability unknown */ Option[String] +) + +object PgConfigViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgConfigViewRow] = new JdbcDecoder[PgConfigViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgConfigViewRow) = + columIndex + 1 -> + PgConfigViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + setting = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgConfigViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val setting = jsonObj.get("setting").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (name.isRight && setting.isRight) + Right(PgConfigViewRow(name = name.toOption.get, setting = setting.toOption.get)) + else Left(List[Either[String, Any]](name, setting).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgConfigViewRow] = new JsonEncoder[PgConfigViewRow] { + override def unsafeEncode(a: PgConfigViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""setting":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.setting, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewStructure.scala new file mode 100644 index 0000000000..0b19f45ea9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_config/PgConfigViewStructure.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_config + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgConfigViewStructure[Row](val prefix: Option[String], val extract: Row => PgConfigViewRow, val merge: (Row, PgConfigViewRow) => Row) + extends Relation[PgConfigViewFields, PgConfigViewRow, Row] + with PgConfigViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val setting = new OptField[String, Row](prefix, "setting", None, None)(x => extract(x).setting, (row, value) => merge(row, extract(row).copy(setting = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, setting) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgConfigViewRow, merge: (NewRow, PgConfigViewRow) => NewRow): PgConfigViewStructure[NewRow] = + new PgConfigViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintFields.scala new file mode 100644 index 0000000000..9b370778d8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintFields.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgConstraintFields[Row] { + val oid: IdField[PgConstraintId, Row] + val conname: Field[String, Row] + val connamespace: Field[/* oid */ Long, Row] + val contype: Field[String, Row] + val condeferrable: Field[Boolean, Row] + val condeferred: Field[Boolean, Row] + val convalidated: Field[Boolean, Row] + val conrelid: Field[/* oid */ Long, Row] + val contypid: Field[/* oid */ Long, Row] + val conindid: Field[/* oid */ Long, Row] + val conparentid: Field[/* oid */ Long, Row] + val confrelid: Field[/* oid */ Long, Row] + val confupdtype: Field[String, Row] + val confdeltype: Field[String, Row] + val confmatchtype: Field[String, Row] + val conislocal: Field[Boolean, Row] + val coninhcount: Field[Int, Row] + val connoinherit: Field[Boolean, Row] + val conkey: OptField[Array[TypoShort], Row] + val confkey: OptField[Array[TypoShort], Row] + val conpfeqop: OptField[Array[/* oid */ Long], Row] + val conppeqop: OptField[Array[/* oid */ Long], Row] + val conffeqop: OptField[Array[/* oid */ Long], Row] + val conexclop: OptField[Array[/* oid */ Long], Row] + val conbin: OptField[TypoPgNodeTree, Row] +} +object PgConstraintFields extends PgConstraintStructure[PgConstraintRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintId.scala new file mode 100644 index 0000000000..fd3e1323d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +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 `pg_catalog.pg_constraint` */ +case class PgConstraintId(value: /* oid */ Long) extends AnyVal +object PgConstraintId { + implicit lazy val arraySetter: Setter[Array[PgConstraintId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgConstraintId, /* oid */ Long] = Bijection[PgConstraintId, /* oid */ Long](_.value)(PgConstraintId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgConstraintId] = JdbcDecoder.longDecoder.map(PgConstraintId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgConstraintId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgConstraintId] = JsonDecoder.long.map(PgConstraintId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgConstraintId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgConstraintId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgConstraintId] = ParameterMetaData.instance[PgConstraintId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgConstraintId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepo.scala new file mode 100644 index 0000000000..c2360171c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgConstraintRepo { + def delete(oid: PgConstraintId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgConstraintFields, PgConstraintRow] + def insert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, PgConstraintRow] + def select: SelectBuilder[PgConstraintFields, PgConstraintRow] + def selectAll: ZStream[ZConnection, Throwable, PgConstraintRow] + def selectById(oid: PgConstraintId): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] + def selectByIds(oids: Array[PgConstraintId]): ZStream[ZConnection, Throwable, PgConstraintRow] + def selectByUnique(conrelid: /* oid */ Long, contypid: /* oid */ Long, conname: String): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] + def update(row: PgConstraintRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgConstraintFields, PgConstraintRow] + def upsert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, UpdateResult[PgConstraintRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoImpl.scala new file mode 100644 index 0000000000..1d4732e1e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoImpl.scala @@ -0,0 +1,144 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgConstraintRepoImpl extends PgConstraintRepo { + override def delete(oid: PgConstraintId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_constraint where "oid" = ${Segment.paramSegment(oid)(PgConstraintId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgConstraintFields, PgConstraintRow] = { + DeleteBuilder("pg_catalog.pg_constraint", PgConstraintFields) + } + override def insert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, PgConstraintRow] = { + sql"""insert into pg_catalog.pg_constraint("oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin") + values (${Segment.paramSegment(unsaved.oid)(PgConstraintId.setter)}::oid, ${Segment.paramSegment(unsaved.conname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.connamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.contype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.condeferrable)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.condeferred)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.convalidated)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.conrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.contypid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.conindid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.conparentid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.confrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.confupdtype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.confdeltype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.confmatchtype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.conislocal)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.coninhcount)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.connoinherit)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.conkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, ${Segment.paramSegment(unsaved.confkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, ${Segment.paramSegment(unsaved.conpfeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.conppeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.conffeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.conexclop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.conbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin" + """.insertReturning(PgConstraintRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgConstraintFields, PgConstraintRow] = { + SelectBuilderSql("pg_catalog.pg_constraint", PgConstraintFields, PgConstraintRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgConstraintRow] = { + sql"""select "oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin" from pg_catalog.pg_constraint""".query(PgConstraintRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgConstraintId): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] = { + sql"""select "oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin" from pg_catalog.pg_constraint where "oid" = ${Segment.paramSegment(oid)(PgConstraintId.setter)}""".query(PgConstraintRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgConstraintId]): ZStream[ZConnection, Throwable, PgConstraintRow] = { + sql"""select "oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin" from pg_catalog.pg_constraint where "oid" = ANY(${Segment.paramSegment(oids)(PgConstraintId.arraySetter)})""".query(PgConstraintRow.jdbcDecoder).selectStream + } + override def selectByUnique(conrelid: /* oid */ Long, contypid: /* oid */ Long, conname: String): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] = { + sql"""select "conrelid", "contypid", "conname" + from pg_catalog.pg_constraint + where "conrelid" = ${Segment.paramSegment(conrelid)(Setter.longSetter)} AND "contypid" = ${Segment.paramSegment(contypid)(Setter.longSetter)} AND "conname" = ${Segment.paramSegment(conname)(Setter.stringSetter)} + """.query(PgConstraintRow.jdbcDecoder).selectOne + } + override def update(row: PgConstraintRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_constraint + set "conname" = ${Segment.paramSegment(row.conname)(Setter.stringSetter)}::name, + "connamespace" = ${Segment.paramSegment(row.connamespace)(Setter.longSetter)}::oid, + "contype" = ${Segment.paramSegment(row.contype)(Setter.stringSetter)}::char, + "condeferrable" = ${Segment.paramSegment(row.condeferrable)(Setter.booleanSetter)}, + "condeferred" = ${Segment.paramSegment(row.condeferred)(Setter.booleanSetter)}, + "convalidated" = ${Segment.paramSegment(row.convalidated)(Setter.booleanSetter)}, + "conrelid" = ${Segment.paramSegment(row.conrelid)(Setter.longSetter)}::oid, + "contypid" = ${Segment.paramSegment(row.contypid)(Setter.longSetter)}::oid, + "conindid" = ${Segment.paramSegment(row.conindid)(Setter.longSetter)}::oid, + "conparentid" = ${Segment.paramSegment(row.conparentid)(Setter.longSetter)}::oid, + "confrelid" = ${Segment.paramSegment(row.confrelid)(Setter.longSetter)}::oid, + "confupdtype" = ${Segment.paramSegment(row.confupdtype)(Setter.stringSetter)}::char, + "confdeltype" = ${Segment.paramSegment(row.confdeltype)(Setter.stringSetter)}::char, + "confmatchtype" = ${Segment.paramSegment(row.confmatchtype)(Setter.stringSetter)}::char, + "conislocal" = ${Segment.paramSegment(row.conislocal)(Setter.booleanSetter)}, + "coninhcount" = ${Segment.paramSegment(row.coninhcount)(Setter.intSetter)}::int4, + "connoinherit" = ${Segment.paramSegment(row.connoinherit)(Setter.booleanSetter)}, + "conkey" = ${Segment.paramSegment(row.conkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, + "confkey" = ${Segment.paramSegment(row.confkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, + "conpfeqop" = ${Segment.paramSegment(row.conpfeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "conppeqop" = ${Segment.paramSegment(row.conppeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "conffeqop" = ${Segment.paramSegment(row.conffeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "conexclop" = ${Segment.paramSegment(row.conexclop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "conbin" = ${Segment.paramSegment(row.conbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgConstraintId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgConstraintFields, PgConstraintRow] = { + UpdateBuilder("pg_catalog.pg_constraint", PgConstraintFields, PgConstraintRow.jdbcDecoder) + } + override def upsert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, UpdateResult[PgConstraintRow]] = { + sql"""insert into pg_catalog.pg_constraint("oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin") + values ( + ${Segment.paramSegment(unsaved.oid)(PgConstraintId.setter)}::oid, + ${Segment.paramSegment(unsaved.conname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.connamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.contype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.condeferrable)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.condeferred)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.convalidated)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.conrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.contypid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.conindid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.conparentid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.confrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.confupdtype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.confdeltype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.confmatchtype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.conislocal)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.coninhcount)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.connoinherit)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.conkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, + ${Segment.paramSegment(unsaved.confkey)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, + ${Segment.paramSegment(unsaved.conpfeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.conppeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.conffeqop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.conexclop)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.conbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("oid") + do update set + "conname" = EXCLUDED."conname", + "connamespace" = EXCLUDED."connamespace", + "contype" = EXCLUDED."contype", + "condeferrable" = EXCLUDED."condeferrable", + "condeferred" = EXCLUDED."condeferred", + "convalidated" = EXCLUDED."convalidated", + "conrelid" = EXCLUDED."conrelid", + "contypid" = EXCLUDED."contypid", + "conindid" = EXCLUDED."conindid", + "conparentid" = EXCLUDED."conparentid", + "confrelid" = EXCLUDED."confrelid", + "confupdtype" = EXCLUDED."confupdtype", + "confdeltype" = EXCLUDED."confdeltype", + "confmatchtype" = EXCLUDED."confmatchtype", + "conislocal" = EXCLUDED."conislocal", + "coninhcount" = EXCLUDED."coninhcount", + "connoinherit" = EXCLUDED."connoinherit", + "conkey" = EXCLUDED."conkey", + "confkey" = EXCLUDED."confkey", + "conpfeqop" = EXCLUDED."conpfeqop", + "conppeqop" = EXCLUDED."conppeqop", + "conffeqop" = EXCLUDED."conffeqop", + "conexclop" = EXCLUDED."conexclop", + "conbin" = EXCLUDED."conbin" + returning "oid", "conname", "connamespace", "contype", "condeferrable", "condeferred", "convalidated", "conrelid", "contypid", "conindid", "conparentid", "confrelid", "confupdtype", "confdeltype", "confmatchtype", "conislocal", "coninhcount", "connoinherit", "conkey", "confkey", "conpfeqop", "conppeqop", "conffeqop", "conexclop", "conbin"""".insertReturning(PgConstraintRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoMock.scala new file mode 100644 index 0000000000..90a54bd2db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgConstraintRepoMock(map: scala.collection.mutable.Map[PgConstraintId, PgConstraintRow] = scala.collection.mutable.Map.empty) extends PgConstraintRepo { + override def delete(oid: PgConstraintId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgConstraintFields, PgConstraintRow] = { + DeleteBuilderMock(DeleteParams.empty, PgConstraintFields, map) + } + override def insert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, PgConstraintRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgConstraintFields, PgConstraintRow] = { + SelectBuilderMock(PgConstraintFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgConstraintRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgConstraintId): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgConstraintId]): ZStream[ZConnection, Throwable, PgConstraintRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(conrelid: /* oid */ Long, contypid: /* oid */ Long, conname: String): ZIO[ZConnection, Throwable, Option[PgConstraintRow]] = { + ZIO.succeed(map.values.find(v => conrelid == v.conrelid && contypid == v.contypid && conname == v.conname)) + } + override def update(row: PgConstraintRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgConstraintFields, PgConstraintRow] = { + UpdateBuilderMock(UpdateParams.empty, PgConstraintFields, map) + } + override def upsert(unsaved: PgConstraintRow): ZIO[ZConnection, Throwable, UpdateResult[PgConstraintRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRow.scala new file mode 100644 index 0000000000..b6bdf15c8e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintRow.scala @@ -0,0 +1,189 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgConstraintRow( + oid: PgConstraintId, + conname: String, + connamespace: /* oid */ Long, + contype: String, + condeferrable: Boolean, + condeferred: Boolean, + convalidated: Boolean, + conrelid: /* oid */ Long, + contypid: /* oid */ Long, + conindid: /* oid */ Long, + conparentid: /* oid */ Long, + confrelid: /* oid */ Long, + confupdtype: String, + confdeltype: String, + confmatchtype: String, + conislocal: Boolean, + coninhcount: Int, + connoinherit: Boolean, + conkey: Option[Array[TypoShort]], + confkey: Option[Array[TypoShort]], + conpfeqop: Option[Array[/* oid */ Long]], + conppeqop: Option[Array[/* oid */ Long]], + conffeqop: Option[Array[/* oid */ Long]], + conexclop: Option[Array[/* oid */ Long]], + conbin: Option[TypoPgNodeTree] +) + +object PgConstraintRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgConstraintRow] = new JdbcDecoder[PgConstraintRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgConstraintRow) = + columIndex + 24 -> + PgConstraintRow( + oid = PgConstraintId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + conname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + connamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + contype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + condeferrable = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + condeferred = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + convalidated = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + conrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + contypid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2, + conindid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 9, rs)._2, + conparentid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 10, rs)._2, + confrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 11, rs)._2, + confupdtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 12, rs)._2, + confdeltype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 13, rs)._2, + confmatchtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 14, rs)._2, + conislocal = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 15, rs)._2, + coninhcount = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 16, rs)._2, + connoinherit = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 17, rs)._2, + conkey = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoShort]]).unsafeDecode(columIndex + 18, rs)._2, + confkey = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoShort]]).unsafeDecode(columIndex + 19, rs)._2, + conpfeqop = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 20, rs)._2, + conppeqop = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 21, rs)._2, + conffeqop = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 22, rs)._2, + conexclop = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 23, rs)._2, + conbin = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 24, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgConstraintRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgConstraintId.jsonDecoder)) + val conname = jsonObj.get("conname").toRight("Missing field 'conname'").flatMap(_.as(JsonDecoder.string)) + val connamespace = jsonObj.get("connamespace").toRight("Missing field 'connamespace'").flatMap(_.as(JsonDecoder.long)) + val contype = jsonObj.get("contype").toRight("Missing field 'contype'").flatMap(_.as(JsonDecoder.string)) + val condeferrable = jsonObj.get("condeferrable").toRight("Missing field 'condeferrable'").flatMap(_.as(JsonDecoder.boolean)) + val condeferred = jsonObj.get("condeferred").toRight("Missing field 'condeferred'").flatMap(_.as(JsonDecoder.boolean)) + val convalidated = jsonObj.get("convalidated").toRight("Missing field 'convalidated'").flatMap(_.as(JsonDecoder.boolean)) + val conrelid = jsonObj.get("conrelid").toRight("Missing field 'conrelid'").flatMap(_.as(JsonDecoder.long)) + val contypid = jsonObj.get("contypid").toRight("Missing field 'contypid'").flatMap(_.as(JsonDecoder.long)) + val conindid = jsonObj.get("conindid").toRight("Missing field 'conindid'").flatMap(_.as(JsonDecoder.long)) + val conparentid = jsonObj.get("conparentid").toRight("Missing field 'conparentid'").flatMap(_.as(JsonDecoder.long)) + val confrelid = jsonObj.get("confrelid").toRight("Missing field 'confrelid'").flatMap(_.as(JsonDecoder.long)) + val confupdtype = jsonObj.get("confupdtype").toRight("Missing field 'confupdtype'").flatMap(_.as(JsonDecoder.string)) + val confdeltype = jsonObj.get("confdeltype").toRight("Missing field 'confdeltype'").flatMap(_.as(JsonDecoder.string)) + val confmatchtype = jsonObj.get("confmatchtype").toRight("Missing field 'confmatchtype'").flatMap(_.as(JsonDecoder.string)) + val conislocal = jsonObj.get("conislocal").toRight("Missing field 'conislocal'").flatMap(_.as(JsonDecoder.boolean)) + val coninhcount = jsonObj.get("coninhcount").toRight("Missing field 'coninhcount'").flatMap(_.as(JsonDecoder.int)) + val connoinherit = jsonObj.get("connoinherit").toRight("Missing field 'connoinherit'").flatMap(_.as(JsonDecoder.boolean)) + val conkey = jsonObj.get("conkey").fold[Either[String, Option[Array[TypoShort]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoShort](TypoShort.jsonDecoder, implicitly)))) + val confkey = jsonObj.get("confkey").fold[Either[String, Option[Array[TypoShort]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoShort](TypoShort.jsonDecoder, implicitly)))) + val conpfeqop = jsonObj.get("conpfeqop").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val conppeqop = jsonObj.get("conppeqop").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val conffeqop = jsonObj.get("conffeqop").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val conexclop = jsonObj.get("conexclop").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val conbin = jsonObj.get("conbin").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (oid.isRight && conname.isRight && connamespace.isRight && contype.isRight && condeferrable.isRight && condeferred.isRight && convalidated.isRight && conrelid.isRight && contypid.isRight && conindid.isRight && conparentid.isRight && confrelid.isRight && confupdtype.isRight && confdeltype.isRight && confmatchtype.isRight && conislocal.isRight && coninhcount.isRight && connoinherit.isRight && conkey.isRight && confkey.isRight && conpfeqop.isRight && conppeqop.isRight && conffeqop.isRight && conexclop.isRight && conbin.isRight) + Right(PgConstraintRow(oid = oid.toOption.get, conname = conname.toOption.get, connamespace = connamespace.toOption.get, contype = contype.toOption.get, condeferrable = condeferrable.toOption.get, condeferred = condeferred.toOption.get, convalidated = convalidated.toOption.get, conrelid = conrelid.toOption.get, contypid = contypid.toOption.get, conindid = conindid.toOption.get, conparentid = conparentid.toOption.get, confrelid = confrelid.toOption.get, confupdtype = confupdtype.toOption.get, confdeltype = confdeltype.toOption.get, confmatchtype = confmatchtype.toOption.get, conislocal = conislocal.toOption.get, coninhcount = coninhcount.toOption.get, connoinherit = connoinherit.toOption.get, conkey = conkey.toOption.get, confkey = confkey.toOption.get, conpfeqop = conpfeqop.toOption.get, conppeqop = conppeqop.toOption.get, conffeqop = conffeqop.toOption.get, conexclop = conexclop.toOption.get, conbin = conbin.toOption.get)) + else Left(List[Either[String, Any]](oid, conname, connamespace, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid, conparentid, confrelid, confupdtype, confdeltype, confmatchtype, conislocal, coninhcount, connoinherit, conkey, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgConstraintRow] = new JsonEncoder[PgConstraintRow] { + override def unsafeEncode(a: PgConstraintRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgConstraintId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""conname":""") + JsonEncoder.string.unsafeEncode(a.conname, indent, out) + out.write(",") + out.write(""""connamespace":""") + JsonEncoder.long.unsafeEncode(a.connamespace, indent, out) + out.write(",") + out.write(""""contype":""") + JsonEncoder.string.unsafeEncode(a.contype, indent, out) + out.write(",") + out.write(""""condeferrable":""") + JsonEncoder.boolean.unsafeEncode(a.condeferrable, indent, out) + out.write(",") + out.write(""""condeferred":""") + JsonEncoder.boolean.unsafeEncode(a.condeferred, indent, out) + out.write(",") + out.write(""""convalidated":""") + JsonEncoder.boolean.unsafeEncode(a.convalidated, indent, out) + out.write(",") + out.write(""""conrelid":""") + JsonEncoder.long.unsafeEncode(a.conrelid, indent, out) + out.write(",") + out.write(""""contypid":""") + JsonEncoder.long.unsafeEncode(a.contypid, indent, out) + out.write(",") + out.write(""""conindid":""") + JsonEncoder.long.unsafeEncode(a.conindid, indent, out) + out.write(",") + out.write(""""conparentid":""") + JsonEncoder.long.unsafeEncode(a.conparentid, indent, out) + out.write(",") + out.write(""""confrelid":""") + JsonEncoder.long.unsafeEncode(a.confrelid, indent, out) + out.write(",") + out.write(""""confupdtype":""") + JsonEncoder.string.unsafeEncode(a.confupdtype, indent, out) + out.write(",") + out.write(""""confdeltype":""") + JsonEncoder.string.unsafeEncode(a.confdeltype, indent, out) + out.write(",") + out.write(""""confmatchtype":""") + JsonEncoder.string.unsafeEncode(a.confmatchtype, indent, out) + out.write(",") + out.write(""""conislocal":""") + JsonEncoder.boolean.unsafeEncode(a.conislocal, indent, out) + out.write(",") + out.write(""""coninhcount":""") + JsonEncoder.int.unsafeEncode(a.coninhcount, indent, out) + out.write(",") + out.write(""""connoinherit":""") + JsonEncoder.boolean.unsafeEncode(a.connoinherit, indent, out) + out.write(",") + out.write(""""conkey":""") + JsonEncoder.option(JsonEncoder.array[TypoShort](TypoShort.jsonEncoder, implicitly)).unsafeEncode(a.conkey, indent, out) + out.write(",") + out.write(""""confkey":""") + JsonEncoder.option(JsonEncoder.array[TypoShort](TypoShort.jsonEncoder, implicitly)).unsafeEncode(a.confkey, indent, out) + out.write(",") + out.write(""""conpfeqop":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.conpfeqop, indent, out) + out.write(",") + out.write(""""conppeqop":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.conppeqop, indent, out) + out.write(",") + out.write(""""conffeqop":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.conffeqop, indent, out) + out.write(",") + out.write(""""conexclop":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.conexclop, indent, out) + out.write(",") + out.write(""""conbin":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.conbin, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintStructure.scala new file mode 100644 index 0000000000..f5d21483a5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_constraint/PgConstraintStructure.scala @@ -0,0 +1,53 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_constraint + +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgConstraintStructure[Row](val prefix: Option[String], val extract: Row => PgConstraintRow, val merge: (Row, PgConstraintRow) => Row) + extends Relation[PgConstraintFields, PgConstraintRow, Row] + with PgConstraintFields[Row] { outer => + + override val oid = new IdField[PgConstraintId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val conname = new Field[String, Row](prefix, "conname", None, Some("name"))(x => extract(x).conname, (row, value) => merge(row, extract(row).copy(conname = value))) + override val connamespace = new Field[/* oid */ Long, Row](prefix, "connamespace", None, Some("oid"))(x => extract(x).connamespace, (row, value) => merge(row, extract(row).copy(connamespace = value))) + override val contype = new Field[String, Row](prefix, "contype", None, Some("char"))(x => extract(x).contype, (row, value) => merge(row, extract(row).copy(contype = value))) + override val condeferrable = new Field[Boolean, Row](prefix, "condeferrable", None, None)(x => extract(x).condeferrable, (row, value) => merge(row, extract(row).copy(condeferrable = value))) + override val condeferred = new Field[Boolean, Row](prefix, "condeferred", None, None)(x => extract(x).condeferred, (row, value) => merge(row, extract(row).copy(condeferred = value))) + override val convalidated = new Field[Boolean, Row](prefix, "convalidated", None, None)(x => extract(x).convalidated, (row, value) => merge(row, extract(row).copy(convalidated = value))) + override val conrelid = new Field[/* oid */ Long, Row](prefix, "conrelid", None, Some("oid"))(x => extract(x).conrelid, (row, value) => merge(row, extract(row).copy(conrelid = value))) + override val contypid = new Field[/* oid */ Long, Row](prefix, "contypid", None, Some("oid"))(x => extract(x).contypid, (row, value) => merge(row, extract(row).copy(contypid = value))) + override val conindid = new Field[/* oid */ Long, Row](prefix, "conindid", None, Some("oid"))(x => extract(x).conindid, (row, value) => merge(row, extract(row).copy(conindid = value))) + override val conparentid = new Field[/* oid */ Long, Row](prefix, "conparentid", None, Some("oid"))(x => extract(x).conparentid, (row, value) => merge(row, extract(row).copy(conparentid = value))) + override val confrelid = new Field[/* oid */ Long, Row](prefix, "confrelid", None, Some("oid"))(x => extract(x).confrelid, (row, value) => merge(row, extract(row).copy(confrelid = value))) + override val confupdtype = new Field[String, Row](prefix, "confupdtype", None, Some("char"))(x => extract(x).confupdtype, (row, value) => merge(row, extract(row).copy(confupdtype = value))) + override val confdeltype = new Field[String, Row](prefix, "confdeltype", None, Some("char"))(x => extract(x).confdeltype, (row, value) => merge(row, extract(row).copy(confdeltype = value))) + override val confmatchtype = new Field[String, Row](prefix, "confmatchtype", None, Some("char"))(x => extract(x).confmatchtype, (row, value) => merge(row, extract(row).copy(confmatchtype = value))) + override val conislocal = new Field[Boolean, Row](prefix, "conislocal", None, None)(x => extract(x).conislocal, (row, value) => merge(row, extract(row).copy(conislocal = value))) + override val coninhcount = new Field[Int, Row](prefix, "coninhcount", None, Some("int4"))(x => extract(x).coninhcount, (row, value) => merge(row, extract(row).copy(coninhcount = value))) + override val connoinherit = new Field[Boolean, Row](prefix, "connoinherit", None, None)(x => extract(x).connoinherit, (row, value) => merge(row, extract(row).copy(connoinherit = value))) + override val conkey = new OptField[Array[TypoShort], Row](prefix, "conkey", None, Some("_int2"))(x => extract(x).conkey, (row, value) => merge(row, extract(row).copy(conkey = value))) + override val confkey = new OptField[Array[TypoShort], Row](prefix, "confkey", None, Some("_int2"))(x => extract(x).confkey, (row, value) => merge(row, extract(row).copy(confkey = value))) + override val conpfeqop = new OptField[Array[/* oid */ Long], Row](prefix, "conpfeqop", None, Some("_oid"))(x => extract(x).conpfeqop, (row, value) => merge(row, extract(row).copy(conpfeqop = value))) + override val conppeqop = new OptField[Array[/* oid */ Long], Row](prefix, "conppeqop", None, Some("_oid"))(x => extract(x).conppeqop, (row, value) => merge(row, extract(row).copy(conppeqop = value))) + override val conffeqop = new OptField[Array[/* oid */ Long], Row](prefix, "conffeqop", None, Some("_oid"))(x => extract(x).conffeqop, (row, value) => merge(row, extract(row).copy(conffeqop = value))) + override val conexclop = new OptField[Array[/* oid */ Long], Row](prefix, "conexclop", None, Some("_oid"))(x => extract(x).conexclop, (row, value) => merge(row, extract(row).copy(conexclop = value))) + override val conbin = new OptField[TypoPgNodeTree, Row](prefix, "conbin", None, Some("pg_node_tree"))(x => extract(x).conbin, (row, value) => merge(row, extract(row).copy(conbin = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, conname, connamespace, contype, condeferrable, condeferred, convalidated, conrelid, contypid, conindid, conparentid, confrelid, confupdtype, confdeltype, confmatchtype, conislocal, coninhcount, connoinherit, conkey, confkey, conpfeqop, conppeqop, conffeqop, conexclop, conbin) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgConstraintRow, merge: (NewRow, PgConstraintRow) => NewRow): PgConstraintStructure[NewRow] = + new PgConstraintStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionFields.scala new file mode 100644 index 0000000000..8821f38964 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgConversionFields[Row] { + val oid: IdField[PgConversionId, Row] + val conname: Field[String, Row] + val connamespace: Field[/* oid */ Long, Row] + val conowner: Field[/* oid */ Long, Row] + val conforencoding: Field[Int, Row] + val contoencoding: Field[Int, Row] + val conproc: Field[TypoRegproc, Row] + val condefault: Field[Boolean, Row] +} +object PgConversionFields extends PgConversionStructure[PgConversionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionId.scala new file mode 100644 index 0000000000..b4d7d2e2d2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +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 `pg_catalog.pg_conversion` */ +case class PgConversionId(value: /* oid */ Long) extends AnyVal +object PgConversionId { + implicit lazy val arraySetter: Setter[Array[PgConversionId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgConversionId, /* oid */ Long] = Bijection[PgConversionId, /* oid */ Long](_.value)(PgConversionId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgConversionId] = JdbcDecoder.longDecoder.map(PgConversionId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgConversionId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgConversionId] = JsonDecoder.long.map(PgConversionId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgConversionId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgConversionId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgConversionId] = ParameterMetaData.instance[PgConversionId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgConversionId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepo.scala new file mode 100644 index 0000000000..b1f357faf3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgConversionRepo { + def delete(oid: PgConversionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgConversionFields, PgConversionRow] + def insert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, PgConversionRow] + def select: SelectBuilder[PgConversionFields, PgConversionRow] + def selectAll: ZStream[ZConnection, Throwable, PgConversionRow] + def selectById(oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] + def selectByIds(oids: Array[PgConversionId]): ZStream[ZConnection, Throwable, PgConversionRow] + def selectByUnique(conname: String, connamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgConversionRow]] + def selectByUnique(connamespace: /* oid */ Long, conforencoding: Int, contoencoding: Int, oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] + def update(row: PgConversionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgConversionFields, PgConversionRow] + def upsert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, UpdateResult[PgConversionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoImpl.scala new file mode 100644 index 0000000000..7a5ca9a470 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoImpl.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgConversionRepoImpl extends PgConversionRepo { + override def delete(oid: PgConversionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_conversion where "oid" = ${Segment.paramSegment(oid)(PgConversionId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgConversionFields, PgConversionRow] = { + DeleteBuilder("pg_catalog.pg_conversion", PgConversionFields) + } + override def insert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, PgConversionRow] = { + sql"""insert into pg_catalog.pg_conversion("oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault") + values (${Segment.paramSegment(unsaved.oid)(PgConversionId.setter)}::oid, ${Segment.paramSegment(unsaved.conname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.connamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.conowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.conforencoding)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.contoencoding)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.conproc)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.condefault)(Setter.booleanSetter)}) + returning "oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault" + """.insertReturning(PgConversionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgConversionFields, PgConversionRow] = { + SelectBuilderSql("pg_catalog.pg_conversion", PgConversionFields, PgConversionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgConversionRow] = { + sql"""select "oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault" from pg_catalog.pg_conversion""".query(PgConversionRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + sql"""select "oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault" from pg_catalog.pg_conversion where "oid" = ${Segment.paramSegment(oid)(PgConversionId.setter)}""".query(PgConversionRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgConversionId]): ZStream[ZConnection, Throwable, PgConversionRow] = { + sql"""select "oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault" from pg_catalog.pg_conversion where "oid" = ANY(${Segment.paramSegment(oids)(PgConversionId.arraySetter)})""".query(PgConversionRow.jdbcDecoder).selectStream + } + override def selectByUnique(conname: String, connamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + sql"""select "conname", "connamespace" + from pg_catalog.pg_conversion + where "conname" = ${Segment.paramSegment(conname)(Setter.stringSetter)} AND "connamespace" = ${Segment.paramSegment(connamespace)(Setter.longSetter)} + """.query(PgConversionRow.jdbcDecoder).selectOne + } + override def selectByUnique(connamespace: /* oid */ Long, conforencoding: Int, contoencoding: Int, oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + sql"""select "connamespace", "conforencoding", "contoencoding", "oid" + from pg_catalog.pg_conversion + where "connamespace" = ${Segment.paramSegment(connamespace)(Setter.longSetter)} AND "conforencoding" = ${Segment.paramSegment(conforencoding)(Setter.intSetter)} AND "contoencoding" = ${Segment.paramSegment(contoencoding)(Setter.intSetter)} AND "oid" = ${Segment.paramSegment(oid)(PgConversionId.setter)} + """.query(PgConversionRow.jdbcDecoder).selectOne + } + override def update(row: PgConversionRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_conversion + set "conname" = ${Segment.paramSegment(row.conname)(Setter.stringSetter)}::name, + "connamespace" = ${Segment.paramSegment(row.connamespace)(Setter.longSetter)}::oid, + "conowner" = ${Segment.paramSegment(row.conowner)(Setter.longSetter)}::oid, + "conforencoding" = ${Segment.paramSegment(row.conforencoding)(Setter.intSetter)}::int4, + "contoencoding" = ${Segment.paramSegment(row.contoencoding)(Setter.intSetter)}::int4, + "conproc" = ${Segment.paramSegment(row.conproc)(TypoRegproc.setter)}::regproc, + "condefault" = ${Segment.paramSegment(row.condefault)(Setter.booleanSetter)} + where "oid" = ${Segment.paramSegment(oid)(PgConversionId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgConversionFields, PgConversionRow] = { + UpdateBuilder("pg_catalog.pg_conversion", PgConversionFields, PgConversionRow.jdbcDecoder) + } + override def upsert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, UpdateResult[PgConversionRow]] = { + sql"""insert into pg_catalog.pg_conversion("oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault") + values ( + ${Segment.paramSegment(unsaved.oid)(PgConversionId.setter)}::oid, + ${Segment.paramSegment(unsaved.conname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.connamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.conowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.conforencoding)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.contoencoding)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.conproc)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.condefault)(Setter.booleanSetter)} + ) + on conflict ("oid") + do update set + "conname" = EXCLUDED."conname", + "connamespace" = EXCLUDED."connamespace", + "conowner" = EXCLUDED."conowner", + "conforencoding" = EXCLUDED."conforencoding", + "contoencoding" = EXCLUDED."contoencoding", + "conproc" = EXCLUDED."conproc", + "condefault" = EXCLUDED."condefault" + returning "oid", "conname", "connamespace", "conowner", "conforencoding", "contoencoding", "conproc", "condefault"""".insertReturning(PgConversionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoMock.scala new file mode 100644 index 0000000000..408e26660c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRepoMock.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgConversionRepoMock(map: scala.collection.mutable.Map[PgConversionId, PgConversionRow] = scala.collection.mutable.Map.empty) extends PgConversionRepo { + override def delete(oid: PgConversionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgConversionFields, PgConversionRow] = { + DeleteBuilderMock(DeleteParams.empty, PgConversionFields, map) + } + override def insert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, PgConversionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgConversionFields, PgConversionRow] = { + SelectBuilderMock(PgConversionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgConversionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgConversionId]): ZStream[ZConnection, Throwable, PgConversionRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(conname: String, connamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + ZIO.succeed(map.values.find(v => conname == v.conname && connamespace == v.connamespace)) + } + override def selectByUnique(connamespace: /* oid */ Long, conforencoding: Int, contoencoding: Int, oid: PgConversionId): ZIO[ZConnection, Throwable, Option[PgConversionRow]] = { + ZIO.succeed(map.values.find(v => connamespace == v.connamespace && conforencoding == v.conforencoding && contoencoding == v.contoencoding && oid == v.oid)) + } + override def update(row: PgConversionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgConversionFields, PgConversionRow] = { + UpdateBuilderMock(UpdateParams.empty, PgConversionFields, map) + } + override def upsert(unsaved: PgConversionRow): ZIO[ZConnection, Throwable, UpdateResult[PgConversionRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRow.scala new file mode 100644 index 0000000000..a34360b358 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgConversionRow( + oid: PgConversionId, + conname: String, + connamespace: /* oid */ Long, + conowner: /* oid */ Long, + conforencoding: Int, + contoencoding: Int, + conproc: TypoRegproc, + condefault: Boolean +) + +object PgConversionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgConversionRow] = new JdbcDecoder[PgConversionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgConversionRow) = + columIndex + 7 -> + PgConversionRow( + oid = PgConversionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + conname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + connamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + conowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + conforencoding = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 4, rs)._2, + contoencoding = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 5, rs)._2, + conproc = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + condefault = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgConversionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgConversionId.jsonDecoder)) + val conname = jsonObj.get("conname").toRight("Missing field 'conname'").flatMap(_.as(JsonDecoder.string)) + val connamespace = jsonObj.get("connamespace").toRight("Missing field 'connamespace'").flatMap(_.as(JsonDecoder.long)) + val conowner = jsonObj.get("conowner").toRight("Missing field 'conowner'").flatMap(_.as(JsonDecoder.long)) + val conforencoding = jsonObj.get("conforencoding").toRight("Missing field 'conforencoding'").flatMap(_.as(JsonDecoder.int)) + val contoencoding = jsonObj.get("contoencoding").toRight("Missing field 'contoencoding'").flatMap(_.as(JsonDecoder.int)) + val conproc = jsonObj.get("conproc").toRight("Missing field 'conproc'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val condefault = jsonObj.get("condefault").toRight("Missing field 'condefault'").flatMap(_.as(JsonDecoder.boolean)) + if (oid.isRight && conname.isRight && connamespace.isRight && conowner.isRight && conforencoding.isRight && contoencoding.isRight && conproc.isRight && condefault.isRight) + Right(PgConversionRow(oid = oid.toOption.get, conname = conname.toOption.get, connamespace = connamespace.toOption.get, conowner = conowner.toOption.get, conforencoding = conforencoding.toOption.get, contoencoding = contoencoding.toOption.get, conproc = conproc.toOption.get, condefault = condefault.toOption.get)) + else Left(List[Either[String, Any]](oid, conname, connamespace, conowner, conforencoding, contoencoding, conproc, condefault).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgConversionRow] = new JsonEncoder[PgConversionRow] { + override def unsafeEncode(a: PgConversionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgConversionId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""conname":""") + JsonEncoder.string.unsafeEncode(a.conname, indent, out) + out.write(",") + out.write(""""connamespace":""") + JsonEncoder.long.unsafeEncode(a.connamespace, indent, out) + out.write(",") + out.write(""""conowner":""") + JsonEncoder.long.unsafeEncode(a.conowner, indent, out) + out.write(",") + out.write(""""conforencoding":""") + JsonEncoder.int.unsafeEncode(a.conforencoding, indent, out) + out.write(",") + out.write(""""contoencoding":""") + JsonEncoder.int.unsafeEncode(a.contoencoding, indent, out) + out.write(",") + out.write(""""conproc":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.conproc, indent, out) + out.write(",") + out.write(""""condefault":""") + JsonEncoder.boolean.unsafeEncode(a.condefault, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionStructure.scala new file mode 100644 index 0000000000..4aa1f3ab95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_conversion/PgConversionStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_conversion + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgConversionStructure[Row](val prefix: Option[String], val extract: Row => PgConversionRow, val merge: (Row, PgConversionRow) => Row) + extends Relation[PgConversionFields, PgConversionRow, Row] + with PgConversionFields[Row] { outer => + + override val oid = new IdField[PgConversionId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val conname = new Field[String, Row](prefix, "conname", None, Some("name"))(x => extract(x).conname, (row, value) => merge(row, extract(row).copy(conname = value))) + override val connamespace = new Field[/* oid */ Long, Row](prefix, "connamespace", None, Some("oid"))(x => extract(x).connamespace, (row, value) => merge(row, extract(row).copy(connamespace = value))) + override val conowner = new Field[/* oid */ Long, Row](prefix, "conowner", None, Some("oid"))(x => extract(x).conowner, (row, value) => merge(row, extract(row).copy(conowner = value))) + override val conforencoding = new Field[Int, Row](prefix, "conforencoding", None, Some("int4"))(x => extract(x).conforencoding, (row, value) => merge(row, extract(row).copy(conforencoding = value))) + override val contoencoding = new Field[Int, Row](prefix, "contoencoding", None, Some("int4"))(x => extract(x).contoencoding, (row, value) => merge(row, extract(row).copy(contoencoding = value))) + override val conproc = new Field[TypoRegproc, Row](prefix, "conproc", None, Some("regproc"))(x => extract(x).conproc, (row, value) => merge(row, extract(row).copy(conproc = value))) + override val condefault = new Field[Boolean, Row](prefix, "condefault", None, None)(x => extract(x).condefault, (row, value) => merge(row, extract(row).copy(condefault = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, conname, connamespace, conowner, conforencoding, contoencoding, conproc, condefault) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgConversionRow, merge: (NewRow, PgConversionRow) => NewRow): PgConversionStructure[NewRow] = + new PgConversionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewFields.scala new file mode 100644 index 0000000000..75cce8ba89 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cursors + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgCursorsViewFields[Row] { + val name: OptField[String, Row] + val statement: OptField[String, Row] + val isHoldable: OptField[Boolean, Row] + val isBinary: OptField[Boolean, Row] + val isScrollable: OptField[Boolean, Row] + val creationTime: OptField[TypoInstant, Row] +} +object PgCursorsViewFields extends PgCursorsViewStructure[PgCursorsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepo.scala new file mode 100644 index 0000000000..309eeed701 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cursors + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgCursorsViewRepo { + def select: SelectBuilder[PgCursorsViewFields, PgCursorsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgCursorsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepoImpl.scala new file mode 100644 index 0000000000..7dd83ebebc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cursors + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgCursorsViewRepoImpl extends PgCursorsViewRepo { + override def select: SelectBuilder[PgCursorsViewFields, PgCursorsViewRow] = { + SelectBuilderSql("pg_catalog.pg_cursors", PgCursorsViewFields, PgCursorsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgCursorsViewRow] = { + sql"""select "name", "statement", "is_holdable", "is_binary", "is_scrollable", "creation_time"::text from pg_catalog.pg_cursors""".query(PgCursorsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRow.scala new file mode 100644 index 0000000000..8a9eebd3dd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewRow.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cursors + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgCursorsViewRow( + name: /* nullability unknown */ Option[String], + statement: /* nullability unknown */ Option[String], + isHoldable: /* nullability unknown */ Option[Boolean], + isBinary: /* nullability unknown */ Option[Boolean], + isScrollable: /* nullability unknown */ Option[Boolean], + creationTime: /* nullability unknown */ Option[TypoInstant] +) + +object PgCursorsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgCursorsViewRow] = new JdbcDecoder[PgCursorsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgCursorsViewRow) = + columIndex + 5 -> + PgCursorsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + statement = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + isHoldable = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 2, rs)._2, + isBinary = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 3, rs)._2, + isScrollable = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 4, rs)._2, + creationTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgCursorsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val statement = jsonObj.get("statement").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val isHoldable = jsonObj.get("is_holdable").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val isBinary = jsonObj.get("is_binary").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val isScrollable = jsonObj.get("is_scrollable").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val creationTime = jsonObj.get("creation_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (name.isRight && statement.isRight && isHoldable.isRight && isBinary.isRight && isScrollable.isRight && creationTime.isRight) + Right(PgCursorsViewRow(name = name.toOption.get, statement = statement.toOption.get, isHoldable = isHoldable.toOption.get, isBinary = isBinary.toOption.get, isScrollable = isScrollable.toOption.get, creationTime = creationTime.toOption.get)) + else Left(List[Either[String, Any]](name, statement, isHoldable, isBinary, isScrollable, creationTime).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgCursorsViewRow] = new JsonEncoder[PgCursorsViewRow] { + override def unsafeEncode(a: PgCursorsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""statement":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statement, indent, out) + out.write(",") + out.write(""""is_holdable":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.isHoldable, indent, out) + out.write(",") + out.write(""""is_binary":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.isBinary, indent, out) + out.write(",") + out.write(""""is_scrollable":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.isScrollable, indent, out) + out.write(",") + out.write(""""creation_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.creationTime, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewStructure.scala new file mode 100644 index 0000000000..c8298e0ae2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_cursors/PgCursorsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_cursors + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgCursorsViewStructure[Row](val prefix: Option[String], val extract: Row => PgCursorsViewRow, val merge: (Row, PgCursorsViewRow) => Row) + extends Relation[PgCursorsViewFields, PgCursorsViewRow, Row] + with PgCursorsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val statement = new OptField[String, Row](prefix, "statement", None, None)(x => extract(x).statement, (row, value) => merge(row, extract(row).copy(statement = value))) + override val isHoldable = new OptField[Boolean, Row](prefix, "is_holdable", None, None)(x => extract(x).isHoldable, (row, value) => merge(row, extract(row).copy(isHoldable = value))) + override val isBinary = new OptField[Boolean, Row](prefix, "is_binary", None, None)(x => extract(x).isBinary, (row, value) => merge(row, extract(row).copy(isBinary = value))) + override val isScrollable = new OptField[Boolean, Row](prefix, "is_scrollable", None, None)(x => extract(x).isScrollable, (row, value) => merge(row, extract(row).copy(isScrollable = value))) + override val creationTime = new OptField[TypoInstant, Row](prefix, "creation_time", Some("text"), None)(x => extract(x).creationTime, (row, value) => merge(row, extract(row).copy(creationTime = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, statement, isHoldable, isBinary, isScrollable, creationTime) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgCursorsViewRow, merge: (NewRow, PgCursorsViewRow) => NewRow): PgCursorsViewStructure[NewRow] = + new PgCursorsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseFields.scala new file mode 100644 index 0000000000..060b9181a9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgDatabaseFields[Row] { + val oid: IdField[PgDatabaseId, Row] + val datname: Field[String, Row] + val datdba: Field[/* oid */ Long, Row] + val encoding: Field[Int, Row] + val datcollate: Field[String, Row] + val datctype: Field[String, Row] + val datistemplate: Field[Boolean, Row] + val datallowconn: Field[Boolean, Row] + val datconnlimit: Field[Int, Row] + val datlastsysoid: Field[/* oid */ Long, Row] + val datfrozenxid: Field[TypoXid, Row] + val datminmxid: Field[TypoXid, Row] + val dattablespace: Field[/* oid */ Long, Row] + val datacl: OptField[Array[TypoAclItem], Row] +} +object PgDatabaseFields extends PgDatabaseStructure[PgDatabaseRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseId.scala new file mode 100644 index 0000000000..caff299516 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +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 `pg_catalog.pg_database` */ +case class PgDatabaseId(value: /* oid */ Long) extends AnyVal +object PgDatabaseId { + implicit lazy val arraySetter: Setter[Array[PgDatabaseId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgDatabaseId, /* oid */ Long] = Bijection[PgDatabaseId, /* oid */ Long](_.value)(PgDatabaseId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgDatabaseId] = JdbcDecoder.longDecoder.map(PgDatabaseId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgDatabaseId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgDatabaseId] = JsonDecoder.long.map(PgDatabaseId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgDatabaseId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgDatabaseId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgDatabaseId] = ParameterMetaData.instance[PgDatabaseId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgDatabaseId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepo.scala new file mode 100644 index 0000000000..ac3c82d4c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgDatabaseRepo { + def delete(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgDatabaseFields, PgDatabaseRow] + def insert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, PgDatabaseRow] + def select: SelectBuilder[PgDatabaseFields, PgDatabaseRow] + def selectAll: ZStream[ZConnection, Throwable, PgDatabaseRow] + def selectById(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] + def selectByIds(oids: Array[PgDatabaseId]): ZStream[ZConnection, Throwable, PgDatabaseRow] + def selectByUnique(datname: String): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] + def update(row: PgDatabaseRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgDatabaseFields, PgDatabaseRow] + def upsert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, UpdateResult[PgDatabaseRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoImpl.scala new file mode 100644 index 0000000000..2342892caa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoImpl.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoXid +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgDatabaseRepoImpl extends PgDatabaseRepo { + override def delete(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_database where "oid" = ${Segment.paramSegment(oid)(PgDatabaseId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgDatabaseFields, PgDatabaseRow] = { + DeleteBuilder("pg_catalog.pg_database", PgDatabaseFields) + } + override def insert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, PgDatabaseRow] = { + sql"""insert into pg_catalog.pg_database("oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl") + values (${Segment.paramSegment(unsaved.oid)(PgDatabaseId.setter)}::oid, ${Segment.paramSegment(unsaved.datname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.datdba)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.encoding)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.datcollate)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.datctype)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.datistemplate)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.datallowconn)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.datconnlimit)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.datlastsysoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.datfrozenxid)(TypoXid.setter)}::xid, ${Segment.paramSegment(unsaved.datminmxid)(TypoXid.setter)}::xid, ${Segment.paramSegment(unsaved.dattablespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.datacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl" + """.insertReturning(PgDatabaseRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgDatabaseFields, PgDatabaseRow] = { + SelectBuilderSql("pg_catalog.pg_database", PgDatabaseFields, PgDatabaseRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDatabaseRow] = { + sql"""select "oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl" from pg_catalog.pg_database""".query(PgDatabaseRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] = { + sql"""select "oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl" from pg_catalog.pg_database where "oid" = ${Segment.paramSegment(oid)(PgDatabaseId.setter)}""".query(PgDatabaseRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgDatabaseId]): ZStream[ZConnection, Throwable, PgDatabaseRow] = { + sql"""select "oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl" from pg_catalog.pg_database where "oid" = ANY(${Segment.paramSegment(oids)(PgDatabaseId.arraySetter)})""".query(PgDatabaseRow.jdbcDecoder).selectStream + } + override def selectByUnique(datname: String): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] = { + sql"""select "datname" + from pg_catalog.pg_database + where "datname" = ${Segment.paramSegment(datname)(Setter.stringSetter)} + """.query(PgDatabaseRow.jdbcDecoder).selectOne + } + override def update(row: PgDatabaseRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_database + set "datname" = ${Segment.paramSegment(row.datname)(Setter.stringSetter)}::name, + "datdba" = ${Segment.paramSegment(row.datdba)(Setter.longSetter)}::oid, + "encoding" = ${Segment.paramSegment(row.encoding)(Setter.intSetter)}::int4, + "datcollate" = ${Segment.paramSegment(row.datcollate)(Setter.stringSetter)}::name, + "datctype" = ${Segment.paramSegment(row.datctype)(Setter.stringSetter)}::name, + "datistemplate" = ${Segment.paramSegment(row.datistemplate)(Setter.booleanSetter)}, + "datallowconn" = ${Segment.paramSegment(row.datallowconn)(Setter.booleanSetter)}, + "datconnlimit" = ${Segment.paramSegment(row.datconnlimit)(Setter.intSetter)}::int4, + "datlastsysoid" = ${Segment.paramSegment(row.datlastsysoid)(Setter.longSetter)}::oid, + "datfrozenxid" = ${Segment.paramSegment(row.datfrozenxid)(TypoXid.setter)}::xid, + "datminmxid" = ${Segment.paramSegment(row.datminmxid)(TypoXid.setter)}::xid, + "dattablespace" = ${Segment.paramSegment(row.dattablespace)(Setter.longSetter)}::oid, + "datacl" = ${Segment.paramSegment(row.datacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgDatabaseId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgDatabaseFields, PgDatabaseRow] = { + UpdateBuilder("pg_catalog.pg_database", PgDatabaseFields, PgDatabaseRow.jdbcDecoder) + } + override def upsert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, UpdateResult[PgDatabaseRow]] = { + sql"""insert into pg_catalog.pg_database("oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgDatabaseId.setter)}::oid, + ${Segment.paramSegment(unsaved.datname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.datdba)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.encoding)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.datcollate)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.datctype)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.datistemplate)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.datallowconn)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.datconnlimit)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.datlastsysoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.datfrozenxid)(TypoXid.setter)}::xid, + ${Segment.paramSegment(unsaved.datminmxid)(TypoXid.setter)}::xid, + ${Segment.paramSegment(unsaved.dattablespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.datacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "datname" = EXCLUDED."datname", + "datdba" = EXCLUDED."datdba", + "encoding" = EXCLUDED."encoding", + "datcollate" = EXCLUDED."datcollate", + "datctype" = EXCLUDED."datctype", + "datistemplate" = EXCLUDED."datistemplate", + "datallowconn" = EXCLUDED."datallowconn", + "datconnlimit" = EXCLUDED."datconnlimit", + "datlastsysoid" = EXCLUDED."datlastsysoid", + "datfrozenxid" = EXCLUDED."datfrozenxid", + "datminmxid" = EXCLUDED."datminmxid", + "dattablespace" = EXCLUDED."dattablespace", + "datacl" = EXCLUDED."datacl" + returning "oid", "datname", "datdba", "encoding", "datcollate", "datctype", "datistemplate", "datallowconn", "datconnlimit", "datlastsysoid", "datfrozenxid", "datminmxid", "dattablespace", "datacl"""".insertReturning(PgDatabaseRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoMock.scala new file mode 100644 index 0000000000..2c23646c92 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgDatabaseRepoMock(map: scala.collection.mutable.Map[PgDatabaseId, PgDatabaseRow] = scala.collection.mutable.Map.empty) extends PgDatabaseRepo { + override def delete(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgDatabaseFields, PgDatabaseRow] = { + DeleteBuilderMock(DeleteParams.empty, PgDatabaseFields, map) + } + override def insert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, PgDatabaseRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgDatabaseFields, PgDatabaseRow] = { + SelectBuilderMock(PgDatabaseFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDatabaseRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgDatabaseId): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgDatabaseId]): ZStream[ZConnection, Throwable, PgDatabaseRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(datname: String): ZIO[ZConnection, Throwable, Option[PgDatabaseRow]] = { + ZIO.succeed(map.values.find(v => datname == v.datname)) + } + override def update(row: PgDatabaseRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgDatabaseFields, PgDatabaseRow] = { + UpdateBuilderMock(UpdateParams.empty, PgDatabaseFields, map) + } + override def upsert(unsaved: PgDatabaseRow): ZIO[ZConnection, Throwable, UpdateResult[PgDatabaseRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRow.scala new file mode 100644 index 0000000000..410fdc4d05 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseRow.scala @@ -0,0 +1,123 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgDatabaseRow( + oid: PgDatabaseId, + datname: String, + datdba: /* oid */ Long, + encoding: Int, + datcollate: String, + datctype: String, + datistemplate: Boolean, + datallowconn: Boolean, + datconnlimit: Int, + datlastsysoid: /* oid */ Long, + datfrozenxid: TypoXid, + datminmxid: TypoXid, + dattablespace: /* oid */ Long, + datacl: Option[Array[TypoAclItem]] +) + +object PgDatabaseRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgDatabaseRow] = new JdbcDecoder[PgDatabaseRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgDatabaseRow) = + columIndex + 13 -> + PgDatabaseRow( + oid = PgDatabaseId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + datname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + datdba = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + encoding = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + datcollate = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + datctype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + datistemplate = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + datallowconn = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + datconnlimit = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 8, rs)._2, + datlastsysoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 9, rs)._2, + datfrozenxid = TypoXid.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + datminmxid = TypoXid.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + dattablespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 12, rs)._2, + datacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 13, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgDatabaseRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgDatabaseId.jsonDecoder)) + val datname = jsonObj.get("datname").toRight("Missing field 'datname'").flatMap(_.as(JsonDecoder.string)) + val datdba = jsonObj.get("datdba").toRight("Missing field 'datdba'").flatMap(_.as(JsonDecoder.long)) + val encoding = jsonObj.get("encoding").toRight("Missing field 'encoding'").flatMap(_.as(JsonDecoder.int)) + val datcollate = jsonObj.get("datcollate").toRight("Missing field 'datcollate'").flatMap(_.as(JsonDecoder.string)) + val datctype = jsonObj.get("datctype").toRight("Missing field 'datctype'").flatMap(_.as(JsonDecoder.string)) + val datistemplate = jsonObj.get("datistemplate").toRight("Missing field 'datistemplate'").flatMap(_.as(JsonDecoder.boolean)) + val datallowconn = jsonObj.get("datallowconn").toRight("Missing field 'datallowconn'").flatMap(_.as(JsonDecoder.boolean)) + val datconnlimit = jsonObj.get("datconnlimit").toRight("Missing field 'datconnlimit'").flatMap(_.as(JsonDecoder.int)) + val datlastsysoid = jsonObj.get("datlastsysoid").toRight("Missing field 'datlastsysoid'").flatMap(_.as(JsonDecoder.long)) + val datfrozenxid = jsonObj.get("datfrozenxid").toRight("Missing field 'datfrozenxid'").flatMap(_.as(TypoXid.jsonDecoder)) + val datminmxid = jsonObj.get("datminmxid").toRight("Missing field 'datminmxid'").flatMap(_.as(TypoXid.jsonDecoder)) + val dattablespace = jsonObj.get("dattablespace").toRight("Missing field 'dattablespace'").flatMap(_.as(JsonDecoder.long)) + val datacl = jsonObj.get("datacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && datname.isRight && datdba.isRight && encoding.isRight && datcollate.isRight && datctype.isRight && datistemplate.isRight && datallowconn.isRight && datconnlimit.isRight && datlastsysoid.isRight && datfrozenxid.isRight && datminmxid.isRight && dattablespace.isRight && datacl.isRight) + Right(PgDatabaseRow(oid = oid.toOption.get, datname = datname.toOption.get, datdba = datdba.toOption.get, encoding = encoding.toOption.get, datcollate = datcollate.toOption.get, datctype = datctype.toOption.get, datistemplate = datistemplate.toOption.get, datallowconn = datallowconn.toOption.get, datconnlimit = datconnlimit.toOption.get, datlastsysoid = datlastsysoid.toOption.get, datfrozenxid = datfrozenxid.toOption.get, datminmxid = datminmxid.toOption.get, dattablespace = dattablespace.toOption.get, datacl = datacl.toOption.get)) + else Left(List[Either[String, Any]](oid, datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDatabaseRow] = new JsonEncoder[PgDatabaseRow] { + override def unsafeEncode(a: PgDatabaseRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgDatabaseId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.string.unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""datdba":""") + JsonEncoder.long.unsafeEncode(a.datdba, indent, out) + out.write(",") + out.write(""""encoding":""") + JsonEncoder.int.unsafeEncode(a.encoding, indent, out) + out.write(",") + out.write(""""datcollate":""") + JsonEncoder.string.unsafeEncode(a.datcollate, indent, out) + out.write(",") + out.write(""""datctype":""") + JsonEncoder.string.unsafeEncode(a.datctype, indent, out) + out.write(",") + out.write(""""datistemplate":""") + JsonEncoder.boolean.unsafeEncode(a.datistemplate, indent, out) + out.write(",") + out.write(""""datallowconn":""") + JsonEncoder.boolean.unsafeEncode(a.datallowconn, indent, out) + out.write(",") + out.write(""""datconnlimit":""") + JsonEncoder.int.unsafeEncode(a.datconnlimit, indent, out) + out.write(",") + out.write(""""datlastsysoid":""") + JsonEncoder.long.unsafeEncode(a.datlastsysoid, indent, out) + out.write(",") + out.write(""""datfrozenxid":""") + TypoXid.jsonEncoder.unsafeEncode(a.datfrozenxid, indent, out) + out.write(",") + out.write(""""datminmxid":""") + TypoXid.jsonEncoder.unsafeEncode(a.datminmxid, indent, out) + out.write(",") + out.write(""""dattablespace":""") + JsonEncoder.long.unsafeEncode(a.dattablespace, indent, out) + out.write(",") + out.write(""""datacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.datacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseStructure.scala new file mode 100644 index 0000000000..9bef2ba97b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_database/PgDatabaseStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_database + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgDatabaseStructure[Row](val prefix: Option[String], val extract: Row => PgDatabaseRow, val merge: (Row, PgDatabaseRow) => Row) + extends Relation[PgDatabaseFields, PgDatabaseRow, Row] + with PgDatabaseFields[Row] { outer => + + override val oid = new IdField[PgDatabaseId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val datname = new Field[String, Row](prefix, "datname", None, Some("name"))(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val datdba = new Field[/* oid */ Long, Row](prefix, "datdba", None, Some("oid"))(x => extract(x).datdba, (row, value) => merge(row, extract(row).copy(datdba = value))) + override val encoding = new Field[Int, Row](prefix, "encoding", None, Some("int4"))(x => extract(x).encoding, (row, value) => merge(row, extract(row).copy(encoding = value))) + override val datcollate = new Field[String, Row](prefix, "datcollate", None, Some("name"))(x => extract(x).datcollate, (row, value) => merge(row, extract(row).copy(datcollate = value))) + override val datctype = new Field[String, Row](prefix, "datctype", None, Some("name"))(x => extract(x).datctype, (row, value) => merge(row, extract(row).copy(datctype = value))) + override val datistemplate = new Field[Boolean, Row](prefix, "datistemplate", None, None)(x => extract(x).datistemplate, (row, value) => merge(row, extract(row).copy(datistemplate = value))) + override val datallowconn = new Field[Boolean, Row](prefix, "datallowconn", None, None)(x => extract(x).datallowconn, (row, value) => merge(row, extract(row).copy(datallowconn = value))) + override val datconnlimit = new Field[Int, Row](prefix, "datconnlimit", None, Some("int4"))(x => extract(x).datconnlimit, (row, value) => merge(row, extract(row).copy(datconnlimit = value))) + override val datlastsysoid = new Field[/* oid */ Long, Row](prefix, "datlastsysoid", None, Some("oid"))(x => extract(x).datlastsysoid, (row, value) => merge(row, extract(row).copy(datlastsysoid = value))) + override val datfrozenxid = new Field[TypoXid, Row](prefix, "datfrozenxid", None, Some("xid"))(x => extract(x).datfrozenxid, (row, value) => merge(row, extract(row).copy(datfrozenxid = value))) + override val datminmxid = new Field[TypoXid, Row](prefix, "datminmxid", None, Some("xid"))(x => extract(x).datminmxid, (row, value) => merge(row, extract(row).copy(datminmxid = value))) + override val dattablespace = new Field[/* oid */ Long, Row](prefix, "dattablespace", None, Some("oid"))(x => extract(x).dattablespace, (row, value) => merge(row, extract(row).copy(dattablespace = value))) + override val datacl = new OptField[Array[TypoAclItem], Row](prefix, "datacl", None, Some("_aclitem"))(x => extract(x).datacl, (row, value) => merge(row, extract(row).copy(datacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, datname, datdba, encoding, datcollate, datctype, datistemplate, datallowconn, datconnlimit, datlastsysoid, datfrozenxid, datminmxid, dattablespace, datacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgDatabaseRow, merge: (NewRow, PgDatabaseRow) => NewRow): PgDatabaseStructure[NewRow] = + new PgDatabaseStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingFields.scala new file mode 100644 index 0000000000..298b708891 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgDbRoleSettingFields[Row] { + val setdatabase: IdField[/* oid */ Long, Row] + val setrole: IdField[/* oid */ Long, Row] + val setconfig: OptField[Array[String], Row] +} +object PgDbRoleSettingFields extends PgDbRoleSettingStructure[PgDbRoleSettingRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingId.scala new file mode 100644 index 0000000000..88a3b622ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_db_role_setting` */ +case class PgDbRoleSettingId(setdatabase: /* oid */ Long, setrole: /* oid */ Long) +object PgDbRoleSettingId { + implicit lazy val jsonDecoder: JsonDecoder[PgDbRoleSettingId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val setdatabase = jsonObj.get("setdatabase").toRight("Missing field 'setdatabase'").flatMap(_.as(JsonDecoder.long)) + val setrole = jsonObj.get("setrole").toRight("Missing field 'setrole'").flatMap(_.as(JsonDecoder.long)) + if (setdatabase.isRight && setrole.isRight) + Right(PgDbRoleSettingId(setdatabase = setdatabase.toOption.get, setrole = setrole.toOption.get)) + else Left(List[Either[String, Any]](setdatabase, setrole).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDbRoleSettingId] = new JsonEncoder[PgDbRoleSettingId] { + override def unsafeEncode(a: PgDbRoleSettingId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""setdatabase":""") + JsonEncoder.long.unsafeEncode(a.setdatabase, indent, out) + out.write(",") + out.write(""""setrole":""") + JsonEncoder.long.unsafeEncode(a.setrole, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgDbRoleSettingId] = Ordering.by(x => (x.setdatabase, x.setrole)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepo.scala new file mode 100644 index 0000000000..2208eabb49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgDbRoleSettingRepo { + def delete(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] + def insert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, PgDbRoleSettingRow] + def select: SelectBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] + def selectAll: ZStream[ZConnection, Throwable, PgDbRoleSettingRow] + def selectById(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Option[PgDbRoleSettingRow]] + def update(row: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] + def upsert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, UpdateResult[PgDbRoleSettingRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoImpl.scala new file mode 100644 index 0000000000..9efd342237 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoImpl.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgDbRoleSettingRepoImpl extends PgDbRoleSettingRepo { + override def delete(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_db_role_setting where "setdatabase" = ${Segment.paramSegment(compositeId.setdatabase)(Setter.longSetter)} AND "setrole" = ${Segment.paramSegment(compositeId.setrole)(Setter.longSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + DeleteBuilder("pg_catalog.pg_db_role_setting", PgDbRoleSettingFields) + } + override def insert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, PgDbRoleSettingRow] = { + sql"""insert into pg_catalog.pg_db_role_setting("setdatabase", "setrole", "setconfig") + values (${Segment.paramSegment(unsaved.setdatabase)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.setrole)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.setconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "setdatabase", "setrole", "setconfig" + """.insertReturning(PgDbRoleSettingRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + SelectBuilderSql("pg_catalog.pg_db_role_setting", PgDbRoleSettingFields, PgDbRoleSettingRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDbRoleSettingRow] = { + sql"""select "setdatabase", "setrole", "setconfig" from pg_catalog.pg_db_role_setting""".query(PgDbRoleSettingRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Option[PgDbRoleSettingRow]] = { + sql"""select "setdatabase", "setrole", "setconfig" from pg_catalog.pg_db_role_setting where "setdatabase" = ${Segment.paramSegment(compositeId.setdatabase)(Setter.longSetter)} AND "setrole" = ${Segment.paramSegment(compositeId.setrole)(Setter.longSetter)}""".query(PgDbRoleSettingRow.jdbcDecoder).selectOne + } + override def update(row: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_db_role_setting + set "setconfig" = ${Segment.paramSegment(row.setconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "setdatabase" = ${Segment.paramSegment(compositeId.setdatabase)(Setter.longSetter)} AND "setrole" = ${Segment.paramSegment(compositeId.setrole)(Setter.longSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + UpdateBuilder("pg_catalog.pg_db_role_setting", PgDbRoleSettingFields, PgDbRoleSettingRow.jdbcDecoder) + } + override def upsert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, UpdateResult[PgDbRoleSettingRow]] = { + sql"""insert into pg_catalog.pg_db_role_setting("setdatabase", "setrole", "setconfig") + values ( + ${Segment.paramSegment(unsaved.setdatabase)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.setrole)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.setconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("setdatabase", "setrole") + do update set + "setconfig" = EXCLUDED."setconfig" + returning "setdatabase", "setrole", "setconfig"""".insertReturning(PgDbRoleSettingRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoMock.scala new file mode 100644 index 0000000000..608f228462 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgDbRoleSettingRepoMock(map: scala.collection.mutable.Map[PgDbRoleSettingId, PgDbRoleSettingRow] = scala.collection.mutable.Map.empty) extends PgDbRoleSettingRepo { + override def delete(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + DeleteBuilderMock(DeleteParams.empty, PgDbRoleSettingFields, map) + } + override def insert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, PgDbRoleSettingRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + SelectBuilderMock(PgDbRoleSettingFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDbRoleSettingRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgDbRoleSettingId): ZIO[ZConnection, Throwable, Option[PgDbRoleSettingRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgDbRoleSettingFields, PgDbRoleSettingRow] = { + UpdateBuilderMock(UpdateParams.empty, PgDbRoleSettingFields, map) + } + override def upsert(unsaved: PgDbRoleSettingRow): ZIO[ZConnection, Throwable, UpdateResult[PgDbRoleSettingRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRow.scala new file mode 100644 index 0000000000..908e54519c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingRow.scala @@ -0,0 +1,57 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgDbRoleSettingRow( + setdatabase: /* oid */ Long, + setrole: /* oid */ Long, + setconfig: Option[Array[String]] +){ + val compositeId: PgDbRoleSettingId = PgDbRoleSettingId(setdatabase, setrole) + } + +object PgDbRoleSettingRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgDbRoleSettingRow] = new JdbcDecoder[PgDbRoleSettingRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgDbRoleSettingRow) = + columIndex + 2 -> + PgDbRoleSettingRow( + setdatabase = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + setrole = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + setconfig = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgDbRoleSettingRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val setdatabase = jsonObj.get("setdatabase").toRight("Missing field 'setdatabase'").flatMap(_.as(JsonDecoder.long)) + val setrole = jsonObj.get("setrole").toRight("Missing field 'setrole'").flatMap(_.as(JsonDecoder.long)) + val setconfig = jsonObj.get("setconfig").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (setdatabase.isRight && setrole.isRight && setconfig.isRight) + Right(PgDbRoleSettingRow(setdatabase = setdatabase.toOption.get, setrole = setrole.toOption.get, setconfig = setconfig.toOption.get)) + else Left(List[Either[String, Any]](setdatabase, setrole, setconfig).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDbRoleSettingRow] = new JsonEncoder[PgDbRoleSettingRow] { + override def unsafeEncode(a: PgDbRoleSettingRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""setdatabase":""") + JsonEncoder.long.unsafeEncode(a.setdatabase, indent, out) + out.write(",") + out.write(""""setrole":""") + JsonEncoder.long.unsafeEncode(a.setrole, indent, out) + out.write(",") + out.write(""""setconfig":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.setconfig, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingStructure.scala new file mode 100644 index 0000000000..127dd0654e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_db_role_setting/PgDbRoleSettingStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_db_role_setting + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgDbRoleSettingStructure[Row](val prefix: Option[String], val extract: Row => PgDbRoleSettingRow, val merge: (Row, PgDbRoleSettingRow) => Row) + extends Relation[PgDbRoleSettingFields, PgDbRoleSettingRow, Row] + with PgDbRoleSettingFields[Row] { outer => + + override val setdatabase = new IdField[/* oid */ Long, Row](prefix, "setdatabase", None, Some("oid"))(x => extract(x).setdatabase, (row, value) => merge(row, extract(row).copy(setdatabase = value))) + override val setrole = new IdField[/* oid */ Long, Row](prefix, "setrole", None, Some("oid"))(x => extract(x).setrole, (row, value) => merge(row, extract(row).copy(setrole = value))) + override val setconfig = new OptField[Array[String], Row](prefix, "setconfig", None, Some("_text"))(x => extract(x).setconfig, (row, value) => merge(row, extract(row).copy(setconfig = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](setdatabase, setrole, setconfig) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgDbRoleSettingRow, merge: (NewRow, PgDbRoleSettingRow) => NewRow): PgDbRoleSettingStructure[NewRow] = + new PgDbRoleSettingStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclFields.scala new file mode 100644 index 0000000000..0096b8a677 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgDefaultAclFields[Row] { + val oid: IdField[PgDefaultAclId, Row] + val defaclrole: Field[/* oid */ Long, Row] + val defaclnamespace: Field[/* oid */ Long, Row] + val defaclobjtype: Field[String, Row] + val defaclacl: Field[Array[TypoAclItem], Row] +} +object PgDefaultAclFields extends PgDefaultAclStructure[PgDefaultAclRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclId.scala new file mode 100644 index 0000000000..d369e5ab5f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +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 `pg_catalog.pg_default_acl` */ +case class PgDefaultAclId(value: /* oid */ Long) extends AnyVal +object PgDefaultAclId { + implicit lazy val arraySetter: Setter[Array[PgDefaultAclId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgDefaultAclId, /* oid */ Long] = Bijection[PgDefaultAclId, /* oid */ Long](_.value)(PgDefaultAclId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgDefaultAclId] = JdbcDecoder.longDecoder.map(PgDefaultAclId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgDefaultAclId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgDefaultAclId] = JsonDecoder.long.map(PgDefaultAclId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgDefaultAclId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgDefaultAclId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgDefaultAclId] = ParameterMetaData.instance[PgDefaultAclId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgDefaultAclId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepo.scala new file mode 100644 index 0000000000..15e53a2272 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgDefaultAclRepo { + def delete(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgDefaultAclFields, PgDefaultAclRow] + def insert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, PgDefaultAclRow] + def select: SelectBuilder[PgDefaultAclFields, PgDefaultAclRow] + def selectAll: ZStream[ZConnection, Throwable, PgDefaultAclRow] + def selectById(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] + def selectByIds(oids: Array[PgDefaultAclId]): ZStream[ZConnection, Throwable, PgDefaultAclRow] + def selectByUnique(defaclrole: /* oid */ Long, defaclnamespace: /* oid */ Long, defaclobjtype: String): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] + def update(row: PgDefaultAclRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgDefaultAclFields, PgDefaultAclRow] + def upsert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, UpdateResult[PgDefaultAclRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoImpl.scala new file mode 100644 index 0000000000..6a1f861169 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoImpl.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgDefaultAclRepoImpl extends PgDefaultAclRepo { + override def delete(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_default_acl where "oid" = ${Segment.paramSegment(oid)(PgDefaultAclId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + DeleteBuilder("pg_catalog.pg_default_acl", PgDefaultAclFields) + } + override def insert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, PgDefaultAclRow] = { + sql"""insert into pg_catalog.pg_default_acl("oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl") + values (${Segment.paramSegment(unsaved.oid)(PgDefaultAclId.setter)}::oid, ${Segment.paramSegment(unsaved.defaclrole)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.defaclnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.defaclobjtype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.defaclacl)(TypoAclItem.arraySetter)}::_aclitem) + returning "oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl" + """.insertReturning(PgDefaultAclRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + SelectBuilderSql("pg_catalog.pg_default_acl", PgDefaultAclFields, PgDefaultAclRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDefaultAclRow] = { + sql"""select "oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl" from pg_catalog.pg_default_acl""".query(PgDefaultAclRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] = { + sql"""select "oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl" from pg_catalog.pg_default_acl where "oid" = ${Segment.paramSegment(oid)(PgDefaultAclId.setter)}""".query(PgDefaultAclRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgDefaultAclId]): ZStream[ZConnection, Throwable, PgDefaultAclRow] = { + sql"""select "oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl" from pg_catalog.pg_default_acl where "oid" = ANY(${Segment.paramSegment(oids)(PgDefaultAclId.arraySetter)})""".query(PgDefaultAclRow.jdbcDecoder).selectStream + } + override def selectByUnique(defaclrole: /* oid */ Long, defaclnamespace: /* oid */ Long, defaclobjtype: String): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] = { + sql"""select "defaclrole", "defaclnamespace", "defaclobjtype" + from pg_catalog.pg_default_acl + where "defaclrole" = ${Segment.paramSegment(defaclrole)(Setter.longSetter)} AND "defaclnamespace" = ${Segment.paramSegment(defaclnamespace)(Setter.longSetter)} AND "defaclobjtype" = ${Segment.paramSegment(defaclobjtype)(Setter.stringSetter)} + """.query(PgDefaultAclRow.jdbcDecoder).selectOne + } + override def update(row: PgDefaultAclRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_default_acl + set "defaclrole" = ${Segment.paramSegment(row.defaclrole)(Setter.longSetter)}::oid, + "defaclnamespace" = ${Segment.paramSegment(row.defaclnamespace)(Setter.longSetter)}::oid, + "defaclobjtype" = ${Segment.paramSegment(row.defaclobjtype)(Setter.stringSetter)}::char, + "defaclacl" = ${Segment.paramSegment(row.defaclacl)(TypoAclItem.arraySetter)}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgDefaultAclId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + UpdateBuilder("pg_catalog.pg_default_acl", PgDefaultAclFields, PgDefaultAclRow.jdbcDecoder) + } + override def upsert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, UpdateResult[PgDefaultAclRow]] = { + sql"""insert into pg_catalog.pg_default_acl("oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgDefaultAclId.setter)}::oid, + ${Segment.paramSegment(unsaved.defaclrole)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.defaclnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.defaclobjtype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.defaclacl)(TypoAclItem.arraySetter)}::_aclitem + ) + on conflict ("oid") + do update set + "defaclrole" = EXCLUDED."defaclrole", + "defaclnamespace" = EXCLUDED."defaclnamespace", + "defaclobjtype" = EXCLUDED."defaclobjtype", + "defaclacl" = EXCLUDED."defaclacl" + returning "oid", "defaclrole", "defaclnamespace", "defaclobjtype", "defaclacl"""".insertReturning(PgDefaultAclRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoMock.scala new file mode 100644 index 0000000000..ca8d2df7a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgDefaultAclRepoMock(map: scala.collection.mutable.Map[PgDefaultAclId, PgDefaultAclRow] = scala.collection.mutable.Map.empty) extends PgDefaultAclRepo { + override def delete(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + DeleteBuilderMock(DeleteParams.empty, PgDefaultAclFields, map) + } + override def insert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, PgDefaultAclRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + SelectBuilderMock(PgDefaultAclFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDefaultAclRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgDefaultAclId): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgDefaultAclId]): ZStream[ZConnection, Throwable, PgDefaultAclRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(defaclrole: /* oid */ Long, defaclnamespace: /* oid */ Long, defaclobjtype: String): ZIO[ZConnection, Throwable, Option[PgDefaultAclRow]] = { + ZIO.succeed(map.values.find(v => defaclrole == v.defaclrole && defaclnamespace == v.defaclnamespace && defaclobjtype == v.defaclobjtype)) + } + override def update(row: PgDefaultAclRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgDefaultAclFields, PgDefaultAclRow] = { + UpdateBuilderMock(UpdateParams.empty, PgDefaultAclFields, map) + } + override def upsert(unsaved: PgDefaultAclRow): ZIO[ZConnection, Throwable, UpdateResult[PgDefaultAclRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRow.scala new file mode 100644 index 0000000000..e5759bb1cb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgDefaultAclRow( + oid: PgDefaultAclId, + defaclrole: /* oid */ Long, + defaclnamespace: /* oid */ Long, + defaclobjtype: String, + defaclacl: Array[TypoAclItem] +) + +object PgDefaultAclRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgDefaultAclRow] = new JdbcDecoder[PgDefaultAclRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgDefaultAclRow) = + columIndex + 4 -> + PgDefaultAclRow( + oid = PgDefaultAclId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + defaclrole = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + defaclnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + defaclobjtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + defaclacl = JdbcDecoder[Array[TypoAclItem]].unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgDefaultAclRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgDefaultAclId.jsonDecoder)) + val defaclrole = jsonObj.get("defaclrole").toRight("Missing field 'defaclrole'").flatMap(_.as(JsonDecoder.long)) + val defaclnamespace = jsonObj.get("defaclnamespace").toRight("Missing field 'defaclnamespace'").flatMap(_.as(JsonDecoder.long)) + val defaclobjtype = jsonObj.get("defaclobjtype").toRight("Missing field 'defaclobjtype'").flatMap(_.as(JsonDecoder.string)) + val defaclacl = jsonObj.get("defaclacl").toRight("Missing field 'defaclacl'").flatMap(_.as(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly))) + if (oid.isRight && defaclrole.isRight && defaclnamespace.isRight && defaclobjtype.isRight && defaclacl.isRight) + Right(PgDefaultAclRow(oid = oid.toOption.get, defaclrole = defaclrole.toOption.get, defaclnamespace = defaclnamespace.toOption.get, defaclobjtype = defaclobjtype.toOption.get, defaclacl = defaclacl.toOption.get)) + else Left(List[Either[String, Any]](oid, defaclrole, defaclnamespace, defaclobjtype, defaclacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDefaultAclRow] = new JsonEncoder[PgDefaultAclRow] { + override def unsafeEncode(a: PgDefaultAclRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgDefaultAclId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""defaclrole":""") + JsonEncoder.long.unsafeEncode(a.defaclrole, indent, out) + out.write(",") + out.write(""""defaclnamespace":""") + JsonEncoder.long.unsafeEncode(a.defaclnamespace, indent, out) + out.write(",") + out.write(""""defaclobjtype":""") + JsonEncoder.string.unsafeEncode(a.defaclobjtype, indent, out) + out.write(",") + out.write(""""defaclacl":""") + JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly).unsafeEncode(a.defaclacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclStructure.scala new file mode 100644 index 0000000000..1f25794b73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_default_acl/PgDefaultAclStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_default_acl + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgDefaultAclStructure[Row](val prefix: Option[String], val extract: Row => PgDefaultAclRow, val merge: (Row, PgDefaultAclRow) => Row) + extends Relation[PgDefaultAclFields, PgDefaultAclRow, Row] + with PgDefaultAclFields[Row] { outer => + + override val oid = new IdField[PgDefaultAclId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val defaclrole = new Field[/* oid */ Long, Row](prefix, "defaclrole", None, Some("oid"))(x => extract(x).defaclrole, (row, value) => merge(row, extract(row).copy(defaclrole = value))) + override val defaclnamespace = new Field[/* oid */ Long, Row](prefix, "defaclnamespace", None, Some("oid"))(x => extract(x).defaclnamespace, (row, value) => merge(row, extract(row).copy(defaclnamespace = value))) + override val defaclobjtype = new Field[String, Row](prefix, "defaclobjtype", None, Some("char"))(x => extract(x).defaclobjtype, (row, value) => merge(row, extract(row).copy(defaclobjtype = value))) + override val defaclacl = new Field[Array[TypoAclItem], Row](prefix, "defaclacl", None, Some("_aclitem"))(x => extract(x).defaclacl, (row, value) => merge(row, extract(row).copy(defaclacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, defaclrole, defaclnamespace, defaclobjtype, defaclacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgDefaultAclRow, merge: (NewRow, PgDefaultAclRow) => NewRow): PgDefaultAclStructure[NewRow] = + new PgDefaultAclStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependFields.scala new file mode 100644 index 0000000000..c5403d7a74 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_depend + +import typo.dsl.SqlExpr.Field + +trait PgDependFields[Row] { + val classid: Field[/* oid */ Long, Row] + val objid: Field[/* oid */ Long, Row] + val objsubid: Field[Int, Row] + val refclassid: Field[/* oid */ Long, Row] + val refobjid: Field[/* oid */ Long, Row] + val refobjsubid: Field[Int, Row] + val deptype: Field[String, Row] +} +object PgDependFields extends PgDependStructure[PgDependRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepo.scala new file mode 100644 index 0000000000..9ecd8c07b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_depend + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgDependRepo { + def delete: DeleteBuilder[PgDependFields, PgDependRow] + def insert(unsaved: PgDependRow): ZIO[ZConnection, Throwable, PgDependRow] + def select: SelectBuilder[PgDependFields, PgDependRow] + def selectAll: ZStream[ZConnection, Throwable, PgDependRow] + def update: UpdateBuilder[PgDependFields, PgDependRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepoImpl.scala new file mode 100644 index 0000000000..8c9be84c3f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRepoImpl.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_depend + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgDependRepoImpl extends PgDependRepo { + override def delete: DeleteBuilder[PgDependFields, PgDependRow] = { + DeleteBuilder("pg_catalog.pg_depend", PgDependFields) + } + override def insert(unsaved: PgDependRow): ZIO[ZConnection, Throwable, PgDependRow] = { + sql"""insert into pg_catalog.pg_depend("classid", "objid", "objsubid", "refclassid", "refobjid", "refobjsubid", "deptype") + values (${Segment.paramSegment(unsaved.classid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.refclassid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.refobjid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.refobjsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.deptype)(Setter.stringSetter)}::char) + returning "classid", "objid", "objsubid", "refclassid", "refobjid", "refobjsubid", "deptype" + """.insertReturning(PgDependRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgDependFields, PgDependRow] = { + SelectBuilderSql("pg_catalog.pg_depend", PgDependFields, PgDependRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDependRow] = { + sql"""select "classid", "objid", "objsubid", "refclassid", "refobjid", "refobjsubid", "deptype" from pg_catalog.pg_depend""".query(PgDependRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[PgDependFields, PgDependRow] = { + UpdateBuilder("pg_catalog.pg_depend", PgDependFields, PgDependRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRow.scala new file mode 100644 index 0000000000..3861845a2e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_depend + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgDependRow( + classid: /* oid */ Long, + objid: /* oid */ Long, + objsubid: Int, + refclassid: /* oid */ Long, + refobjid: /* oid */ Long, + refobjsubid: Int, + deptype: String +) + +object PgDependRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgDependRow] = new JdbcDecoder[PgDependRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgDependRow) = + columIndex + 6 -> + PgDependRow( + classid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + objid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + objsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + refclassid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + refobjid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + refobjsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 5, rs)._2, + deptype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgDependRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val classid = jsonObj.get("classid").toRight("Missing field 'classid'").flatMap(_.as(JsonDecoder.long)) + val objid = jsonObj.get("objid").toRight("Missing field 'objid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val refclassid = jsonObj.get("refclassid").toRight("Missing field 'refclassid'").flatMap(_.as(JsonDecoder.long)) + val refobjid = jsonObj.get("refobjid").toRight("Missing field 'refobjid'").flatMap(_.as(JsonDecoder.long)) + val refobjsubid = jsonObj.get("refobjsubid").toRight("Missing field 'refobjsubid'").flatMap(_.as(JsonDecoder.int)) + val deptype = jsonObj.get("deptype").toRight("Missing field 'deptype'").flatMap(_.as(JsonDecoder.string)) + if (classid.isRight && objid.isRight && objsubid.isRight && refclassid.isRight && refobjid.isRight && refobjsubid.isRight && deptype.isRight) + Right(PgDependRow(classid = classid.toOption.get, objid = objid.toOption.get, objsubid = objsubid.toOption.get, refclassid = refclassid.toOption.get, refobjid = refobjid.toOption.get, refobjsubid = refobjsubid.toOption.get, deptype = deptype.toOption.get)) + else Left(List[Either[String, Any]](classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDependRow] = new JsonEncoder[PgDependRow] { + override def unsafeEncode(a: PgDependRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""classid":""") + JsonEncoder.long.unsafeEncode(a.classid, indent, out) + out.write(",") + out.write(""""objid":""") + JsonEncoder.long.unsafeEncode(a.objid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""refclassid":""") + JsonEncoder.long.unsafeEncode(a.refclassid, indent, out) + out.write(",") + out.write(""""refobjid":""") + JsonEncoder.long.unsafeEncode(a.refobjid, indent, out) + out.write(",") + out.write(""""refobjsubid":""") + JsonEncoder.int.unsafeEncode(a.refobjsubid, indent, out) + out.write(",") + out.write(""""deptype":""") + JsonEncoder.string.unsafeEncode(a.deptype, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependStructure.scala new file mode 100644 index 0000000000..8762144f3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_depend/PgDependStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_depend + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PgDependStructure[Row](val prefix: Option[String], val extract: Row => PgDependRow, val merge: (Row, PgDependRow) => Row) + extends Relation[PgDependFields, PgDependRow, Row] + with PgDependFields[Row] { outer => + + override val classid = new Field[/* oid */ Long, Row](prefix, "classid", None, Some("oid"))(x => extract(x).classid, (row, value) => merge(row, extract(row).copy(classid = value))) + override val objid = new Field[/* oid */ Long, Row](prefix, "objid", None, Some("oid"))(x => extract(x).objid, (row, value) => merge(row, extract(row).copy(objid = value))) + override val objsubid = new Field[Int, Row](prefix, "objsubid", None, Some("int4"))(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val refclassid = new Field[/* oid */ Long, Row](prefix, "refclassid", None, Some("oid"))(x => extract(x).refclassid, (row, value) => merge(row, extract(row).copy(refclassid = value))) + override val refobjid = new Field[/* oid */ Long, Row](prefix, "refobjid", None, Some("oid"))(x => extract(x).refobjid, (row, value) => merge(row, extract(row).copy(refobjid = value))) + override val refobjsubid = new Field[Int, Row](prefix, "refobjsubid", None, Some("int4"))(x => extract(x).refobjsubid, (row, value) => merge(row, extract(row).copy(refobjsubid = value))) + override val deptype = new Field[String, Row](prefix, "deptype", None, Some("char"))(x => extract(x).deptype, (row, value) => merge(row, extract(row).copy(deptype = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](classid, objid, objsubid, refclassid, refobjid, refobjsubid, deptype) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgDependRow, merge: (NewRow, PgDependRow) => NewRow): PgDependStructure[NewRow] = + new PgDependStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionFields.scala new file mode 100644 index 0000000000..c7499aa473 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgDescriptionFields[Row] { + val objoid: IdField[/* oid */ Long, Row] + val classoid: IdField[/* oid */ Long, Row] + val objsubid: IdField[Int, Row] + val description: Field[String, Row] +} +object PgDescriptionFields extends PgDescriptionStructure[PgDescriptionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionId.scala new file mode 100644 index 0000000000..7e3a827e8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionId.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_description` */ +case class PgDescriptionId(objoid: /* oid */ Long, classoid: /* oid */ Long, objsubid: Int) +object PgDescriptionId { + implicit lazy val jsonDecoder: JsonDecoder[PgDescriptionId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + if (objoid.isRight && classoid.isRight && objsubid.isRight) + Right(PgDescriptionId(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDescriptionId] = new JsonEncoder[PgDescriptionId] { + override def unsafeEncode(a: PgDescriptionId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgDescriptionId] = Ordering.by(x => (x.objoid, x.classoid, x.objsubid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepo.scala new file mode 100644 index 0000000000..3e5db69beb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgDescriptionRepo { + def delete(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgDescriptionFields, PgDescriptionRow] + def insert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, PgDescriptionRow] + def select: SelectBuilder[PgDescriptionFields, PgDescriptionRow] + def selectAll: ZStream[ZConnection, Throwable, PgDescriptionRow] + def selectById(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Option[PgDescriptionRow]] + def update(row: PgDescriptionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgDescriptionFields, PgDescriptionRow] + def upsert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgDescriptionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoImpl.scala new file mode 100644 index 0000000000..34bbeea928 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgDescriptionRepoImpl extends PgDescriptionRepo { + override def delete(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_description where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgDescriptionFields, PgDescriptionRow] = { + DeleteBuilder("pg_catalog.pg_description", PgDescriptionFields) + } + override def insert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, PgDescriptionRow] = { + sql"""insert into pg_catalog.pg_description("objoid", "classoid", "objsubid", "description") + values (${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}) + returning "objoid", "classoid", "objsubid", "description" + """.insertReturning(PgDescriptionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgDescriptionFields, PgDescriptionRow] = { + SelectBuilderSql("pg_catalog.pg_description", PgDescriptionFields, PgDescriptionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDescriptionRow] = { + sql"""select "objoid", "classoid", "objsubid", "description" from pg_catalog.pg_description""".query(PgDescriptionRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Option[PgDescriptionRow]] = { + sql"""select "objoid", "classoid", "objsubid", "description" from pg_catalog.pg_description where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".query(PgDescriptionRow.jdbcDecoder).selectOne + } + override def update(row: PgDescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_description + set "description" = ${Segment.paramSegment(row.description)(Setter.stringSetter)} + where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgDescriptionFields, PgDescriptionRow] = { + UpdateBuilder("pg_catalog.pg_description", PgDescriptionFields, PgDescriptionRow.jdbcDecoder) + } + override def upsert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgDescriptionRow]] = { + sql"""insert into pg_catalog.pg_description("objoid", "classoid", "objsubid", "description") + values ( + ${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)} + ) + on conflict ("objoid", "classoid", "objsubid") + do update set + "description" = EXCLUDED."description" + returning "objoid", "classoid", "objsubid", "description"""".insertReturning(PgDescriptionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoMock.scala new file mode 100644 index 0000000000..a5dabb3e3d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgDescriptionRepoMock(map: scala.collection.mutable.Map[PgDescriptionId, PgDescriptionRow] = scala.collection.mutable.Map.empty) extends PgDescriptionRepo { + override def delete(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgDescriptionFields, PgDescriptionRow] = { + DeleteBuilderMock(DeleteParams.empty, PgDescriptionFields, map) + } + override def insert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, PgDescriptionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgDescriptionFields, PgDescriptionRow] = { + SelectBuilderMock(PgDescriptionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgDescriptionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgDescriptionId): ZIO[ZConnection, Throwable, Option[PgDescriptionRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgDescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgDescriptionFields, PgDescriptionRow] = { + UpdateBuilderMock(UpdateParams.empty, PgDescriptionFields, map) + } + override def upsert(unsaved: PgDescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgDescriptionRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRow.scala new file mode 100644 index 0000000000..bdb7f3b4fa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgDescriptionRow( + objoid: /* oid */ Long, + classoid: /* oid */ Long, + objsubid: Int, + description: String +){ + val compositeId: PgDescriptionId = PgDescriptionId(objoid, classoid, objsubid) + } + +object PgDescriptionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgDescriptionRow] = new JdbcDecoder[PgDescriptionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgDescriptionRow) = + columIndex + 3 -> + PgDescriptionRow( + objoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + objsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgDescriptionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && objsubid.isRight && description.isRight) + Right(PgDescriptionRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get, description = description.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid, description).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgDescriptionRow] = new JsonEncoder[PgDescriptionRow] { + override def unsafeEncode(a: PgDescriptionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionStructure.scala new file mode 100644 index 0000000000..6254a33274 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_description/PgDescriptionStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_description + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgDescriptionStructure[Row](val prefix: Option[String], val extract: Row => PgDescriptionRow, val merge: (Row, PgDescriptionRow) => Row) + extends Relation[PgDescriptionFields, PgDescriptionRow, Row] + with PgDescriptionFields[Row] { outer => + + override val objoid = new IdField[/* oid */ Long, Row](prefix, "objoid", None, Some("oid"))(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new IdField[/* oid */ Long, Row](prefix, "classoid", None, Some("oid"))(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val objsubid = new IdField[Int, Row](prefix, "objsubid", None, Some("int4"))(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val description = new Field[String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, objsubid, description) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgDescriptionRow, merge: (NewRow, PgDescriptionRow) => NewRow): PgDescriptionStructure[NewRow] = + new PgDescriptionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumFields.scala new file mode 100644 index 0000000000..4b88248d49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgEnumFields[Row] { + val oid: IdField[PgEnumId, Row] + val enumtypid: Field[/* oid */ Long, Row] + val enumsortorder: Field[Float, Row] + val enumlabel: Field[String, Row] +} +object PgEnumFields extends PgEnumStructure[PgEnumRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumId.scala new file mode 100644 index 0000000000..fc6fd21b3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +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 `pg_catalog.pg_enum` */ +case class PgEnumId(value: /* oid */ Long) extends AnyVal +object PgEnumId { + implicit lazy val arraySetter: Setter[Array[PgEnumId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgEnumId, /* oid */ Long] = Bijection[PgEnumId, /* oid */ Long](_.value)(PgEnumId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgEnumId] = JdbcDecoder.longDecoder.map(PgEnumId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgEnumId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgEnumId] = JsonDecoder.long.map(PgEnumId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgEnumId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgEnumId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgEnumId] = ParameterMetaData.instance[PgEnumId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgEnumId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepo.scala new file mode 100644 index 0000000000..be8e7030ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgEnumRepo { + def delete(oid: PgEnumId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgEnumFields, PgEnumRow] + def insert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, PgEnumRow] + def select: SelectBuilder[PgEnumFields, PgEnumRow] + def selectAll: ZStream[ZConnection, Throwable, PgEnumRow] + def selectById(oid: PgEnumId): ZIO[ZConnection, Throwable, Option[PgEnumRow]] + def selectByIds(oids: Array[PgEnumId]): ZStream[ZConnection, Throwable, PgEnumRow] + def selectByUnique(enumtypid: /* oid */ Long, enumlabel: String): ZIO[ZConnection, Throwable, Option[PgEnumRow]] + def selectByUnique(enumtypid: /* oid */ Long, enumsortorder: Float): ZIO[ZConnection, Throwable, Option[PgEnumRow]] + def update(row: PgEnumRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgEnumFields, PgEnumRow] + def upsert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, UpdateResult[PgEnumRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoImpl.scala new file mode 100644 index 0000000000..8816d6f102 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoImpl.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgEnumRepoImpl extends PgEnumRepo { + override def delete(oid: PgEnumId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_enum where "oid" = ${Segment.paramSegment(oid)(PgEnumId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgEnumFields, PgEnumRow] = { + DeleteBuilder("pg_catalog.pg_enum", PgEnumFields) + } + override def insert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, PgEnumRow] = { + sql"""insert into pg_catalog.pg_enum("oid", "enumtypid", "enumsortorder", "enumlabel") + values (${Segment.paramSegment(unsaved.oid)(PgEnumId.setter)}::oid, ${Segment.paramSegment(unsaved.enumtypid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.enumsortorder)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.enumlabel)(Setter.stringSetter)}::name) + returning "oid", "enumtypid", "enumsortorder", "enumlabel" + """.insertReturning(PgEnumRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgEnumFields, PgEnumRow] = { + SelectBuilderSql("pg_catalog.pg_enum", PgEnumFields, PgEnumRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgEnumRow] = { + sql"""select "oid", "enumtypid", "enumsortorder", "enumlabel" from pg_catalog.pg_enum""".query(PgEnumRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgEnumId): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + sql"""select "oid", "enumtypid", "enumsortorder", "enumlabel" from pg_catalog.pg_enum where "oid" = ${Segment.paramSegment(oid)(PgEnumId.setter)}""".query(PgEnumRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgEnumId]): ZStream[ZConnection, Throwable, PgEnumRow] = { + sql"""select "oid", "enumtypid", "enumsortorder", "enumlabel" from pg_catalog.pg_enum where "oid" = ANY(${Segment.paramSegment(oids)(PgEnumId.arraySetter)})""".query(PgEnumRow.jdbcDecoder).selectStream + } + override def selectByUnique(enumtypid: /* oid */ Long, enumlabel: String): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + sql"""select "enumtypid", "enumlabel" + from pg_catalog.pg_enum + where "enumtypid" = ${Segment.paramSegment(enumtypid)(Setter.longSetter)} AND "enumlabel" = ${Segment.paramSegment(enumlabel)(Setter.stringSetter)} + """.query(PgEnumRow.jdbcDecoder).selectOne + } + override def selectByUnique(enumtypid: /* oid */ Long, enumsortorder: Float): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + sql"""select "enumtypid", "enumsortorder" + from pg_catalog.pg_enum + where "enumtypid" = ${Segment.paramSegment(enumtypid)(Setter.longSetter)} AND "enumsortorder" = ${Segment.paramSegment(enumsortorder)(Setter.floatSetter)} + """.query(PgEnumRow.jdbcDecoder).selectOne + } + override def update(row: PgEnumRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_enum + set "enumtypid" = ${Segment.paramSegment(row.enumtypid)(Setter.longSetter)}::oid, + "enumsortorder" = ${Segment.paramSegment(row.enumsortorder)(Setter.floatSetter)}::float4, + "enumlabel" = ${Segment.paramSegment(row.enumlabel)(Setter.stringSetter)}::name + where "oid" = ${Segment.paramSegment(oid)(PgEnumId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgEnumFields, PgEnumRow] = { + UpdateBuilder("pg_catalog.pg_enum", PgEnumFields, PgEnumRow.jdbcDecoder) + } + override def upsert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, UpdateResult[PgEnumRow]] = { + sql"""insert into pg_catalog.pg_enum("oid", "enumtypid", "enumsortorder", "enumlabel") + values ( + ${Segment.paramSegment(unsaved.oid)(PgEnumId.setter)}::oid, + ${Segment.paramSegment(unsaved.enumtypid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.enumsortorder)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.enumlabel)(Setter.stringSetter)}::name + ) + on conflict ("oid") + do update set + "enumtypid" = EXCLUDED."enumtypid", + "enumsortorder" = EXCLUDED."enumsortorder", + "enumlabel" = EXCLUDED."enumlabel" + returning "oid", "enumtypid", "enumsortorder", "enumlabel"""".insertReturning(PgEnumRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoMock.scala new file mode 100644 index 0000000000..8353424fcb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRepoMock.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgEnumRepoMock(map: scala.collection.mutable.Map[PgEnumId, PgEnumRow] = scala.collection.mutable.Map.empty) extends PgEnumRepo { + override def delete(oid: PgEnumId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgEnumFields, PgEnumRow] = { + DeleteBuilderMock(DeleteParams.empty, PgEnumFields, map) + } + override def insert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, PgEnumRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgEnumFields, PgEnumRow] = { + SelectBuilderMock(PgEnumFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgEnumRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgEnumId): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgEnumId]): ZStream[ZConnection, Throwable, PgEnumRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(enumtypid: /* oid */ Long, enumlabel: String): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + ZIO.succeed(map.values.find(v => enumtypid == v.enumtypid && enumlabel == v.enumlabel)) + } + override def selectByUnique(enumtypid: /* oid */ Long, enumsortorder: Float): ZIO[ZConnection, Throwable, Option[PgEnumRow]] = { + ZIO.succeed(map.values.find(v => enumtypid == v.enumtypid && enumsortorder == v.enumsortorder)) + } + override def update(row: PgEnumRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgEnumFields, PgEnumRow] = { + UpdateBuilderMock(UpdateParams.empty, PgEnumFields, map) + } + override def upsert(unsaved: PgEnumRow): ZIO[ZConnection, Throwable, UpdateResult[PgEnumRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRow.scala new file mode 100644 index 0000000000..25891441b3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgEnumRow( + oid: PgEnumId, + enumtypid: /* oid */ Long, + enumsortorder: Float, + enumlabel: String +) + +object PgEnumRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgEnumRow] = new JdbcDecoder[PgEnumRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgEnumRow) = + columIndex + 3 -> + PgEnumRow( + oid = PgEnumId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + enumtypid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + enumsortorder = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 2, rs)._2, + enumlabel = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgEnumRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgEnumId.jsonDecoder)) + val enumtypid = jsonObj.get("enumtypid").toRight("Missing field 'enumtypid'").flatMap(_.as(JsonDecoder.long)) + val enumsortorder = jsonObj.get("enumsortorder").toRight("Missing field 'enumsortorder'").flatMap(_.as(JsonDecoder.float)) + val enumlabel = jsonObj.get("enumlabel").toRight("Missing field 'enumlabel'").flatMap(_.as(JsonDecoder.string)) + if (oid.isRight && enumtypid.isRight && enumsortorder.isRight && enumlabel.isRight) + Right(PgEnumRow(oid = oid.toOption.get, enumtypid = enumtypid.toOption.get, enumsortorder = enumsortorder.toOption.get, enumlabel = enumlabel.toOption.get)) + else Left(List[Either[String, Any]](oid, enumtypid, enumsortorder, enumlabel).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgEnumRow] = new JsonEncoder[PgEnumRow] { + override def unsafeEncode(a: PgEnumRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgEnumId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""enumtypid":""") + JsonEncoder.long.unsafeEncode(a.enumtypid, indent, out) + out.write(",") + out.write(""""enumsortorder":""") + JsonEncoder.float.unsafeEncode(a.enumsortorder, indent, out) + out.write(",") + out.write(""""enumlabel":""") + JsonEncoder.string.unsafeEncode(a.enumlabel, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumStructure.scala new file mode 100644 index 0000000000..87f513a3bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_enum/PgEnumStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_enum + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgEnumStructure[Row](val prefix: Option[String], val extract: Row => PgEnumRow, val merge: (Row, PgEnumRow) => Row) + extends Relation[PgEnumFields, PgEnumRow, Row] + with PgEnumFields[Row] { outer => + + override val oid = new IdField[PgEnumId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val enumtypid = new Field[/* oid */ Long, Row](prefix, "enumtypid", None, Some("oid"))(x => extract(x).enumtypid, (row, value) => merge(row, extract(row).copy(enumtypid = value))) + override val enumsortorder = new Field[Float, Row](prefix, "enumsortorder", None, Some("float4"))(x => extract(x).enumsortorder, (row, value) => merge(row, extract(row).copy(enumsortorder = value))) + override val enumlabel = new Field[String, Row](prefix, "enumlabel", None, Some("name"))(x => extract(x).enumlabel, (row, value) => merge(row, extract(row).copy(enumlabel = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, enumtypid, enumsortorder, enumlabel) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgEnumRow, merge: (NewRow, PgEnumRow) => NewRow): PgEnumStructure[NewRow] = + new PgEnumStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerFields.scala new file mode 100644 index 0000000000..a1c8f8ae9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgEventTriggerFields[Row] { + val oid: IdField[PgEventTriggerId, Row] + val evtname: Field[String, Row] + val evtevent: Field[String, Row] + val evtowner: Field[/* oid */ Long, Row] + val evtfoid: Field[/* oid */ Long, Row] + val evtenabled: Field[String, Row] + val evttags: OptField[Array[String], Row] +} +object PgEventTriggerFields extends PgEventTriggerStructure[PgEventTriggerRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerId.scala new file mode 100644 index 0000000000..544ebdd9aa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +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 `pg_catalog.pg_event_trigger` */ +case class PgEventTriggerId(value: /* oid */ Long) extends AnyVal +object PgEventTriggerId { + implicit lazy val arraySetter: Setter[Array[PgEventTriggerId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgEventTriggerId, /* oid */ Long] = Bijection[PgEventTriggerId, /* oid */ Long](_.value)(PgEventTriggerId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgEventTriggerId] = JdbcDecoder.longDecoder.map(PgEventTriggerId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgEventTriggerId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgEventTriggerId] = JsonDecoder.long.map(PgEventTriggerId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgEventTriggerId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgEventTriggerId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgEventTriggerId] = ParameterMetaData.instance[PgEventTriggerId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgEventTriggerId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepo.scala new file mode 100644 index 0000000000..da20a460cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgEventTriggerRepo { + def delete(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgEventTriggerFields, PgEventTriggerRow] + def insert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, PgEventTriggerRow] + def select: SelectBuilder[PgEventTriggerFields, PgEventTriggerRow] + def selectAll: ZStream[ZConnection, Throwable, PgEventTriggerRow] + def selectById(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] + def selectByIds(oids: Array[PgEventTriggerId]): ZStream[ZConnection, Throwable, PgEventTriggerRow] + def selectByUnique(evtname: String): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] + def update(row: PgEventTriggerRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgEventTriggerFields, PgEventTriggerRow] + def upsert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgEventTriggerRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoImpl.scala new file mode 100644 index 0000000000..81d5a758a9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoImpl.scala @@ -0,0 +1,88 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgEventTriggerRepoImpl extends PgEventTriggerRepo { + override def delete(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_event_trigger where "oid" = ${Segment.paramSegment(oid)(PgEventTriggerId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + DeleteBuilder("pg_catalog.pg_event_trigger", PgEventTriggerFields) + } + override def insert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, PgEventTriggerRow] = { + sql"""insert into pg_catalog.pg_event_trigger("oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags") + values (${Segment.paramSegment(unsaved.oid)(PgEventTriggerId.setter)}::oid, ${Segment.paramSegment(unsaved.evtname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.evtevent)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.evtowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.evtfoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.evtenabled)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.evttags)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags" + """.insertReturning(PgEventTriggerRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + SelectBuilderSql("pg_catalog.pg_event_trigger", PgEventTriggerFields, PgEventTriggerRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgEventTriggerRow] = { + sql"""select "oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags" from pg_catalog.pg_event_trigger""".query(PgEventTriggerRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] = { + sql"""select "oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags" from pg_catalog.pg_event_trigger where "oid" = ${Segment.paramSegment(oid)(PgEventTriggerId.setter)}""".query(PgEventTriggerRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgEventTriggerId]): ZStream[ZConnection, Throwable, PgEventTriggerRow] = { + sql"""select "oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags" from pg_catalog.pg_event_trigger where "oid" = ANY(${Segment.paramSegment(oids)(PgEventTriggerId.arraySetter)})""".query(PgEventTriggerRow.jdbcDecoder).selectStream + } + override def selectByUnique(evtname: String): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] = { + sql"""select "evtname" + from pg_catalog.pg_event_trigger + where "evtname" = ${Segment.paramSegment(evtname)(Setter.stringSetter)} + """.query(PgEventTriggerRow.jdbcDecoder).selectOne + } + override def update(row: PgEventTriggerRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_event_trigger + set "evtname" = ${Segment.paramSegment(row.evtname)(Setter.stringSetter)}::name, + "evtevent" = ${Segment.paramSegment(row.evtevent)(Setter.stringSetter)}::name, + "evtowner" = ${Segment.paramSegment(row.evtowner)(Setter.longSetter)}::oid, + "evtfoid" = ${Segment.paramSegment(row.evtfoid)(Setter.longSetter)}::oid, + "evtenabled" = ${Segment.paramSegment(row.evtenabled)(Setter.stringSetter)}::char, + "evttags" = ${Segment.paramSegment(row.evttags)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgEventTriggerId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + UpdateBuilder("pg_catalog.pg_event_trigger", PgEventTriggerFields, PgEventTriggerRow.jdbcDecoder) + } + override def upsert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgEventTriggerRow]] = { + sql"""insert into pg_catalog.pg_event_trigger("oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags") + values ( + ${Segment.paramSegment(unsaved.oid)(PgEventTriggerId.setter)}::oid, + ${Segment.paramSegment(unsaved.evtname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.evtevent)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.evtowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.evtfoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.evtenabled)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.evttags)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "evtname" = EXCLUDED."evtname", + "evtevent" = EXCLUDED."evtevent", + "evtowner" = EXCLUDED."evtowner", + "evtfoid" = EXCLUDED."evtfoid", + "evtenabled" = EXCLUDED."evtenabled", + "evttags" = EXCLUDED."evttags" + returning "oid", "evtname", "evtevent", "evtowner", "evtfoid", "evtenabled", "evttags"""".insertReturning(PgEventTriggerRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoMock.scala new file mode 100644 index 0000000000..3021b9a9fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgEventTriggerRepoMock(map: scala.collection.mutable.Map[PgEventTriggerId, PgEventTriggerRow] = scala.collection.mutable.Map.empty) extends PgEventTriggerRepo { + override def delete(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + DeleteBuilderMock(DeleteParams.empty, PgEventTriggerFields, map) + } + override def insert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, PgEventTriggerRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + SelectBuilderMock(PgEventTriggerFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgEventTriggerRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgEventTriggerId): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgEventTriggerId]): ZStream[ZConnection, Throwable, PgEventTriggerRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(evtname: String): ZIO[ZConnection, Throwable, Option[PgEventTriggerRow]] = { + ZIO.succeed(map.values.find(v => evtname == v.evtname)) + } + override def update(row: PgEventTriggerRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgEventTriggerFields, PgEventTriggerRow] = { + UpdateBuilderMock(UpdateParams.empty, PgEventTriggerFields, map) + } + override def upsert(unsaved: PgEventTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgEventTriggerRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRow.scala new file mode 100644 index 0000000000..0c6e72c0e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgEventTriggerRow( + oid: PgEventTriggerId, + evtname: String, + evtevent: String, + evtowner: /* oid */ Long, + evtfoid: /* oid */ Long, + evtenabled: String, + evttags: Option[Array[String]] +) + +object PgEventTriggerRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgEventTriggerRow] = new JdbcDecoder[PgEventTriggerRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgEventTriggerRow) = + columIndex + 6 -> + PgEventTriggerRow( + oid = PgEventTriggerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + evtname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + evtevent = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + evtowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + evtfoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + evtenabled = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + evttags = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgEventTriggerRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgEventTriggerId.jsonDecoder)) + val evtname = jsonObj.get("evtname").toRight("Missing field 'evtname'").flatMap(_.as(JsonDecoder.string)) + val evtevent = jsonObj.get("evtevent").toRight("Missing field 'evtevent'").flatMap(_.as(JsonDecoder.string)) + val evtowner = jsonObj.get("evtowner").toRight("Missing field 'evtowner'").flatMap(_.as(JsonDecoder.long)) + val evtfoid = jsonObj.get("evtfoid").toRight("Missing field 'evtfoid'").flatMap(_.as(JsonDecoder.long)) + val evtenabled = jsonObj.get("evtenabled").toRight("Missing field 'evtenabled'").flatMap(_.as(JsonDecoder.string)) + val evttags = jsonObj.get("evttags").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && evtname.isRight && evtevent.isRight && evtowner.isRight && evtfoid.isRight && evtenabled.isRight && evttags.isRight) + Right(PgEventTriggerRow(oid = oid.toOption.get, evtname = evtname.toOption.get, evtevent = evtevent.toOption.get, evtowner = evtowner.toOption.get, evtfoid = evtfoid.toOption.get, evtenabled = evtenabled.toOption.get, evttags = evttags.toOption.get)) + else Left(List[Either[String, Any]](oid, evtname, evtevent, evtowner, evtfoid, evtenabled, evttags).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgEventTriggerRow] = new JsonEncoder[PgEventTriggerRow] { + override def unsafeEncode(a: PgEventTriggerRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgEventTriggerId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""evtname":""") + JsonEncoder.string.unsafeEncode(a.evtname, indent, out) + out.write(",") + out.write(""""evtevent":""") + JsonEncoder.string.unsafeEncode(a.evtevent, indent, out) + out.write(",") + out.write(""""evtowner":""") + JsonEncoder.long.unsafeEncode(a.evtowner, indent, out) + out.write(",") + out.write(""""evtfoid":""") + JsonEncoder.long.unsafeEncode(a.evtfoid, indent, out) + out.write(",") + out.write(""""evtenabled":""") + JsonEncoder.string.unsafeEncode(a.evtenabled, indent, out) + out.write(",") + out.write(""""evttags":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.evttags, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerStructure.scala new file mode 100644 index 0000000000..da06923e35 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_event_trigger/PgEventTriggerStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_event_trigger + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgEventTriggerStructure[Row](val prefix: Option[String], val extract: Row => PgEventTriggerRow, val merge: (Row, PgEventTriggerRow) => Row) + extends Relation[PgEventTriggerFields, PgEventTriggerRow, Row] + with PgEventTriggerFields[Row] { outer => + + override val oid = new IdField[PgEventTriggerId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val evtname = new Field[String, Row](prefix, "evtname", None, Some("name"))(x => extract(x).evtname, (row, value) => merge(row, extract(row).copy(evtname = value))) + override val evtevent = new Field[String, Row](prefix, "evtevent", None, Some("name"))(x => extract(x).evtevent, (row, value) => merge(row, extract(row).copy(evtevent = value))) + override val evtowner = new Field[/* oid */ Long, Row](prefix, "evtowner", None, Some("oid"))(x => extract(x).evtowner, (row, value) => merge(row, extract(row).copy(evtowner = value))) + override val evtfoid = new Field[/* oid */ Long, Row](prefix, "evtfoid", None, Some("oid"))(x => extract(x).evtfoid, (row, value) => merge(row, extract(row).copy(evtfoid = value))) + override val evtenabled = new Field[String, Row](prefix, "evtenabled", None, Some("char"))(x => extract(x).evtenabled, (row, value) => merge(row, extract(row).copy(evtenabled = value))) + override val evttags = new OptField[Array[String], Row](prefix, "evttags", None, Some("_text"))(x => extract(x).evttags, (row, value) => merge(row, extract(row).copy(evttags = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, evtname, evtevent, evtowner, evtfoid, evtenabled, evttags) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgEventTriggerRow, merge: (NewRow, PgEventTriggerRow) => NewRow): PgEventTriggerStructure[NewRow] = + new PgEventTriggerStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionFields.scala new file mode 100644 index 0000000000..89bdd21e92 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgExtensionFields[Row] { + val oid: IdField[PgExtensionId, Row] + val extname: Field[String, Row] + val extowner: Field[/* oid */ Long, Row] + val extnamespace: Field[/* oid */ Long, Row] + val extrelocatable: Field[Boolean, Row] + val extversion: Field[String, Row] + val extconfig: OptField[Array[/* oid */ Long], Row] + val extcondition: OptField[Array[String], Row] +} +object PgExtensionFields extends PgExtensionStructure[PgExtensionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionId.scala new file mode 100644 index 0000000000..09c0e4402d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +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 `pg_catalog.pg_extension` */ +case class PgExtensionId(value: /* oid */ Long) extends AnyVal +object PgExtensionId { + implicit lazy val arraySetter: Setter[Array[PgExtensionId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgExtensionId, /* oid */ Long] = Bijection[PgExtensionId, /* oid */ Long](_.value)(PgExtensionId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgExtensionId] = JdbcDecoder.longDecoder.map(PgExtensionId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgExtensionId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgExtensionId] = JsonDecoder.long.map(PgExtensionId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgExtensionId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgExtensionId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgExtensionId] = ParameterMetaData.instance[PgExtensionId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgExtensionId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepo.scala new file mode 100644 index 0000000000..cad2ebcfd3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgExtensionRepo { + def delete(oid: PgExtensionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgExtensionFields, PgExtensionRow] + def insert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, PgExtensionRow] + def select: SelectBuilder[PgExtensionFields, PgExtensionRow] + def selectAll: ZStream[ZConnection, Throwable, PgExtensionRow] + def selectById(oid: PgExtensionId): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] + def selectByIds(oids: Array[PgExtensionId]): ZStream[ZConnection, Throwable, PgExtensionRow] + def selectByUnique(extname: String): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] + def update(row: PgExtensionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgExtensionFields, PgExtensionRow] + def upsert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, UpdateResult[PgExtensionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoImpl.scala new file mode 100644 index 0000000000..84cd841a7d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoImpl.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgExtensionRepoImpl extends PgExtensionRepo { + override def delete(oid: PgExtensionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_extension where "oid" = ${Segment.paramSegment(oid)(PgExtensionId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgExtensionFields, PgExtensionRow] = { + DeleteBuilder("pg_catalog.pg_extension", PgExtensionFields) + } + override def insert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, PgExtensionRow] = { + sql"""insert into pg_catalog.pg_extension("oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition") + values (${Segment.paramSegment(unsaved.oid)(PgExtensionId.setter)}::oid, ${Segment.paramSegment(unsaved.extname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.extowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.extnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.extrelocatable)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.extversion)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.extconfig)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.extcondition)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition" + """.insertReturning(PgExtensionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgExtensionFields, PgExtensionRow] = { + SelectBuilderSql("pg_catalog.pg_extension", PgExtensionFields, PgExtensionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgExtensionRow] = { + sql"""select "oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition" from pg_catalog.pg_extension""".query(PgExtensionRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgExtensionId): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] = { + sql"""select "oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition" from pg_catalog.pg_extension where "oid" = ${Segment.paramSegment(oid)(PgExtensionId.setter)}""".query(PgExtensionRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgExtensionId]): ZStream[ZConnection, Throwable, PgExtensionRow] = { + sql"""select "oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition" from pg_catalog.pg_extension where "oid" = ANY(${Segment.paramSegment(oids)(PgExtensionId.arraySetter)})""".query(PgExtensionRow.jdbcDecoder).selectStream + } + override def selectByUnique(extname: String): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] = { + sql"""select "extname" + from pg_catalog.pg_extension + where "extname" = ${Segment.paramSegment(extname)(Setter.stringSetter)} + """.query(PgExtensionRow.jdbcDecoder).selectOne + } + override def update(row: PgExtensionRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_extension + set "extname" = ${Segment.paramSegment(row.extname)(Setter.stringSetter)}::name, + "extowner" = ${Segment.paramSegment(row.extowner)(Setter.longSetter)}::oid, + "extnamespace" = ${Segment.paramSegment(row.extnamespace)(Setter.longSetter)}::oid, + "extrelocatable" = ${Segment.paramSegment(row.extrelocatable)(Setter.booleanSetter)}, + "extversion" = ${Segment.paramSegment(row.extversion)(Setter.stringSetter)}, + "extconfig" = ${Segment.paramSegment(row.extconfig)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "extcondition" = ${Segment.paramSegment(row.extcondition)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgExtensionId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgExtensionFields, PgExtensionRow] = { + UpdateBuilder("pg_catalog.pg_extension", PgExtensionFields, PgExtensionRow.jdbcDecoder) + } + override def upsert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, UpdateResult[PgExtensionRow]] = { + sql"""insert into pg_catalog.pg_extension("oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition") + values ( + ${Segment.paramSegment(unsaved.oid)(PgExtensionId.setter)}::oid, + ${Segment.paramSegment(unsaved.extname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.extowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.extnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.extrelocatable)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.extversion)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.extconfig)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.extcondition)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "extname" = EXCLUDED."extname", + "extowner" = EXCLUDED."extowner", + "extnamespace" = EXCLUDED."extnamespace", + "extrelocatable" = EXCLUDED."extrelocatable", + "extversion" = EXCLUDED."extversion", + "extconfig" = EXCLUDED."extconfig", + "extcondition" = EXCLUDED."extcondition" + returning "oid", "extname", "extowner", "extnamespace", "extrelocatable", "extversion", "extconfig", "extcondition"""".insertReturning(PgExtensionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoMock.scala new file mode 100644 index 0000000000..4a178cc7ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgExtensionRepoMock(map: scala.collection.mutable.Map[PgExtensionId, PgExtensionRow] = scala.collection.mutable.Map.empty) extends PgExtensionRepo { + override def delete(oid: PgExtensionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgExtensionFields, PgExtensionRow] = { + DeleteBuilderMock(DeleteParams.empty, PgExtensionFields, map) + } + override def insert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, PgExtensionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgExtensionFields, PgExtensionRow] = { + SelectBuilderMock(PgExtensionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgExtensionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgExtensionId): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgExtensionId]): ZStream[ZConnection, Throwable, PgExtensionRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(extname: String): ZIO[ZConnection, Throwable, Option[PgExtensionRow]] = { + ZIO.succeed(map.values.find(v => extname == v.extname)) + } + override def update(row: PgExtensionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgExtensionFields, PgExtensionRow] = { + UpdateBuilderMock(UpdateParams.empty, PgExtensionFields, map) + } + override def upsert(unsaved: PgExtensionRow): ZIO[ZConnection, Throwable, UpdateResult[PgExtensionRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRow.scala new file mode 100644 index 0000000000..959ab539f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgExtensionRow( + oid: PgExtensionId, + extname: String, + extowner: /* oid */ Long, + extnamespace: /* oid */ Long, + extrelocatable: Boolean, + extversion: String, + extconfig: Option[Array[/* oid */ Long]], + extcondition: Option[Array[String]] +) + +object PgExtensionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgExtensionRow] = new JdbcDecoder[PgExtensionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgExtensionRow) = + columIndex + 7 -> + PgExtensionRow( + oid = PgExtensionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + extname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + extowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + extnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + extrelocatable = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + extversion = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + extconfig = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 6, rs)._2, + extcondition = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgExtensionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgExtensionId.jsonDecoder)) + val extname = jsonObj.get("extname").toRight("Missing field 'extname'").flatMap(_.as(JsonDecoder.string)) + val extowner = jsonObj.get("extowner").toRight("Missing field 'extowner'").flatMap(_.as(JsonDecoder.long)) + val extnamespace = jsonObj.get("extnamespace").toRight("Missing field 'extnamespace'").flatMap(_.as(JsonDecoder.long)) + val extrelocatable = jsonObj.get("extrelocatable").toRight("Missing field 'extrelocatable'").flatMap(_.as(JsonDecoder.boolean)) + val extversion = jsonObj.get("extversion").toRight("Missing field 'extversion'").flatMap(_.as(JsonDecoder.string)) + val extconfig = jsonObj.get("extconfig").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val extcondition = jsonObj.get("extcondition").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && extname.isRight && extowner.isRight && extnamespace.isRight && extrelocatable.isRight && extversion.isRight && extconfig.isRight && extcondition.isRight) + Right(PgExtensionRow(oid = oid.toOption.get, extname = extname.toOption.get, extowner = extowner.toOption.get, extnamespace = extnamespace.toOption.get, extrelocatable = extrelocatable.toOption.get, extversion = extversion.toOption.get, extconfig = extconfig.toOption.get, extcondition = extcondition.toOption.get)) + else Left(List[Either[String, Any]](oid, extname, extowner, extnamespace, extrelocatable, extversion, extconfig, extcondition).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgExtensionRow] = new JsonEncoder[PgExtensionRow] { + override def unsafeEncode(a: PgExtensionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgExtensionId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""extname":""") + JsonEncoder.string.unsafeEncode(a.extname, indent, out) + out.write(",") + out.write(""""extowner":""") + JsonEncoder.long.unsafeEncode(a.extowner, indent, out) + out.write(",") + out.write(""""extnamespace":""") + JsonEncoder.long.unsafeEncode(a.extnamespace, indent, out) + out.write(",") + out.write(""""extrelocatable":""") + JsonEncoder.boolean.unsafeEncode(a.extrelocatable, indent, out) + out.write(",") + out.write(""""extversion":""") + JsonEncoder.string.unsafeEncode(a.extversion, indent, out) + out.write(",") + out.write(""""extconfig":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.extconfig, indent, out) + out.write(",") + out.write(""""extcondition":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.extcondition, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionStructure.scala new file mode 100644 index 0000000000..27023a1563 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_extension/PgExtensionStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_extension + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgExtensionStructure[Row](val prefix: Option[String], val extract: Row => PgExtensionRow, val merge: (Row, PgExtensionRow) => Row) + extends Relation[PgExtensionFields, PgExtensionRow, Row] + with PgExtensionFields[Row] { outer => + + override val oid = new IdField[PgExtensionId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val extname = new Field[String, Row](prefix, "extname", None, Some("name"))(x => extract(x).extname, (row, value) => merge(row, extract(row).copy(extname = value))) + override val extowner = new Field[/* oid */ Long, Row](prefix, "extowner", None, Some("oid"))(x => extract(x).extowner, (row, value) => merge(row, extract(row).copy(extowner = value))) + override val extnamespace = new Field[/* oid */ Long, Row](prefix, "extnamespace", None, Some("oid"))(x => extract(x).extnamespace, (row, value) => merge(row, extract(row).copy(extnamespace = value))) + override val extrelocatable = new Field[Boolean, Row](prefix, "extrelocatable", None, None)(x => extract(x).extrelocatable, (row, value) => merge(row, extract(row).copy(extrelocatable = value))) + override val extversion = new Field[String, Row](prefix, "extversion", None, None)(x => extract(x).extversion, (row, value) => merge(row, extract(row).copy(extversion = value))) + override val extconfig = new OptField[Array[/* oid */ Long], Row](prefix, "extconfig", None, Some("_oid"))(x => extract(x).extconfig, (row, value) => merge(row, extract(row).copy(extconfig = value))) + override val extcondition = new OptField[Array[String], Row](prefix, "extcondition", None, Some("_text"))(x => extract(x).extcondition, (row, value) => merge(row, extract(row).copy(extcondition = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, extname, extowner, extnamespace, extrelocatable, extversion, extconfig, extcondition) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgExtensionRow, merge: (NewRow, PgExtensionRow) => NewRow): PgExtensionStructure[NewRow] = + new PgExtensionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewFields.scala new file mode 100644 index 0000000000..52722d267f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_file_settings + +import typo.dsl.SqlExpr.OptField + +trait PgFileSettingsViewFields[Row] { + val sourcefile: OptField[String, Row] + val sourceline: OptField[Int, Row] + val seqno: OptField[Int, Row] + val name: OptField[String, Row] + val setting: OptField[String, Row] + val applied: OptField[Boolean, Row] + val error: OptField[String, Row] +} +object PgFileSettingsViewFields extends PgFileSettingsViewStructure[PgFileSettingsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepo.scala new file mode 100644 index 0000000000..efe7ebab61 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_file_settings + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgFileSettingsViewRepo { + def select: SelectBuilder[PgFileSettingsViewFields, PgFileSettingsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgFileSettingsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepoImpl.scala new file mode 100644 index 0000000000..0613242a60 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_file_settings + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgFileSettingsViewRepoImpl extends PgFileSettingsViewRepo { + override def select: SelectBuilder[PgFileSettingsViewFields, PgFileSettingsViewRow] = { + SelectBuilderSql("pg_catalog.pg_file_settings", PgFileSettingsViewFields, PgFileSettingsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgFileSettingsViewRow] = { + sql"""select "sourcefile", "sourceline", "seqno", "name", "setting", "applied", "error" from pg_catalog.pg_file_settings""".query(PgFileSettingsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRow.scala new file mode 100644 index 0000000000..741e3eed11 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_file_settings + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgFileSettingsViewRow( + sourcefile: /* nullability unknown */ Option[String], + sourceline: /* nullability unknown */ Option[Int], + seqno: /* nullability unknown */ Option[Int], + name: /* nullability unknown */ Option[String], + setting: /* nullability unknown */ Option[String], + applied: /* nullability unknown */ Option[Boolean], + error: /* nullability unknown */ Option[String] +) + +object PgFileSettingsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgFileSettingsViewRow] = new JdbcDecoder[PgFileSettingsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgFileSettingsViewRow) = + columIndex + 6 -> + PgFileSettingsViewRow( + sourcefile = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + sourceline = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 1, rs)._2, + seqno = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 2, rs)._2, + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + setting = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + applied = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 5, rs)._2, + error = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgFileSettingsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val sourcefile = jsonObj.get("sourcefile").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sourceline = jsonObj.get("sourceline").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val seqno = jsonObj.get("seqno").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val setting = jsonObj.get("setting").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val applied = jsonObj.get("applied").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val error = jsonObj.get("error").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (sourcefile.isRight && sourceline.isRight && seqno.isRight && name.isRight && setting.isRight && applied.isRight && error.isRight) + Right(PgFileSettingsViewRow(sourcefile = sourcefile.toOption.get, sourceline = sourceline.toOption.get, seqno = seqno.toOption.get, name = name.toOption.get, setting = setting.toOption.get, applied = applied.toOption.get, error = error.toOption.get)) + else Left(List[Either[String, Any]](sourcefile, sourceline, seqno, name, setting, applied, error).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgFileSettingsViewRow] = new JsonEncoder[PgFileSettingsViewRow] { + override def unsafeEncode(a: PgFileSettingsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""sourcefile":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sourcefile, indent, out) + out.write(",") + out.write(""""sourceline":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.sourceline, indent, out) + out.write(",") + out.write(""""seqno":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.seqno, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""setting":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.setting, indent, out) + out.write(",") + out.write(""""applied":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.applied, indent, out) + out.write(",") + out.write(""""error":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.error, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewStructure.scala new file mode 100644 index 0000000000..3a14995694 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_file_settings/PgFileSettingsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_file_settings + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgFileSettingsViewStructure[Row](val prefix: Option[String], val extract: Row => PgFileSettingsViewRow, val merge: (Row, PgFileSettingsViewRow) => Row) + extends Relation[PgFileSettingsViewFields, PgFileSettingsViewRow, Row] + with PgFileSettingsViewFields[Row] { outer => + + override val sourcefile = new OptField[String, Row](prefix, "sourcefile", None, None)(x => extract(x).sourcefile, (row, value) => merge(row, extract(row).copy(sourcefile = value))) + override val sourceline = new OptField[Int, Row](prefix, "sourceline", None, None)(x => extract(x).sourceline, (row, value) => merge(row, extract(row).copy(sourceline = value))) + override val seqno = new OptField[Int, Row](prefix, "seqno", None, None)(x => extract(x).seqno, (row, value) => merge(row, extract(row).copy(seqno = value))) + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val setting = new OptField[String, Row](prefix, "setting", None, None)(x => extract(x).setting, (row, value) => merge(row, extract(row).copy(setting = value))) + override val applied = new OptField[Boolean, Row](prefix, "applied", None, None)(x => extract(x).applied, (row, value) => merge(row, extract(row).copy(applied = value))) + override val error = new OptField[String, Row](prefix, "error", None, None)(x => extract(x).error, (row, value) => merge(row, extract(row).copy(error = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](sourcefile, sourceline, seqno, name, setting, applied, error) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgFileSettingsViewRow, merge: (NewRow, PgFileSettingsViewRow) => NewRow): PgFileSettingsViewStructure[NewRow] = + new PgFileSettingsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperFields.scala new file mode 100644 index 0000000000..19212e67a6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgForeignDataWrapperFields[Row] { + val oid: IdField[PgForeignDataWrapperId, Row] + val fdwname: Field[String, Row] + val fdwowner: Field[/* oid */ Long, Row] + val fdwhandler: Field[/* oid */ Long, Row] + val fdwvalidator: Field[/* oid */ Long, Row] + val fdwacl: OptField[Array[TypoAclItem], Row] + val fdwoptions: OptField[Array[String], Row] +} +object PgForeignDataWrapperFields extends PgForeignDataWrapperStructure[PgForeignDataWrapperRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperId.scala new file mode 100644 index 0000000000..e83f8e1392 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +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 `pg_catalog.pg_foreign_data_wrapper` */ +case class PgForeignDataWrapperId(value: /* oid */ Long) extends AnyVal +object PgForeignDataWrapperId { + implicit lazy val arraySetter: Setter[Array[PgForeignDataWrapperId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgForeignDataWrapperId, /* oid */ Long] = Bijection[PgForeignDataWrapperId, /* oid */ Long](_.value)(PgForeignDataWrapperId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignDataWrapperId] = JdbcDecoder.longDecoder.map(PgForeignDataWrapperId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgForeignDataWrapperId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgForeignDataWrapperId] = JsonDecoder.long.map(PgForeignDataWrapperId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgForeignDataWrapperId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgForeignDataWrapperId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgForeignDataWrapperId] = ParameterMetaData.instance[PgForeignDataWrapperId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgForeignDataWrapperId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepo.scala new file mode 100644 index 0000000000..3a5c203d93 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignDataWrapperRepo { + def delete(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] + def insert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, PgForeignDataWrapperRow] + def select: SelectBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] + def selectById(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] + def selectByIds(oids: Array[PgForeignDataWrapperId]): ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] + def selectByUnique(fdwname: String): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] + def update(row: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] + def upsert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignDataWrapperRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoImpl.scala new file mode 100644 index 0000000000..e4fcca0771 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoImpl.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignDataWrapperRepoImpl extends PgForeignDataWrapperRepo { + override def delete(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_foreign_data_wrapper where "oid" = ${Segment.paramSegment(oid)(PgForeignDataWrapperId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + DeleteBuilder("pg_catalog.pg_foreign_data_wrapper", PgForeignDataWrapperFields) + } + override def insert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, PgForeignDataWrapperRow] = { + sql"""insert into pg_catalog.pg_foreign_data_wrapper("oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions") + values (${Segment.paramSegment(unsaved.oid)(PgForeignDataWrapperId.setter)}::oid, ${Segment.paramSegment(unsaved.fdwname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.fdwowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.fdwhandler)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.fdwvalidator)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.fdwacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, ${Segment.paramSegment(unsaved.fdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions" + """.insertReturning(PgForeignDataWrapperRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + SelectBuilderSql("pg_catalog.pg_foreign_data_wrapper", PgForeignDataWrapperFields, PgForeignDataWrapperRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] = { + sql"""select "oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions" from pg_catalog.pg_foreign_data_wrapper""".query(PgForeignDataWrapperRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] = { + sql"""select "oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions" from pg_catalog.pg_foreign_data_wrapper where "oid" = ${Segment.paramSegment(oid)(PgForeignDataWrapperId.setter)}""".query(PgForeignDataWrapperRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgForeignDataWrapperId]): ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] = { + sql"""select "oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions" from pg_catalog.pg_foreign_data_wrapper where "oid" = ANY(${Segment.paramSegment(oids)(PgForeignDataWrapperId.arraySetter)})""".query(PgForeignDataWrapperRow.jdbcDecoder).selectStream + } + override def selectByUnique(fdwname: String): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] = { + sql"""select "fdwname" + from pg_catalog.pg_foreign_data_wrapper + where "fdwname" = ${Segment.paramSegment(fdwname)(Setter.stringSetter)} + """.query(PgForeignDataWrapperRow.jdbcDecoder).selectOne + } + override def update(row: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_foreign_data_wrapper + set "fdwname" = ${Segment.paramSegment(row.fdwname)(Setter.stringSetter)}::name, + "fdwowner" = ${Segment.paramSegment(row.fdwowner)(Setter.longSetter)}::oid, + "fdwhandler" = ${Segment.paramSegment(row.fdwhandler)(Setter.longSetter)}::oid, + "fdwvalidator" = ${Segment.paramSegment(row.fdwvalidator)(Setter.longSetter)}::oid, + "fdwacl" = ${Segment.paramSegment(row.fdwacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + "fdwoptions" = ${Segment.paramSegment(row.fdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgForeignDataWrapperId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + UpdateBuilder("pg_catalog.pg_foreign_data_wrapper", PgForeignDataWrapperFields, PgForeignDataWrapperRow.jdbcDecoder) + } + override def upsert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignDataWrapperRow]] = { + sql"""insert into pg_catalog.pg_foreign_data_wrapper("oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions") + values ( + ${Segment.paramSegment(unsaved.oid)(PgForeignDataWrapperId.setter)}::oid, + ${Segment.paramSegment(unsaved.fdwname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.fdwowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.fdwhandler)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.fdwvalidator)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.fdwacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + ${Segment.paramSegment(unsaved.fdwoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "fdwname" = EXCLUDED."fdwname", + "fdwowner" = EXCLUDED."fdwowner", + "fdwhandler" = EXCLUDED."fdwhandler", + "fdwvalidator" = EXCLUDED."fdwvalidator", + "fdwacl" = EXCLUDED."fdwacl", + "fdwoptions" = EXCLUDED."fdwoptions" + returning "oid", "fdwname", "fdwowner", "fdwhandler", "fdwvalidator", "fdwacl", "fdwoptions"""".insertReturning(PgForeignDataWrapperRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoMock.scala new file mode 100644 index 0000000000..f33221bd6d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgForeignDataWrapperRepoMock(map: scala.collection.mutable.Map[PgForeignDataWrapperId, PgForeignDataWrapperRow] = scala.collection.mutable.Map.empty) extends PgForeignDataWrapperRepo { + override def delete(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + DeleteBuilderMock(DeleteParams.empty, PgForeignDataWrapperFields, map) + } + override def insert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, PgForeignDataWrapperRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + SelectBuilderMock(PgForeignDataWrapperFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgForeignDataWrapperId): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgForeignDataWrapperId]): ZStream[ZConnection, Throwable, PgForeignDataWrapperRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(fdwname: String): ZIO[ZConnection, Throwable, Option[PgForeignDataWrapperRow]] = { + ZIO.succeed(map.values.find(v => fdwname == v.fdwname)) + } + override def update(row: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgForeignDataWrapperFields, PgForeignDataWrapperRow] = { + UpdateBuilderMock(UpdateParams.empty, PgForeignDataWrapperFields, map) + } + override def upsert(unsaved: PgForeignDataWrapperRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignDataWrapperRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRow.scala new file mode 100644 index 0000000000..61e0b81f49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignDataWrapperRow( + oid: PgForeignDataWrapperId, + fdwname: String, + fdwowner: /* oid */ Long, + fdwhandler: /* oid */ Long, + fdwvalidator: /* oid */ Long, + fdwacl: Option[Array[TypoAclItem]], + fdwoptions: Option[Array[String]] +) + +object PgForeignDataWrapperRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignDataWrapperRow] = new JdbcDecoder[PgForeignDataWrapperRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignDataWrapperRow) = + columIndex + 6 -> + PgForeignDataWrapperRow( + oid = PgForeignDataWrapperId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + fdwname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + fdwowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + fdwhandler = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + fdwvalidator = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + fdwacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 5, rs)._2, + fdwoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignDataWrapperRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgForeignDataWrapperId.jsonDecoder)) + val fdwname = jsonObj.get("fdwname").toRight("Missing field 'fdwname'").flatMap(_.as(JsonDecoder.string)) + val fdwowner = jsonObj.get("fdwowner").toRight("Missing field 'fdwowner'").flatMap(_.as(JsonDecoder.long)) + val fdwhandler = jsonObj.get("fdwhandler").toRight("Missing field 'fdwhandler'").flatMap(_.as(JsonDecoder.long)) + val fdwvalidator = jsonObj.get("fdwvalidator").toRight("Missing field 'fdwvalidator'").flatMap(_.as(JsonDecoder.long)) + val fdwacl = jsonObj.get("fdwacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + val fdwoptions = jsonObj.get("fdwoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && fdwname.isRight && fdwowner.isRight && fdwhandler.isRight && fdwvalidator.isRight && fdwacl.isRight && fdwoptions.isRight) + Right(PgForeignDataWrapperRow(oid = oid.toOption.get, fdwname = fdwname.toOption.get, fdwowner = fdwowner.toOption.get, fdwhandler = fdwhandler.toOption.get, fdwvalidator = fdwvalidator.toOption.get, fdwacl = fdwacl.toOption.get, fdwoptions = fdwoptions.toOption.get)) + else Left(List[Either[String, Any]](oid, fdwname, fdwowner, fdwhandler, fdwvalidator, fdwacl, fdwoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignDataWrapperRow] = new JsonEncoder[PgForeignDataWrapperRow] { + override def unsafeEncode(a: PgForeignDataWrapperRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgForeignDataWrapperId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""fdwname":""") + JsonEncoder.string.unsafeEncode(a.fdwname, indent, out) + out.write(",") + out.write(""""fdwowner":""") + JsonEncoder.long.unsafeEncode(a.fdwowner, indent, out) + out.write(",") + out.write(""""fdwhandler":""") + JsonEncoder.long.unsafeEncode(a.fdwhandler, indent, out) + out.write(",") + out.write(""""fdwvalidator":""") + JsonEncoder.long.unsafeEncode(a.fdwvalidator, indent, out) + out.write(",") + out.write(""""fdwacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.fdwacl, indent, out) + out.write(",") + out.write(""""fdwoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.fdwoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperStructure.scala new file mode 100644 index 0000000000..b7aabdfb34 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_data_wrapper/PgForeignDataWrapperStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_data_wrapper + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignDataWrapperStructure[Row](val prefix: Option[String], val extract: Row => PgForeignDataWrapperRow, val merge: (Row, PgForeignDataWrapperRow) => Row) + extends Relation[PgForeignDataWrapperFields, PgForeignDataWrapperRow, Row] + with PgForeignDataWrapperFields[Row] { outer => + + override val oid = new IdField[PgForeignDataWrapperId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val fdwname = new Field[String, Row](prefix, "fdwname", None, Some("name"))(x => extract(x).fdwname, (row, value) => merge(row, extract(row).copy(fdwname = value))) + override val fdwowner = new Field[/* oid */ Long, Row](prefix, "fdwowner", None, Some("oid"))(x => extract(x).fdwowner, (row, value) => merge(row, extract(row).copy(fdwowner = value))) + override val fdwhandler = new Field[/* oid */ Long, Row](prefix, "fdwhandler", None, Some("oid"))(x => extract(x).fdwhandler, (row, value) => merge(row, extract(row).copy(fdwhandler = value))) + override val fdwvalidator = new Field[/* oid */ Long, Row](prefix, "fdwvalidator", None, Some("oid"))(x => extract(x).fdwvalidator, (row, value) => merge(row, extract(row).copy(fdwvalidator = value))) + override val fdwacl = new OptField[Array[TypoAclItem], Row](prefix, "fdwacl", None, Some("_aclitem"))(x => extract(x).fdwacl, (row, value) => merge(row, extract(row).copy(fdwacl = value))) + override val fdwoptions = new OptField[Array[String], Row](prefix, "fdwoptions", None, Some("_text"))(x => extract(x).fdwoptions, (row, value) => merge(row, extract(row).copy(fdwoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, fdwname, fdwowner, fdwhandler, fdwvalidator, fdwacl, fdwoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignDataWrapperRow, merge: (NewRow, PgForeignDataWrapperRow) => NewRow): PgForeignDataWrapperStructure[NewRow] = + new PgForeignDataWrapperStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerFields.scala new file mode 100644 index 0000000000..66ffd217b5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgForeignServerFields[Row] { + val oid: IdField[PgForeignServerId, Row] + val srvname: Field[String, Row] + val srvowner: Field[/* oid */ Long, Row] + val srvfdw: Field[/* oid */ Long, Row] + val srvtype: OptField[String, Row] + val srvversion: OptField[String, Row] + val srvacl: OptField[Array[TypoAclItem], Row] + val srvoptions: OptField[Array[String], Row] +} +object PgForeignServerFields extends PgForeignServerStructure[PgForeignServerRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerId.scala new file mode 100644 index 0000000000..0f692990e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +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 `pg_catalog.pg_foreign_server` */ +case class PgForeignServerId(value: /* oid */ Long) extends AnyVal +object PgForeignServerId { + implicit lazy val arraySetter: Setter[Array[PgForeignServerId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgForeignServerId, /* oid */ Long] = Bijection[PgForeignServerId, /* oid */ Long](_.value)(PgForeignServerId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignServerId] = JdbcDecoder.longDecoder.map(PgForeignServerId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgForeignServerId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgForeignServerId] = JsonDecoder.long.map(PgForeignServerId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgForeignServerId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgForeignServerId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgForeignServerId] = ParameterMetaData.instance[PgForeignServerId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgForeignServerId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepo.scala new file mode 100644 index 0000000000..80a7c1661f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignServerRepo { + def delete(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgForeignServerFields, PgForeignServerRow] + def insert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, PgForeignServerRow] + def select: SelectBuilder[PgForeignServerFields, PgForeignServerRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignServerRow] + def selectById(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] + def selectByIds(oids: Array[PgForeignServerId]): ZStream[ZConnection, Throwable, PgForeignServerRow] + def selectByUnique(srvname: String): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] + def update(row: PgForeignServerRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgForeignServerFields, PgForeignServerRow] + def upsert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignServerRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoImpl.scala new file mode 100644 index 0000000000..89e8801840 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoImpl.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignServerRepoImpl extends PgForeignServerRepo { + override def delete(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_foreign_server where "oid" = ${Segment.paramSegment(oid)(PgForeignServerId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgForeignServerFields, PgForeignServerRow] = { + DeleteBuilder("pg_catalog.pg_foreign_server", PgForeignServerFields) + } + override def insert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, PgForeignServerRow] = { + sql"""insert into pg_catalog.pg_foreign_server("oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions") + values (${Segment.paramSegment(unsaved.oid)(PgForeignServerId.setter)}::oid, ${Segment.paramSegment(unsaved.srvname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.srvowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.srvfdw)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.srvtype)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.srvversion)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.srvacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, ${Segment.paramSegment(unsaved.srvoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions" + """.insertReturning(PgForeignServerRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgForeignServerFields, PgForeignServerRow] = { + SelectBuilderSql("pg_catalog.pg_foreign_server", PgForeignServerFields, PgForeignServerRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignServerRow] = { + sql"""select "oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions" from pg_catalog.pg_foreign_server""".query(PgForeignServerRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] = { + sql"""select "oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions" from pg_catalog.pg_foreign_server where "oid" = ${Segment.paramSegment(oid)(PgForeignServerId.setter)}""".query(PgForeignServerRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgForeignServerId]): ZStream[ZConnection, Throwable, PgForeignServerRow] = { + sql"""select "oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions" from pg_catalog.pg_foreign_server where "oid" = ANY(${Segment.paramSegment(oids)(PgForeignServerId.arraySetter)})""".query(PgForeignServerRow.jdbcDecoder).selectStream + } + override def selectByUnique(srvname: String): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] = { + sql"""select "srvname" + from pg_catalog.pg_foreign_server + where "srvname" = ${Segment.paramSegment(srvname)(Setter.stringSetter)} + """.query(PgForeignServerRow.jdbcDecoder).selectOne + } + override def update(row: PgForeignServerRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_foreign_server + set "srvname" = ${Segment.paramSegment(row.srvname)(Setter.stringSetter)}::name, + "srvowner" = ${Segment.paramSegment(row.srvowner)(Setter.longSetter)}::oid, + "srvfdw" = ${Segment.paramSegment(row.srvfdw)(Setter.longSetter)}::oid, + "srvtype" = ${Segment.paramSegment(row.srvtype)(Setter.optionParamSetter(Setter.stringSetter))}, + "srvversion" = ${Segment.paramSegment(row.srvversion)(Setter.optionParamSetter(Setter.stringSetter))}, + "srvacl" = ${Segment.paramSegment(row.srvacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + "srvoptions" = ${Segment.paramSegment(row.srvoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgForeignServerId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgForeignServerFields, PgForeignServerRow] = { + UpdateBuilder("pg_catalog.pg_foreign_server", PgForeignServerFields, PgForeignServerRow.jdbcDecoder) + } + override def upsert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignServerRow]] = { + sql"""insert into pg_catalog.pg_foreign_server("oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions") + values ( + ${Segment.paramSegment(unsaved.oid)(PgForeignServerId.setter)}::oid, + ${Segment.paramSegment(unsaved.srvname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.srvowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.srvfdw)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.srvtype)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.srvversion)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.srvacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + ${Segment.paramSegment(unsaved.srvoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "srvname" = EXCLUDED."srvname", + "srvowner" = EXCLUDED."srvowner", + "srvfdw" = EXCLUDED."srvfdw", + "srvtype" = EXCLUDED."srvtype", + "srvversion" = EXCLUDED."srvversion", + "srvacl" = EXCLUDED."srvacl", + "srvoptions" = EXCLUDED."srvoptions" + returning "oid", "srvname", "srvowner", "srvfdw", "srvtype", "srvversion", "srvacl", "srvoptions"""".insertReturning(PgForeignServerRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoMock.scala new file mode 100644 index 0000000000..6d68a3b7ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgForeignServerRepoMock(map: scala.collection.mutable.Map[PgForeignServerId, PgForeignServerRow] = scala.collection.mutable.Map.empty) extends PgForeignServerRepo { + override def delete(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgForeignServerFields, PgForeignServerRow] = { + DeleteBuilderMock(DeleteParams.empty, PgForeignServerFields, map) + } + override def insert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, PgForeignServerRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgForeignServerFields, PgForeignServerRow] = { + SelectBuilderMock(PgForeignServerFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignServerRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgForeignServerId): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgForeignServerId]): ZStream[ZConnection, Throwable, PgForeignServerRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(srvname: String): ZIO[ZConnection, Throwable, Option[PgForeignServerRow]] = { + ZIO.succeed(map.values.find(v => srvname == v.srvname)) + } + override def update(row: PgForeignServerRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgForeignServerFields, PgForeignServerRow] = { + UpdateBuilderMock(UpdateParams.empty, PgForeignServerFields, map) + } + override def upsert(unsaved: PgForeignServerRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignServerRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRow.scala new file mode 100644 index 0000000000..02678d4a22 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignServerRow( + oid: PgForeignServerId, + srvname: String, + srvowner: /* oid */ Long, + srvfdw: /* oid */ Long, + srvtype: Option[String], + srvversion: Option[String], + srvacl: Option[Array[TypoAclItem]], + srvoptions: Option[Array[String]] +) + +object PgForeignServerRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignServerRow] = new JdbcDecoder[PgForeignServerRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignServerRow) = + columIndex + 7 -> + PgForeignServerRow( + oid = PgForeignServerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + srvname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + srvowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + srvfdw = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + srvtype = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + srvversion = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + srvacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 6, rs)._2, + srvoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignServerRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgForeignServerId.jsonDecoder)) + val srvname = jsonObj.get("srvname").toRight("Missing field 'srvname'").flatMap(_.as(JsonDecoder.string)) + val srvowner = jsonObj.get("srvowner").toRight("Missing field 'srvowner'").flatMap(_.as(JsonDecoder.long)) + val srvfdw = jsonObj.get("srvfdw").toRight("Missing field 'srvfdw'").flatMap(_.as(JsonDecoder.long)) + val srvtype = jsonObj.get("srvtype").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val srvversion = jsonObj.get("srvversion").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val srvacl = jsonObj.get("srvacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + val srvoptions = jsonObj.get("srvoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && srvname.isRight && srvowner.isRight && srvfdw.isRight && srvtype.isRight && srvversion.isRight && srvacl.isRight && srvoptions.isRight) + Right(PgForeignServerRow(oid = oid.toOption.get, srvname = srvname.toOption.get, srvowner = srvowner.toOption.get, srvfdw = srvfdw.toOption.get, srvtype = srvtype.toOption.get, srvversion = srvversion.toOption.get, srvacl = srvacl.toOption.get, srvoptions = srvoptions.toOption.get)) + else Left(List[Either[String, Any]](oid, srvname, srvowner, srvfdw, srvtype, srvversion, srvacl, srvoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignServerRow] = new JsonEncoder[PgForeignServerRow] { + override def unsafeEncode(a: PgForeignServerRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgForeignServerId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""srvname":""") + JsonEncoder.string.unsafeEncode(a.srvname, indent, out) + out.write(",") + out.write(""""srvowner":""") + JsonEncoder.long.unsafeEncode(a.srvowner, indent, out) + out.write(",") + out.write(""""srvfdw":""") + JsonEncoder.long.unsafeEncode(a.srvfdw, indent, out) + out.write(",") + out.write(""""srvtype":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.srvtype, indent, out) + out.write(",") + out.write(""""srvversion":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.srvversion, indent, out) + out.write(",") + out.write(""""srvacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.srvacl, indent, out) + out.write(",") + out.write(""""srvoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.srvoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerStructure.scala new file mode 100644 index 0000000000..921f4489f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_server/PgForeignServerStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_server + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignServerStructure[Row](val prefix: Option[String], val extract: Row => PgForeignServerRow, val merge: (Row, PgForeignServerRow) => Row) + extends Relation[PgForeignServerFields, PgForeignServerRow, Row] + with PgForeignServerFields[Row] { outer => + + override val oid = new IdField[PgForeignServerId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val srvname = new Field[String, Row](prefix, "srvname", None, Some("name"))(x => extract(x).srvname, (row, value) => merge(row, extract(row).copy(srvname = value))) + override val srvowner = new Field[/* oid */ Long, Row](prefix, "srvowner", None, Some("oid"))(x => extract(x).srvowner, (row, value) => merge(row, extract(row).copy(srvowner = value))) + override val srvfdw = new Field[/* oid */ Long, Row](prefix, "srvfdw", None, Some("oid"))(x => extract(x).srvfdw, (row, value) => merge(row, extract(row).copy(srvfdw = value))) + override val srvtype = new OptField[String, Row](prefix, "srvtype", None, None)(x => extract(x).srvtype, (row, value) => merge(row, extract(row).copy(srvtype = value))) + override val srvversion = new OptField[String, Row](prefix, "srvversion", None, None)(x => extract(x).srvversion, (row, value) => merge(row, extract(row).copy(srvversion = value))) + override val srvacl = new OptField[Array[TypoAclItem], Row](prefix, "srvacl", None, Some("_aclitem"))(x => extract(x).srvacl, (row, value) => merge(row, extract(row).copy(srvacl = value))) + override val srvoptions = new OptField[Array[String], Row](prefix, "srvoptions", None, Some("_text"))(x => extract(x).srvoptions, (row, value) => merge(row, extract(row).copy(srvoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, srvname, srvowner, srvfdw, srvtype, srvversion, srvacl, srvoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignServerRow, merge: (NewRow, PgForeignServerRow) => NewRow): PgForeignServerStructure[NewRow] = + new PgForeignServerStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableFields.scala new file mode 100644 index 0000000000..d23055cc3e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgForeignTableFields[Row] { + val ftrelid: IdField[PgForeignTableId, Row] + val ftserver: Field[/* oid */ Long, Row] + val ftoptions: OptField[Array[String], Row] +} +object PgForeignTableFields extends PgForeignTableStructure[PgForeignTableRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableId.scala new file mode 100644 index 0000000000..a13b70cd33 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +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 `pg_catalog.pg_foreign_table` */ +case class PgForeignTableId(value: /* oid */ Long) extends AnyVal +object PgForeignTableId { + implicit lazy val arraySetter: Setter[Array[PgForeignTableId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgForeignTableId, /* oid */ Long] = Bijection[PgForeignTableId, /* oid */ Long](_.value)(PgForeignTableId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignTableId] = JdbcDecoder.longDecoder.map(PgForeignTableId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgForeignTableId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgForeignTableId] = JsonDecoder.long.map(PgForeignTableId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgForeignTableId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgForeignTableId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgForeignTableId] = ParameterMetaData.instance[PgForeignTableId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgForeignTableId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepo.scala new file mode 100644 index 0000000000..3ff6fa57c5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgForeignTableRepo { + def delete(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgForeignTableFields, PgForeignTableRow] + def insert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, PgForeignTableRow] + def select: SelectBuilder[PgForeignTableFields, PgForeignTableRow] + def selectAll: ZStream[ZConnection, Throwable, PgForeignTableRow] + def selectById(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Option[PgForeignTableRow]] + def selectByIds(ftrelids: Array[PgForeignTableId]): ZStream[ZConnection, Throwable, PgForeignTableRow] + def update(row: PgForeignTableRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgForeignTableFields, PgForeignTableRow] + def upsert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignTableRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoImpl.scala new file mode 100644 index 0000000000..4ffeac992e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoImpl.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgForeignTableRepoImpl extends PgForeignTableRepo { + override def delete(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_foreign_table where "ftrelid" = ${Segment.paramSegment(ftrelid)(PgForeignTableId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgForeignTableFields, PgForeignTableRow] = { + DeleteBuilder("pg_catalog.pg_foreign_table", PgForeignTableFields) + } + override def insert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, PgForeignTableRow] = { + sql"""insert into pg_catalog.pg_foreign_table("ftrelid", "ftserver", "ftoptions") + values (${Segment.paramSegment(unsaved.ftrelid)(PgForeignTableId.setter)}::oid, ${Segment.paramSegment(unsaved.ftserver)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.ftoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "ftrelid", "ftserver", "ftoptions" + """.insertReturning(PgForeignTableRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgForeignTableFields, PgForeignTableRow] = { + SelectBuilderSql("pg_catalog.pg_foreign_table", PgForeignTableFields, PgForeignTableRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignTableRow] = { + sql"""select "ftrelid", "ftserver", "ftoptions" from pg_catalog.pg_foreign_table""".query(PgForeignTableRow.jdbcDecoder).selectStream + } + override def selectById(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Option[PgForeignTableRow]] = { + sql"""select "ftrelid", "ftserver", "ftoptions" from pg_catalog.pg_foreign_table where "ftrelid" = ${Segment.paramSegment(ftrelid)(PgForeignTableId.setter)}""".query(PgForeignTableRow.jdbcDecoder).selectOne + } + override def selectByIds(ftrelids: Array[PgForeignTableId]): ZStream[ZConnection, Throwable, PgForeignTableRow] = { + sql"""select "ftrelid", "ftserver", "ftoptions" from pg_catalog.pg_foreign_table where "ftrelid" = ANY(${Segment.paramSegment(ftrelids)(PgForeignTableId.arraySetter)})""".query(PgForeignTableRow.jdbcDecoder).selectStream + } + override def update(row: PgForeignTableRow): ZIO[ZConnection, Throwable, Boolean] = { + val ftrelid = row.ftrelid + sql"""update pg_catalog.pg_foreign_table + set "ftserver" = ${Segment.paramSegment(row.ftserver)(Setter.longSetter)}::oid, + "ftoptions" = ${Segment.paramSegment(row.ftoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "ftrelid" = ${Segment.paramSegment(ftrelid)(PgForeignTableId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgForeignTableFields, PgForeignTableRow] = { + UpdateBuilder("pg_catalog.pg_foreign_table", PgForeignTableFields, PgForeignTableRow.jdbcDecoder) + } + override def upsert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignTableRow]] = { + sql"""insert into pg_catalog.pg_foreign_table("ftrelid", "ftserver", "ftoptions") + values ( + ${Segment.paramSegment(unsaved.ftrelid)(PgForeignTableId.setter)}::oid, + ${Segment.paramSegment(unsaved.ftserver)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.ftoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("ftrelid") + do update set + "ftserver" = EXCLUDED."ftserver", + "ftoptions" = EXCLUDED."ftoptions" + returning "ftrelid", "ftserver", "ftoptions"""".insertReturning(PgForeignTableRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoMock.scala new file mode 100644 index 0000000000..bddc174635 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgForeignTableRepoMock(map: scala.collection.mutable.Map[PgForeignTableId, PgForeignTableRow] = scala.collection.mutable.Map.empty) extends PgForeignTableRepo { + override def delete(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(ftrelid).isDefined) + } + override def delete: DeleteBuilder[PgForeignTableFields, PgForeignTableRow] = { + DeleteBuilderMock(DeleteParams.empty, PgForeignTableFields, map) + } + override def insert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, PgForeignTableRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.ftrelid)) + sys.error(s"id ${unsaved.ftrelid} already exists") + else + map.put(unsaved.ftrelid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgForeignTableFields, PgForeignTableRow] = { + SelectBuilderMock(PgForeignTableFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgForeignTableRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(ftrelid: PgForeignTableId): ZIO[ZConnection, Throwable, Option[PgForeignTableRow]] = { + ZIO.succeed(map.get(ftrelid)) + } + override def selectByIds(ftrelids: Array[PgForeignTableId]): ZStream[ZConnection, Throwable, PgForeignTableRow] = { + ZStream.fromIterable(ftrelids.flatMap(map.get)) + } + override def update(row: PgForeignTableRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.ftrelid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.ftrelid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgForeignTableFields, PgForeignTableRow] = { + UpdateBuilderMock(UpdateParams.empty, PgForeignTableFields, map) + } + override def upsert(unsaved: PgForeignTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgForeignTableRow]] = { + ZIO.succeed { + map.put(unsaved.ftrelid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRow.scala new file mode 100644 index 0000000000..f5289d9290 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableRow.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgForeignTableRow( + ftrelid: PgForeignTableId, + ftserver: /* oid */ Long, + ftoptions: Option[Array[String]] +) + +object PgForeignTableRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgForeignTableRow] = new JdbcDecoder[PgForeignTableRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgForeignTableRow) = + columIndex + 2 -> + PgForeignTableRow( + ftrelid = PgForeignTableId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + ftserver = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + ftoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgForeignTableRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val ftrelid = jsonObj.get("ftrelid").toRight("Missing field 'ftrelid'").flatMap(_.as(PgForeignTableId.jsonDecoder)) + val ftserver = jsonObj.get("ftserver").toRight("Missing field 'ftserver'").flatMap(_.as(JsonDecoder.long)) + val ftoptions = jsonObj.get("ftoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (ftrelid.isRight && ftserver.isRight && ftoptions.isRight) + Right(PgForeignTableRow(ftrelid = ftrelid.toOption.get, ftserver = ftserver.toOption.get, ftoptions = ftoptions.toOption.get)) + else Left(List[Either[String, Any]](ftrelid, ftserver, ftoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgForeignTableRow] = new JsonEncoder[PgForeignTableRow] { + override def unsafeEncode(a: PgForeignTableRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""ftrelid":""") + PgForeignTableId.jsonEncoder.unsafeEncode(a.ftrelid, indent, out) + out.write(",") + out.write(""""ftserver":""") + JsonEncoder.long.unsafeEncode(a.ftserver, indent, out) + out.write(",") + out.write(""""ftoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.ftoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableStructure.scala new file mode 100644 index 0000000000..7543993bdb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_foreign_table/PgForeignTableStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_foreign_table + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgForeignTableStructure[Row](val prefix: Option[String], val extract: Row => PgForeignTableRow, val merge: (Row, PgForeignTableRow) => Row) + extends Relation[PgForeignTableFields, PgForeignTableRow, Row] + with PgForeignTableFields[Row] { outer => + + override val ftrelid = new IdField[PgForeignTableId, Row](prefix, "ftrelid", None, Some("oid"))(x => extract(x).ftrelid, (row, value) => merge(row, extract(row).copy(ftrelid = value))) + override val ftserver = new Field[/* oid */ Long, Row](prefix, "ftserver", None, Some("oid"))(x => extract(x).ftserver, (row, value) => merge(row, extract(row).copy(ftserver = value))) + override val ftoptions = new OptField[Array[String], Row](prefix, "ftoptions", None, Some("_text"))(x => extract(x).ftoptions, (row, value) => merge(row, extract(row).copy(ftoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](ftrelid, ftserver, ftoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgForeignTableRow, merge: (NewRow, PgForeignTableRow) => NewRow): PgForeignTableStructure[NewRow] = + new PgForeignTableStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewFields.scala new file mode 100644 index 0000000000..42f012e23c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_group + +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgGroupViewFields[Row] { + val groname: Field[String, Row] + val grosysid: Field[PgAuthidId, Row] + val grolist: OptField[Array[/* oid */ Long], Row] +} +object PgGroupViewFields extends PgGroupViewStructure[PgGroupViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepo.scala new file mode 100644 index 0000000000..2015383854 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_group + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgGroupViewRepo { + def select: SelectBuilder[PgGroupViewFields, PgGroupViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgGroupViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepoImpl.scala new file mode 100644 index 0000000000..4de950b835 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_group + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgGroupViewRepoImpl extends PgGroupViewRepo { + override def select: SelectBuilder[PgGroupViewFields, PgGroupViewRow] = { + SelectBuilderSql("pg_catalog.pg_group", PgGroupViewFields, PgGroupViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgGroupViewRow] = { + sql"""select "groname", "grosysid", "grolist" from pg_catalog.pg_group""".query(PgGroupViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRow.scala new file mode 100644 index 0000000000..e91f8acb6c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_group + +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgGroupViewRow( + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + groname: String, + /** Points to [[pg_authid.PgAuthidRow.oid]] */ + grosysid: PgAuthidId, + grolist: /* nullability unknown */ Option[Array[/* oid */ Long]] +) + +object PgGroupViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgGroupViewRow] = new JdbcDecoder[PgGroupViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgGroupViewRow) = + columIndex + 2 -> + PgGroupViewRow( + groname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + grosysid = PgAuthidId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + grolist = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgGroupViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val groname = jsonObj.get("groname").toRight("Missing field 'groname'").flatMap(_.as(JsonDecoder.string)) + val grosysid = jsonObj.get("grosysid").toRight("Missing field 'grosysid'").flatMap(_.as(PgAuthidId.jsonDecoder)) + val grolist = jsonObj.get("grolist").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + if (groname.isRight && grosysid.isRight && grolist.isRight) + Right(PgGroupViewRow(groname = groname.toOption.get, grosysid = grosysid.toOption.get, grolist = grolist.toOption.get)) + else Left(List[Either[String, Any]](groname, grosysid, grolist).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgGroupViewRow] = new JsonEncoder[PgGroupViewRow] { + override def unsafeEncode(a: PgGroupViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""groname":""") + JsonEncoder.string.unsafeEncode(a.groname, indent, out) + out.write(",") + out.write(""""grosysid":""") + PgAuthidId.jsonEncoder.unsafeEncode(a.grosysid, indent, out) + out.write(",") + out.write(""""grolist":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.grolist, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewStructure.scala new file mode 100644 index 0000000000..9222cddddd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_group/PgGroupViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_group + +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgGroupViewStructure[Row](val prefix: Option[String], val extract: Row => PgGroupViewRow, val merge: (Row, PgGroupViewRow) => Row) + extends Relation[PgGroupViewFields, PgGroupViewRow, Row] + with PgGroupViewFields[Row] { outer => + + override val groname = new Field[String, Row](prefix, "groname", None, None)(x => extract(x).groname, (row, value) => merge(row, extract(row).copy(groname = value))) + override val grosysid = new Field[PgAuthidId, Row](prefix, "grosysid", None, None)(x => extract(x).grosysid, (row, value) => merge(row, extract(row).copy(grosysid = value))) + override val grolist = new OptField[Array[/* oid */ Long], Row](prefix, "grolist", None, None)(x => extract(x).grolist, (row, value) => merge(row, extract(row).copy(grolist = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](groname, grosysid, grolist) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgGroupViewRow, merge: (NewRow, PgGroupViewRow) => NewRow): PgGroupViewStructure[NewRow] = + new PgGroupViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewFields.scala new file mode 100644 index 0000000000..6cc77939fb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_hba_file_rules + +import typo.dsl.SqlExpr.OptField + +trait PgHbaFileRulesViewFields[Row] { + val lineNumber: OptField[Int, Row] + val `type`: OptField[String, Row] + val database: OptField[Array[String], Row] + val userName: OptField[Array[String], Row] + val address: OptField[String, Row] + val netmask: OptField[String, Row] + val authMethod: OptField[String, Row] + val options: OptField[Array[String], Row] + val error: OptField[String, Row] +} +object PgHbaFileRulesViewFields extends PgHbaFileRulesViewStructure[PgHbaFileRulesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepo.scala new file mode 100644 index 0000000000..80e185b90e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_hba_file_rules + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgHbaFileRulesViewRepo { + def select: SelectBuilder[PgHbaFileRulesViewFields, PgHbaFileRulesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgHbaFileRulesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepoImpl.scala new file mode 100644 index 0000000000..1024dd614f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_hba_file_rules + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgHbaFileRulesViewRepoImpl extends PgHbaFileRulesViewRepo { + override def select: SelectBuilder[PgHbaFileRulesViewFields, PgHbaFileRulesViewRow] = { + SelectBuilderSql("pg_catalog.pg_hba_file_rules", PgHbaFileRulesViewFields, PgHbaFileRulesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgHbaFileRulesViewRow] = { + sql"""select "line_number", "type", "database", "user_name", "address", "netmask", "auth_method", "options", "error" from pg_catalog.pg_hba_file_rules""".query(PgHbaFileRulesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRow.scala new file mode 100644 index 0000000000..d1086674bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_hba_file_rules + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgHbaFileRulesViewRow( + lineNumber: /* nullability unknown */ Option[Int], + `type`: /* nullability unknown */ Option[String], + database: /* nullability unknown */ Option[Array[String]], + userName: /* nullability unknown */ Option[Array[String]], + address: /* nullability unknown */ Option[String], + netmask: /* nullability unknown */ Option[String], + authMethod: /* nullability unknown */ Option[String], + options: /* nullability unknown */ Option[Array[String]], + error: /* nullability unknown */ Option[String] +) + +object PgHbaFileRulesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgHbaFileRulesViewRow] = new JdbcDecoder[PgHbaFileRulesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgHbaFileRulesViewRow) = + columIndex + 8 -> + PgHbaFileRulesViewRow( + lineNumber = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + `type` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + database = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 2, rs)._2, + userName = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 3, rs)._2, + address = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + netmask = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + authMethod = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + options = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 7, rs)._2, + error = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgHbaFileRulesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val lineNumber = jsonObj.get("line_number").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val `type` = jsonObj.get("type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val database = jsonObj.get("database").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val userName = jsonObj.get("user_name").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val address = jsonObj.get("address").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val netmask = jsonObj.get("netmask").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val authMethod = jsonObj.get("auth_method").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val options = jsonObj.get("options").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val error = jsonObj.get("error").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (lineNumber.isRight && `type`.isRight && database.isRight && userName.isRight && address.isRight && netmask.isRight && authMethod.isRight && options.isRight && error.isRight) + Right(PgHbaFileRulesViewRow(lineNumber = lineNumber.toOption.get, `type` = `type`.toOption.get, database = database.toOption.get, userName = userName.toOption.get, address = address.toOption.get, netmask = netmask.toOption.get, authMethod = authMethod.toOption.get, options = options.toOption.get, error = error.toOption.get)) + else Left(List[Either[String, Any]](lineNumber, `type`, database, userName, address, netmask, authMethod, options, error).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgHbaFileRulesViewRow] = new JsonEncoder[PgHbaFileRulesViewRow] { + override def unsafeEncode(a: PgHbaFileRulesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""line_number":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.lineNumber, indent, out) + out.write(",") + out.write(""""type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`type`, indent, out) + out.write(",") + out.write(""""database":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.database, indent, out) + out.write(",") + out.write(""""user_name":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.userName, indent, out) + out.write(",") + out.write(""""address":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.address, indent, out) + out.write(",") + out.write(""""netmask":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.netmask, indent, out) + out.write(",") + out.write(""""auth_method":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.authMethod, indent, out) + out.write(",") + out.write(""""options":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.options, indent, out) + out.write(",") + out.write(""""error":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.error, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewStructure.scala new file mode 100644 index 0000000000..735511d66f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_hba_file_rules/PgHbaFileRulesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_hba_file_rules + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgHbaFileRulesViewStructure[Row](val prefix: Option[String], val extract: Row => PgHbaFileRulesViewRow, val merge: (Row, PgHbaFileRulesViewRow) => Row) + extends Relation[PgHbaFileRulesViewFields, PgHbaFileRulesViewRow, Row] + with PgHbaFileRulesViewFields[Row] { outer => + + override val lineNumber = new OptField[Int, Row](prefix, "line_number", None, None)(x => extract(x).lineNumber, (row, value) => merge(row, extract(row).copy(lineNumber = value))) + override val `type` = new OptField[String, Row](prefix, "type", None, None)(x => extract(x).`type`, (row, value) => merge(row, extract(row).copy(`type` = value))) + override val database = new OptField[Array[String], Row](prefix, "database", None, None)(x => extract(x).database, (row, value) => merge(row, extract(row).copy(database = value))) + override val userName = new OptField[Array[String], Row](prefix, "user_name", None, None)(x => extract(x).userName, (row, value) => merge(row, extract(row).copy(userName = value))) + override val address = new OptField[String, Row](prefix, "address", None, None)(x => extract(x).address, (row, value) => merge(row, extract(row).copy(address = value))) + override val netmask = new OptField[String, Row](prefix, "netmask", None, None)(x => extract(x).netmask, (row, value) => merge(row, extract(row).copy(netmask = value))) + override val authMethod = new OptField[String, Row](prefix, "auth_method", None, None)(x => extract(x).authMethod, (row, value) => merge(row, extract(row).copy(authMethod = value))) + override val options = new OptField[Array[String], Row](prefix, "options", None, None)(x => extract(x).options, (row, value) => merge(row, extract(row).copy(options = value))) + override val error = new OptField[String, Row](prefix, "error", None, None)(x => extract(x).error, (row, value) => merge(row, extract(row).copy(error = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](lineNumber, `type`, database, userName, address, netmask, authMethod, options, error) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgHbaFileRulesViewRow, merge: (NewRow, PgHbaFileRulesViewRow) => NewRow): PgHbaFileRulesViewStructure[NewRow] = + new PgHbaFileRulesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexFields.scala new file mode 100644 index 0000000000..acb6d72eb8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexFields.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgIndexFields[Row] { + val indexrelid: IdField[PgIndexId, Row] + val indrelid: Field[/* oid */ Long, Row] + val indnatts: Field[TypoShort, Row] + val indnkeyatts: Field[TypoShort, Row] + val indisunique: Field[Boolean, Row] + val indisprimary: Field[Boolean, Row] + val indisexclusion: Field[Boolean, Row] + val indimmediate: Field[Boolean, Row] + val indisclustered: Field[Boolean, Row] + val indisvalid: Field[Boolean, Row] + val indcheckxmin: Field[Boolean, Row] + val indisready: Field[Boolean, Row] + val indislive: Field[Boolean, Row] + val indisreplident: Field[Boolean, Row] + val indkey: Field[TypoInt2Vector, Row] + val indcollation: Field[TypoOidVector, Row] + val indclass: Field[TypoOidVector, Row] + val indoption: Field[TypoInt2Vector, Row] + val indexprs: OptField[TypoPgNodeTree, Row] + val indpred: OptField[TypoPgNodeTree, Row] +} +object PgIndexFields extends PgIndexStructure[PgIndexRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexId.scala new file mode 100644 index 0000000000..de2afbc849 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +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 `pg_catalog.pg_index` */ +case class PgIndexId(value: /* oid */ Long) extends AnyVal +object PgIndexId { + implicit lazy val arraySetter: Setter[Array[PgIndexId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgIndexId, /* oid */ Long] = Bijection[PgIndexId, /* oid */ Long](_.value)(PgIndexId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgIndexId] = JdbcDecoder.longDecoder.map(PgIndexId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgIndexId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgIndexId] = JsonDecoder.long.map(PgIndexId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgIndexId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgIndexId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgIndexId] = ParameterMetaData.instance[PgIndexId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgIndexId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepo.scala new file mode 100644 index 0000000000..2685e0f873 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgIndexRepo { + def delete(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgIndexFields, PgIndexRow] + def insert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, PgIndexRow] + def select: SelectBuilder[PgIndexFields, PgIndexRow] + def selectAll: ZStream[ZConnection, Throwable, PgIndexRow] + def selectById(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Option[PgIndexRow]] + def selectByIds(indexrelids: Array[PgIndexId]): ZStream[ZConnection, Throwable, PgIndexRow] + def update(row: PgIndexRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgIndexFields, PgIndexRow] + def upsert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, UpdateResult[PgIndexRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoImpl.scala new file mode 100644 index 0000000000..c08a5ef386 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoImpl.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgIndexRepoImpl extends PgIndexRepo { + override def delete(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_index where "indexrelid" = ${Segment.paramSegment(indexrelid)(PgIndexId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgIndexFields, PgIndexRow] = { + DeleteBuilder("pg_catalog.pg_index", PgIndexFields) + } + override def insert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, PgIndexRow] = { + sql"""insert into pg_catalog.pg_index("indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred") + values (${Segment.paramSegment(unsaved.indexrelid)(PgIndexId.setter)}::oid, ${Segment.paramSegment(unsaved.indrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.indnatts)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.indnkeyatts)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.indisunique)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisprimary)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisexclusion)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indimmediate)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisclustered)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisvalid)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indcheckxmin)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisready)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indislive)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indisreplident)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.indkey)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.indcollation)(TypoOidVector.setter)}::oidvector, ${Segment.paramSegment(unsaved.indclass)(TypoOidVector.setter)}::oidvector, ${Segment.paramSegment(unsaved.indoption)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.indexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.indpred)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred" + """.insertReturning(PgIndexRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgIndexFields, PgIndexRow] = { + SelectBuilderSql("pg_catalog.pg_index", PgIndexFields, PgIndexRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgIndexRow] = { + sql"""select "indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred" from pg_catalog.pg_index""".query(PgIndexRow.jdbcDecoder).selectStream + } + override def selectById(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Option[PgIndexRow]] = { + sql"""select "indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred" from pg_catalog.pg_index where "indexrelid" = ${Segment.paramSegment(indexrelid)(PgIndexId.setter)}""".query(PgIndexRow.jdbcDecoder).selectOne + } + override def selectByIds(indexrelids: Array[PgIndexId]): ZStream[ZConnection, Throwable, PgIndexRow] = { + sql"""select "indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred" from pg_catalog.pg_index where "indexrelid" = ANY(${Segment.paramSegment(indexrelids)(PgIndexId.arraySetter)})""".query(PgIndexRow.jdbcDecoder).selectStream + } + override def update(row: PgIndexRow): ZIO[ZConnection, Throwable, Boolean] = { + val indexrelid = row.indexrelid + sql"""update pg_catalog.pg_index + set "indrelid" = ${Segment.paramSegment(row.indrelid)(Setter.longSetter)}::oid, + "indnatts" = ${Segment.paramSegment(row.indnatts)(TypoShort.setter)}::int2, + "indnkeyatts" = ${Segment.paramSegment(row.indnkeyatts)(TypoShort.setter)}::int2, + "indisunique" = ${Segment.paramSegment(row.indisunique)(Setter.booleanSetter)}, + "indisprimary" = ${Segment.paramSegment(row.indisprimary)(Setter.booleanSetter)}, + "indisexclusion" = ${Segment.paramSegment(row.indisexclusion)(Setter.booleanSetter)}, + "indimmediate" = ${Segment.paramSegment(row.indimmediate)(Setter.booleanSetter)}, + "indisclustered" = ${Segment.paramSegment(row.indisclustered)(Setter.booleanSetter)}, + "indisvalid" = ${Segment.paramSegment(row.indisvalid)(Setter.booleanSetter)}, + "indcheckxmin" = ${Segment.paramSegment(row.indcheckxmin)(Setter.booleanSetter)}, + "indisready" = ${Segment.paramSegment(row.indisready)(Setter.booleanSetter)}, + "indislive" = ${Segment.paramSegment(row.indislive)(Setter.booleanSetter)}, + "indisreplident" = ${Segment.paramSegment(row.indisreplident)(Setter.booleanSetter)}, + "indkey" = ${Segment.paramSegment(row.indkey)(TypoInt2Vector.setter)}::int2vector, + "indcollation" = ${Segment.paramSegment(row.indcollation)(TypoOidVector.setter)}::oidvector, + "indclass" = ${Segment.paramSegment(row.indclass)(TypoOidVector.setter)}::oidvector, + "indoption" = ${Segment.paramSegment(row.indoption)(TypoInt2Vector.setter)}::int2vector, + "indexprs" = ${Segment.paramSegment(row.indexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "indpred" = ${Segment.paramSegment(row.indpred)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "indexrelid" = ${Segment.paramSegment(indexrelid)(PgIndexId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgIndexFields, PgIndexRow] = { + UpdateBuilder("pg_catalog.pg_index", PgIndexFields, PgIndexRow.jdbcDecoder) + } + override def upsert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, UpdateResult[PgIndexRow]] = { + sql"""insert into pg_catalog.pg_index("indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred") + values ( + ${Segment.paramSegment(unsaved.indexrelid)(PgIndexId.setter)}::oid, + ${Segment.paramSegment(unsaved.indrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.indnatts)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.indnkeyatts)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.indisunique)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisprimary)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisexclusion)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indimmediate)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisclustered)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisvalid)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indcheckxmin)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisready)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indislive)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indisreplident)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.indkey)(TypoInt2Vector.setter)}::int2vector, + ${Segment.paramSegment(unsaved.indcollation)(TypoOidVector.setter)}::oidvector, + ${Segment.paramSegment(unsaved.indclass)(TypoOidVector.setter)}::oidvector, + ${Segment.paramSegment(unsaved.indoption)(TypoInt2Vector.setter)}::int2vector, + ${Segment.paramSegment(unsaved.indexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.indpred)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("indexrelid") + do update set + "indrelid" = EXCLUDED."indrelid", + "indnatts" = EXCLUDED."indnatts", + "indnkeyatts" = EXCLUDED."indnkeyatts", + "indisunique" = EXCLUDED."indisunique", + "indisprimary" = EXCLUDED."indisprimary", + "indisexclusion" = EXCLUDED."indisexclusion", + "indimmediate" = EXCLUDED."indimmediate", + "indisclustered" = EXCLUDED."indisclustered", + "indisvalid" = EXCLUDED."indisvalid", + "indcheckxmin" = EXCLUDED."indcheckxmin", + "indisready" = EXCLUDED."indisready", + "indislive" = EXCLUDED."indislive", + "indisreplident" = EXCLUDED."indisreplident", + "indkey" = EXCLUDED."indkey", + "indcollation" = EXCLUDED."indcollation", + "indclass" = EXCLUDED."indclass", + "indoption" = EXCLUDED."indoption", + "indexprs" = EXCLUDED."indexprs", + "indpred" = EXCLUDED."indpred" + returning "indexrelid", "indrelid", "indnatts", "indnkeyatts", "indisunique", "indisprimary", "indisexclusion", "indimmediate", "indisclustered", "indisvalid", "indcheckxmin", "indisready", "indislive", "indisreplident", "indkey", "indcollation", "indclass", "indoption", "indexprs", "indpred"""".insertReturning(PgIndexRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoMock.scala new file mode 100644 index 0000000000..51560fb4a0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgIndexRepoMock(map: scala.collection.mutable.Map[PgIndexId, PgIndexRow] = scala.collection.mutable.Map.empty) extends PgIndexRepo { + override def delete(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(indexrelid).isDefined) + } + override def delete: DeleteBuilder[PgIndexFields, PgIndexRow] = { + DeleteBuilderMock(DeleteParams.empty, PgIndexFields, map) + } + override def insert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, PgIndexRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.indexrelid)) + sys.error(s"id ${unsaved.indexrelid} already exists") + else + map.put(unsaved.indexrelid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgIndexFields, PgIndexRow] = { + SelectBuilderMock(PgIndexFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgIndexRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(indexrelid: PgIndexId): ZIO[ZConnection, Throwable, Option[PgIndexRow]] = { + ZIO.succeed(map.get(indexrelid)) + } + override def selectByIds(indexrelids: Array[PgIndexId]): ZStream[ZConnection, Throwable, PgIndexRow] = { + ZStream.fromIterable(indexrelids.flatMap(map.get)) + } + override def update(row: PgIndexRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.indexrelid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.indexrelid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgIndexFields, PgIndexRow] = { + UpdateBuilderMock(UpdateParams.empty, PgIndexFields, map) + } + override def upsert(unsaved: PgIndexRow): ZIO[ZConnection, Throwable, UpdateResult[PgIndexRow]] = { + ZIO.succeed { + map.put(unsaved.indexrelid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRow.scala new file mode 100644 index 0000000000..d5d8ce0c63 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexRow.scala @@ -0,0 +1,161 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgIndexRow( + indexrelid: PgIndexId, + indrelid: /* oid */ Long, + indnatts: TypoShort, + indnkeyatts: TypoShort, + indisunique: Boolean, + indisprimary: Boolean, + indisexclusion: Boolean, + indimmediate: Boolean, + indisclustered: Boolean, + indisvalid: Boolean, + indcheckxmin: Boolean, + indisready: Boolean, + indislive: Boolean, + indisreplident: Boolean, + indkey: TypoInt2Vector, + indcollation: TypoOidVector, + indclass: TypoOidVector, + indoption: TypoInt2Vector, + indexprs: Option[TypoPgNodeTree], + indpred: Option[TypoPgNodeTree] +) + +object PgIndexRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgIndexRow] = new JdbcDecoder[PgIndexRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgIndexRow) = + columIndex + 19 -> + PgIndexRow( + indexrelid = PgIndexId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + indrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + indnatts = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + indnkeyatts = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + indisunique = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + indisprimary = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + indisexclusion = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + indimmediate = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + indisclustered = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 8, rs)._2, + indisvalid = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 9, rs)._2, + indcheckxmin = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 10, rs)._2, + indisready = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 11, rs)._2, + indislive = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 12, rs)._2, + indisreplident = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 13, rs)._2, + indkey = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + indcollation = TypoOidVector.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + indclass = TypoOidVector.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + indoption = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 17, rs)._2, + indexprs = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + indpred = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 19, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgIndexRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val indexrelid = jsonObj.get("indexrelid").toRight("Missing field 'indexrelid'").flatMap(_.as(PgIndexId.jsonDecoder)) + val indrelid = jsonObj.get("indrelid").toRight("Missing field 'indrelid'").flatMap(_.as(JsonDecoder.long)) + val indnatts = jsonObj.get("indnatts").toRight("Missing field 'indnatts'").flatMap(_.as(TypoShort.jsonDecoder)) + val indnkeyatts = jsonObj.get("indnkeyatts").toRight("Missing field 'indnkeyatts'").flatMap(_.as(TypoShort.jsonDecoder)) + val indisunique = jsonObj.get("indisunique").toRight("Missing field 'indisunique'").flatMap(_.as(JsonDecoder.boolean)) + val indisprimary = jsonObj.get("indisprimary").toRight("Missing field 'indisprimary'").flatMap(_.as(JsonDecoder.boolean)) + val indisexclusion = jsonObj.get("indisexclusion").toRight("Missing field 'indisexclusion'").flatMap(_.as(JsonDecoder.boolean)) + val indimmediate = jsonObj.get("indimmediate").toRight("Missing field 'indimmediate'").flatMap(_.as(JsonDecoder.boolean)) + val indisclustered = jsonObj.get("indisclustered").toRight("Missing field 'indisclustered'").flatMap(_.as(JsonDecoder.boolean)) + val indisvalid = jsonObj.get("indisvalid").toRight("Missing field 'indisvalid'").flatMap(_.as(JsonDecoder.boolean)) + val indcheckxmin = jsonObj.get("indcheckxmin").toRight("Missing field 'indcheckxmin'").flatMap(_.as(JsonDecoder.boolean)) + val indisready = jsonObj.get("indisready").toRight("Missing field 'indisready'").flatMap(_.as(JsonDecoder.boolean)) + val indislive = jsonObj.get("indislive").toRight("Missing field 'indislive'").flatMap(_.as(JsonDecoder.boolean)) + val indisreplident = jsonObj.get("indisreplident").toRight("Missing field 'indisreplident'").flatMap(_.as(JsonDecoder.boolean)) + val indkey = jsonObj.get("indkey").toRight("Missing field 'indkey'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val indcollation = jsonObj.get("indcollation").toRight("Missing field 'indcollation'").flatMap(_.as(TypoOidVector.jsonDecoder)) + val indclass = jsonObj.get("indclass").toRight("Missing field 'indclass'").flatMap(_.as(TypoOidVector.jsonDecoder)) + val indoption = jsonObj.get("indoption").toRight("Missing field 'indoption'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val indexprs = jsonObj.get("indexprs").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val indpred = jsonObj.get("indpred").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (indexrelid.isRight && indrelid.isRight && indnatts.isRight && indnkeyatts.isRight && indisunique.isRight && indisprimary.isRight && indisexclusion.isRight && indimmediate.isRight && indisclustered.isRight && indisvalid.isRight && indcheckxmin.isRight && indisready.isRight && indislive.isRight && indisreplident.isRight && indkey.isRight && indcollation.isRight && indclass.isRight && indoption.isRight && indexprs.isRight && indpred.isRight) + Right(PgIndexRow(indexrelid = indexrelid.toOption.get, indrelid = indrelid.toOption.get, indnatts = indnatts.toOption.get, indnkeyatts = indnkeyatts.toOption.get, indisunique = indisunique.toOption.get, indisprimary = indisprimary.toOption.get, indisexclusion = indisexclusion.toOption.get, indimmediate = indimmediate.toOption.get, indisclustered = indisclustered.toOption.get, indisvalid = indisvalid.toOption.get, indcheckxmin = indcheckxmin.toOption.get, indisready = indisready.toOption.get, indislive = indislive.toOption.get, indisreplident = indisreplident.toOption.get, indkey = indkey.toOption.get, indcollation = indcollation.toOption.get, indclass = indclass.toOption.get, indoption = indoption.toOption.get, indexprs = indexprs.toOption.get, indpred = indpred.toOption.get)) + else Left(List[Either[String, Any]](indexrelid, indrelid, indnatts, indnkeyatts, indisunique, indisprimary, indisexclusion, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgIndexRow] = new JsonEncoder[PgIndexRow] { + override def unsafeEncode(a: PgIndexRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""indexrelid":""") + PgIndexId.jsonEncoder.unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""indrelid":""") + JsonEncoder.long.unsafeEncode(a.indrelid, indent, out) + out.write(",") + out.write(""""indnatts":""") + TypoShort.jsonEncoder.unsafeEncode(a.indnatts, indent, out) + out.write(",") + out.write(""""indnkeyatts":""") + TypoShort.jsonEncoder.unsafeEncode(a.indnkeyatts, indent, out) + out.write(",") + out.write(""""indisunique":""") + JsonEncoder.boolean.unsafeEncode(a.indisunique, indent, out) + out.write(",") + out.write(""""indisprimary":""") + JsonEncoder.boolean.unsafeEncode(a.indisprimary, indent, out) + out.write(",") + out.write(""""indisexclusion":""") + JsonEncoder.boolean.unsafeEncode(a.indisexclusion, indent, out) + out.write(",") + out.write(""""indimmediate":""") + JsonEncoder.boolean.unsafeEncode(a.indimmediate, indent, out) + out.write(",") + out.write(""""indisclustered":""") + JsonEncoder.boolean.unsafeEncode(a.indisclustered, indent, out) + out.write(",") + out.write(""""indisvalid":""") + JsonEncoder.boolean.unsafeEncode(a.indisvalid, indent, out) + out.write(",") + out.write(""""indcheckxmin":""") + JsonEncoder.boolean.unsafeEncode(a.indcheckxmin, indent, out) + out.write(",") + out.write(""""indisready":""") + JsonEncoder.boolean.unsafeEncode(a.indisready, indent, out) + out.write(",") + out.write(""""indislive":""") + JsonEncoder.boolean.unsafeEncode(a.indislive, indent, out) + out.write(",") + out.write(""""indisreplident":""") + JsonEncoder.boolean.unsafeEncode(a.indisreplident, indent, out) + out.write(",") + out.write(""""indkey":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.indkey, indent, out) + out.write(",") + out.write(""""indcollation":""") + TypoOidVector.jsonEncoder.unsafeEncode(a.indcollation, indent, out) + out.write(",") + out.write(""""indclass":""") + TypoOidVector.jsonEncoder.unsafeEncode(a.indclass, indent, out) + out.write(",") + out.write(""""indoption":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.indoption, indent, out) + out.write(",") + out.write(""""indexprs":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.indexprs, indent, out) + out.write(",") + out.write(""""indpred":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.indpred, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexStructure.scala new file mode 100644 index 0000000000..ea4e3c3fd4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_index/PgIndexStructure.scala @@ -0,0 +1,50 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_index + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgIndexStructure[Row](val prefix: Option[String], val extract: Row => PgIndexRow, val merge: (Row, PgIndexRow) => Row) + extends Relation[PgIndexFields, PgIndexRow, Row] + with PgIndexFields[Row] { outer => + + override val indexrelid = new IdField[PgIndexId, Row](prefix, "indexrelid", None, Some("oid"))(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val indrelid = new Field[/* oid */ Long, Row](prefix, "indrelid", None, Some("oid"))(x => extract(x).indrelid, (row, value) => merge(row, extract(row).copy(indrelid = value))) + override val indnatts = new Field[TypoShort, Row](prefix, "indnatts", None, Some("int2"))(x => extract(x).indnatts, (row, value) => merge(row, extract(row).copy(indnatts = value))) + override val indnkeyatts = new Field[TypoShort, Row](prefix, "indnkeyatts", None, Some("int2"))(x => extract(x).indnkeyatts, (row, value) => merge(row, extract(row).copy(indnkeyatts = value))) + override val indisunique = new Field[Boolean, Row](prefix, "indisunique", None, None)(x => extract(x).indisunique, (row, value) => merge(row, extract(row).copy(indisunique = value))) + override val indisprimary = new Field[Boolean, Row](prefix, "indisprimary", None, None)(x => extract(x).indisprimary, (row, value) => merge(row, extract(row).copy(indisprimary = value))) + override val indisexclusion = new Field[Boolean, Row](prefix, "indisexclusion", None, None)(x => extract(x).indisexclusion, (row, value) => merge(row, extract(row).copy(indisexclusion = value))) + override val indimmediate = new Field[Boolean, Row](prefix, "indimmediate", None, None)(x => extract(x).indimmediate, (row, value) => merge(row, extract(row).copy(indimmediate = value))) + override val indisclustered = new Field[Boolean, Row](prefix, "indisclustered", None, None)(x => extract(x).indisclustered, (row, value) => merge(row, extract(row).copy(indisclustered = value))) + override val indisvalid = new Field[Boolean, Row](prefix, "indisvalid", None, None)(x => extract(x).indisvalid, (row, value) => merge(row, extract(row).copy(indisvalid = value))) + override val indcheckxmin = new Field[Boolean, Row](prefix, "indcheckxmin", None, None)(x => extract(x).indcheckxmin, (row, value) => merge(row, extract(row).copy(indcheckxmin = value))) + override val indisready = new Field[Boolean, Row](prefix, "indisready", None, None)(x => extract(x).indisready, (row, value) => merge(row, extract(row).copy(indisready = value))) + override val indislive = new Field[Boolean, Row](prefix, "indislive", None, None)(x => extract(x).indislive, (row, value) => merge(row, extract(row).copy(indislive = value))) + override val indisreplident = new Field[Boolean, Row](prefix, "indisreplident", None, None)(x => extract(x).indisreplident, (row, value) => merge(row, extract(row).copy(indisreplident = value))) + override val indkey = new Field[TypoInt2Vector, Row](prefix, "indkey", None, Some("int2vector"))(x => extract(x).indkey, (row, value) => merge(row, extract(row).copy(indkey = value))) + override val indcollation = new Field[TypoOidVector, Row](prefix, "indcollation", None, Some("oidvector"))(x => extract(x).indcollation, (row, value) => merge(row, extract(row).copy(indcollation = value))) + override val indclass = new Field[TypoOidVector, Row](prefix, "indclass", None, Some("oidvector"))(x => extract(x).indclass, (row, value) => merge(row, extract(row).copy(indclass = value))) + override val indoption = new Field[TypoInt2Vector, Row](prefix, "indoption", None, Some("int2vector"))(x => extract(x).indoption, (row, value) => merge(row, extract(row).copy(indoption = value))) + override val indexprs = new OptField[TypoPgNodeTree, Row](prefix, "indexprs", None, Some("pg_node_tree"))(x => extract(x).indexprs, (row, value) => merge(row, extract(row).copy(indexprs = value))) + override val indpred = new OptField[TypoPgNodeTree, Row](prefix, "indpred", None, Some("pg_node_tree"))(x => extract(x).indpred, (row, value) => merge(row, extract(row).copy(indpred = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](indexrelid, indrelid, indnatts, indnkeyatts, indisunique, indisprimary, indisexclusion, indimmediate, indisclustered, indisvalid, indcheckxmin, indisready, indislive, indisreplident, indkey, indcollation, indclass, indoption, indexprs, indpred) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgIndexRow, merge: (NewRow, PgIndexRow) => NewRow): PgIndexStructure[NewRow] = + new PgIndexStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewFields.scala new file mode 100644 index 0000000000..0c2feca0a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_indexes + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgIndexesViewFields[Row] { + val schemaname: OptField[String, Row] + val tablename: Field[String, Row] + val indexname: Field[String, Row] + val tablespace: OptField[String, Row] + val indexdef: OptField[String, Row] +} +object PgIndexesViewFields extends PgIndexesViewStructure[PgIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepo.scala new file mode 100644 index 0000000000..2bde048bfb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgIndexesViewRepo { + def select: SelectBuilder[PgIndexesViewFields, PgIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..bc649bfa40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgIndexesViewRepoImpl extends PgIndexesViewRepo { + override def select: SelectBuilder[PgIndexesViewFields, PgIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_indexes", PgIndexesViewFields, PgIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgIndexesViewRow] = { + sql"""select "schemaname", "tablename", "indexname", "tablespace", "indexdef" from pg_catalog.pg_indexes""".query(PgIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRow.scala new file mode 100644 index 0000000000..79da796c4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_indexes + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgIndexesViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + indexname: String, + /** Points to [[pg_tablespace.PgTablespaceRow.spcname]] */ + tablespace: Option[String], + indexdef: /* nullability unknown */ Option[String] +) + +object PgIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgIndexesViewRow] = new JdbcDecoder[PgIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgIndexesViewRow) = + columIndex + 4 -> + PgIndexesViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + indexname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + tablespace = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexdef = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val indexname = jsonObj.get("indexname").toRight("Missing field 'indexname'").flatMap(_.as(JsonDecoder.string)) + val tablespace = jsonObj.get("tablespace").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val indexdef = jsonObj.get("indexdef").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (schemaname.isRight && tablename.isRight && indexname.isRight && tablespace.isRight && indexdef.isRight) + Right(PgIndexesViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, indexname = indexname.toOption.get, tablespace = tablespace.toOption.get, indexdef = indexdef.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, indexname, tablespace, indexdef).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgIndexesViewRow] = new JsonEncoder[PgIndexesViewRow] { + override def unsafeEncode(a: PgIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""indexname":""") + JsonEncoder.string.unsafeEncode(a.indexname, indent, out) + out.write(",") + out.write(""""tablespace":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tablespace, indent, out) + out.write(",") + out.write(""""indexdef":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.indexdef, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewStructure.scala new file mode 100644 index 0000000000..e3ff6a5b31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_indexes/PgIndexesViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_indexes + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgIndexesViewRow, val merge: (Row, PgIndexesViewRow) => Row) + extends Relation[PgIndexesViewFields, PgIndexesViewRow, Row] + with PgIndexesViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val indexname = new Field[String, Row](prefix, "indexname", None, None)(x => extract(x).indexname, (row, value) => merge(row, extract(row).copy(indexname = value))) + override val tablespace = new OptField[String, Row](prefix, "tablespace", None, None)(x => extract(x).tablespace, (row, value) => merge(row, extract(row).copy(tablespace = value))) + override val indexdef = new OptField[String, Row](prefix, "indexdef", None, None)(x => extract(x).indexdef, (row, value) => merge(row, extract(row).copy(indexdef = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, indexname, tablespace, indexdef) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgIndexesViewRow, merge: (NewRow, PgIndexesViewRow) => NewRow): PgIndexesViewStructure[NewRow] = + new PgIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsFields.scala new file mode 100644 index 0000000000..743a4f648e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgInheritsFields[Row] { + val inhrelid: IdField[/* oid */ Long, Row] + val inhparent: Field[/* oid */ Long, Row] + val inhseqno: IdField[Int, Row] + val inhdetachpending: Field[Boolean, Row] +} +object PgInheritsFields extends PgInheritsStructure[PgInheritsRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsId.scala new file mode 100644 index 0000000000..ac6ff1857c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_inherits` */ +case class PgInheritsId(inhrelid: /* oid */ Long, inhseqno: Int) +object PgInheritsId { + implicit lazy val jsonDecoder: JsonDecoder[PgInheritsId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val inhrelid = jsonObj.get("inhrelid").toRight("Missing field 'inhrelid'").flatMap(_.as(JsonDecoder.long)) + val inhseqno = jsonObj.get("inhseqno").toRight("Missing field 'inhseqno'").flatMap(_.as(JsonDecoder.int)) + if (inhrelid.isRight && inhseqno.isRight) + Right(PgInheritsId(inhrelid = inhrelid.toOption.get, inhseqno = inhseqno.toOption.get)) + else Left(List[Either[String, Any]](inhrelid, inhseqno).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgInheritsId] = new JsonEncoder[PgInheritsId] { + override def unsafeEncode(a: PgInheritsId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""inhrelid":""") + JsonEncoder.long.unsafeEncode(a.inhrelid, indent, out) + out.write(",") + out.write(""""inhseqno":""") + JsonEncoder.int.unsafeEncode(a.inhseqno, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgInheritsId] = Ordering.by(x => (x.inhrelid, x.inhseqno)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepo.scala new file mode 100644 index 0000000000..49d874e195 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgInheritsRepo { + def delete(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgInheritsFields, PgInheritsRow] + def insert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, PgInheritsRow] + def select: SelectBuilder[PgInheritsFields, PgInheritsRow] + def selectAll: ZStream[ZConnection, Throwable, PgInheritsRow] + def selectById(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Option[PgInheritsRow]] + def update(row: PgInheritsRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgInheritsFields, PgInheritsRow] + def upsert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInheritsRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoImpl.scala new file mode 100644 index 0000000000..079127a2bc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoImpl.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgInheritsRepoImpl extends PgInheritsRepo { + override def delete(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_inherits where "inhrelid" = ${Segment.paramSegment(compositeId.inhrelid)(Setter.longSetter)} AND "inhseqno" = ${Segment.paramSegment(compositeId.inhseqno)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgInheritsFields, PgInheritsRow] = { + DeleteBuilder("pg_catalog.pg_inherits", PgInheritsFields) + } + override def insert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, PgInheritsRow] = { + sql"""insert into pg_catalog.pg_inherits("inhrelid", "inhparent", "inhseqno", "inhdetachpending") + values (${Segment.paramSegment(unsaved.inhrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.inhparent)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.inhseqno)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.inhdetachpending)(Setter.booleanSetter)}) + returning "inhrelid", "inhparent", "inhseqno", "inhdetachpending" + """.insertReturning(PgInheritsRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgInheritsFields, PgInheritsRow] = { + SelectBuilderSql("pg_catalog.pg_inherits", PgInheritsFields, PgInheritsRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgInheritsRow] = { + sql"""select "inhrelid", "inhparent", "inhseqno", "inhdetachpending" from pg_catalog.pg_inherits""".query(PgInheritsRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Option[PgInheritsRow]] = { + sql"""select "inhrelid", "inhparent", "inhseqno", "inhdetachpending" from pg_catalog.pg_inherits where "inhrelid" = ${Segment.paramSegment(compositeId.inhrelid)(Setter.longSetter)} AND "inhseqno" = ${Segment.paramSegment(compositeId.inhseqno)(Setter.intSetter)}""".query(PgInheritsRow.jdbcDecoder).selectOne + } + override def update(row: PgInheritsRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_inherits + set "inhparent" = ${Segment.paramSegment(row.inhparent)(Setter.longSetter)}::oid, + "inhdetachpending" = ${Segment.paramSegment(row.inhdetachpending)(Setter.booleanSetter)} + where "inhrelid" = ${Segment.paramSegment(compositeId.inhrelid)(Setter.longSetter)} AND "inhseqno" = ${Segment.paramSegment(compositeId.inhseqno)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgInheritsFields, PgInheritsRow] = { + UpdateBuilder("pg_catalog.pg_inherits", PgInheritsFields, PgInheritsRow.jdbcDecoder) + } + override def upsert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInheritsRow]] = { + sql"""insert into pg_catalog.pg_inherits("inhrelid", "inhparent", "inhseqno", "inhdetachpending") + values ( + ${Segment.paramSegment(unsaved.inhrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.inhparent)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.inhseqno)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.inhdetachpending)(Setter.booleanSetter)} + ) + on conflict ("inhrelid", "inhseqno") + do update set + "inhparent" = EXCLUDED."inhparent", + "inhdetachpending" = EXCLUDED."inhdetachpending" + returning "inhrelid", "inhparent", "inhseqno", "inhdetachpending"""".insertReturning(PgInheritsRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoMock.scala new file mode 100644 index 0000000000..64d7b6690e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgInheritsRepoMock(map: scala.collection.mutable.Map[PgInheritsId, PgInheritsRow] = scala.collection.mutable.Map.empty) extends PgInheritsRepo { + override def delete(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgInheritsFields, PgInheritsRow] = { + DeleteBuilderMock(DeleteParams.empty, PgInheritsFields, map) + } + override def insert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, PgInheritsRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgInheritsFields, PgInheritsRow] = { + SelectBuilderMock(PgInheritsFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgInheritsRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgInheritsId): ZIO[ZConnection, Throwable, Option[PgInheritsRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgInheritsRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgInheritsFields, PgInheritsRow] = { + UpdateBuilderMock(UpdateParams.empty, PgInheritsFields, map) + } + override def upsert(unsaved: PgInheritsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInheritsRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRow.scala new file mode 100644 index 0000000000..dee44ebea0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgInheritsRow( + inhrelid: /* oid */ Long, + inhparent: /* oid */ Long, + inhseqno: Int, + inhdetachpending: Boolean +){ + val compositeId: PgInheritsId = PgInheritsId(inhrelid, inhseqno) + } + +object PgInheritsRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgInheritsRow] = new JdbcDecoder[PgInheritsRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgInheritsRow) = + columIndex + 3 -> + PgInheritsRow( + inhrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + inhparent = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + inhseqno = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + inhdetachpending = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgInheritsRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val inhrelid = jsonObj.get("inhrelid").toRight("Missing field 'inhrelid'").flatMap(_.as(JsonDecoder.long)) + val inhparent = jsonObj.get("inhparent").toRight("Missing field 'inhparent'").flatMap(_.as(JsonDecoder.long)) + val inhseqno = jsonObj.get("inhseqno").toRight("Missing field 'inhseqno'").flatMap(_.as(JsonDecoder.int)) + val inhdetachpending = jsonObj.get("inhdetachpending").toRight("Missing field 'inhdetachpending'").flatMap(_.as(JsonDecoder.boolean)) + if (inhrelid.isRight && inhparent.isRight && inhseqno.isRight && inhdetachpending.isRight) + Right(PgInheritsRow(inhrelid = inhrelid.toOption.get, inhparent = inhparent.toOption.get, inhseqno = inhseqno.toOption.get, inhdetachpending = inhdetachpending.toOption.get)) + else Left(List[Either[String, Any]](inhrelid, inhparent, inhseqno, inhdetachpending).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgInheritsRow] = new JsonEncoder[PgInheritsRow] { + override def unsafeEncode(a: PgInheritsRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""inhrelid":""") + JsonEncoder.long.unsafeEncode(a.inhrelid, indent, out) + out.write(",") + out.write(""""inhparent":""") + JsonEncoder.long.unsafeEncode(a.inhparent, indent, out) + out.write(",") + out.write(""""inhseqno":""") + JsonEncoder.int.unsafeEncode(a.inhseqno, indent, out) + out.write(",") + out.write(""""inhdetachpending":""") + JsonEncoder.boolean.unsafeEncode(a.inhdetachpending, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsStructure.scala new file mode 100644 index 0000000000..cc31dfbe69 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_inherits/PgInheritsStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_inherits + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgInheritsStructure[Row](val prefix: Option[String], val extract: Row => PgInheritsRow, val merge: (Row, PgInheritsRow) => Row) + extends Relation[PgInheritsFields, PgInheritsRow, Row] + with PgInheritsFields[Row] { outer => + + override val inhrelid = new IdField[/* oid */ Long, Row](prefix, "inhrelid", None, Some("oid"))(x => extract(x).inhrelid, (row, value) => merge(row, extract(row).copy(inhrelid = value))) + override val inhparent = new Field[/* oid */ Long, Row](prefix, "inhparent", None, Some("oid"))(x => extract(x).inhparent, (row, value) => merge(row, extract(row).copy(inhparent = value))) + override val inhseqno = new IdField[Int, Row](prefix, "inhseqno", None, Some("int4"))(x => extract(x).inhseqno, (row, value) => merge(row, extract(row).copy(inhseqno = value))) + override val inhdetachpending = new Field[Boolean, Row](prefix, "inhdetachpending", None, None)(x => extract(x).inhdetachpending, (row, value) => merge(row, extract(row).copy(inhdetachpending = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](inhrelid, inhparent, inhseqno, inhdetachpending) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgInheritsRow, merge: (NewRow, PgInheritsRow) => NewRow): PgInheritsStructure[NewRow] = + new PgInheritsStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsFields.scala new file mode 100644 index 0000000000..9addacc9a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgInitPrivsFields[Row] { + val objoid: IdField[/* oid */ Long, Row] + val classoid: IdField[/* oid */ Long, Row] + val objsubid: IdField[Int, Row] + val privtype: Field[String, Row] + val initprivs: Field[Array[TypoAclItem], Row] +} +object PgInitPrivsFields extends PgInitPrivsStructure[PgInitPrivsRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsId.scala new file mode 100644 index 0000000000..3efaa863fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsId.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_init_privs` */ +case class PgInitPrivsId(objoid: /* oid */ Long, classoid: /* oid */ Long, objsubid: Int) +object PgInitPrivsId { + implicit lazy val jsonDecoder: JsonDecoder[PgInitPrivsId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + if (objoid.isRight && classoid.isRight && objsubid.isRight) + Right(PgInitPrivsId(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgInitPrivsId] = new JsonEncoder[PgInitPrivsId] { + override def unsafeEncode(a: PgInitPrivsId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgInitPrivsId] = Ordering.by(x => (x.objoid, x.classoid, x.objsubid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepo.scala new file mode 100644 index 0000000000..d0f61270fa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgInitPrivsRepo { + def delete(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgInitPrivsFields, PgInitPrivsRow] + def insert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, PgInitPrivsRow] + def select: SelectBuilder[PgInitPrivsFields, PgInitPrivsRow] + def selectAll: ZStream[ZConnection, Throwable, PgInitPrivsRow] + def selectById(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Option[PgInitPrivsRow]] + def update(row: PgInitPrivsRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgInitPrivsFields, PgInitPrivsRow] + def upsert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInitPrivsRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoImpl.scala new file mode 100644 index 0000000000..e80d6f14f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoImpl.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgInitPrivsRepoImpl extends PgInitPrivsRepo { + override def delete(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_init_privs where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + DeleteBuilder("pg_catalog.pg_init_privs", PgInitPrivsFields) + } + override def insert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, PgInitPrivsRow] = { + sql"""insert into pg_catalog.pg_init_privs("objoid", "classoid", "objsubid", "privtype", "initprivs") + values (${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.privtype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.initprivs)(TypoAclItem.arraySetter)}::_aclitem) + returning "objoid", "classoid", "objsubid", "privtype", "initprivs" + """.insertReturning(PgInitPrivsRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + SelectBuilderSql("pg_catalog.pg_init_privs", PgInitPrivsFields, PgInitPrivsRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgInitPrivsRow] = { + sql"""select "objoid", "classoid", "objsubid", "privtype", "initprivs" from pg_catalog.pg_init_privs""".query(PgInitPrivsRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Option[PgInitPrivsRow]] = { + sql"""select "objoid", "classoid", "objsubid", "privtype", "initprivs" from pg_catalog.pg_init_privs where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".query(PgInitPrivsRow.jdbcDecoder).selectOne + } + override def update(row: PgInitPrivsRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_init_privs + set "privtype" = ${Segment.paramSegment(row.privtype)(Setter.stringSetter)}::char, + "initprivs" = ${Segment.paramSegment(row.initprivs)(TypoAclItem.arraySetter)}::_aclitem + where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + UpdateBuilder("pg_catalog.pg_init_privs", PgInitPrivsFields, PgInitPrivsRow.jdbcDecoder) + } + override def upsert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInitPrivsRow]] = { + sql"""insert into pg_catalog.pg_init_privs("objoid", "classoid", "objsubid", "privtype", "initprivs") + values ( + ${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.privtype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.initprivs)(TypoAclItem.arraySetter)}::_aclitem + ) + on conflict ("objoid", "classoid", "objsubid") + do update set + "privtype" = EXCLUDED."privtype", + "initprivs" = EXCLUDED."initprivs" + returning "objoid", "classoid", "objsubid", "privtype", "initprivs"""".insertReturning(PgInitPrivsRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoMock.scala new file mode 100644 index 0000000000..1628ac339e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgInitPrivsRepoMock(map: scala.collection.mutable.Map[PgInitPrivsId, PgInitPrivsRow] = scala.collection.mutable.Map.empty) extends PgInitPrivsRepo { + override def delete(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + DeleteBuilderMock(DeleteParams.empty, PgInitPrivsFields, map) + } + override def insert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, PgInitPrivsRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + SelectBuilderMock(PgInitPrivsFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgInitPrivsRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgInitPrivsId): ZIO[ZConnection, Throwable, Option[PgInitPrivsRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgInitPrivsRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgInitPrivsFields, PgInitPrivsRow] = { + UpdateBuilderMock(UpdateParams.empty, PgInitPrivsFields, map) + } + override def upsert(unsaved: PgInitPrivsRow): ZIO[ZConnection, Throwable, UpdateResult[PgInitPrivsRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRow.scala new file mode 100644 index 0000000000..cdcbffda95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsRow.scala @@ -0,0 +1,70 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgInitPrivsRow( + objoid: /* oid */ Long, + classoid: /* oid */ Long, + objsubid: Int, + privtype: String, + initprivs: Array[TypoAclItem] +){ + val compositeId: PgInitPrivsId = PgInitPrivsId(objoid, classoid, objsubid) + } + +object PgInitPrivsRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgInitPrivsRow] = new JdbcDecoder[PgInitPrivsRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgInitPrivsRow) = + columIndex + 4 -> + PgInitPrivsRow( + objoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + objsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + privtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + initprivs = JdbcDecoder[Array[TypoAclItem]].unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgInitPrivsRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val privtype = jsonObj.get("privtype").toRight("Missing field 'privtype'").flatMap(_.as(JsonDecoder.string)) + val initprivs = jsonObj.get("initprivs").toRight("Missing field 'initprivs'").flatMap(_.as(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly))) + if (objoid.isRight && classoid.isRight && objsubid.isRight && privtype.isRight && initprivs.isRight) + Right(PgInitPrivsRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get, privtype = privtype.toOption.get, initprivs = initprivs.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid, privtype, initprivs).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgInitPrivsRow] = new JsonEncoder[PgInitPrivsRow] { + override def unsafeEncode(a: PgInitPrivsRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""privtype":""") + JsonEncoder.string.unsafeEncode(a.privtype, indent, out) + out.write(",") + out.write(""""initprivs":""") + JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly).unsafeEncode(a.initprivs, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsStructure.scala new file mode 100644 index 0000000000..234f9aa194 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_init_privs/PgInitPrivsStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_init_privs + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgInitPrivsStructure[Row](val prefix: Option[String], val extract: Row => PgInitPrivsRow, val merge: (Row, PgInitPrivsRow) => Row) + extends Relation[PgInitPrivsFields, PgInitPrivsRow, Row] + with PgInitPrivsFields[Row] { outer => + + override val objoid = new IdField[/* oid */ Long, Row](prefix, "objoid", None, Some("oid"))(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new IdField[/* oid */ Long, Row](prefix, "classoid", None, Some("oid"))(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val objsubid = new IdField[Int, Row](prefix, "objsubid", None, Some("int4"))(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val privtype = new Field[String, Row](prefix, "privtype", None, Some("char"))(x => extract(x).privtype, (row, value) => merge(row, extract(row).copy(privtype = value))) + override val initprivs = new Field[Array[TypoAclItem], Row](prefix, "initprivs", None, Some("_aclitem"))(x => extract(x).initprivs, (row, value) => merge(row, extract(row).copy(initprivs = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, objsubid, privtype, initprivs) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgInitPrivsRow, merge: (NewRow, PgInitPrivsRow) => NewRow): PgInitPrivsStructure[NewRow] = + new PgInitPrivsStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageFields.scala new file mode 100644 index 0000000000..1c19a7aedd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgLanguageFields[Row] { + val oid: IdField[PgLanguageId, Row] + val lanname: Field[String, Row] + val lanowner: Field[/* oid */ Long, Row] + val lanispl: Field[Boolean, Row] + val lanpltrusted: Field[Boolean, Row] + val lanplcallfoid: Field[/* oid */ Long, Row] + val laninline: Field[/* oid */ Long, Row] + val lanvalidator: Field[/* oid */ Long, Row] + val lanacl: OptField[Array[TypoAclItem], Row] +} +object PgLanguageFields extends PgLanguageStructure[PgLanguageRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageId.scala new file mode 100644 index 0000000000..cb94c76c24 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +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 `pg_catalog.pg_language` */ +case class PgLanguageId(value: /* oid */ Long) extends AnyVal +object PgLanguageId { + implicit lazy val arraySetter: Setter[Array[PgLanguageId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgLanguageId, /* oid */ Long] = Bijection[PgLanguageId, /* oid */ Long](_.value)(PgLanguageId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgLanguageId] = JdbcDecoder.longDecoder.map(PgLanguageId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgLanguageId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgLanguageId] = JsonDecoder.long.map(PgLanguageId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgLanguageId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgLanguageId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgLanguageId] = ParameterMetaData.instance[PgLanguageId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgLanguageId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepo.scala new file mode 100644 index 0000000000..2ec6e57578 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgLanguageRepo { + def delete(oid: PgLanguageId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgLanguageFields, PgLanguageRow] + def insert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, PgLanguageRow] + def select: SelectBuilder[PgLanguageFields, PgLanguageRow] + def selectAll: ZStream[ZConnection, Throwable, PgLanguageRow] + def selectById(oid: PgLanguageId): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] + def selectByIds(oids: Array[PgLanguageId]): ZStream[ZConnection, Throwable, PgLanguageRow] + def selectByUnique(lanname: String): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] + def update(row: PgLanguageRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgLanguageFields, PgLanguageRow] + def upsert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, UpdateResult[PgLanguageRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoImpl.scala new file mode 100644 index 0000000000..9339f10df2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoImpl.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgLanguageRepoImpl extends PgLanguageRepo { + override def delete(oid: PgLanguageId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_language where "oid" = ${Segment.paramSegment(oid)(PgLanguageId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgLanguageFields, PgLanguageRow] = { + DeleteBuilder("pg_catalog.pg_language", PgLanguageFields) + } + override def insert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, PgLanguageRow] = { + sql"""insert into pg_catalog.pg_language("oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl") + values (${Segment.paramSegment(unsaved.oid)(PgLanguageId.setter)}::oid, ${Segment.paramSegment(unsaved.lanname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.lanowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.lanispl)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.lanpltrusted)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.lanplcallfoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.laninline)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.lanvalidator)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.lanacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl" + """.insertReturning(PgLanguageRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgLanguageFields, PgLanguageRow] = { + SelectBuilderSql("pg_catalog.pg_language", PgLanguageFields, PgLanguageRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLanguageRow] = { + sql"""select "oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl" from pg_catalog.pg_language""".query(PgLanguageRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgLanguageId): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] = { + sql"""select "oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl" from pg_catalog.pg_language where "oid" = ${Segment.paramSegment(oid)(PgLanguageId.setter)}""".query(PgLanguageRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgLanguageId]): ZStream[ZConnection, Throwable, PgLanguageRow] = { + sql"""select "oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl" from pg_catalog.pg_language where "oid" = ANY(${Segment.paramSegment(oids)(PgLanguageId.arraySetter)})""".query(PgLanguageRow.jdbcDecoder).selectStream + } + override def selectByUnique(lanname: String): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] = { + sql"""select "lanname" + from pg_catalog.pg_language + where "lanname" = ${Segment.paramSegment(lanname)(Setter.stringSetter)} + """.query(PgLanguageRow.jdbcDecoder).selectOne + } + override def update(row: PgLanguageRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_language + set "lanname" = ${Segment.paramSegment(row.lanname)(Setter.stringSetter)}::name, + "lanowner" = ${Segment.paramSegment(row.lanowner)(Setter.longSetter)}::oid, + "lanispl" = ${Segment.paramSegment(row.lanispl)(Setter.booleanSetter)}, + "lanpltrusted" = ${Segment.paramSegment(row.lanpltrusted)(Setter.booleanSetter)}, + "lanplcallfoid" = ${Segment.paramSegment(row.lanplcallfoid)(Setter.longSetter)}::oid, + "laninline" = ${Segment.paramSegment(row.laninline)(Setter.longSetter)}::oid, + "lanvalidator" = ${Segment.paramSegment(row.lanvalidator)(Setter.longSetter)}::oid, + "lanacl" = ${Segment.paramSegment(row.lanacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgLanguageId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgLanguageFields, PgLanguageRow] = { + UpdateBuilder("pg_catalog.pg_language", PgLanguageFields, PgLanguageRow.jdbcDecoder) + } + override def upsert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, UpdateResult[PgLanguageRow]] = { + sql"""insert into pg_catalog.pg_language("oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgLanguageId.setter)}::oid, + ${Segment.paramSegment(unsaved.lanname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.lanowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.lanispl)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.lanpltrusted)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.lanplcallfoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.laninline)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.lanvalidator)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.lanacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "lanname" = EXCLUDED."lanname", + "lanowner" = EXCLUDED."lanowner", + "lanispl" = EXCLUDED."lanispl", + "lanpltrusted" = EXCLUDED."lanpltrusted", + "lanplcallfoid" = EXCLUDED."lanplcallfoid", + "laninline" = EXCLUDED."laninline", + "lanvalidator" = EXCLUDED."lanvalidator", + "lanacl" = EXCLUDED."lanacl" + returning "oid", "lanname", "lanowner", "lanispl", "lanpltrusted", "lanplcallfoid", "laninline", "lanvalidator", "lanacl"""".insertReturning(PgLanguageRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoMock.scala new file mode 100644 index 0000000000..fce14b9dd1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgLanguageRepoMock(map: scala.collection.mutable.Map[PgLanguageId, PgLanguageRow] = scala.collection.mutable.Map.empty) extends PgLanguageRepo { + override def delete(oid: PgLanguageId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgLanguageFields, PgLanguageRow] = { + DeleteBuilderMock(DeleteParams.empty, PgLanguageFields, map) + } + override def insert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, PgLanguageRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgLanguageFields, PgLanguageRow] = { + SelectBuilderMock(PgLanguageFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLanguageRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgLanguageId): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgLanguageId]): ZStream[ZConnection, Throwable, PgLanguageRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(lanname: String): ZIO[ZConnection, Throwable, Option[PgLanguageRow]] = { + ZIO.succeed(map.values.find(v => lanname == v.lanname)) + } + override def update(row: PgLanguageRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgLanguageFields, PgLanguageRow] = { + UpdateBuilderMock(UpdateParams.empty, PgLanguageFields, map) + } + override def upsert(unsaved: PgLanguageRow): ZIO[ZConnection, Throwable, UpdateResult[PgLanguageRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRow.scala new file mode 100644 index 0000000000..d683031de0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageRow.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgLanguageRow( + oid: PgLanguageId, + lanname: String, + lanowner: /* oid */ Long, + lanispl: Boolean, + lanpltrusted: Boolean, + lanplcallfoid: /* oid */ Long, + laninline: /* oid */ Long, + lanvalidator: /* oid */ Long, + lanacl: Option[Array[TypoAclItem]] +) + +object PgLanguageRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgLanguageRow] = new JdbcDecoder[PgLanguageRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgLanguageRow) = + columIndex + 8 -> + PgLanguageRow( + oid = PgLanguageId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + lanname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + lanowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + lanispl = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + lanpltrusted = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + lanplcallfoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + laninline = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + lanvalidator = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + lanacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgLanguageRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgLanguageId.jsonDecoder)) + val lanname = jsonObj.get("lanname").toRight("Missing field 'lanname'").flatMap(_.as(JsonDecoder.string)) + val lanowner = jsonObj.get("lanowner").toRight("Missing field 'lanowner'").flatMap(_.as(JsonDecoder.long)) + val lanispl = jsonObj.get("lanispl").toRight("Missing field 'lanispl'").flatMap(_.as(JsonDecoder.boolean)) + val lanpltrusted = jsonObj.get("lanpltrusted").toRight("Missing field 'lanpltrusted'").flatMap(_.as(JsonDecoder.boolean)) + val lanplcallfoid = jsonObj.get("lanplcallfoid").toRight("Missing field 'lanplcallfoid'").flatMap(_.as(JsonDecoder.long)) + val laninline = jsonObj.get("laninline").toRight("Missing field 'laninline'").flatMap(_.as(JsonDecoder.long)) + val lanvalidator = jsonObj.get("lanvalidator").toRight("Missing field 'lanvalidator'").flatMap(_.as(JsonDecoder.long)) + val lanacl = jsonObj.get("lanacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && lanname.isRight && lanowner.isRight && lanispl.isRight && lanpltrusted.isRight && lanplcallfoid.isRight && laninline.isRight && lanvalidator.isRight && lanacl.isRight) + Right(PgLanguageRow(oid = oid.toOption.get, lanname = lanname.toOption.get, lanowner = lanowner.toOption.get, lanispl = lanispl.toOption.get, lanpltrusted = lanpltrusted.toOption.get, lanplcallfoid = lanplcallfoid.toOption.get, laninline = laninline.toOption.get, lanvalidator = lanvalidator.toOption.get, lanacl = lanacl.toOption.get)) + else Left(List[Either[String, Any]](oid, lanname, lanowner, lanispl, lanpltrusted, lanplcallfoid, laninline, lanvalidator, lanacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgLanguageRow] = new JsonEncoder[PgLanguageRow] { + override def unsafeEncode(a: PgLanguageRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgLanguageId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""lanname":""") + JsonEncoder.string.unsafeEncode(a.lanname, indent, out) + out.write(",") + out.write(""""lanowner":""") + JsonEncoder.long.unsafeEncode(a.lanowner, indent, out) + out.write(",") + out.write(""""lanispl":""") + JsonEncoder.boolean.unsafeEncode(a.lanispl, indent, out) + out.write(",") + out.write(""""lanpltrusted":""") + JsonEncoder.boolean.unsafeEncode(a.lanpltrusted, indent, out) + out.write(",") + out.write(""""lanplcallfoid":""") + JsonEncoder.long.unsafeEncode(a.lanplcallfoid, indent, out) + out.write(",") + out.write(""""laninline":""") + JsonEncoder.long.unsafeEncode(a.laninline, indent, out) + out.write(",") + out.write(""""lanvalidator":""") + JsonEncoder.long.unsafeEncode(a.lanvalidator, indent, out) + out.write(",") + out.write(""""lanacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.lanacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageStructure.scala new file mode 100644 index 0000000000..c21a8f5692 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_language/PgLanguageStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_language + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgLanguageStructure[Row](val prefix: Option[String], val extract: Row => PgLanguageRow, val merge: (Row, PgLanguageRow) => Row) + extends Relation[PgLanguageFields, PgLanguageRow, Row] + with PgLanguageFields[Row] { outer => + + override val oid = new IdField[PgLanguageId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val lanname = new Field[String, Row](prefix, "lanname", None, Some("name"))(x => extract(x).lanname, (row, value) => merge(row, extract(row).copy(lanname = value))) + override val lanowner = new Field[/* oid */ Long, Row](prefix, "lanowner", None, Some("oid"))(x => extract(x).lanowner, (row, value) => merge(row, extract(row).copy(lanowner = value))) + override val lanispl = new Field[Boolean, Row](prefix, "lanispl", None, None)(x => extract(x).lanispl, (row, value) => merge(row, extract(row).copy(lanispl = value))) + override val lanpltrusted = new Field[Boolean, Row](prefix, "lanpltrusted", None, None)(x => extract(x).lanpltrusted, (row, value) => merge(row, extract(row).copy(lanpltrusted = value))) + override val lanplcallfoid = new Field[/* oid */ Long, Row](prefix, "lanplcallfoid", None, Some("oid"))(x => extract(x).lanplcallfoid, (row, value) => merge(row, extract(row).copy(lanplcallfoid = value))) + override val laninline = new Field[/* oid */ Long, Row](prefix, "laninline", None, Some("oid"))(x => extract(x).laninline, (row, value) => merge(row, extract(row).copy(laninline = value))) + override val lanvalidator = new Field[/* oid */ Long, Row](prefix, "lanvalidator", None, Some("oid"))(x => extract(x).lanvalidator, (row, value) => merge(row, extract(row).copy(lanvalidator = value))) + override val lanacl = new OptField[Array[TypoAclItem], Row](prefix, "lanacl", None, Some("_aclitem"))(x => extract(x).lanacl, (row, value) => merge(row, extract(row).copy(lanacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, lanname, lanowner, lanispl, lanpltrusted, lanplcallfoid, laninline, lanvalidator, lanacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgLanguageRow, merge: (NewRow, PgLanguageRow) => NewRow): PgLanguageStructure[NewRow] = + new PgLanguageStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectFields.scala new file mode 100644 index 0000000000..d669a611bc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import adventureworks.customtypes.TypoBytea +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgLargeobjectFields[Row] { + val loid: IdField[/* oid */ Long, Row] + val pageno: IdField[Int, Row] + val data: Field[TypoBytea, Row] +} +object PgLargeobjectFields extends PgLargeobjectStructure[PgLargeobjectRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectId.scala new file mode 100644 index 0000000000..3e12acf117 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_largeobject` */ +case class PgLargeobjectId(loid: /* oid */ Long, pageno: Int) +object PgLargeobjectId { + implicit lazy val jsonDecoder: JsonDecoder[PgLargeobjectId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val loid = jsonObj.get("loid").toRight("Missing field 'loid'").flatMap(_.as(JsonDecoder.long)) + val pageno = jsonObj.get("pageno").toRight("Missing field 'pageno'").flatMap(_.as(JsonDecoder.int)) + if (loid.isRight && pageno.isRight) + Right(PgLargeobjectId(loid = loid.toOption.get, pageno = pageno.toOption.get)) + else Left(List[Either[String, Any]](loid, pageno).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgLargeobjectId] = new JsonEncoder[PgLargeobjectId] { + override def unsafeEncode(a: PgLargeobjectId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""loid":""") + JsonEncoder.long.unsafeEncode(a.loid, indent, out) + out.write(",") + out.write(""""pageno":""") + JsonEncoder.int.unsafeEncode(a.pageno, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgLargeobjectId] = Ordering.by(x => (x.loid, x.pageno)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepo.scala new file mode 100644 index 0000000000..030cd777a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgLargeobjectRepo { + def delete(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgLargeobjectFields, PgLargeobjectRow] + def insert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, PgLargeobjectRow] + def select: SelectBuilder[PgLargeobjectFields, PgLargeobjectRow] + def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectRow] + def selectById(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Option[PgLargeobjectRow]] + def update(row: PgLargeobjectRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgLargeobjectFields, PgLargeobjectRow] + def upsert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoImpl.scala new file mode 100644 index 0000000000..c892758dd9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import adventureworks.customtypes.TypoBytea +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgLargeobjectRepoImpl extends PgLargeobjectRepo { + override def delete(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_largeobject where "loid" = ${Segment.paramSegment(compositeId.loid)(Setter.longSetter)} AND "pageno" = ${Segment.paramSegment(compositeId.pageno)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + DeleteBuilder("pg_catalog.pg_largeobject", PgLargeobjectFields) + } + override def insert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, PgLargeobjectRow] = { + sql"""insert into pg_catalog.pg_largeobject("loid", "pageno", "data") + values (${Segment.paramSegment(unsaved.loid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.pageno)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.data)(TypoBytea.setter)}::bytea) + returning "loid", "pageno", "data" + """.insertReturning(PgLargeobjectRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + SelectBuilderSql("pg_catalog.pg_largeobject", PgLargeobjectFields, PgLargeobjectRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectRow] = { + sql"""select "loid", "pageno", "data" from pg_catalog.pg_largeobject""".query(PgLargeobjectRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Option[PgLargeobjectRow]] = { + sql"""select "loid", "pageno", "data" from pg_catalog.pg_largeobject where "loid" = ${Segment.paramSegment(compositeId.loid)(Setter.longSetter)} AND "pageno" = ${Segment.paramSegment(compositeId.pageno)(Setter.intSetter)}""".query(PgLargeobjectRow.jdbcDecoder).selectOne + } + override def update(row: PgLargeobjectRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_largeobject + set "data" = ${Segment.paramSegment(row.data)(TypoBytea.setter)}::bytea + where "loid" = ${Segment.paramSegment(compositeId.loid)(Setter.longSetter)} AND "pageno" = ${Segment.paramSegment(compositeId.pageno)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + UpdateBuilder("pg_catalog.pg_largeobject", PgLargeobjectFields, PgLargeobjectRow.jdbcDecoder) + } + override def upsert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectRow]] = { + sql"""insert into pg_catalog.pg_largeobject("loid", "pageno", "data") + values ( + ${Segment.paramSegment(unsaved.loid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.pageno)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.data)(TypoBytea.setter)}::bytea + ) + on conflict ("loid", "pageno") + do update set + "data" = EXCLUDED."data" + returning "loid", "pageno", "data"""".insertReturning(PgLargeobjectRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoMock.scala new file mode 100644 index 0000000000..687fa890d6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgLargeobjectRepoMock(map: scala.collection.mutable.Map[PgLargeobjectId, PgLargeobjectRow] = scala.collection.mutable.Map.empty) extends PgLargeobjectRepo { + override def delete(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + DeleteBuilderMock(DeleteParams.empty, PgLargeobjectFields, map) + } + override def insert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, PgLargeobjectRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + SelectBuilderMock(PgLargeobjectFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgLargeobjectId): ZIO[ZConnection, Throwable, Option[PgLargeobjectRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgLargeobjectRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgLargeobjectFields, PgLargeobjectRow] = { + UpdateBuilderMock(UpdateParams.empty, PgLargeobjectFields, map) + } + override def upsert(unsaved: PgLargeobjectRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRow.scala new file mode 100644 index 0000000000..1609d04fbb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import adventureworks.customtypes.TypoBytea +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgLargeobjectRow( + loid: /* oid */ Long, + pageno: Int, + data: TypoBytea +){ + val compositeId: PgLargeobjectId = PgLargeobjectId(loid, pageno) + } + +object PgLargeobjectRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgLargeobjectRow] = new JdbcDecoder[PgLargeobjectRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgLargeobjectRow) = + columIndex + 2 -> + PgLargeobjectRow( + loid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + pageno = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + data = TypoBytea.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgLargeobjectRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val loid = jsonObj.get("loid").toRight("Missing field 'loid'").flatMap(_.as(JsonDecoder.long)) + val pageno = jsonObj.get("pageno").toRight("Missing field 'pageno'").flatMap(_.as(JsonDecoder.int)) + val data = jsonObj.get("data").toRight("Missing field 'data'").flatMap(_.as(TypoBytea.jsonDecoder)) + if (loid.isRight && pageno.isRight && data.isRight) + Right(PgLargeobjectRow(loid = loid.toOption.get, pageno = pageno.toOption.get, data = data.toOption.get)) + else Left(List[Either[String, Any]](loid, pageno, data).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgLargeobjectRow] = new JsonEncoder[PgLargeobjectRow] { + override def unsafeEncode(a: PgLargeobjectRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""loid":""") + JsonEncoder.long.unsafeEncode(a.loid, indent, out) + out.write(",") + out.write(""""pageno":""") + JsonEncoder.int.unsafeEncode(a.pageno, indent, out) + out.write(",") + out.write(""""data":""") + TypoBytea.jsonEncoder.unsafeEncode(a.data, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectStructure.scala new file mode 100644 index 0000000000..852a6a7fa5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject/PgLargeobjectStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject + +import adventureworks.customtypes.TypoBytea +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgLargeobjectStructure[Row](val prefix: Option[String], val extract: Row => PgLargeobjectRow, val merge: (Row, PgLargeobjectRow) => Row) + extends Relation[PgLargeobjectFields, PgLargeobjectRow, Row] + with PgLargeobjectFields[Row] { outer => + + override val loid = new IdField[/* oid */ Long, Row](prefix, "loid", None, Some("oid"))(x => extract(x).loid, (row, value) => merge(row, extract(row).copy(loid = value))) + override val pageno = new IdField[Int, Row](prefix, "pageno", None, Some("int4"))(x => extract(x).pageno, (row, value) => merge(row, extract(row).copy(pageno = value))) + override val data = new Field[TypoBytea, Row](prefix, "data", None, Some("bytea"))(x => extract(x).data, (row, value) => merge(row, extract(row).copy(data = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](loid, pageno, data) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgLargeobjectRow, merge: (NewRow, PgLargeobjectRow) => NewRow): PgLargeobjectStructure[NewRow] = + new PgLargeobjectStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataFields.scala new file mode 100644 index 0000000000..8f6ef3a3a7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgLargeobjectMetadataFields[Row] { + val oid: IdField[PgLargeobjectMetadataId, Row] + val lomowner: Field[/* oid */ Long, Row] + val lomacl: OptField[Array[TypoAclItem], Row] +} +object PgLargeobjectMetadataFields extends PgLargeobjectMetadataStructure[PgLargeobjectMetadataRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataId.scala new file mode 100644 index 0000000000..dc7afe9f7e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +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 `pg_catalog.pg_largeobject_metadata` */ +case class PgLargeobjectMetadataId(value: /* oid */ Long) extends AnyVal +object PgLargeobjectMetadataId { + implicit lazy val arraySetter: Setter[Array[PgLargeobjectMetadataId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgLargeobjectMetadataId, /* oid */ Long] = Bijection[PgLargeobjectMetadataId, /* oid */ Long](_.value)(PgLargeobjectMetadataId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgLargeobjectMetadataId] = JdbcDecoder.longDecoder.map(PgLargeobjectMetadataId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgLargeobjectMetadataId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgLargeobjectMetadataId] = JsonDecoder.long.map(PgLargeobjectMetadataId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgLargeobjectMetadataId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgLargeobjectMetadataId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgLargeobjectMetadataId] = ParameterMetaData.instance[PgLargeobjectMetadataId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgLargeobjectMetadataId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepo.scala new file mode 100644 index 0000000000..f4e03a180b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgLargeobjectMetadataRepo { + def delete(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] + def insert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, PgLargeobjectMetadataRow] + def select: SelectBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] + def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] + def selectById(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Option[PgLargeobjectMetadataRow]] + def selectByIds(oids: Array[PgLargeobjectMetadataId]): ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] + def update(row: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] + def upsert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectMetadataRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoImpl.scala new file mode 100644 index 0000000000..89264f64c9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoImpl.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgLargeobjectMetadataRepoImpl extends PgLargeobjectMetadataRepo { + override def delete(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_largeobject_metadata where "oid" = ${Segment.paramSegment(oid)(PgLargeobjectMetadataId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + DeleteBuilder("pg_catalog.pg_largeobject_metadata", PgLargeobjectMetadataFields) + } + override def insert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + sql"""insert into pg_catalog.pg_largeobject_metadata("oid", "lomowner", "lomacl") + values (${Segment.paramSegment(unsaved.oid)(PgLargeobjectMetadataId.setter)}::oid, ${Segment.paramSegment(unsaved.lomowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.lomacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "lomowner", "lomacl" + """.insertReturning(PgLargeobjectMetadataRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + SelectBuilderSql("pg_catalog.pg_largeobject_metadata", PgLargeobjectMetadataFields, PgLargeobjectMetadataRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + sql"""select "oid", "lomowner", "lomacl" from pg_catalog.pg_largeobject_metadata""".query(PgLargeobjectMetadataRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Option[PgLargeobjectMetadataRow]] = { + sql"""select "oid", "lomowner", "lomacl" from pg_catalog.pg_largeobject_metadata where "oid" = ${Segment.paramSegment(oid)(PgLargeobjectMetadataId.setter)}""".query(PgLargeobjectMetadataRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgLargeobjectMetadataId]): ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + sql"""select "oid", "lomowner", "lomacl" from pg_catalog.pg_largeobject_metadata where "oid" = ANY(${Segment.paramSegment(oids)(PgLargeobjectMetadataId.arraySetter)})""".query(PgLargeobjectMetadataRow.jdbcDecoder).selectStream + } + override def update(row: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_largeobject_metadata + set "lomowner" = ${Segment.paramSegment(row.lomowner)(Setter.longSetter)}::oid, + "lomacl" = ${Segment.paramSegment(row.lomacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgLargeobjectMetadataId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + UpdateBuilder("pg_catalog.pg_largeobject_metadata", PgLargeobjectMetadataFields, PgLargeobjectMetadataRow.jdbcDecoder) + } + override def upsert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectMetadataRow]] = { + sql"""insert into pg_catalog.pg_largeobject_metadata("oid", "lomowner", "lomacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgLargeobjectMetadataId.setter)}::oid, + ${Segment.paramSegment(unsaved.lomowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.lomacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "lomowner" = EXCLUDED."lomowner", + "lomacl" = EXCLUDED."lomacl" + returning "oid", "lomowner", "lomacl"""".insertReturning(PgLargeobjectMetadataRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoMock.scala new file mode 100644 index 0000000000..200cd28a25 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgLargeobjectMetadataRepoMock(map: scala.collection.mutable.Map[PgLargeobjectMetadataId, PgLargeobjectMetadataRow] = scala.collection.mutable.Map.empty) extends PgLargeobjectMetadataRepo { + override def delete(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + DeleteBuilderMock(DeleteParams.empty, PgLargeobjectMetadataFields, map) + } + override def insert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + SelectBuilderMock(PgLargeobjectMetadataFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgLargeobjectMetadataId): ZIO[ZConnection, Throwable, Option[PgLargeobjectMetadataRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgLargeobjectMetadataId]): ZStream[ZConnection, Throwable, PgLargeobjectMetadataRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def update(row: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow] = { + UpdateBuilderMock(UpdateParams.empty, PgLargeobjectMetadataFields, map) + } + override def upsert(unsaved: PgLargeobjectMetadataRow): ZIO[ZConnection, Throwable, UpdateResult[PgLargeobjectMetadataRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRow.scala new file mode 100644 index 0000000000..c7394e50d8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataRow.scala @@ -0,0 +1,56 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgLargeobjectMetadataRow( + oid: PgLargeobjectMetadataId, + lomowner: /* oid */ Long, + lomacl: Option[Array[TypoAclItem]] +) + +object PgLargeobjectMetadataRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgLargeobjectMetadataRow] = new JdbcDecoder[PgLargeobjectMetadataRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgLargeobjectMetadataRow) = + columIndex + 2 -> + PgLargeobjectMetadataRow( + oid = PgLargeobjectMetadataId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + lomowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + lomacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgLargeobjectMetadataRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgLargeobjectMetadataId.jsonDecoder)) + val lomowner = jsonObj.get("lomowner").toRight("Missing field 'lomowner'").flatMap(_.as(JsonDecoder.long)) + val lomacl = jsonObj.get("lomacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && lomowner.isRight && lomacl.isRight) + Right(PgLargeobjectMetadataRow(oid = oid.toOption.get, lomowner = lomowner.toOption.get, lomacl = lomacl.toOption.get)) + else Left(List[Either[String, Any]](oid, lomowner, lomacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgLargeobjectMetadataRow] = new JsonEncoder[PgLargeobjectMetadataRow] { + override def unsafeEncode(a: PgLargeobjectMetadataRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgLargeobjectMetadataId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""lomowner":""") + JsonEncoder.long.unsafeEncode(a.lomowner, indent, out) + out.write(",") + out.write(""""lomacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.lomacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataStructure.scala new file mode 100644 index 0000000000..38aad2d29b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_largeobject_metadata/PgLargeobjectMetadataStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_largeobject_metadata + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgLargeobjectMetadataStructure[Row](val prefix: Option[String], val extract: Row => PgLargeobjectMetadataRow, val merge: (Row, PgLargeobjectMetadataRow) => Row) + extends Relation[PgLargeobjectMetadataFields, PgLargeobjectMetadataRow, Row] + with PgLargeobjectMetadataFields[Row] { outer => + + override val oid = new IdField[PgLargeobjectMetadataId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val lomowner = new Field[/* oid */ Long, Row](prefix, "lomowner", None, Some("oid"))(x => extract(x).lomowner, (row, value) => merge(row, extract(row).copy(lomowner = value))) + override val lomacl = new OptField[Array[TypoAclItem], Row](prefix, "lomacl", None, Some("_aclitem"))(x => extract(x).lomacl, (row, value) => merge(row, extract(row).copy(lomacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, lomowner, lomacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgLargeobjectMetadataRow, merge: (NewRow, PgLargeobjectMetadataRow) => NewRow): PgLargeobjectMetadataStructure[NewRow] = + new PgLargeobjectMetadataStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewFields.scala new file mode 100644 index 0000000000..42f779d5be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewFields.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_locks + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.OptField + +trait PgLocksViewFields[Row] { + val locktype: OptField[String, Row] + val database: OptField[/* oid */ Long, Row] + val relation: OptField[/* oid */ Long, Row] + val page: OptField[Int, Row] + val tuple: OptField[TypoShort, Row] + val virtualxid: OptField[String, Row] + val transactionid: OptField[TypoXid, Row] + val classid: OptField[/* oid */ Long, Row] + val objid: OptField[/* oid */ Long, Row] + val objsubid: OptField[TypoShort, Row] + val virtualtransaction: OptField[String, Row] + val pid: OptField[Int, Row] + val mode: OptField[String, Row] + val granted: OptField[Boolean, Row] + val fastpath: OptField[Boolean, Row] + val waitstart: OptField[TypoInstant, Row] +} +object PgLocksViewFields extends PgLocksViewStructure[PgLocksViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepo.scala new file mode 100644 index 0000000000..52f77e75c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_locks + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgLocksViewRepo { + def select: SelectBuilder[PgLocksViewFields, PgLocksViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgLocksViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepoImpl.scala new file mode 100644 index 0000000000..18f9a8c4aa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_locks + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgLocksViewRepoImpl extends PgLocksViewRepo { + override def select: SelectBuilder[PgLocksViewFields, PgLocksViewRow] = { + SelectBuilderSql("pg_catalog.pg_locks", PgLocksViewFields, PgLocksViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgLocksViewRow] = { + sql"""select "locktype", "database", "relation", "page", "tuple", "virtualxid", "transactionid", "classid", "objid", "objsubid", "virtualtransaction", "pid", "mode", "granted", "fastpath", "waitstart"::text from pg_catalog.pg_locks""".query(PgLocksViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRow.scala new file mode 100644 index 0000000000..f6003ed397 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewRow.scala @@ -0,0 +1,136 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_locks + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgLocksViewRow( + locktype: /* nullability unknown */ Option[String], + database: /* nullability unknown */ Option[/* oid */ Long], + relation: /* nullability unknown */ Option[/* oid */ Long], + page: /* nullability unknown */ Option[Int], + tuple: /* nullability unknown */ Option[TypoShort], + virtualxid: /* nullability unknown */ Option[String], + transactionid: /* nullability unknown */ Option[TypoXid], + classid: /* nullability unknown */ Option[/* oid */ Long], + objid: /* nullability unknown */ Option[/* oid */ Long], + objsubid: /* nullability unknown */ Option[TypoShort], + virtualtransaction: /* nullability unknown */ Option[String], + pid: /* nullability unknown */ Option[Int], + mode: /* nullability unknown */ Option[String], + granted: /* nullability unknown */ Option[Boolean], + fastpath: /* nullability unknown */ Option[Boolean], + waitstart: /* nullability unknown */ Option[TypoInstant] +) + +object PgLocksViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgLocksViewRow] = new JdbcDecoder[PgLocksViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgLocksViewRow) = + columIndex + 15 -> + PgLocksViewRow( + locktype = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + database = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + relation = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + page = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + tuple = JdbcDecoder.optionDecoder(TypoShort.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + virtualxid = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + transactionid = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + classid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + objid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + objsubid = JdbcDecoder.optionDecoder(TypoShort.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + virtualtransaction = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 11, rs)._2, + mode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + granted = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 13, rs)._2, + fastpath = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 14, rs)._2, + waitstart = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgLocksViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val locktype = jsonObj.get("locktype").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val database = jsonObj.get("database").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val relation = jsonObj.get("relation").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val page = jsonObj.get("page").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val tuple = jsonObj.get("tuple").fold[Either[String, Option[TypoShort]]](Right(None))(_.as(JsonDecoder.option(TypoShort.jsonDecoder))) + val virtualxid = jsonObj.get("virtualxid").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val transactionid = jsonObj.get("transactionid").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val classid = jsonObj.get("classid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val objid = jsonObj.get("objid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val objsubid = jsonObj.get("objsubid").fold[Either[String, Option[TypoShort]]](Right(None))(_.as(JsonDecoder.option(TypoShort.jsonDecoder))) + val virtualtransaction = jsonObj.get("virtualtransaction").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val mode = jsonObj.get("mode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val granted = jsonObj.get("granted").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val fastpath = jsonObj.get("fastpath").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val waitstart = jsonObj.get("waitstart").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (locktype.isRight && database.isRight && relation.isRight && page.isRight && tuple.isRight && virtualxid.isRight && transactionid.isRight && classid.isRight && objid.isRight && objsubid.isRight && virtualtransaction.isRight && pid.isRight && mode.isRight && granted.isRight && fastpath.isRight && waitstart.isRight) + Right(PgLocksViewRow(locktype = locktype.toOption.get, database = database.toOption.get, relation = relation.toOption.get, page = page.toOption.get, tuple = tuple.toOption.get, virtualxid = virtualxid.toOption.get, transactionid = transactionid.toOption.get, classid = classid.toOption.get, objid = objid.toOption.get, objsubid = objsubid.toOption.get, virtualtransaction = virtualtransaction.toOption.get, pid = pid.toOption.get, mode = mode.toOption.get, granted = granted.toOption.get, fastpath = fastpath.toOption.get, waitstart = waitstart.toOption.get)) + else Left(List[Either[String, Any]](locktype, database, relation, page, tuple, virtualxid, transactionid, classid, objid, objsubid, virtualtransaction, pid, mode, granted, fastpath, waitstart).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgLocksViewRow] = new JsonEncoder[PgLocksViewRow] { + override def unsafeEncode(a: PgLocksViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""locktype":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.locktype, indent, out) + out.write(",") + out.write(""""database":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.database, indent, out) + out.write(",") + out.write(""""relation":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relation, indent, out) + out.write(",") + out.write(""""page":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.page, indent, out) + out.write(",") + out.write(""""tuple":""") + JsonEncoder.option(TypoShort.jsonEncoder).unsafeEncode(a.tuple, indent, out) + out.write(",") + out.write(""""virtualxid":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.virtualxid, indent, out) + out.write(",") + out.write(""""transactionid":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""classid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.classid, indent, out) + out.write(",") + out.write(""""objid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.objid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.option(TypoShort.jsonEncoder).unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""virtualtransaction":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.virtualtransaction, indent, out) + out.write(",") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""mode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.mode, indent, out) + out.write(",") + out.write(""""granted":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.granted, indent, out) + out.write(",") + out.write(""""fastpath":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.fastpath, indent, out) + out.write(",") + out.write(""""waitstart":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.waitstart, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewStructure.scala new file mode 100644 index 0000000000..89bd8e07b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_locks/PgLocksViewStructure.scala @@ -0,0 +1,43 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_locks + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgLocksViewStructure[Row](val prefix: Option[String], val extract: Row => PgLocksViewRow, val merge: (Row, PgLocksViewRow) => Row) + extends Relation[PgLocksViewFields, PgLocksViewRow, Row] + with PgLocksViewFields[Row] { outer => + + override val locktype = new OptField[String, Row](prefix, "locktype", None, None)(x => extract(x).locktype, (row, value) => merge(row, extract(row).copy(locktype = value))) + override val database = new OptField[/* oid */ Long, Row](prefix, "database", None, None)(x => extract(x).database, (row, value) => merge(row, extract(row).copy(database = value))) + override val relation = new OptField[/* oid */ Long, Row](prefix, "relation", None, None)(x => extract(x).relation, (row, value) => merge(row, extract(row).copy(relation = value))) + override val page = new OptField[Int, Row](prefix, "page", None, None)(x => extract(x).page, (row, value) => merge(row, extract(row).copy(page = value))) + override val tuple = new OptField[TypoShort, Row](prefix, "tuple", None, None)(x => extract(x).tuple, (row, value) => merge(row, extract(row).copy(tuple = value))) + override val virtualxid = new OptField[String, Row](prefix, "virtualxid", None, None)(x => extract(x).virtualxid, (row, value) => merge(row, extract(row).copy(virtualxid = value))) + override val transactionid = new OptField[TypoXid, Row](prefix, "transactionid", None, None)(x => extract(x).transactionid, (row, value) => merge(row, extract(row).copy(transactionid = value))) + override val classid = new OptField[/* oid */ Long, Row](prefix, "classid", None, None)(x => extract(x).classid, (row, value) => merge(row, extract(row).copy(classid = value))) + override val objid = new OptField[/* oid */ Long, Row](prefix, "objid", None, None)(x => extract(x).objid, (row, value) => merge(row, extract(row).copy(objid = value))) + override val objsubid = new OptField[TypoShort, Row](prefix, "objsubid", None, None)(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val virtualtransaction = new OptField[String, Row](prefix, "virtualtransaction", None, None)(x => extract(x).virtualtransaction, (row, value) => merge(row, extract(row).copy(virtualtransaction = value))) + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val mode = new OptField[String, Row](prefix, "mode", None, None)(x => extract(x).mode, (row, value) => merge(row, extract(row).copy(mode = value))) + override val granted = new OptField[Boolean, Row](prefix, "granted", None, None)(x => extract(x).granted, (row, value) => merge(row, extract(row).copy(granted = value))) + override val fastpath = new OptField[Boolean, Row](prefix, "fastpath", None, None)(x => extract(x).fastpath, (row, value) => merge(row, extract(row).copy(fastpath = value))) + override val waitstart = new OptField[TypoInstant, Row](prefix, "waitstart", Some("text"), None)(x => extract(x).waitstart, (row, value) => merge(row, extract(row).copy(waitstart = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](locktype, database, relation, page, tuple, virtualxid, transactionid, classid, objid, objsubid, virtualtransaction, pid, mode, granted, fastpath, waitstart) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgLocksViewRow, merge: (NewRow, PgLocksViewRow) => NewRow): PgLocksViewStructure[NewRow] = + new PgLocksViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewFields.scala new file mode 100644 index 0000000000..c1e4ff88aa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_matviews + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgMatviewsViewFields[Row] { + val schemaname: OptField[String, Row] + val matviewname: Field[String, Row] + val matviewowner: OptField[String, Row] + val tablespace: OptField[String, Row] + val hasindexes: Field[Boolean, Row] + val ispopulated: Field[Boolean, Row] + val definition: OptField[String, Row] +} +object PgMatviewsViewFields extends PgMatviewsViewStructure[PgMatviewsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepo.scala new file mode 100644 index 0000000000..b29c68bb99 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_matviews + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgMatviewsViewRepo { + def select: SelectBuilder[PgMatviewsViewFields, PgMatviewsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgMatviewsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepoImpl.scala new file mode 100644 index 0000000000..f0b171b51d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_matviews + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgMatviewsViewRepoImpl extends PgMatviewsViewRepo { + override def select: SelectBuilder[PgMatviewsViewFields, PgMatviewsViewRow] = { + SelectBuilderSql("pg_catalog.pg_matviews", PgMatviewsViewFields, PgMatviewsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgMatviewsViewRow] = { + sql"""select "schemaname", "matviewname", "matviewowner", "tablespace", "hasindexes", "ispopulated", "definition" from pg_catalog.pg_matviews""".query(PgMatviewsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRow.scala new file mode 100644 index 0000000000..3955db51f3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewRow.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_matviews + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgMatviewsViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + matviewname: String, + matviewowner: /* nullability unknown */ Option[String], + /** Points to [[pg_tablespace.PgTablespaceRow.spcname]] */ + tablespace: Option[String], + /** Points to [[pg_class.PgClassRow.relhasindex]] */ + hasindexes: Boolean, + /** Points to [[pg_class.PgClassRow.relispopulated]] */ + ispopulated: Boolean, + definition: /* nullability unknown */ Option[String] +) + +object PgMatviewsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgMatviewsViewRow] = new JdbcDecoder[PgMatviewsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgMatviewsViewRow) = + columIndex + 6 -> + PgMatviewsViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + matviewname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + matviewowner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tablespace = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + hasindexes = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + ispopulated = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + definition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgMatviewsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val matviewname = jsonObj.get("matviewname").toRight("Missing field 'matviewname'").flatMap(_.as(JsonDecoder.string)) + val matviewowner = jsonObj.get("matviewowner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablespace = jsonObj.get("tablespace").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val hasindexes = jsonObj.get("hasindexes").toRight("Missing field 'hasindexes'").flatMap(_.as(JsonDecoder.boolean)) + val ispopulated = jsonObj.get("ispopulated").toRight("Missing field 'ispopulated'").flatMap(_.as(JsonDecoder.boolean)) + val definition = jsonObj.get("definition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (schemaname.isRight && matviewname.isRight && matviewowner.isRight && tablespace.isRight && hasindexes.isRight && ispopulated.isRight && definition.isRight) + Right(PgMatviewsViewRow(schemaname = schemaname.toOption.get, matviewname = matviewname.toOption.get, matviewowner = matviewowner.toOption.get, tablespace = tablespace.toOption.get, hasindexes = hasindexes.toOption.get, ispopulated = ispopulated.toOption.get, definition = definition.toOption.get)) + else Left(List[Either[String, Any]](schemaname, matviewname, matviewowner, tablespace, hasindexes, ispopulated, definition).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgMatviewsViewRow] = new JsonEncoder[PgMatviewsViewRow] { + override def unsafeEncode(a: PgMatviewsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""matviewname":""") + JsonEncoder.string.unsafeEncode(a.matviewname, indent, out) + out.write(",") + out.write(""""matviewowner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.matviewowner, indent, out) + out.write(",") + out.write(""""tablespace":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tablespace, indent, out) + out.write(",") + out.write(""""hasindexes":""") + JsonEncoder.boolean.unsafeEncode(a.hasindexes, indent, out) + out.write(",") + out.write(""""ispopulated":""") + JsonEncoder.boolean.unsafeEncode(a.ispopulated, indent, out) + out.write(",") + out.write(""""definition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.definition, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewStructure.scala new file mode 100644 index 0000000000..6963f888c9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_matviews/PgMatviewsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_matviews + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgMatviewsViewStructure[Row](val prefix: Option[String], val extract: Row => PgMatviewsViewRow, val merge: (Row, PgMatviewsViewRow) => Row) + extends Relation[PgMatviewsViewFields, PgMatviewsViewRow, Row] + with PgMatviewsViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val matviewname = new Field[String, Row](prefix, "matviewname", None, None)(x => extract(x).matviewname, (row, value) => merge(row, extract(row).copy(matviewname = value))) + override val matviewowner = new OptField[String, Row](prefix, "matviewowner", None, None)(x => extract(x).matviewowner, (row, value) => merge(row, extract(row).copy(matviewowner = value))) + override val tablespace = new OptField[String, Row](prefix, "tablespace", None, None)(x => extract(x).tablespace, (row, value) => merge(row, extract(row).copy(tablespace = value))) + override val hasindexes = new Field[Boolean, Row](prefix, "hasindexes", None, None)(x => extract(x).hasindexes, (row, value) => merge(row, extract(row).copy(hasindexes = value))) + override val ispopulated = new Field[Boolean, Row](prefix, "ispopulated", None, None)(x => extract(x).ispopulated, (row, value) => merge(row, extract(row).copy(ispopulated = value))) + override val definition = new OptField[String, Row](prefix, "definition", None, None)(x => extract(x).definition, (row, value) => merge(row, extract(row).copy(definition = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, matviewname, matviewowner, tablespace, hasindexes, ispopulated, definition) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgMatviewsViewRow, merge: (NewRow, PgMatviewsViewRow) => NewRow): PgMatviewsViewStructure[NewRow] = + new PgMatviewsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceFields.scala new file mode 100644 index 0000000000..02ac158630 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgNamespaceFields[Row] { + val oid: IdField[PgNamespaceId, Row] + val nspname: Field[String, Row] + val nspowner: Field[/* oid */ Long, Row] + val nspacl: OptField[Array[TypoAclItem], Row] +} +object PgNamespaceFields extends PgNamespaceStructure[PgNamespaceRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceId.scala new file mode 100644 index 0000000000..b3d18298f6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +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 `pg_catalog.pg_namespace` */ +case class PgNamespaceId(value: /* oid */ Long) extends AnyVal +object PgNamespaceId { + implicit lazy val arraySetter: Setter[Array[PgNamespaceId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgNamespaceId, /* oid */ Long] = Bijection[PgNamespaceId, /* oid */ Long](_.value)(PgNamespaceId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgNamespaceId] = JdbcDecoder.longDecoder.map(PgNamespaceId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgNamespaceId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgNamespaceId] = JsonDecoder.long.map(PgNamespaceId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgNamespaceId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgNamespaceId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgNamespaceId] = ParameterMetaData.instance[PgNamespaceId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgNamespaceId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepo.scala new file mode 100644 index 0000000000..015045bd02 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgNamespaceRepo { + def delete(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgNamespaceFields, PgNamespaceRow] + def insert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, PgNamespaceRow] + def select: SelectBuilder[PgNamespaceFields, PgNamespaceRow] + def selectAll: ZStream[ZConnection, Throwable, PgNamespaceRow] + def selectById(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] + def selectByIds(oids: Array[PgNamespaceId]): ZStream[ZConnection, Throwable, PgNamespaceRow] + def selectByUnique(nspname: String): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] + def update(row: PgNamespaceRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgNamespaceFields, PgNamespaceRow] + def upsert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgNamespaceRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoImpl.scala new file mode 100644 index 0000000000..74f81bdb9c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoImpl.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgNamespaceRepoImpl extends PgNamespaceRepo { + override def delete(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_namespace where "oid" = ${Segment.paramSegment(oid)(PgNamespaceId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgNamespaceFields, PgNamespaceRow] = { + DeleteBuilder("pg_catalog.pg_namespace", PgNamespaceFields) + } + override def insert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, PgNamespaceRow] = { + sql"""insert into pg_catalog.pg_namespace("oid", "nspname", "nspowner", "nspacl") + values (${Segment.paramSegment(unsaved.oid)(PgNamespaceId.setter)}::oid, ${Segment.paramSegment(unsaved.nspname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.nspowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.nspacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "nspname", "nspowner", "nspacl" + """.insertReturning(PgNamespaceRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgNamespaceFields, PgNamespaceRow] = { + SelectBuilderSql("pg_catalog.pg_namespace", PgNamespaceFields, PgNamespaceRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgNamespaceRow] = { + sql"""select "oid", "nspname", "nspowner", "nspacl" from pg_catalog.pg_namespace""".query(PgNamespaceRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] = { + sql"""select "oid", "nspname", "nspowner", "nspacl" from pg_catalog.pg_namespace where "oid" = ${Segment.paramSegment(oid)(PgNamespaceId.setter)}""".query(PgNamespaceRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgNamespaceId]): ZStream[ZConnection, Throwable, PgNamespaceRow] = { + sql"""select "oid", "nspname", "nspowner", "nspacl" from pg_catalog.pg_namespace where "oid" = ANY(${Segment.paramSegment(oids)(PgNamespaceId.arraySetter)})""".query(PgNamespaceRow.jdbcDecoder).selectStream + } + override def selectByUnique(nspname: String): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] = { + sql"""select "nspname" + from pg_catalog.pg_namespace + where "nspname" = ${Segment.paramSegment(nspname)(Setter.stringSetter)} + """.query(PgNamespaceRow.jdbcDecoder).selectOne + } + override def update(row: PgNamespaceRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_namespace + set "nspname" = ${Segment.paramSegment(row.nspname)(Setter.stringSetter)}::name, + "nspowner" = ${Segment.paramSegment(row.nspowner)(Setter.longSetter)}::oid, + "nspacl" = ${Segment.paramSegment(row.nspacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgNamespaceId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgNamespaceFields, PgNamespaceRow] = { + UpdateBuilder("pg_catalog.pg_namespace", PgNamespaceFields, PgNamespaceRow.jdbcDecoder) + } + override def upsert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgNamespaceRow]] = { + sql"""insert into pg_catalog.pg_namespace("oid", "nspname", "nspowner", "nspacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgNamespaceId.setter)}::oid, + ${Segment.paramSegment(unsaved.nspname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.nspowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.nspacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "nspname" = EXCLUDED."nspname", + "nspowner" = EXCLUDED."nspowner", + "nspacl" = EXCLUDED."nspacl" + returning "oid", "nspname", "nspowner", "nspacl"""".insertReturning(PgNamespaceRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoMock.scala new file mode 100644 index 0000000000..649172a5c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgNamespaceRepoMock(map: scala.collection.mutable.Map[PgNamespaceId, PgNamespaceRow] = scala.collection.mutable.Map.empty) extends PgNamespaceRepo { + override def delete(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgNamespaceFields, PgNamespaceRow] = { + DeleteBuilderMock(DeleteParams.empty, PgNamespaceFields, map) + } + override def insert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, PgNamespaceRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgNamespaceFields, PgNamespaceRow] = { + SelectBuilderMock(PgNamespaceFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgNamespaceRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgNamespaceId): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgNamespaceId]): ZStream[ZConnection, Throwable, PgNamespaceRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(nspname: String): ZIO[ZConnection, Throwable, Option[PgNamespaceRow]] = { + ZIO.succeed(map.values.find(v => nspname == v.nspname)) + } + override def update(row: PgNamespaceRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgNamespaceFields, PgNamespaceRow] = { + UpdateBuilderMock(UpdateParams.empty, PgNamespaceFields, map) + } + override def upsert(unsaved: PgNamespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgNamespaceRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRow.scala new file mode 100644 index 0000000000..fee3eda9a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceRow.scala @@ -0,0 +1,62 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgNamespaceRow( + oid: PgNamespaceId, + nspname: String, + nspowner: /* oid */ Long, + nspacl: Option[Array[TypoAclItem]] +) + +object PgNamespaceRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgNamespaceRow] = new JdbcDecoder[PgNamespaceRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgNamespaceRow) = + columIndex + 3 -> + PgNamespaceRow( + oid = PgNamespaceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + nspname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + nspowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + nspacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgNamespaceRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgNamespaceId.jsonDecoder)) + val nspname = jsonObj.get("nspname").toRight("Missing field 'nspname'").flatMap(_.as(JsonDecoder.string)) + val nspowner = jsonObj.get("nspowner").toRight("Missing field 'nspowner'").flatMap(_.as(JsonDecoder.long)) + val nspacl = jsonObj.get("nspacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && nspname.isRight && nspowner.isRight && nspacl.isRight) + Right(PgNamespaceRow(oid = oid.toOption.get, nspname = nspname.toOption.get, nspowner = nspowner.toOption.get, nspacl = nspacl.toOption.get)) + else Left(List[Either[String, Any]](oid, nspname, nspowner, nspacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgNamespaceRow] = new JsonEncoder[PgNamespaceRow] { + override def unsafeEncode(a: PgNamespaceRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgNamespaceId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""nspname":""") + JsonEncoder.string.unsafeEncode(a.nspname, indent, out) + out.write(",") + out.write(""""nspowner":""") + JsonEncoder.long.unsafeEncode(a.nspowner, indent, out) + out.write(",") + out.write(""""nspacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.nspacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceStructure.scala new file mode 100644 index 0000000000..74ecca8c06 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_namespace/PgNamespaceStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_namespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgNamespaceStructure[Row](val prefix: Option[String], val extract: Row => PgNamespaceRow, val merge: (Row, PgNamespaceRow) => Row) + extends Relation[PgNamespaceFields, PgNamespaceRow, Row] + with PgNamespaceFields[Row] { outer => + + override val oid = new IdField[PgNamespaceId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val nspname = new Field[String, Row](prefix, "nspname", None, Some("name"))(x => extract(x).nspname, (row, value) => merge(row, extract(row).copy(nspname = value))) + override val nspowner = new Field[/* oid */ Long, Row](prefix, "nspowner", None, Some("oid"))(x => extract(x).nspowner, (row, value) => merge(row, extract(row).copy(nspowner = value))) + override val nspacl = new OptField[Array[TypoAclItem], Row](prefix, "nspacl", None, Some("_aclitem"))(x => extract(x).nspacl, (row, value) => merge(row, extract(row).copy(nspacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, nspname, nspowner, nspacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgNamespaceRow, merge: (NewRow, PgNamespaceRow) => NewRow): PgNamespaceStructure[NewRow] = + new PgNamespaceStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassFields.scala new file mode 100644 index 0000000000..62bf390f4a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgOpclassFields[Row] { + val oid: IdField[PgOpclassId, Row] + val opcmethod: Field[/* oid */ Long, Row] + val opcname: Field[String, Row] + val opcnamespace: Field[/* oid */ Long, Row] + val opcowner: Field[/* oid */ Long, Row] + val opcfamily: Field[/* oid */ Long, Row] + val opcintype: Field[/* oid */ Long, Row] + val opcdefault: Field[Boolean, Row] + val opckeytype: Field[/* oid */ Long, Row] +} +object PgOpclassFields extends PgOpclassStructure[PgOpclassRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassId.scala new file mode 100644 index 0000000000..8bff9f4968 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +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 `pg_catalog.pg_opclass` */ +case class PgOpclassId(value: /* oid */ Long) extends AnyVal +object PgOpclassId { + implicit lazy val arraySetter: Setter[Array[PgOpclassId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgOpclassId, /* oid */ Long] = Bijection[PgOpclassId, /* oid */ Long](_.value)(PgOpclassId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgOpclassId] = JdbcDecoder.longDecoder.map(PgOpclassId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgOpclassId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgOpclassId] = JsonDecoder.long.map(PgOpclassId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgOpclassId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgOpclassId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgOpclassId] = ParameterMetaData.instance[PgOpclassId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgOpclassId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepo.scala new file mode 100644 index 0000000000..101c54625b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgOpclassRepo { + def delete(oid: PgOpclassId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgOpclassFields, PgOpclassRow] + def insert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, PgOpclassRow] + def select: SelectBuilder[PgOpclassFields, PgOpclassRow] + def selectAll: ZStream[ZConnection, Throwable, PgOpclassRow] + def selectById(oid: PgOpclassId): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] + def selectByIds(oids: Array[PgOpclassId]): ZStream[ZConnection, Throwable, PgOpclassRow] + def selectByUnique(opcmethod: /* oid */ Long, opcname: String, opcnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] + def update(row: PgOpclassRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgOpclassFields, PgOpclassRow] + def upsert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpclassRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoImpl.scala new file mode 100644 index 0000000000..7305093719 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgOpclassRepoImpl extends PgOpclassRepo { + override def delete(oid: PgOpclassId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_opclass where "oid" = ${Segment.paramSegment(oid)(PgOpclassId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgOpclassFields, PgOpclassRow] = { + DeleteBuilder("pg_catalog.pg_opclass", PgOpclassFields) + } + override def insert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, PgOpclassRow] = { + sql"""insert into pg_catalog.pg_opclass("oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype") + values (${Segment.paramSegment(unsaved.oid)(PgOpclassId.setter)}::oid, ${Segment.paramSegment(unsaved.opcmethod)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opcname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.opcnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opcowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opcfamily)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opcintype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opcdefault)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.opckeytype)(Setter.longSetter)}::oid) + returning "oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype" + """.insertReturning(PgOpclassRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgOpclassFields, PgOpclassRow] = { + SelectBuilderSql("pg_catalog.pg_opclass", PgOpclassFields, PgOpclassRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOpclassRow] = { + sql"""select "oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype" from pg_catalog.pg_opclass""".query(PgOpclassRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgOpclassId): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] = { + sql"""select "oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype" from pg_catalog.pg_opclass where "oid" = ${Segment.paramSegment(oid)(PgOpclassId.setter)}""".query(PgOpclassRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgOpclassId]): ZStream[ZConnection, Throwable, PgOpclassRow] = { + sql"""select "oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype" from pg_catalog.pg_opclass where "oid" = ANY(${Segment.paramSegment(oids)(PgOpclassId.arraySetter)})""".query(PgOpclassRow.jdbcDecoder).selectStream + } + override def selectByUnique(opcmethod: /* oid */ Long, opcname: String, opcnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] = { + sql"""select "opcmethod", "opcname", "opcnamespace" + from pg_catalog.pg_opclass + where "opcmethod" = ${Segment.paramSegment(opcmethod)(Setter.longSetter)} AND "opcname" = ${Segment.paramSegment(opcname)(Setter.stringSetter)} AND "opcnamespace" = ${Segment.paramSegment(opcnamespace)(Setter.longSetter)} + """.query(PgOpclassRow.jdbcDecoder).selectOne + } + override def update(row: PgOpclassRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_opclass + set "opcmethod" = ${Segment.paramSegment(row.opcmethod)(Setter.longSetter)}::oid, + "opcname" = ${Segment.paramSegment(row.opcname)(Setter.stringSetter)}::name, + "opcnamespace" = ${Segment.paramSegment(row.opcnamespace)(Setter.longSetter)}::oid, + "opcowner" = ${Segment.paramSegment(row.opcowner)(Setter.longSetter)}::oid, + "opcfamily" = ${Segment.paramSegment(row.opcfamily)(Setter.longSetter)}::oid, + "opcintype" = ${Segment.paramSegment(row.opcintype)(Setter.longSetter)}::oid, + "opcdefault" = ${Segment.paramSegment(row.opcdefault)(Setter.booleanSetter)}, + "opckeytype" = ${Segment.paramSegment(row.opckeytype)(Setter.longSetter)}::oid + where "oid" = ${Segment.paramSegment(oid)(PgOpclassId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgOpclassFields, PgOpclassRow] = { + UpdateBuilder("pg_catalog.pg_opclass", PgOpclassFields, PgOpclassRow.jdbcDecoder) + } + override def upsert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpclassRow]] = { + sql"""insert into pg_catalog.pg_opclass("oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype") + values ( + ${Segment.paramSegment(unsaved.oid)(PgOpclassId.setter)}::oid, + ${Segment.paramSegment(unsaved.opcmethod)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opcname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.opcnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opcowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opcfamily)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opcintype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opcdefault)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.opckeytype)(Setter.longSetter)}::oid + ) + on conflict ("oid") + do update set + "opcmethod" = EXCLUDED."opcmethod", + "opcname" = EXCLUDED."opcname", + "opcnamespace" = EXCLUDED."opcnamespace", + "opcowner" = EXCLUDED."opcowner", + "opcfamily" = EXCLUDED."opcfamily", + "opcintype" = EXCLUDED."opcintype", + "opcdefault" = EXCLUDED."opcdefault", + "opckeytype" = EXCLUDED."opckeytype" + returning "oid", "opcmethod", "opcname", "opcnamespace", "opcowner", "opcfamily", "opcintype", "opcdefault", "opckeytype"""".insertReturning(PgOpclassRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoMock.scala new file mode 100644 index 0000000000..c8302b24e1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgOpclassRepoMock(map: scala.collection.mutable.Map[PgOpclassId, PgOpclassRow] = scala.collection.mutable.Map.empty) extends PgOpclassRepo { + override def delete(oid: PgOpclassId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgOpclassFields, PgOpclassRow] = { + DeleteBuilderMock(DeleteParams.empty, PgOpclassFields, map) + } + override def insert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, PgOpclassRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgOpclassFields, PgOpclassRow] = { + SelectBuilderMock(PgOpclassFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOpclassRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgOpclassId): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgOpclassId]): ZStream[ZConnection, Throwable, PgOpclassRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(opcmethod: /* oid */ Long, opcname: String, opcnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpclassRow]] = { + ZIO.succeed(map.values.find(v => opcmethod == v.opcmethod && opcname == v.opcname && opcnamespace == v.opcnamespace)) + } + override def update(row: PgOpclassRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgOpclassFields, PgOpclassRow] = { + UpdateBuilderMock(UpdateParams.empty, PgOpclassFields, map) + } + override def upsert(unsaved: PgOpclassRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpclassRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRow.scala new file mode 100644 index 0000000000..3aaa454439 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgOpclassRow( + oid: PgOpclassId, + opcmethod: /* oid */ Long, + opcname: String, + opcnamespace: /* oid */ Long, + opcowner: /* oid */ Long, + opcfamily: /* oid */ Long, + opcintype: /* oid */ Long, + opcdefault: Boolean, + opckeytype: /* oid */ Long +) + +object PgOpclassRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgOpclassRow] = new JdbcDecoder[PgOpclassRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgOpclassRow) = + columIndex + 8 -> + PgOpclassRow( + oid = PgOpclassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + opcmethod = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + opcname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + opcnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + opcowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + opcfamily = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + opcintype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + opcdefault = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + opckeytype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgOpclassRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgOpclassId.jsonDecoder)) + val opcmethod = jsonObj.get("opcmethod").toRight("Missing field 'opcmethod'").flatMap(_.as(JsonDecoder.long)) + val opcname = jsonObj.get("opcname").toRight("Missing field 'opcname'").flatMap(_.as(JsonDecoder.string)) + val opcnamespace = jsonObj.get("opcnamespace").toRight("Missing field 'opcnamespace'").flatMap(_.as(JsonDecoder.long)) + val opcowner = jsonObj.get("opcowner").toRight("Missing field 'opcowner'").flatMap(_.as(JsonDecoder.long)) + val opcfamily = jsonObj.get("opcfamily").toRight("Missing field 'opcfamily'").flatMap(_.as(JsonDecoder.long)) + val opcintype = jsonObj.get("opcintype").toRight("Missing field 'opcintype'").flatMap(_.as(JsonDecoder.long)) + val opcdefault = jsonObj.get("opcdefault").toRight("Missing field 'opcdefault'").flatMap(_.as(JsonDecoder.boolean)) + val opckeytype = jsonObj.get("opckeytype").toRight("Missing field 'opckeytype'").flatMap(_.as(JsonDecoder.long)) + if (oid.isRight && opcmethod.isRight && opcname.isRight && opcnamespace.isRight && opcowner.isRight && opcfamily.isRight && opcintype.isRight && opcdefault.isRight && opckeytype.isRight) + Right(PgOpclassRow(oid = oid.toOption.get, opcmethod = opcmethod.toOption.get, opcname = opcname.toOption.get, opcnamespace = opcnamespace.toOption.get, opcowner = opcowner.toOption.get, opcfamily = opcfamily.toOption.get, opcintype = opcintype.toOption.get, opcdefault = opcdefault.toOption.get, opckeytype = opckeytype.toOption.get)) + else Left(List[Either[String, Any]](oid, opcmethod, opcname, opcnamespace, opcowner, opcfamily, opcintype, opcdefault, opckeytype).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgOpclassRow] = new JsonEncoder[PgOpclassRow] { + override def unsafeEncode(a: PgOpclassRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgOpclassId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""opcmethod":""") + JsonEncoder.long.unsafeEncode(a.opcmethod, indent, out) + out.write(",") + out.write(""""opcname":""") + JsonEncoder.string.unsafeEncode(a.opcname, indent, out) + out.write(",") + out.write(""""opcnamespace":""") + JsonEncoder.long.unsafeEncode(a.opcnamespace, indent, out) + out.write(",") + out.write(""""opcowner":""") + JsonEncoder.long.unsafeEncode(a.opcowner, indent, out) + out.write(",") + out.write(""""opcfamily":""") + JsonEncoder.long.unsafeEncode(a.opcfamily, indent, out) + out.write(",") + out.write(""""opcintype":""") + JsonEncoder.long.unsafeEncode(a.opcintype, indent, out) + out.write(",") + out.write(""""opcdefault":""") + JsonEncoder.boolean.unsafeEncode(a.opcdefault, indent, out) + out.write(",") + out.write(""""opckeytype":""") + JsonEncoder.long.unsafeEncode(a.opckeytype, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassStructure.scala new file mode 100644 index 0000000000..1b9e802a05 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opclass/PgOpclassStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opclass + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgOpclassStructure[Row](val prefix: Option[String], val extract: Row => PgOpclassRow, val merge: (Row, PgOpclassRow) => Row) + extends Relation[PgOpclassFields, PgOpclassRow, Row] + with PgOpclassFields[Row] { outer => + + override val oid = new IdField[PgOpclassId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val opcmethod = new Field[/* oid */ Long, Row](prefix, "opcmethod", None, Some("oid"))(x => extract(x).opcmethod, (row, value) => merge(row, extract(row).copy(opcmethod = value))) + override val opcname = new Field[String, Row](prefix, "opcname", None, Some("name"))(x => extract(x).opcname, (row, value) => merge(row, extract(row).copy(opcname = value))) + override val opcnamespace = new Field[/* oid */ Long, Row](prefix, "opcnamespace", None, Some("oid"))(x => extract(x).opcnamespace, (row, value) => merge(row, extract(row).copy(opcnamespace = value))) + override val opcowner = new Field[/* oid */ Long, Row](prefix, "opcowner", None, Some("oid"))(x => extract(x).opcowner, (row, value) => merge(row, extract(row).copy(opcowner = value))) + override val opcfamily = new Field[/* oid */ Long, Row](prefix, "opcfamily", None, Some("oid"))(x => extract(x).opcfamily, (row, value) => merge(row, extract(row).copy(opcfamily = value))) + override val opcintype = new Field[/* oid */ Long, Row](prefix, "opcintype", None, Some("oid"))(x => extract(x).opcintype, (row, value) => merge(row, extract(row).copy(opcintype = value))) + override val opcdefault = new Field[Boolean, Row](prefix, "opcdefault", None, None)(x => extract(x).opcdefault, (row, value) => merge(row, extract(row).copy(opcdefault = value))) + override val opckeytype = new Field[/* oid */ Long, Row](prefix, "opckeytype", None, Some("oid"))(x => extract(x).opckeytype, (row, value) => merge(row, extract(row).copy(opckeytype = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, opcmethod, opcname, opcnamespace, opcowner, opcfamily, opcintype, opcdefault, opckeytype) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgOpclassRow, merge: (NewRow, PgOpclassRow) => NewRow): PgOpclassStructure[NewRow] = + new PgOpclassStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorFields.scala new file mode 100644 index 0000000000..02dac0e78d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgOperatorFields[Row] { + val oid: IdField[PgOperatorId, Row] + val oprname: Field[String, Row] + val oprnamespace: Field[/* oid */ Long, Row] + val oprowner: Field[/* oid */ Long, Row] + val oprkind: Field[String, Row] + val oprcanmerge: Field[Boolean, Row] + val oprcanhash: Field[Boolean, Row] + val oprleft: Field[/* oid */ Long, Row] + val oprright: Field[/* oid */ Long, Row] + val oprresult: Field[/* oid */ Long, Row] + val oprcom: Field[/* oid */ Long, Row] + val oprnegate: Field[/* oid */ Long, Row] + val oprcode: Field[TypoRegproc, Row] + val oprrest: Field[TypoRegproc, Row] + val oprjoin: Field[TypoRegproc, Row] +} +object PgOperatorFields extends PgOperatorStructure[PgOperatorRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorId.scala new file mode 100644 index 0000000000..25da04e23a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +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 `pg_catalog.pg_operator` */ +case class PgOperatorId(value: /* oid */ Long) extends AnyVal +object PgOperatorId { + implicit lazy val arraySetter: Setter[Array[PgOperatorId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgOperatorId, /* oid */ Long] = Bijection[PgOperatorId, /* oid */ Long](_.value)(PgOperatorId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgOperatorId] = JdbcDecoder.longDecoder.map(PgOperatorId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgOperatorId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgOperatorId] = JsonDecoder.long.map(PgOperatorId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgOperatorId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgOperatorId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgOperatorId] = ParameterMetaData.instance[PgOperatorId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgOperatorId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepo.scala new file mode 100644 index 0000000000..aba8fb554c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgOperatorRepo { + def delete(oid: PgOperatorId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgOperatorFields, PgOperatorRow] + def insert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, PgOperatorRow] + def select: SelectBuilder[PgOperatorFields, PgOperatorRow] + def selectAll: ZStream[ZConnection, Throwable, PgOperatorRow] + def selectById(oid: PgOperatorId): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] + def selectByIds(oids: Array[PgOperatorId]): ZStream[ZConnection, Throwable, PgOperatorRow] + def selectByUnique(oprname: String, oprleft: /* oid */ Long, oprright: /* oid */ Long, oprnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] + def update(row: PgOperatorRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgOperatorFields, PgOperatorRow] + def upsert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, UpdateResult[PgOperatorRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoImpl.scala new file mode 100644 index 0000000000..4432a66320 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoImpl.scala @@ -0,0 +1,113 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgOperatorRepoImpl extends PgOperatorRepo { + override def delete(oid: PgOperatorId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_operator where "oid" = ${Segment.paramSegment(oid)(PgOperatorId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgOperatorFields, PgOperatorRow] = { + DeleteBuilder("pg_catalog.pg_operator", PgOperatorFields) + } + override def insert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, PgOperatorRow] = { + sql"""insert into pg_catalog.pg_operator("oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin") + values (${Segment.paramSegment(unsaved.oid)(PgOperatorId.setter)}::oid, ${Segment.paramSegment(unsaved.oprname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.oprnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprkind)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.oprcanmerge)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.oprcanhash)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.oprleft)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprright)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprresult)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprcom)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprnegate)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.oprcode)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.oprrest)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.oprjoin)(TypoRegproc.setter)}::regproc) + returning "oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin" + """.insertReturning(PgOperatorRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgOperatorFields, PgOperatorRow] = { + SelectBuilderSql("pg_catalog.pg_operator", PgOperatorFields, PgOperatorRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOperatorRow] = { + sql"""select "oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin" from pg_catalog.pg_operator""".query(PgOperatorRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgOperatorId): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] = { + sql"""select "oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin" from pg_catalog.pg_operator where "oid" = ${Segment.paramSegment(oid)(PgOperatorId.setter)}""".query(PgOperatorRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgOperatorId]): ZStream[ZConnection, Throwable, PgOperatorRow] = { + sql"""select "oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin" from pg_catalog.pg_operator where "oid" = ANY(${Segment.paramSegment(oids)(PgOperatorId.arraySetter)})""".query(PgOperatorRow.jdbcDecoder).selectStream + } + override def selectByUnique(oprname: String, oprleft: /* oid */ Long, oprright: /* oid */ Long, oprnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] = { + sql"""select "oprname", "oprleft", "oprright", "oprnamespace" + from pg_catalog.pg_operator + where "oprname" = ${Segment.paramSegment(oprname)(Setter.stringSetter)} AND "oprleft" = ${Segment.paramSegment(oprleft)(Setter.longSetter)} AND "oprright" = ${Segment.paramSegment(oprright)(Setter.longSetter)} AND "oprnamespace" = ${Segment.paramSegment(oprnamespace)(Setter.longSetter)} + """.query(PgOperatorRow.jdbcDecoder).selectOne + } + override def update(row: PgOperatorRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_operator + set "oprname" = ${Segment.paramSegment(row.oprname)(Setter.stringSetter)}::name, + "oprnamespace" = ${Segment.paramSegment(row.oprnamespace)(Setter.longSetter)}::oid, + "oprowner" = ${Segment.paramSegment(row.oprowner)(Setter.longSetter)}::oid, + "oprkind" = ${Segment.paramSegment(row.oprkind)(Setter.stringSetter)}::char, + "oprcanmerge" = ${Segment.paramSegment(row.oprcanmerge)(Setter.booleanSetter)}, + "oprcanhash" = ${Segment.paramSegment(row.oprcanhash)(Setter.booleanSetter)}, + "oprleft" = ${Segment.paramSegment(row.oprleft)(Setter.longSetter)}::oid, + "oprright" = ${Segment.paramSegment(row.oprright)(Setter.longSetter)}::oid, + "oprresult" = ${Segment.paramSegment(row.oprresult)(Setter.longSetter)}::oid, + "oprcom" = ${Segment.paramSegment(row.oprcom)(Setter.longSetter)}::oid, + "oprnegate" = ${Segment.paramSegment(row.oprnegate)(Setter.longSetter)}::oid, + "oprcode" = ${Segment.paramSegment(row.oprcode)(TypoRegproc.setter)}::regproc, + "oprrest" = ${Segment.paramSegment(row.oprrest)(TypoRegproc.setter)}::regproc, + "oprjoin" = ${Segment.paramSegment(row.oprjoin)(TypoRegproc.setter)}::regproc + where "oid" = ${Segment.paramSegment(oid)(PgOperatorId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgOperatorFields, PgOperatorRow] = { + UpdateBuilder("pg_catalog.pg_operator", PgOperatorFields, PgOperatorRow.jdbcDecoder) + } + override def upsert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, UpdateResult[PgOperatorRow]] = { + sql"""insert into pg_catalog.pg_operator("oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin") + values ( + ${Segment.paramSegment(unsaved.oid)(PgOperatorId.setter)}::oid, + ${Segment.paramSegment(unsaved.oprname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.oprnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprkind)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.oprcanmerge)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.oprcanhash)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.oprleft)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprright)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprresult)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprcom)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprnegate)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.oprcode)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.oprrest)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.oprjoin)(TypoRegproc.setter)}::regproc + ) + on conflict ("oid") + do update set + "oprname" = EXCLUDED."oprname", + "oprnamespace" = EXCLUDED."oprnamespace", + "oprowner" = EXCLUDED."oprowner", + "oprkind" = EXCLUDED."oprkind", + "oprcanmerge" = EXCLUDED."oprcanmerge", + "oprcanhash" = EXCLUDED."oprcanhash", + "oprleft" = EXCLUDED."oprleft", + "oprright" = EXCLUDED."oprright", + "oprresult" = EXCLUDED."oprresult", + "oprcom" = EXCLUDED."oprcom", + "oprnegate" = EXCLUDED."oprnegate", + "oprcode" = EXCLUDED."oprcode", + "oprrest" = EXCLUDED."oprrest", + "oprjoin" = EXCLUDED."oprjoin" + returning "oid", "oprname", "oprnamespace", "oprowner", "oprkind", "oprcanmerge", "oprcanhash", "oprleft", "oprright", "oprresult", "oprcom", "oprnegate", "oprcode", "oprrest", "oprjoin"""".insertReturning(PgOperatorRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoMock.scala new file mode 100644 index 0000000000..333cbc2519 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgOperatorRepoMock(map: scala.collection.mutable.Map[PgOperatorId, PgOperatorRow] = scala.collection.mutable.Map.empty) extends PgOperatorRepo { + override def delete(oid: PgOperatorId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgOperatorFields, PgOperatorRow] = { + DeleteBuilderMock(DeleteParams.empty, PgOperatorFields, map) + } + override def insert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, PgOperatorRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgOperatorFields, PgOperatorRow] = { + SelectBuilderMock(PgOperatorFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOperatorRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgOperatorId): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgOperatorId]): ZStream[ZConnection, Throwable, PgOperatorRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(oprname: String, oprleft: /* oid */ Long, oprright: /* oid */ Long, oprnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOperatorRow]] = { + ZIO.succeed(map.values.find(v => oprname == v.oprname && oprleft == v.oprleft && oprright == v.oprright && oprnamespace == v.oprnamespace)) + } + override def update(row: PgOperatorRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgOperatorFields, PgOperatorRow] = { + UpdateBuilderMock(UpdateParams.empty, PgOperatorFields, map) + } + override def upsert(unsaved: PgOperatorRow): ZIO[ZConnection, Throwable, UpdateResult[PgOperatorRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRow.scala new file mode 100644 index 0000000000..842eb84d8a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorRow.scala @@ -0,0 +1,128 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgOperatorRow( + oid: PgOperatorId, + oprname: String, + oprnamespace: /* oid */ Long, + oprowner: /* oid */ Long, + oprkind: String, + oprcanmerge: Boolean, + oprcanhash: Boolean, + oprleft: /* oid */ Long, + oprright: /* oid */ Long, + oprresult: /* oid */ Long, + oprcom: /* oid */ Long, + oprnegate: /* oid */ Long, + oprcode: TypoRegproc, + oprrest: TypoRegproc, + oprjoin: TypoRegproc +) + +object PgOperatorRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgOperatorRow] = new JdbcDecoder[PgOperatorRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgOperatorRow) = + columIndex + 14 -> + PgOperatorRow( + oid = PgOperatorId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + oprname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + oprnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + oprowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + oprkind = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + oprcanmerge = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + oprcanhash = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + oprleft = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + oprright = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2, + oprresult = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 9, rs)._2, + oprcom = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 10, rs)._2, + oprnegate = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 11, rs)._2, + oprcode = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + oprrest = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + oprjoin = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgOperatorRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgOperatorId.jsonDecoder)) + val oprname = jsonObj.get("oprname").toRight("Missing field 'oprname'").flatMap(_.as(JsonDecoder.string)) + val oprnamespace = jsonObj.get("oprnamespace").toRight("Missing field 'oprnamespace'").flatMap(_.as(JsonDecoder.long)) + val oprowner = jsonObj.get("oprowner").toRight("Missing field 'oprowner'").flatMap(_.as(JsonDecoder.long)) + val oprkind = jsonObj.get("oprkind").toRight("Missing field 'oprkind'").flatMap(_.as(JsonDecoder.string)) + val oprcanmerge = jsonObj.get("oprcanmerge").toRight("Missing field 'oprcanmerge'").flatMap(_.as(JsonDecoder.boolean)) + val oprcanhash = jsonObj.get("oprcanhash").toRight("Missing field 'oprcanhash'").flatMap(_.as(JsonDecoder.boolean)) + val oprleft = jsonObj.get("oprleft").toRight("Missing field 'oprleft'").flatMap(_.as(JsonDecoder.long)) + val oprright = jsonObj.get("oprright").toRight("Missing field 'oprright'").flatMap(_.as(JsonDecoder.long)) + val oprresult = jsonObj.get("oprresult").toRight("Missing field 'oprresult'").flatMap(_.as(JsonDecoder.long)) + val oprcom = jsonObj.get("oprcom").toRight("Missing field 'oprcom'").flatMap(_.as(JsonDecoder.long)) + val oprnegate = jsonObj.get("oprnegate").toRight("Missing field 'oprnegate'").flatMap(_.as(JsonDecoder.long)) + val oprcode = jsonObj.get("oprcode").toRight("Missing field 'oprcode'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val oprrest = jsonObj.get("oprrest").toRight("Missing field 'oprrest'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val oprjoin = jsonObj.get("oprjoin").toRight("Missing field 'oprjoin'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (oid.isRight && oprname.isRight && oprnamespace.isRight && oprowner.isRight && oprkind.isRight && oprcanmerge.isRight && oprcanhash.isRight && oprleft.isRight && oprright.isRight && oprresult.isRight && oprcom.isRight && oprnegate.isRight && oprcode.isRight && oprrest.isRight && oprjoin.isRight) + Right(PgOperatorRow(oid = oid.toOption.get, oprname = oprname.toOption.get, oprnamespace = oprnamespace.toOption.get, oprowner = oprowner.toOption.get, oprkind = oprkind.toOption.get, oprcanmerge = oprcanmerge.toOption.get, oprcanhash = oprcanhash.toOption.get, oprleft = oprleft.toOption.get, oprright = oprright.toOption.get, oprresult = oprresult.toOption.get, oprcom = oprcom.toOption.get, oprnegate = oprnegate.toOption.get, oprcode = oprcode.toOption.get, oprrest = oprrest.toOption.get, oprjoin = oprjoin.toOption.get)) + else Left(List[Either[String, Any]](oid, oprname, oprnamespace, oprowner, oprkind, oprcanmerge, oprcanhash, oprleft, oprright, oprresult, oprcom, oprnegate, oprcode, oprrest, oprjoin).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgOperatorRow] = new JsonEncoder[PgOperatorRow] { + override def unsafeEncode(a: PgOperatorRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgOperatorId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""oprname":""") + JsonEncoder.string.unsafeEncode(a.oprname, indent, out) + out.write(",") + out.write(""""oprnamespace":""") + JsonEncoder.long.unsafeEncode(a.oprnamespace, indent, out) + out.write(",") + out.write(""""oprowner":""") + JsonEncoder.long.unsafeEncode(a.oprowner, indent, out) + out.write(",") + out.write(""""oprkind":""") + JsonEncoder.string.unsafeEncode(a.oprkind, indent, out) + out.write(",") + out.write(""""oprcanmerge":""") + JsonEncoder.boolean.unsafeEncode(a.oprcanmerge, indent, out) + out.write(",") + out.write(""""oprcanhash":""") + JsonEncoder.boolean.unsafeEncode(a.oprcanhash, indent, out) + out.write(",") + out.write(""""oprleft":""") + JsonEncoder.long.unsafeEncode(a.oprleft, indent, out) + out.write(",") + out.write(""""oprright":""") + JsonEncoder.long.unsafeEncode(a.oprright, indent, out) + out.write(",") + out.write(""""oprresult":""") + JsonEncoder.long.unsafeEncode(a.oprresult, indent, out) + out.write(",") + out.write(""""oprcom":""") + JsonEncoder.long.unsafeEncode(a.oprcom, indent, out) + out.write(",") + out.write(""""oprnegate":""") + JsonEncoder.long.unsafeEncode(a.oprnegate, indent, out) + out.write(",") + out.write(""""oprcode":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.oprcode, indent, out) + out.write(",") + out.write(""""oprrest":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.oprrest, indent, out) + out.write(",") + out.write(""""oprjoin":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.oprjoin, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorStructure.scala new file mode 100644 index 0000000000..e0e9c6b3be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_operator/PgOperatorStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_operator + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgOperatorStructure[Row](val prefix: Option[String], val extract: Row => PgOperatorRow, val merge: (Row, PgOperatorRow) => Row) + extends Relation[PgOperatorFields, PgOperatorRow, Row] + with PgOperatorFields[Row] { outer => + + override val oid = new IdField[PgOperatorId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val oprname = new Field[String, Row](prefix, "oprname", None, Some("name"))(x => extract(x).oprname, (row, value) => merge(row, extract(row).copy(oprname = value))) + override val oprnamespace = new Field[/* oid */ Long, Row](prefix, "oprnamespace", None, Some("oid"))(x => extract(x).oprnamespace, (row, value) => merge(row, extract(row).copy(oprnamespace = value))) + override val oprowner = new Field[/* oid */ Long, Row](prefix, "oprowner", None, Some("oid"))(x => extract(x).oprowner, (row, value) => merge(row, extract(row).copy(oprowner = value))) + override val oprkind = new Field[String, Row](prefix, "oprkind", None, Some("char"))(x => extract(x).oprkind, (row, value) => merge(row, extract(row).copy(oprkind = value))) + override val oprcanmerge = new Field[Boolean, Row](prefix, "oprcanmerge", None, None)(x => extract(x).oprcanmerge, (row, value) => merge(row, extract(row).copy(oprcanmerge = value))) + override val oprcanhash = new Field[Boolean, Row](prefix, "oprcanhash", None, None)(x => extract(x).oprcanhash, (row, value) => merge(row, extract(row).copy(oprcanhash = value))) + override val oprleft = new Field[/* oid */ Long, Row](prefix, "oprleft", None, Some("oid"))(x => extract(x).oprleft, (row, value) => merge(row, extract(row).copy(oprleft = value))) + override val oprright = new Field[/* oid */ Long, Row](prefix, "oprright", None, Some("oid"))(x => extract(x).oprright, (row, value) => merge(row, extract(row).copy(oprright = value))) + override val oprresult = new Field[/* oid */ Long, Row](prefix, "oprresult", None, Some("oid"))(x => extract(x).oprresult, (row, value) => merge(row, extract(row).copy(oprresult = value))) + override val oprcom = new Field[/* oid */ Long, Row](prefix, "oprcom", None, Some("oid"))(x => extract(x).oprcom, (row, value) => merge(row, extract(row).copy(oprcom = value))) + override val oprnegate = new Field[/* oid */ Long, Row](prefix, "oprnegate", None, Some("oid"))(x => extract(x).oprnegate, (row, value) => merge(row, extract(row).copy(oprnegate = value))) + override val oprcode = new Field[TypoRegproc, Row](prefix, "oprcode", None, Some("regproc"))(x => extract(x).oprcode, (row, value) => merge(row, extract(row).copy(oprcode = value))) + override val oprrest = new Field[TypoRegproc, Row](prefix, "oprrest", None, Some("regproc"))(x => extract(x).oprrest, (row, value) => merge(row, extract(row).copy(oprrest = value))) + override val oprjoin = new Field[TypoRegproc, Row](prefix, "oprjoin", None, Some("regproc"))(x => extract(x).oprjoin, (row, value) => merge(row, extract(row).copy(oprjoin = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, oprname, oprnamespace, oprowner, oprkind, oprcanmerge, oprcanhash, oprleft, oprright, oprresult, oprcom, oprnegate, oprcode, oprrest, oprjoin) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgOperatorRow, merge: (NewRow, PgOperatorRow) => NewRow): PgOperatorStructure[NewRow] = + new PgOperatorStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyFields.scala new file mode 100644 index 0000000000..6d5005a641 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgOpfamilyFields[Row] { + val oid: IdField[PgOpfamilyId, Row] + val opfmethod: Field[/* oid */ Long, Row] + val opfname: Field[String, Row] + val opfnamespace: Field[/* oid */ Long, Row] + val opfowner: Field[/* oid */ Long, Row] +} +object PgOpfamilyFields extends PgOpfamilyStructure[PgOpfamilyRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyId.scala new file mode 100644 index 0000000000..081ec9c5cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +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 `pg_catalog.pg_opfamily` */ +case class PgOpfamilyId(value: /* oid */ Long) extends AnyVal +object PgOpfamilyId { + implicit lazy val arraySetter: Setter[Array[PgOpfamilyId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgOpfamilyId, /* oid */ Long] = Bijection[PgOpfamilyId, /* oid */ Long](_.value)(PgOpfamilyId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgOpfamilyId] = JdbcDecoder.longDecoder.map(PgOpfamilyId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgOpfamilyId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgOpfamilyId] = JsonDecoder.long.map(PgOpfamilyId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgOpfamilyId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgOpfamilyId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgOpfamilyId] = ParameterMetaData.instance[PgOpfamilyId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgOpfamilyId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepo.scala new file mode 100644 index 0000000000..19a50a0131 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgOpfamilyRepo { + def delete(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgOpfamilyFields, PgOpfamilyRow] + def insert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, PgOpfamilyRow] + def select: SelectBuilder[PgOpfamilyFields, PgOpfamilyRow] + def selectAll: ZStream[ZConnection, Throwable, PgOpfamilyRow] + def selectById(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] + def selectByIds(oids: Array[PgOpfamilyId]): ZStream[ZConnection, Throwable, PgOpfamilyRow] + def selectByUnique(opfmethod: /* oid */ Long, opfname: String, opfnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] + def update(row: PgOpfamilyRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgOpfamilyFields, PgOpfamilyRow] + def upsert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpfamilyRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoImpl.scala new file mode 100644 index 0000000000..cad2bc95e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoImpl.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgOpfamilyRepoImpl extends PgOpfamilyRepo { + override def delete(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_opfamily where "oid" = ${Segment.paramSegment(oid)(PgOpfamilyId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + DeleteBuilder("pg_catalog.pg_opfamily", PgOpfamilyFields) + } + override def insert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, PgOpfamilyRow] = { + sql"""insert into pg_catalog.pg_opfamily("oid", "opfmethod", "opfname", "opfnamespace", "opfowner") + values (${Segment.paramSegment(unsaved.oid)(PgOpfamilyId.setter)}::oid, ${Segment.paramSegment(unsaved.opfmethod)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opfname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.opfnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.opfowner)(Setter.longSetter)}::oid) + returning "oid", "opfmethod", "opfname", "opfnamespace", "opfowner" + """.insertReturning(PgOpfamilyRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + SelectBuilderSql("pg_catalog.pg_opfamily", PgOpfamilyFields, PgOpfamilyRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOpfamilyRow] = { + sql"""select "oid", "opfmethod", "opfname", "opfnamespace", "opfowner" from pg_catalog.pg_opfamily""".query(PgOpfamilyRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] = { + sql"""select "oid", "opfmethod", "opfname", "opfnamespace", "opfowner" from pg_catalog.pg_opfamily where "oid" = ${Segment.paramSegment(oid)(PgOpfamilyId.setter)}""".query(PgOpfamilyRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgOpfamilyId]): ZStream[ZConnection, Throwable, PgOpfamilyRow] = { + sql"""select "oid", "opfmethod", "opfname", "opfnamespace", "opfowner" from pg_catalog.pg_opfamily where "oid" = ANY(${Segment.paramSegment(oids)(PgOpfamilyId.arraySetter)})""".query(PgOpfamilyRow.jdbcDecoder).selectStream + } + override def selectByUnique(opfmethod: /* oid */ Long, opfname: String, opfnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] = { + sql"""select "opfmethod", "opfname", "opfnamespace" + from pg_catalog.pg_opfamily + where "opfmethod" = ${Segment.paramSegment(opfmethod)(Setter.longSetter)} AND "opfname" = ${Segment.paramSegment(opfname)(Setter.stringSetter)} AND "opfnamespace" = ${Segment.paramSegment(opfnamespace)(Setter.longSetter)} + """.query(PgOpfamilyRow.jdbcDecoder).selectOne + } + override def update(row: PgOpfamilyRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_opfamily + set "opfmethod" = ${Segment.paramSegment(row.opfmethod)(Setter.longSetter)}::oid, + "opfname" = ${Segment.paramSegment(row.opfname)(Setter.stringSetter)}::name, + "opfnamespace" = ${Segment.paramSegment(row.opfnamespace)(Setter.longSetter)}::oid, + "opfowner" = ${Segment.paramSegment(row.opfowner)(Setter.longSetter)}::oid + where "oid" = ${Segment.paramSegment(oid)(PgOpfamilyId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + UpdateBuilder("pg_catalog.pg_opfamily", PgOpfamilyFields, PgOpfamilyRow.jdbcDecoder) + } + override def upsert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpfamilyRow]] = { + sql"""insert into pg_catalog.pg_opfamily("oid", "opfmethod", "opfname", "opfnamespace", "opfowner") + values ( + ${Segment.paramSegment(unsaved.oid)(PgOpfamilyId.setter)}::oid, + ${Segment.paramSegment(unsaved.opfmethod)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opfname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.opfnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.opfowner)(Setter.longSetter)}::oid + ) + on conflict ("oid") + do update set + "opfmethod" = EXCLUDED."opfmethod", + "opfname" = EXCLUDED."opfname", + "opfnamespace" = EXCLUDED."opfnamespace", + "opfowner" = EXCLUDED."opfowner" + returning "oid", "opfmethod", "opfname", "opfnamespace", "opfowner"""".insertReturning(PgOpfamilyRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoMock.scala new file mode 100644 index 0000000000..32b9f231b0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgOpfamilyRepoMock(map: scala.collection.mutable.Map[PgOpfamilyId, PgOpfamilyRow] = scala.collection.mutable.Map.empty) extends PgOpfamilyRepo { + override def delete(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + DeleteBuilderMock(DeleteParams.empty, PgOpfamilyFields, map) + } + override def insert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, PgOpfamilyRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + SelectBuilderMock(PgOpfamilyFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgOpfamilyRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgOpfamilyId): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgOpfamilyId]): ZStream[ZConnection, Throwable, PgOpfamilyRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(opfmethod: /* oid */ Long, opfname: String, opfnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgOpfamilyRow]] = { + ZIO.succeed(map.values.find(v => opfmethod == v.opfmethod && opfname == v.opfname && opfnamespace == v.opfnamespace)) + } + override def update(row: PgOpfamilyRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgOpfamilyFields, PgOpfamilyRow] = { + UpdateBuilderMock(UpdateParams.empty, PgOpfamilyFields, map) + } + override def upsert(unsaved: PgOpfamilyRow): ZIO[ZConnection, Throwable, UpdateResult[PgOpfamilyRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRow.scala new file mode 100644 index 0000000000..a29050204e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyRow.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgOpfamilyRow( + oid: PgOpfamilyId, + opfmethod: /* oid */ Long, + opfname: String, + opfnamespace: /* oid */ Long, + opfowner: /* oid */ Long +) + +object PgOpfamilyRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgOpfamilyRow] = new JdbcDecoder[PgOpfamilyRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgOpfamilyRow) = + columIndex + 4 -> + PgOpfamilyRow( + oid = PgOpfamilyId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + opfmethod = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + opfname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + opfnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + opfowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgOpfamilyRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgOpfamilyId.jsonDecoder)) + val opfmethod = jsonObj.get("opfmethod").toRight("Missing field 'opfmethod'").flatMap(_.as(JsonDecoder.long)) + val opfname = jsonObj.get("opfname").toRight("Missing field 'opfname'").flatMap(_.as(JsonDecoder.string)) + val opfnamespace = jsonObj.get("opfnamespace").toRight("Missing field 'opfnamespace'").flatMap(_.as(JsonDecoder.long)) + val opfowner = jsonObj.get("opfowner").toRight("Missing field 'opfowner'").flatMap(_.as(JsonDecoder.long)) + if (oid.isRight && opfmethod.isRight && opfname.isRight && opfnamespace.isRight && opfowner.isRight) + Right(PgOpfamilyRow(oid = oid.toOption.get, opfmethod = opfmethod.toOption.get, opfname = opfname.toOption.get, opfnamespace = opfnamespace.toOption.get, opfowner = opfowner.toOption.get)) + else Left(List[Either[String, Any]](oid, opfmethod, opfname, opfnamespace, opfowner).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgOpfamilyRow] = new JsonEncoder[PgOpfamilyRow] { + override def unsafeEncode(a: PgOpfamilyRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgOpfamilyId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""opfmethod":""") + JsonEncoder.long.unsafeEncode(a.opfmethod, indent, out) + out.write(",") + out.write(""""opfname":""") + JsonEncoder.string.unsafeEncode(a.opfname, indent, out) + out.write(",") + out.write(""""opfnamespace":""") + JsonEncoder.long.unsafeEncode(a.opfnamespace, indent, out) + out.write(",") + out.write(""""opfowner":""") + JsonEncoder.long.unsafeEncode(a.opfowner, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyStructure.scala new file mode 100644 index 0000000000..441b8423d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_opfamily/PgOpfamilyStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_opfamily + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgOpfamilyStructure[Row](val prefix: Option[String], val extract: Row => PgOpfamilyRow, val merge: (Row, PgOpfamilyRow) => Row) + extends Relation[PgOpfamilyFields, PgOpfamilyRow, Row] + with PgOpfamilyFields[Row] { outer => + + override val oid = new IdField[PgOpfamilyId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val opfmethod = new Field[/* oid */ Long, Row](prefix, "opfmethod", None, Some("oid"))(x => extract(x).opfmethod, (row, value) => merge(row, extract(row).copy(opfmethod = value))) + override val opfname = new Field[String, Row](prefix, "opfname", None, Some("name"))(x => extract(x).opfname, (row, value) => merge(row, extract(row).copy(opfname = value))) + override val opfnamespace = new Field[/* oid */ Long, Row](prefix, "opfnamespace", None, Some("oid"))(x => extract(x).opfnamespace, (row, value) => merge(row, extract(row).copy(opfnamespace = value))) + override val opfowner = new Field[/* oid */ Long, Row](prefix, "opfowner", None, Some("oid"))(x => extract(x).opfowner, (row, value) => merge(row, extract(row).copy(opfowner = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, opfmethod, opfname, opfnamespace, opfowner) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgOpfamilyRow, merge: (NewRow, PgOpfamilyRow) => NewRow): PgOpfamilyStructure[NewRow] = + new PgOpfamilyStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableFields.scala new file mode 100644 index 0000000000..96a25a9cb1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgPartitionedTableFields[Row] { + val partrelid: IdField[PgPartitionedTableId, Row] + val partstrat: Field[String, Row] + val partnatts: Field[TypoShort, Row] + val partdefid: Field[/* oid */ Long, Row] + val partattrs: Field[TypoInt2Vector, Row] + val partclass: Field[TypoOidVector, Row] + val partcollation: Field[TypoOidVector, Row] + val partexprs: OptField[TypoPgNodeTree, Row] +} +object PgPartitionedTableFields extends PgPartitionedTableStructure[PgPartitionedTableRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableId.scala new file mode 100644 index 0000000000..b1c614b2a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +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 `pg_catalog.pg_partitioned_table` */ +case class PgPartitionedTableId(value: /* oid */ Long) extends AnyVal +object PgPartitionedTableId { + implicit lazy val arraySetter: Setter[Array[PgPartitionedTableId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgPartitionedTableId, /* oid */ Long] = Bijection[PgPartitionedTableId, /* oid */ Long](_.value)(PgPartitionedTableId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgPartitionedTableId] = JdbcDecoder.longDecoder.map(PgPartitionedTableId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgPartitionedTableId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgPartitionedTableId] = JsonDecoder.long.map(PgPartitionedTableId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgPartitionedTableId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgPartitionedTableId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgPartitionedTableId] = ParameterMetaData.instance[PgPartitionedTableId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgPartitionedTableId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepo.scala new file mode 100644 index 0000000000..51bc561ede --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPartitionedTableRepo { + def delete(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgPartitionedTableFields, PgPartitionedTableRow] + def insert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, PgPartitionedTableRow] + def select: SelectBuilder[PgPartitionedTableFields, PgPartitionedTableRow] + def selectAll: ZStream[ZConnection, Throwable, PgPartitionedTableRow] + def selectById(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Option[PgPartitionedTableRow]] + def selectByIds(partrelids: Array[PgPartitionedTableId]): ZStream[ZConnection, Throwable, PgPartitionedTableRow] + def update(row: PgPartitionedTableRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgPartitionedTableFields, PgPartitionedTableRow] + def upsert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgPartitionedTableRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoImpl.scala new file mode 100644 index 0000000000..89a595322f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoImpl.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPartitionedTableRepoImpl extends PgPartitionedTableRepo { + override def delete(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_partitioned_table where "partrelid" = ${Segment.paramSegment(partrelid)(PgPartitionedTableId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + DeleteBuilder("pg_catalog.pg_partitioned_table", PgPartitionedTableFields) + } + override def insert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, PgPartitionedTableRow] = { + sql"""insert into pg_catalog.pg_partitioned_table("partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs") + values (${Segment.paramSegment(unsaved.partrelid)(PgPartitionedTableId.setter)}::oid, ${Segment.paramSegment(unsaved.partstrat)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.partnatts)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.partdefid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.partattrs)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.partclass)(TypoOidVector.setter)}::oidvector, ${Segment.paramSegment(unsaved.partcollation)(TypoOidVector.setter)}::oidvector, ${Segment.paramSegment(unsaved.partexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs" + """.insertReturning(PgPartitionedTableRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + SelectBuilderSql("pg_catalog.pg_partitioned_table", PgPartitionedTableFields, PgPartitionedTableRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPartitionedTableRow] = { + sql"""select "partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs" from pg_catalog.pg_partitioned_table""".query(PgPartitionedTableRow.jdbcDecoder).selectStream + } + override def selectById(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Option[PgPartitionedTableRow]] = { + sql"""select "partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs" from pg_catalog.pg_partitioned_table where "partrelid" = ${Segment.paramSegment(partrelid)(PgPartitionedTableId.setter)}""".query(PgPartitionedTableRow.jdbcDecoder).selectOne + } + override def selectByIds(partrelids: Array[PgPartitionedTableId]): ZStream[ZConnection, Throwable, PgPartitionedTableRow] = { + sql"""select "partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs" from pg_catalog.pg_partitioned_table where "partrelid" = ANY(${Segment.paramSegment(partrelids)(PgPartitionedTableId.arraySetter)})""".query(PgPartitionedTableRow.jdbcDecoder).selectStream + } + override def update(row: PgPartitionedTableRow): ZIO[ZConnection, Throwable, Boolean] = { + val partrelid = row.partrelid + sql"""update pg_catalog.pg_partitioned_table + set "partstrat" = ${Segment.paramSegment(row.partstrat)(Setter.stringSetter)}::char, + "partnatts" = ${Segment.paramSegment(row.partnatts)(TypoShort.setter)}::int2, + "partdefid" = ${Segment.paramSegment(row.partdefid)(Setter.longSetter)}::oid, + "partattrs" = ${Segment.paramSegment(row.partattrs)(TypoInt2Vector.setter)}::int2vector, + "partclass" = ${Segment.paramSegment(row.partclass)(TypoOidVector.setter)}::oidvector, + "partcollation" = ${Segment.paramSegment(row.partcollation)(TypoOidVector.setter)}::oidvector, + "partexprs" = ${Segment.paramSegment(row.partexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "partrelid" = ${Segment.paramSegment(partrelid)(PgPartitionedTableId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + UpdateBuilder("pg_catalog.pg_partitioned_table", PgPartitionedTableFields, PgPartitionedTableRow.jdbcDecoder) + } + override def upsert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgPartitionedTableRow]] = { + sql"""insert into pg_catalog.pg_partitioned_table("partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs") + values ( + ${Segment.paramSegment(unsaved.partrelid)(PgPartitionedTableId.setter)}::oid, + ${Segment.paramSegment(unsaved.partstrat)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.partnatts)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.partdefid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.partattrs)(TypoInt2Vector.setter)}::int2vector, + ${Segment.paramSegment(unsaved.partclass)(TypoOidVector.setter)}::oidvector, + ${Segment.paramSegment(unsaved.partcollation)(TypoOidVector.setter)}::oidvector, + ${Segment.paramSegment(unsaved.partexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("partrelid") + do update set + "partstrat" = EXCLUDED."partstrat", + "partnatts" = EXCLUDED."partnatts", + "partdefid" = EXCLUDED."partdefid", + "partattrs" = EXCLUDED."partattrs", + "partclass" = EXCLUDED."partclass", + "partcollation" = EXCLUDED."partcollation", + "partexprs" = EXCLUDED."partexprs" + returning "partrelid", "partstrat", "partnatts", "partdefid", "partattrs", "partclass", "partcollation", "partexprs"""".insertReturning(PgPartitionedTableRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoMock.scala new file mode 100644 index 0000000000..c4fe2cb577 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgPartitionedTableRepoMock(map: scala.collection.mutable.Map[PgPartitionedTableId, PgPartitionedTableRow] = scala.collection.mutable.Map.empty) extends PgPartitionedTableRepo { + override def delete(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(partrelid).isDefined) + } + override def delete: DeleteBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + DeleteBuilderMock(DeleteParams.empty, PgPartitionedTableFields, map) + } + override def insert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, PgPartitionedTableRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.partrelid)) + sys.error(s"id ${unsaved.partrelid} already exists") + else + map.put(unsaved.partrelid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + SelectBuilderMock(PgPartitionedTableFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPartitionedTableRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(partrelid: PgPartitionedTableId): ZIO[ZConnection, Throwable, Option[PgPartitionedTableRow]] = { + ZIO.succeed(map.get(partrelid)) + } + override def selectByIds(partrelids: Array[PgPartitionedTableId]): ZStream[ZConnection, Throwable, PgPartitionedTableRow] = { + ZStream.fromIterable(partrelids.flatMap(map.get)) + } + override def update(row: PgPartitionedTableRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.partrelid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.partrelid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgPartitionedTableFields, PgPartitionedTableRow] = { + UpdateBuilderMock(UpdateParams.empty, PgPartitionedTableFields, map) + } + override def upsert(unsaved: PgPartitionedTableRow): ZIO[ZConnection, Throwable, UpdateResult[PgPartitionedTableRow]] = { + ZIO.succeed { + map.put(unsaved.partrelid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRow.scala new file mode 100644 index 0000000000..6114a1a6f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPartitionedTableRow( + partrelid: PgPartitionedTableId, + partstrat: String, + partnatts: TypoShort, + partdefid: /* oid */ Long, + partattrs: TypoInt2Vector, + partclass: TypoOidVector, + partcollation: TypoOidVector, + partexprs: Option[TypoPgNodeTree] +) + +object PgPartitionedTableRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPartitionedTableRow] = new JdbcDecoder[PgPartitionedTableRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPartitionedTableRow) = + columIndex + 7 -> + PgPartitionedTableRow( + partrelid = PgPartitionedTableId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + partstrat = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + partnatts = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + partdefid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + partattrs = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + partclass = TypoOidVector.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + partcollation = TypoOidVector.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + partexprs = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPartitionedTableRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val partrelid = jsonObj.get("partrelid").toRight("Missing field 'partrelid'").flatMap(_.as(PgPartitionedTableId.jsonDecoder)) + val partstrat = jsonObj.get("partstrat").toRight("Missing field 'partstrat'").flatMap(_.as(JsonDecoder.string)) + val partnatts = jsonObj.get("partnatts").toRight("Missing field 'partnatts'").flatMap(_.as(TypoShort.jsonDecoder)) + val partdefid = jsonObj.get("partdefid").toRight("Missing field 'partdefid'").flatMap(_.as(JsonDecoder.long)) + val partattrs = jsonObj.get("partattrs").toRight("Missing field 'partattrs'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val partclass = jsonObj.get("partclass").toRight("Missing field 'partclass'").flatMap(_.as(TypoOidVector.jsonDecoder)) + val partcollation = jsonObj.get("partcollation").toRight("Missing field 'partcollation'").flatMap(_.as(TypoOidVector.jsonDecoder)) + val partexprs = jsonObj.get("partexprs").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (partrelid.isRight && partstrat.isRight && partnatts.isRight && partdefid.isRight && partattrs.isRight && partclass.isRight && partcollation.isRight && partexprs.isRight) + Right(PgPartitionedTableRow(partrelid = partrelid.toOption.get, partstrat = partstrat.toOption.get, partnatts = partnatts.toOption.get, partdefid = partdefid.toOption.get, partattrs = partattrs.toOption.get, partclass = partclass.toOption.get, partcollation = partcollation.toOption.get, partexprs = partexprs.toOption.get)) + else Left(List[Either[String, Any]](partrelid, partstrat, partnatts, partdefid, partattrs, partclass, partcollation, partexprs).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPartitionedTableRow] = new JsonEncoder[PgPartitionedTableRow] { + override def unsafeEncode(a: PgPartitionedTableRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""partrelid":""") + PgPartitionedTableId.jsonEncoder.unsafeEncode(a.partrelid, indent, out) + out.write(",") + out.write(""""partstrat":""") + JsonEncoder.string.unsafeEncode(a.partstrat, indent, out) + out.write(",") + out.write(""""partnatts":""") + TypoShort.jsonEncoder.unsafeEncode(a.partnatts, indent, out) + out.write(",") + out.write(""""partdefid":""") + JsonEncoder.long.unsafeEncode(a.partdefid, indent, out) + out.write(",") + out.write(""""partattrs":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.partattrs, indent, out) + out.write(",") + out.write(""""partclass":""") + TypoOidVector.jsonEncoder.unsafeEncode(a.partclass, indent, out) + out.write(",") + out.write(""""partcollation":""") + TypoOidVector.jsonEncoder.unsafeEncode(a.partcollation, indent, out) + out.write(",") + out.write(""""partexprs":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.partexprs, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableStructure.scala new file mode 100644 index 0000000000..aaaa448b0d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_partitioned_table/PgPartitionedTableStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_partitioned_table + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgPartitionedTableStructure[Row](val prefix: Option[String], val extract: Row => PgPartitionedTableRow, val merge: (Row, PgPartitionedTableRow) => Row) + extends Relation[PgPartitionedTableFields, PgPartitionedTableRow, Row] + with PgPartitionedTableFields[Row] { outer => + + override val partrelid = new IdField[PgPartitionedTableId, Row](prefix, "partrelid", None, Some("oid"))(x => extract(x).partrelid, (row, value) => merge(row, extract(row).copy(partrelid = value))) + override val partstrat = new Field[String, Row](prefix, "partstrat", None, Some("char"))(x => extract(x).partstrat, (row, value) => merge(row, extract(row).copy(partstrat = value))) + override val partnatts = new Field[TypoShort, Row](prefix, "partnatts", None, Some("int2"))(x => extract(x).partnatts, (row, value) => merge(row, extract(row).copy(partnatts = value))) + override val partdefid = new Field[/* oid */ Long, Row](prefix, "partdefid", None, Some("oid"))(x => extract(x).partdefid, (row, value) => merge(row, extract(row).copy(partdefid = value))) + override val partattrs = new Field[TypoInt2Vector, Row](prefix, "partattrs", None, Some("int2vector"))(x => extract(x).partattrs, (row, value) => merge(row, extract(row).copy(partattrs = value))) + override val partclass = new Field[TypoOidVector, Row](prefix, "partclass", None, Some("oidvector"))(x => extract(x).partclass, (row, value) => merge(row, extract(row).copy(partclass = value))) + override val partcollation = new Field[TypoOidVector, Row](prefix, "partcollation", None, Some("oidvector"))(x => extract(x).partcollation, (row, value) => merge(row, extract(row).copy(partcollation = value))) + override val partexprs = new OptField[TypoPgNodeTree, Row](prefix, "partexprs", None, Some("pg_node_tree"))(x => extract(x).partexprs, (row, value) => merge(row, extract(row).copy(partexprs = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](partrelid, partstrat, partnatts, partdefid, partattrs, partclass, partcollation, partexprs) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPartitionedTableRow, merge: (NewRow, PgPartitionedTableRow) => NewRow): PgPartitionedTableStructure[NewRow] = + new PgPartitionedTableStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewFields.scala new file mode 100644 index 0000000000..30a1e1bd98 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policies + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgPoliciesViewFields[Row] { + val schemaname: Field[String, Row] + val tablename: Field[String, Row] + val policyname: Field[String, Row] + val permissive: OptField[String, Row] + val roles: OptField[Array[String], Row] + val cmd: OptField[String, Row] + val qual: OptField[String, Row] + val withCheck: OptField[String, Row] +} +object PgPoliciesViewFields extends PgPoliciesViewStructure[PgPoliciesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepo.scala new file mode 100644 index 0000000000..a2a6eb4f4b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policies + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPoliciesViewRepo { + def select: SelectBuilder[PgPoliciesViewFields, PgPoliciesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgPoliciesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepoImpl.scala new file mode 100644 index 0000000000..a8b129ee6c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policies + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPoliciesViewRepoImpl extends PgPoliciesViewRepo { + override def select: SelectBuilder[PgPoliciesViewFields, PgPoliciesViewRow] = { + SelectBuilderSql("pg_catalog.pg_policies", PgPoliciesViewFields, PgPoliciesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPoliciesViewRow] = { + sql"""select "schemaname", "tablename", "policyname", "permissive", "roles", "cmd", "qual", "with_check" from pg_catalog.pg_policies""".query(PgPoliciesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRow.scala new file mode 100644 index 0000000000..8314660424 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewRow.scala @@ -0,0 +1,88 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policies + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPoliciesViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_policy.PgPolicyRow.polname]] */ + policyname: String, + permissive: /* nullability unknown */ Option[String], + roles: /* nullability unknown */ Option[Array[String]], + cmd: /* nullability unknown */ Option[String], + qual: /* nullability unknown */ Option[String], + withCheck: /* nullability unknown */ Option[String] +) + +object PgPoliciesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPoliciesViewRow] = new JdbcDecoder[PgPoliciesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPoliciesViewRow) = + columIndex + 7 -> + PgPoliciesViewRow( + schemaname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + policyname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + permissive = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + roles = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 4, rs)._2, + cmd = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + qual = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + withCheck = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPoliciesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").toRight("Missing field 'schemaname'").flatMap(_.as(JsonDecoder.string)) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val policyname = jsonObj.get("policyname").toRight("Missing field 'policyname'").flatMap(_.as(JsonDecoder.string)) + val permissive = jsonObj.get("permissive").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val roles = jsonObj.get("roles").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val cmd = jsonObj.get("cmd").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val qual = jsonObj.get("qual").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val withCheck = jsonObj.get("with_check").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (schemaname.isRight && tablename.isRight && policyname.isRight && permissive.isRight && roles.isRight && cmd.isRight && qual.isRight && withCheck.isRight) + Right(PgPoliciesViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, policyname = policyname.toOption.get, permissive = permissive.toOption.get, roles = roles.toOption.get, cmd = cmd.toOption.get, qual = qual.toOption.get, withCheck = withCheck.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, policyname, permissive, roles, cmd, qual, withCheck).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPoliciesViewRow] = new JsonEncoder[PgPoliciesViewRow] { + override def unsafeEncode(a: PgPoliciesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.string.unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""policyname":""") + JsonEncoder.string.unsafeEncode(a.policyname, indent, out) + out.write(",") + out.write(""""permissive":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.permissive, indent, out) + out.write(",") + out.write(""""roles":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.roles, indent, out) + out.write(",") + out.write(""""cmd":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.cmd, indent, out) + out.write(",") + out.write(""""qual":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.qual, indent, out) + out.write(",") + out.write(""""with_check":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.withCheck, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewStructure.scala new file mode 100644 index 0000000000..b887a89489 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policies/PgPoliciesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policies + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgPoliciesViewStructure[Row](val prefix: Option[String], val extract: Row => PgPoliciesViewRow, val merge: (Row, PgPoliciesViewRow) => Row) + extends Relation[PgPoliciesViewFields, PgPoliciesViewRow, Row] + with PgPoliciesViewFields[Row] { outer => + + override val schemaname = new Field[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val policyname = new Field[String, Row](prefix, "policyname", None, None)(x => extract(x).policyname, (row, value) => merge(row, extract(row).copy(policyname = value))) + override val permissive = new OptField[String, Row](prefix, "permissive", None, None)(x => extract(x).permissive, (row, value) => merge(row, extract(row).copy(permissive = value))) + override val roles = new OptField[Array[String], Row](prefix, "roles", None, None)(x => extract(x).roles, (row, value) => merge(row, extract(row).copy(roles = value))) + override val cmd = new OptField[String, Row](prefix, "cmd", None, None)(x => extract(x).cmd, (row, value) => merge(row, extract(row).copy(cmd = value))) + override val qual = new OptField[String, Row](prefix, "qual", None, None)(x => extract(x).qual, (row, value) => merge(row, extract(row).copy(qual = value))) + override val withCheck = new OptField[String, Row](prefix, "with_check", None, None)(x => extract(x).withCheck, (row, value) => merge(row, extract(row).copy(withCheck = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, policyname, permissive, roles, cmd, qual, withCheck) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPoliciesViewRow, merge: (NewRow, PgPoliciesViewRow) => NewRow): PgPoliciesViewStructure[NewRow] = + new PgPoliciesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyFields.scala new file mode 100644 index 0000000000..c405d7e15f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgPolicyFields[Row] { + val oid: IdField[PgPolicyId, Row] + val polname: Field[String, Row] + val polrelid: Field[/* oid */ Long, Row] + val polcmd: Field[String, Row] + val polpermissive: Field[Boolean, Row] + val polroles: Field[Array[/* oid */ Long], Row] + val polqual: OptField[TypoPgNodeTree, Row] + val polwithcheck: OptField[TypoPgNodeTree, Row] +} +object PgPolicyFields extends PgPolicyStructure[PgPolicyRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyId.scala new file mode 100644 index 0000000000..54e41d4e6d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +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 `pg_catalog.pg_policy` */ +case class PgPolicyId(value: /* oid */ Long) extends AnyVal +object PgPolicyId { + implicit lazy val arraySetter: Setter[Array[PgPolicyId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgPolicyId, /* oid */ Long] = Bijection[PgPolicyId, /* oid */ Long](_.value)(PgPolicyId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgPolicyId] = JdbcDecoder.longDecoder.map(PgPolicyId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgPolicyId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgPolicyId] = JsonDecoder.long.map(PgPolicyId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgPolicyId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgPolicyId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgPolicyId] = ParameterMetaData.instance[PgPolicyId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgPolicyId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepo.scala new file mode 100644 index 0000000000..297da3c3de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPolicyRepo { + def delete(oid: PgPolicyId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgPolicyFields, PgPolicyRow] + def insert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, PgPolicyRow] + def select: SelectBuilder[PgPolicyFields, PgPolicyRow] + def selectAll: ZStream[ZConnection, Throwable, PgPolicyRow] + def selectById(oid: PgPolicyId): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] + def selectByIds(oids: Array[PgPolicyId]): ZStream[ZConnection, Throwable, PgPolicyRow] + def selectByUnique(polrelid: /* oid */ Long, polname: String): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] + def update(row: PgPolicyRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgPolicyFields, PgPolicyRow] + def upsert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, UpdateResult[PgPolicyRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoImpl.scala new file mode 100644 index 0000000000..4fe246abb9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoImpl.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPolicyRepoImpl extends PgPolicyRepo { + override def delete(oid: PgPolicyId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_policy where "oid" = ${Segment.paramSegment(oid)(PgPolicyId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgPolicyFields, PgPolicyRow] = { + DeleteBuilder("pg_catalog.pg_policy", PgPolicyFields) + } + override def insert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, PgPolicyRow] = { + sql"""insert into pg_catalog.pg_policy("oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck") + values (${Segment.paramSegment(unsaved.oid)(PgPolicyId.setter)}::oid, ${Segment.paramSegment(unsaved.polname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.polrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.polcmd)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.polpermissive)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.polroles)(adventureworks.LongArraySetter)}::_oid, ${Segment.paramSegment(unsaved.polqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.polwithcheck)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck" + """.insertReturning(PgPolicyRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgPolicyFields, PgPolicyRow] = { + SelectBuilderSql("pg_catalog.pg_policy", PgPolicyFields, PgPolicyRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPolicyRow] = { + sql"""select "oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck" from pg_catalog.pg_policy""".query(PgPolicyRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgPolicyId): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] = { + sql"""select "oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck" from pg_catalog.pg_policy where "oid" = ${Segment.paramSegment(oid)(PgPolicyId.setter)}""".query(PgPolicyRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgPolicyId]): ZStream[ZConnection, Throwable, PgPolicyRow] = { + sql"""select "oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck" from pg_catalog.pg_policy where "oid" = ANY(${Segment.paramSegment(oids)(PgPolicyId.arraySetter)})""".query(PgPolicyRow.jdbcDecoder).selectStream + } + override def selectByUnique(polrelid: /* oid */ Long, polname: String): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] = { + sql"""select "polrelid", "polname" + from pg_catalog.pg_policy + where "polrelid" = ${Segment.paramSegment(polrelid)(Setter.longSetter)} AND "polname" = ${Segment.paramSegment(polname)(Setter.stringSetter)} + """.query(PgPolicyRow.jdbcDecoder).selectOne + } + override def update(row: PgPolicyRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_policy + set "polname" = ${Segment.paramSegment(row.polname)(Setter.stringSetter)}::name, + "polrelid" = ${Segment.paramSegment(row.polrelid)(Setter.longSetter)}::oid, + "polcmd" = ${Segment.paramSegment(row.polcmd)(Setter.stringSetter)}::char, + "polpermissive" = ${Segment.paramSegment(row.polpermissive)(Setter.booleanSetter)}, + "polroles" = ${Segment.paramSegment(row.polroles)(adventureworks.LongArraySetter)}::_oid, + "polqual" = ${Segment.paramSegment(row.polqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "polwithcheck" = ${Segment.paramSegment(row.polwithcheck)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgPolicyId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgPolicyFields, PgPolicyRow] = { + UpdateBuilder("pg_catalog.pg_policy", PgPolicyFields, PgPolicyRow.jdbcDecoder) + } + override def upsert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, UpdateResult[PgPolicyRow]] = { + sql"""insert into pg_catalog.pg_policy("oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck") + values ( + ${Segment.paramSegment(unsaved.oid)(PgPolicyId.setter)}::oid, + ${Segment.paramSegment(unsaved.polname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.polrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.polcmd)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.polpermissive)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.polroles)(adventureworks.LongArraySetter)}::_oid, + ${Segment.paramSegment(unsaved.polqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.polwithcheck)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("oid") + do update set + "polname" = EXCLUDED."polname", + "polrelid" = EXCLUDED."polrelid", + "polcmd" = EXCLUDED."polcmd", + "polpermissive" = EXCLUDED."polpermissive", + "polroles" = EXCLUDED."polroles", + "polqual" = EXCLUDED."polqual", + "polwithcheck" = EXCLUDED."polwithcheck" + returning "oid", "polname", "polrelid", "polcmd", "polpermissive", "polroles", "polqual", "polwithcheck"""".insertReturning(PgPolicyRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoMock.scala new file mode 100644 index 0000000000..39976e1a9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgPolicyRepoMock(map: scala.collection.mutable.Map[PgPolicyId, PgPolicyRow] = scala.collection.mutable.Map.empty) extends PgPolicyRepo { + override def delete(oid: PgPolicyId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgPolicyFields, PgPolicyRow] = { + DeleteBuilderMock(DeleteParams.empty, PgPolicyFields, map) + } + override def insert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, PgPolicyRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgPolicyFields, PgPolicyRow] = { + SelectBuilderMock(PgPolicyFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPolicyRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgPolicyId): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgPolicyId]): ZStream[ZConnection, Throwable, PgPolicyRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(polrelid: /* oid */ Long, polname: String): ZIO[ZConnection, Throwable, Option[PgPolicyRow]] = { + ZIO.succeed(map.values.find(v => polrelid == v.polrelid && polname == v.polname)) + } + override def update(row: PgPolicyRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgPolicyFields, PgPolicyRow] = { + UpdateBuilderMock(UpdateParams.empty, PgPolicyFields, map) + } + override def upsert(unsaved: PgPolicyRow): ZIO[ZConnection, Throwable, UpdateResult[PgPolicyRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRow.scala new file mode 100644 index 0000000000..35c057b079 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import adventureworks.customtypes.TypoPgNodeTree +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPolicyRow( + oid: PgPolicyId, + polname: String, + polrelid: /* oid */ Long, + polcmd: String, + polpermissive: Boolean, + polroles: Array[/* oid */ Long], + polqual: Option[TypoPgNodeTree], + polwithcheck: Option[TypoPgNodeTree] +) + +object PgPolicyRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPolicyRow] = new JdbcDecoder[PgPolicyRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPolicyRow) = + columIndex + 7 -> + PgPolicyRow( + oid = PgPolicyId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + polname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + polrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + polcmd = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + polpermissive = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + polroles = adventureworks.LongArrayDecoder.unsafeDecode(columIndex + 5, rs)._2, + polqual = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + polwithcheck = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPolicyRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgPolicyId.jsonDecoder)) + val polname = jsonObj.get("polname").toRight("Missing field 'polname'").flatMap(_.as(JsonDecoder.string)) + val polrelid = jsonObj.get("polrelid").toRight("Missing field 'polrelid'").flatMap(_.as(JsonDecoder.long)) + val polcmd = jsonObj.get("polcmd").toRight("Missing field 'polcmd'").flatMap(_.as(JsonDecoder.string)) + val polpermissive = jsonObj.get("polpermissive").toRight("Missing field 'polpermissive'").flatMap(_.as(JsonDecoder.boolean)) + val polroles = jsonObj.get("polroles").toRight("Missing field 'polroles'").flatMap(_.as(JsonDecoder.array[Long](JsonDecoder.long, implicitly))) + val polqual = jsonObj.get("polqual").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val polwithcheck = jsonObj.get("polwithcheck").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (oid.isRight && polname.isRight && polrelid.isRight && polcmd.isRight && polpermissive.isRight && polroles.isRight && polqual.isRight && polwithcheck.isRight) + Right(PgPolicyRow(oid = oid.toOption.get, polname = polname.toOption.get, polrelid = polrelid.toOption.get, polcmd = polcmd.toOption.get, polpermissive = polpermissive.toOption.get, polroles = polroles.toOption.get, polqual = polqual.toOption.get, polwithcheck = polwithcheck.toOption.get)) + else Left(List[Either[String, Any]](oid, polname, polrelid, polcmd, polpermissive, polroles, polqual, polwithcheck).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPolicyRow] = new JsonEncoder[PgPolicyRow] { + override def unsafeEncode(a: PgPolicyRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgPolicyId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""polname":""") + JsonEncoder.string.unsafeEncode(a.polname, indent, out) + out.write(",") + out.write(""""polrelid":""") + JsonEncoder.long.unsafeEncode(a.polrelid, indent, out) + out.write(",") + out.write(""""polcmd":""") + JsonEncoder.string.unsafeEncode(a.polcmd, indent, out) + out.write(",") + out.write(""""polpermissive":""") + JsonEncoder.boolean.unsafeEncode(a.polpermissive, indent, out) + out.write(",") + out.write(""""polroles":""") + JsonEncoder.array[Long](JsonEncoder.long, implicitly).unsafeEncode(a.polroles, indent, out) + out.write(",") + out.write(""""polqual":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.polqual, indent, out) + out.write(",") + out.write(""""polwithcheck":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.polwithcheck, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyStructure.scala new file mode 100644 index 0000000000..c8fc73eabc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_policy/PgPolicyStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_policy + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgPolicyStructure[Row](val prefix: Option[String], val extract: Row => PgPolicyRow, val merge: (Row, PgPolicyRow) => Row) + extends Relation[PgPolicyFields, PgPolicyRow, Row] + with PgPolicyFields[Row] { outer => + + override val oid = new IdField[PgPolicyId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val polname = new Field[String, Row](prefix, "polname", None, Some("name"))(x => extract(x).polname, (row, value) => merge(row, extract(row).copy(polname = value))) + override val polrelid = new Field[/* oid */ Long, Row](prefix, "polrelid", None, Some("oid"))(x => extract(x).polrelid, (row, value) => merge(row, extract(row).copy(polrelid = value))) + override val polcmd = new Field[String, Row](prefix, "polcmd", None, Some("char"))(x => extract(x).polcmd, (row, value) => merge(row, extract(row).copy(polcmd = value))) + override val polpermissive = new Field[Boolean, Row](prefix, "polpermissive", None, None)(x => extract(x).polpermissive, (row, value) => merge(row, extract(row).copy(polpermissive = value))) + override val polroles = new Field[Array[/* oid */ Long], Row](prefix, "polroles", None, Some("_oid"))(x => extract(x).polroles, (row, value) => merge(row, extract(row).copy(polroles = value))) + override val polqual = new OptField[TypoPgNodeTree, Row](prefix, "polqual", None, Some("pg_node_tree"))(x => extract(x).polqual, (row, value) => merge(row, extract(row).copy(polqual = value))) + override val polwithcheck = new OptField[TypoPgNodeTree, Row](prefix, "polwithcheck", None, Some("pg_node_tree"))(x => extract(x).polwithcheck, (row, value) => merge(row, extract(row).copy(polwithcheck = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, polname, polrelid, polcmd, polpermissive, polroles, polqual, polwithcheck) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPolicyRow, merge: (NewRow, PgPolicyRow) => NewRow): PgPolicyStructure[NewRow] = + new PgPolicyStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewFields.scala new file mode 100644 index 0000000000..9707a496de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_statements + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoRegtype +import typo.dsl.SqlExpr.OptField + +trait PgPreparedStatementsViewFields[Row] { + val name: OptField[String, Row] + val statement: OptField[String, Row] + val prepareTime: OptField[TypoInstant, Row] + val parameterTypes: OptField[Array[TypoRegtype], Row] + val fromSql: OptField[Boolean, Row] + val genericPlans: OptField[Long, Row] + val customPlans: OptField[Long, Row] +} +object PgPreparedStatementsViewFields extends PgPreparedStatementsViewStructure[PgPreparedStatementsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepo.scala new file mode 100644 index 0000000000..3e413990c4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_statements + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPreparedStatementsViewRepo { + def select: SelectBuilder[PgPreparedStatementsViewFields, PgPreparedStatementsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgPreparedStatementsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepoImpl.scala new file mode 100644 index 0000000000..4599b5f602 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_statements + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPreparedStatementsViewRepoImpl extends PgPreparedStatementsViewRepo { + override def select: SelectBuilder[PgPreparedStatementsViewFields, PgPreparedStatementsViewRow] = { + SelectBuilderSql("pg_catalog.pg_prepared_statements", PgPreparedStatementsViewFields, PgPreparedStatementsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPreparedStatementsViewRow] = { + sql"""select "name", "statement", "prepare_time"::text, "parameter_types", "from_sql", "generic_plans", "custom_plans" from pg_catalog.pg_prepared_statements""".query(PgPreparedStatementsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRow.scala new file mode 100644 index 0000000000..be795b158b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_statements + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoRegtype +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPreparedStatementsViewRow( + name: /* nullability unknown */ Option[String], + statement: /* nullability unknown */ Option[String], + prepareTime: /* nullability unknown */ Option[TypoInstant], + parameterTypes: /* nullability unknown */ Option[Array[TypoRegtype]], + fromSql: /* nullability unknown */ Option[Boolean], + genericPlans: /* nullability unknown */ Option[Long], + customPlans: /* nullability unknown */ Option[Long] +) + +object PgPreparedStatementsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPreparedStatementsViewRow] = new JdbcDecoder[PgPreparedStatementsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPreparedStatementsViewRow) = + columIndex + 6 -> + PgPreparedStatementsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + statement = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + prepareTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + parameterTypes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoRegtype]]).unsafeDecode(columIndex + 3, rs)._2, + fromSql = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 4, rs)._2, + genericPlans = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + customPlans = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPreparedStatementsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val statement = jsonObj.get("statement").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val prepareTime = jsonObj.get("prepare_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val parameterTypes = jsonObj.get("parameter_types").fold[Either[String, Option[Array[TypoRegtype]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoRegtype](TypoRegtype.jsonDecoder, implicitly)))) + val fromSql = jsonObj.get("from_sql").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val genericPlans = jsonObj.get("generic_plans").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val customPlans = jsonObj.get("custom_plans").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (name.isRight && statement.isRight && prepareTime.isRight && parameterTypes.isRight && fromSql.isRight && genericPlans.isRight && customPlans.isRight) + Right(PgPreparedStatementsViewRow(name = name.toOption.get, statement = statement.toOption.get, prepareTime = prepareTime.toOption.get, parameterTypes = parameterTypes.toOption.get, fromSql = fromSql.toOption.get, genericPlans = genericPlans.toOption.get, customPlans = customPlans.toOption.get)) + else Left(List[Either[String, Any]](name, statement, prepareTime, parameterTypes, fromSql, genericPlans, customPlans).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPreparedStatementsViewRow] = new JsonEncoder[PgPreparedStatementsViewRow] { + override def unsafeEncode(a: PgPreparedStatementsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""statement":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statement, indent, out) + out.write(",") + out.write(""""prepare_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.prepareTime, indent, out) + out.write(",") + out.write(""""parameter_types":""") + JsonEncoder.option(JsonEncoder.array[TypoRegtype](TypoRegtype.jsonEncoder, implicitly)).unsafeEncode(a.parameterTypes, indent, out) + out.write(",") + out.write(""""from_sql":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.fromSql, indent, out) + out.write(",") + out.write(""""generic_plans":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.genericPlans, indent, out) + out.write(",") + out.write(""""custom_plans":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.customPlans, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewStructure.scala new file mode 100644 index 0000000000..4441a3e775 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_statements/PgPreparedStatementsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_statements + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoRegtype +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgPreparedStatementsViewStructure[Row](val prefix: Option[String], val extract: Row => PgPreparedStatementsViewRow, val merge: (Row, PgPreparedStatementsViewRow) => Row) + extends Relation[PgPreparedStatementsViewFields, PgPreparedStatementsViewRow, Row] + with PgPreparedStatementsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val statement = new OptField[String, Row](prefix, "statement", None, None)(x => extract(x).statement, (row, value) => merge(row, extract(row).copy(statement = value))) + override val prepareTime = new OptField[TypoInstant, Row](prefix, "prepare_time", Some("text"), None)(x => extract(x).prepareTime, (row, value) => merge(row, extract(row).copy(prepareTime = value))) + override val parameterTypes = new OptField[Array[TypoRegtype], Row](prefix, "parameter_types", None, None)(x => extract(x).parameterTypes, (row, value) => merge(row, extract(row).copy(parameterTypes = value))) + override val fromSql = new OptField[Boolean, Row](prefix, "from_sql", None, None)(x => extract(x).fromSql, (row, value) => merge(row, extract(row).copy(fromSql = value))) + override val genericPlans = new OptField[Long, Row](prefix, "generic_plans", None, None)(x => extract(x).genericPlans, (row, value) => merge(row, extract(row).copy(genericPlans = value))) + override val customPlans = new OptField[Long, Row](prefix, "custom_plans", None, None)(x => extract(x).customPlans, (row, value) => merge(row, extract(row).copy(customPlans = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, statement, prepareTime, parameterTypes, fromSql, genericPlans, customPlans) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPreparedStatementsViewRow, merge: (NewRow, PgPreparedStatementsViewRow) => NewRow): PgPreparedStatementsViewStructure[NewRow] = + new PgPreparedStatementsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewFields.scala new file mode 100644 index 0000000000..6e7d868efb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_xacts + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.OptField + +trait PgPreparedXactsViewFields[Row] { + val transaction: OptField[TypoXid, Row] + val gid: OptField[String, Row] + val prepared: OptField[TypoInstant, Row] + val owner: OptField[String, Row] + val database: OptField[String, Row] +} +object PgPreparedXactsViewFields extends PgPreparedXactsViewStructure[PgPreparedXactsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepo.scala new file mode 100644 index 0000000000..36e41d804d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_xacts + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPreparedXactsViewRepo { + def select: SelectBuilder[PgPreparedXactsViewFields, PgPreparedXactsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgPreparedXactsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepoImpl.scala new file mode 100644 index 0000000000..2b9e677283 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_xacts + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPreparedXactsViewRepoImpl extends PgPreparedXactsViewRepo { + override def select: SelectBuilder[PgPreparedXactsViewFields, PgPreparedXactsViewRow] = { + SelectBuilderSql("pg_catalog.pg_prepared_xacts", PgPreparedXactsViewFields, PgPreparedXactsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPreparedXactsViewRow] = { + sql"""select "transaction", "gid", "prepared"::text, "owner", "database" from pg_catalog.pg_prepared_xacts""".query(PgPreparedXactsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRow.scala new file mode 100644 index 0000000000..bfca02da77 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_xacts + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPreparedXactsViewRow( + transaction: /* nullability unknown */ Option[TypoXid], + gid: /* nullability unknown */ Option[String], + prepared: /* nullability unknown */ Option[TypoInstant], + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + owner: Option[String], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + database: Option[String] +) + +object PgPreparedXactsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPreparedXactsViewRow] = new JdbcDecoder[PgPreparedXactsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPreparedXactsViewRow) = + columIndex + 4 -> + PgPreparedXactsViewRow( + transaction = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + gid = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + prepared = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + owner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + database = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPreparedXactsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val transaction = jsonObj.get("transaction").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val gid = jsonObj.get("gid").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val prepared = jsonObj.get("prepared").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val owner = jsonObj.get("owner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val database = jsonObj.get("database").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (transaction.isRight && gid.isRight && prepared.isRight && owner.isRight && database.isRight) + Right(PgPreparedXactsViewRow(transaction = transaction.toOption.get, gid = gid.toOption.get, prepared = prepared.toOption.get, owner = owner.toOption.get, database = database.toOption.get)) + else Left(List[Either[String, Any]](transaction, gid, prepared, owner, database).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPreparedXactsViewRow] = new JsonEncoder[PgPreparedXactsViewRow] { + override def unsafeEncode(a: PgPreparedXactsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""transaction":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.transaction, indent, out) + out.write(",") + out.write(""""gid":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.gid, indent, out) + out.write(",") + out.write(""""prepared":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.prepared, indent, out) + out.write(",") + out.write(""""owner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.owner, indent, out) + out.write(",") + out.write(""""database":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.database, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewStructure.scala new file mode 100644 index 0000000000..10c7bb8240 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_prepared_xacts/PgPreparedXactsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_prepared_xacts + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgPreparedXactsViewStructure[Row](val prefix: Option[String], val extract: Row => PgPreparedXactsViewRow, val merge: (Row, PgPreparedXactsViewRow) => Row) + extends Relation[PgPreparedXactsViewFields, PgPreparedXactsViewRow, Row] + with PgPreparedXactsViewFields[Row] { outer => + + override val transaction = new OptField[TypoXid, Row](prefix, "transaction", None, None)(x => extract(x).transaction, (row, value) => merge(row, extract(row).copy(transaction = value))) + override val gid = new OptField[String, Row](prefix, "gid", None, None)(x => extract(x).gid, (row, value) => merge(row, extract(row).copy(gid = value))) + override val prepared = new OptField[TypoInstant, Row](prefix, "prepared", Some("text"), None)(x => extract(x).prepared, (row, value) => merge(row, extract(row).copy(prepared = value))) + override val owner = new OptField[String, Row](prefix, "owner", None, None)(x => extract(x).owner, (row, value) => merge(row, extract(row).copy(owner = value))) + override val database = new OptField[String, Row](prefix, "database", None, None)(x => extract(x).database, (row, value) => merge(row, extract(row).copy(database = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](transaction, gid, prepared, owner, database) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPreparedXactsViewRow, merge: (NewRow, PgPreparedXactsViewRow) => NewRow): PgPreparedXactsViewStructure[NewRow] = + new PgPreparedXactsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcFields.scala new file mode 100644 index 0000000000..99d3a9b7a6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcFields.scala @@ -0,0 +1,52 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgProcFields[Row] { + val oid: IdField[PgProcId, Row] + val proname: Field[String, Row] + val pronamespace: Field[/* oid */ Long, Row] + val proowner: Field[/* oid */ Long, Row] + val prolang: Field[/* oid */ Long, Row] + val procost: Field[Float, Row] + val prorows: Field[Float, Row] + val provariadic: Field[/* oid */ Long, Row] + val prosupport: Field[TypoRegproc, Row] + val prokind: Field[String, Row] + val prosecdef: Field[Boolean, Row] + val proleakproof: Field[Boolean, Row] + val proisstrict: Field[Boolean, Row] + val proretset: Field[Boolean, Row] + val provolatile: Field[String, Row] + val proparallel: Field[String, Row] + val pronargs: Field[TypoShort, Row] + val pronargdefaults: Field[TypoShort, Row] + val prorettype: Field[/* oid */ Long, Row] + val proargtypes: Field[TypoOidVector, Row] + val proallargtypes: OptField[Array[/* oid */ Long], Row] + val proargmodes: OptField[Array[String], Row] + val proargnames: OptField[Array[String], Row] + val proargdefaults: OptField[TypoPgNodeTree, Row] + val protrftypes: OptField[Array[/* oid */ Long], Row] + val prosrc: Field[String, Row] + val probin: OptField[String, Row] + val prosqlbody: OptField[TypoPgNodeTree, Row] + val proconfig: OptField[Array[String], Row] + val proacl: OptField[Array[TypoAclItem], Row] +} +object PgProcFields extends PgProcStructure[PgProcRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcId.scala new file mode 100644 index 0000000000..a9de61f794 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +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 `pg_catalog.pg_proc` */ +case class PgProcId(value: /* oid */ Long) extends AnyVal +object PgProcId { + implicit lazy val arraySetter: Setter[Array[PgProcId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgProcId, /* oid */ Long] = Bijection[PgProcId, /* oid */ Long](_.value)(PgProcId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgProcId] = JdbcDecoder.longDecoder.map(PgProcId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgProcId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgProcId] = JsonDecoder.long.map(PgProcId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgProcId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgProcId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgProcId] = ParameterMetaData.instance[PgProcId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgProcId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepo.scala new file mode 100644 index 0000000000..33e1f26cad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoOidVector +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgProcRepo { + def delete(oid: PgProcId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgProcFields, PgProcRow] + def insert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, PgProcRow] + def select: SelectBuilder[PgProcFields, PgProcRow] + def selectAll: ZStream[ZConnection, Throwable, PgProcRow] + def selectById(oid: PgProcId): ZIO[ZConnection, Throwable, Option[PgProcRow]] + def selectByIds(oids: Array[PgProcId]): ZStream[ZConnection, Throwable, PgProcRow] + def selectByUnique(proname: String, proargtypes: TypoOidVector, pronamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgProcRow]] + def update(row: PgProcRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgProcFields, PgProcRow] + def upsert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, UpdateResult[PgProcRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoImpl.scala new file mode 100644 index 0000000000..886f3ebf83 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoImpl.scala @@ -0,0 +1,162 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgProcRepoImpl extends PgProcRepo { + override def delete(oid: PgProcId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_proc where "oid" = ${Segment.paramSegment(oid)(PgProcId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgProcFields, PgProcRow] = { + DeleteBuilder("pg_catalog.pg_proc", PgProcFields) + } + override def insert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, PgProcRow] = { + sql"""insert into pg_catalog.pg_proc("oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl") + values (${Segment.paramSegment(unsaved.oid)(PgProcId.setter)}::oid, ${Segment.paramSegment(unsaved.proname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.pronamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.proowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.prolang)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.procost)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.prorows)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.provariadic)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.prosupport)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.prokind)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.prosecdef)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.proleakproof)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.proisstrict)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.proretset)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.provolatile)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.proparallel)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.pronargs)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.pronargdefaults)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.prorettype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.proargtypes)(TypoOidVector.setter)}::oidvector, ${Segment.paramSegment(unsaved.proallargtypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.proargmodes)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_char, ${Segment.paramSegment(unsaved.proargnames)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.proargdefaults)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.protrftypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, ${Segment.paramSegment(unsaved.prosrc)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.probin)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.prosqlbody)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.proconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.proacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl" + """.insertReturning(PgProcRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgProcFields, PgProcRow] = { + SelectBuilderSql("pg_catalog.pg_proc", PgProcFields, PgProcRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgProcRow] = { + sql"""select "oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl" from pg_catalog.pg_proc""".query(PgProcRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgProcId): ZIO[ZConnection, Throwable, Option[PgProcRow]] = { + sql"""select "oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl" from pg_catalog.pg_proc where "oid" = ${Segment.paramSegment(oid)(PgProcId.setter)}""".query(PgProcRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgProcId]): ZStream[ZConnection, Throwable, PgProcRow] = { + sql"""select "oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl" from pg_catalog.pg_proc where "oid" = ANY(${Segment.paramSegment(oids)(PgProcId.arraySetter)})""".query(PgProcRow.jdbcDecoder).selectStream + } + override def selectByUnique(proname: String, proargtypes: TypoOidVector, pronamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgProcRow]] = { + sql"""select "proname", "proargtypes", "pronamespace" + from pg_catalog.pg_proc + where "proname" = ${Segment.paramSegment(proname)(Setter.stringSetter)} AND "proargtypes" = ${Segment.paramSegment(proargtypes)(TypoOidVector.setter)} AND "pronamespace" = ${Segment.paramSegment(pronamespace)(Setter.longSetter)} + """.query(PgProcRow.jdbcDecoder).selectOne + } + override def update(row: PgProcRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_proc + set "proname" = ${Segment.paramSegment(row.proname)(Setter.stringSetter)}::name, + "pronamespace" = ${Segment.paramSegment(row.pronamespace)(Setter.longSetter)}::oid, + "proowner" = ${Segment.paramSegment(row.proowner)(Setter.longSetter)}::oid, + "prolang" = ${Segment.paramSegment(row.prolang)(Setter.longSetter)}::oid, + "procost" = ${Segment.paramSegment(row.procost)(Setter.floatSetter)}::float4, + "prorows" = ${Segment.paramSegment(row.prorows)(Setter.floatSetter)}::float4, + "provariadic" = ${Segment.paramSegment(row.provariadic)(Setter.longSetter)}::oid, + "prosupport" = ${Segment.paramSegment(row.prosupport)(TypoRegproc.setter)}::regproc, + "prokind" = ${Segment.paramSegment(row.prokind)(Setter.stringSetter)}::char, + "prosecdef" = ${Segment.paramSegment(row.prosecdef)(Setter.booleanSetter)}, + "proleakproof" = ${Segment.paramSegment(row.proleakproof)(Setter.booleanSetter)}, + "proisstrict" = ${Segment.paramSegment(row.proisstrict)(Setter.booleanSetter)}, + "proretset" = ${Segment.paramSegment(row.proretset)(Setter.booleanSetter)}, + "provolatile" = ${Segment.paramSegment(row.provolatile)(Setter.stringSetter)}::char, + "proparallel" = ${Segment.paramSegment(row.proparallel)(Setter.stringSetter)}::char, + "pronargs" = ${Segment.paramSegment(row.pronargs)(TypoShort.setter)}::int2, + "pronargdefaults" = ${Segment.paramSegment(row.pronargdefaults)(TypoShort.setter)}::int2, + "prorettype" = ${Segment.paramSegment(row.prorettype)(Setter.longSetter)}::oid, + "proargtypes" = ${Segment.paramSegment(row.proargtypes)(TypoOidVector.setter)}::oidvector, + "proallargtypes" = ${Segment.paramSegment(row.proallargtypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "proargmodes" = ${Segment.paramSegment(row.proargmodes)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_char, + "proargnames" = ${Segment.paramSegment(row.proargnames)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + "proargdefaults" = ${Segment.paramSegment(row.proargdefaults)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "protrftypes" = ${Segment.paramSegment(row.protrftypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + "prosrc" = ${Segment.paramSegment(row.prosrc)(Setter.stringSetter)}, + "probin" = ${Segment.paramSegment(row.probin)(Setter.optionParamSetter(Setter.stringSetter))}, + "prosqlbody" = ${Segment.paramSegment(row.prosqlbody)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "proconfig" = ${Segment.paramSegment(row.proconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + "proacl" = ${Segment.paramSegment(row.proacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgProcId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgProcFields, PgProcRow] = { + UpdateBuilder("pg_catalog.pg_proc", PgProcFields, PgProcRow.jdbcDecoder) + } + override def upsert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, UpdateResult[PgProcRow]] = { + sql"""insert into pg_catalog.pg_proc("oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgProcId.setter)}::oid, + ${Segment.paramSegment(unsaved.proname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.pronamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.proowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.prolang)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.procost)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.prorows)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.provariadic)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.prosupport)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.prokind)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.prosecdef)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.proleakproof)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.proisstrict)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.proretset)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.provolatile)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.proparallel)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.pronargs)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.pronargdefaults)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.prorettype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.proargtypes)(TypoOidVector.setter)}::oidvector, + ${Segment.paramSegment(unsaved.proallargtypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.proargmodes)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_char, + ${Segment.paramSegment(unsaved.proargnames)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + ${Segment.paramSegment(unsaved.proargdefaults)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.protrftypes)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_oid, + ${Segment.paramSegment(unsaved.prosrc)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.probin)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.prosqlbody)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.proconfig)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, + ${Segment.paramSegment(unsaved.proacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "proname" = EXCLUDED."proname", + "pronamespace" = EXCLUDED."pronamespace", + "proowner" = EXCLUDED."proowner", + "prolang" = EXCLUDED."prolang", + "procost" = EXCLUDED."procost", + "prorows" = EXCLUDED."prorows", + "provariadic" = EXCLUDED."provariadic", + "prosupport" = EXCLUDED."prosupport", + "prokind" = EXCLUDED."prokind", + "prosecdef" = EXCLUDED."prosecdef", + "proleakproof" = EXCLUDED."proleakproof", + "proisstrict" = EXCLUDED."proisstrict", + "proretset" = EXCLUDED."proretset", + "provolatile" = EXCLUDED."provolatile", + "proparallel" = EXCLUDED."proparallel", + "pronargs" = EXCLUDED."pronargs", + "pronargdefaults" = EXCLUDED."pronargdefaults", + "prorettype" = EXCLUDED."prorettype", + "proargtypes" = EXCLUDED."proargtypes", + "proallargtypes" = EXCLUDED."proallargtypes", + "proargmodes" = EXCLUDED."proargmodes", + "proargnames" = EXCLUDED."proargnames", + "proargdefaults" = EXCLUDED."proargdefaults", + "protrftypes" = EXCLUDED."protrftypes", + "prosrc" = EXCLUDED."prosrc", + "probin" = EXCLUDED."probin", + "prosqlbody" = EXCLUDED."prosqlbody", + "proconfig" = EXCLUDED."proconfig", + "proacl" = EXCLUDED."proacl" + returning "oid", "proname", "pronamespace", "proowner", "prolang", "procost", "prorows", "provariadic", "prosupport", "prokind", "prosecdef", "proleakproof", "proisstrict", "proretset", "provolatile", "proparallel", "pronargs", "pronargdefaults", "prorettype", "proargtypes", "proallargtypes", "proargmodes", "proargnames", "proargdefaults", "protrftypes", "prosrc", "probin", "prosqlbody", "proconfig", "proacl"""".insertReturning(PgProcRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoMock.scala new file mode 100644 index 0000000000..872f543f6e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoOidVector +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgProcRepoMock(map: scala.collection.mutable.Map[PgProcId, PgProcRow] = scala.collection.mutable.Map.empty) extends PgProcRepo { + override def delete(oid: PgProcId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgProcFields, PgProcRow] = { + DeleteBuilderMock(DeleteParams.empty, PgProcFields, map) + } + override def insert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, PgProcRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgProcFields, PgProcRow] = { + SelectBuilderMock(PgProcFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgProcRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgProcId): ZIO[ZConnection, Throwable, Option[PgProcRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgProcId]): ZStream[ZConnection, Throwable, PgProcRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(proname: String, proargtypes: TypoOidVector, pronamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgProcRow]] = { + ZIO.succeed(map.values.find(v => proname == v.proname && proargtypes == v.proargtypes && pronamespace == v.pronamespace)) + } + override def update(row: PgProcRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgProcFields, PgProcRow] = { + UpdateBuilderMock(UpdateParams.empty, PgProcFields, map) + } + override def upsert(unsaved: PgProcRow): ZIO[ZConnection, Throwable, UpdateResult[PgProcRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRow.scala new file mode 100644 index 0000000000..3eea36ab95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcRow.scala @@ -0,0 +1,222 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgProcRow( + oid: PgProcId, + proname: String, + pronamespace: /* oid */ Long, + proowner: /* oid */ Long, + prolang: /* oid */ Long, + procost: Float, + prorows: Float, + provariadic: /* oid */ Long, + prosupport: TypoRegproc, + prokind: String, + prosecdef: Boolean, + proleakproof: Boolean, + proisstrict: Boolean, + proretset: Boolean, + provolatile: String, + proparallel: String, + pronargs: TypoShort, + pronargdefaults: TypoShort, + prorettype: /* oid */ Long, + proargtypes: TypoOidVector, + proallargtypes: Option[Array[/* oid */ Long]], + proargmodes: Option[Array[String]], + proargnames: Option[Array[String]], + proargdefaults: Option[TypoPgNodeTree], + protrftypes: Option[Array[/* oid */ Long]], + prosrc: String, + probin: Option[String], + prosqlbody: Option[TypoPgNodeTree], + proconfig: Option[Array[String]], + proacl: Option[Array[TypoAclItem]] +) + +object PgProcRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgProcRow] = new JdbcDecoder[PgProcRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgProcRow) = + columIndex + 29 -> + PgProcRow( + oid = PgProcId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + proname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + pronamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + proowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + prolang = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + procost = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 5, rs)._2, + prorows = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 6, rs)._2, + provariadic = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + prosupport = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + prokind = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 9, rs)._2, + prosecdef = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 10, rs)._2, + proleakproof = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 11, rs)._2, + proisstrict = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 12, rs)._2, + proretset = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 13, rs)._2, + provolatile = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 14, rs)._2, + proparallel = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 15, rs)._2, + pronargs = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + pronargdefaults = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 17, rs)._2, + prorettype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 18, rs)._2, + proargtypes = TypoOidVector.jdbcDecoder.unsafeDecode(columIndex + 19, rs)._2, + proallargtypes = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 20, rs)._2, + proargmodes = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 21, rs)._2, + proargnames = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 22, rs)._2, + proargdefaults = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 23, rs)._2, + protrftypes = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 24, rs)._2, + prosrc = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 25, rs)._2, + probin = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 26, rs)._2, + prosqlbody = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 27, rs)._2, + proconfig = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 28, rs)._2, + proacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 29, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgProcRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgProcId.jsonDecoder)) + val proname = jsonObj.get("proname").toRight("Missing field 'proname'").flatMap(_.as(JsonDecoder.string)) + val pronamespace = jsonObj.get("pronamespace").toRight("Missing field 'pronamespace'").flatMap(_.as(JsonDecoder.long)) + val proowner = jsonObj.get("proowner").toRight("Missing field 'proowner'").flatMap(_.as(JsonDecoder.long)) + val prolang = jsonObj.get("prolang").toRight("Missing field 'prolang'").flatMap(_.as(JsonDecoder.long)) + val procost = jsonObj.get("procost").toRight("Missing field 'procost'").flatMap(_.as(JsonDecoder.float)) + val prorows = jsonObj.get("prorows").toRight("Missing field 'prorows'").flatMap(_.as(JsonDecoder.float)) + val provariadic = jsonObj.get("provariadic").toRight("Missing field 'provariadic'").flatMap(_.as(JsonDecoder.long)) + val prosupport = jsonObj.get("prosupport").toRight("Missing field 'prosupport'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val prokind = jsonObj.get("prokind").toRight("Missing field 'prokind'").flatMap(_.as(JsonDecoder.string)) + val prosecdef = jsonObj.get("prosecdef").toRight("Missing field 'prosecdef'").flatMap(_.as(JsonDecoder.boolean)) + val proleakproof = jsonObj.get("proleakproof").toRight("Missing field 'proleakproof'").flatMap(_.as(JsonDecoder.boolean)) + val proisstrict = jsonObj.get("proisstrict").toRight("Missing field 'proisstrict'").flatMap(_.as(JsonDecoder.boolean)) + val proretset = jsonObj.get("proretset").toRight("Missing field 'proretset'").flatMap(_.as(JsonDecoder.boolean)) + val provolatile = jsonObj.get("provolatile").toRight("Missing field 'provolatile'").flatMap(_.as(JsonDecoder.string)) + val proparallel = jsonObj.get("proparallel").toRight("Missing field 'proparallel'").flatMap(_.as(JsonDecoder.string)) + val pronargs = jsonObj.get("pronargs").toRight("Missing field 'pronargs'").flatMap(_.as(TypoShort.jsonDecoder)) + val pronargdefaults = jsonObj.get("pronargdefaults").toRight("Missing field 'pronargdefaults'").flatMap(_.as(TypoShort.jsonDecoder)) + val prorettype = jsonObj.get("prorettype").toRight("Missing field 'prorettype'").flatMap(_.as(JsonDecoder.long)) + val proargtypes = jsonObj.get("proargtypes").toRight("Missing field 'proargtypes'").flatMap(_.as(TypoOidVector.jsonDecoder)) + val proallargtypes = jsonObj.get("proallargtypes").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val proargmodes = jsonObj.get("proargmodes").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val proargnames = jsonObj.get("proargnames").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val proargdefaults = jsonObj.get("proargdefaults").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val protrftypes = jsonObj.get("protrftypes").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val prosrc = jsonObj.get("prosrc").toRight("Missing field 'prosrc'").flatMap(_.as(JsonDecoder.string)) + val probin = jsonObj.get("probin").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val prosqlbody = jsonObj.get("prosqlbody").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val proconfig = jsonObj.get("proconfig").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val proacl = jsonObj.get("proacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && proname.isRight && pronamespace.isRight && proowner.isRight && prolang.isRight && procost.isRight && prorows.isRight && provariadic.isRight && prosupport.isRight && prokind.isRight && prosecdef.isRight && proleakproof.isRight && proisstrict.isRight && proretset.isRight && provolatile.isRight && proparallel.isRight && pronargs.isRight && pronargdefaults.isRight && prorettype.isRight && proargtypes.isRight && proallargtypes.isRight && proargmodes.isRight && proargnames.isRight && proargdefaults.isRight && protrftypes.isRight && prosrc.isRight && probin.isRight && prosqlbody.isRight && proconfig.isRight && proacl.isRight) + Right(PgProcRow(oid = oid.toOption.get, proname = proname.toOption.get, pronamespace = pronamespace.toOption.get, proowner = proowner.toOption.get, prolang = prolang.toOption.get, procost = procost.toOption.get, prorows = prorows.toOption.get, provariadic = provariadic.toOption.get, prosupport = prosupport.toOption.get, prokind = prokind.toOption.get, prosecdef = prosecdef.toOption.get, proleakproof = proleakproof.toOption.get, proisstrict = proisstrict.toOption.get, proretset = proretset.toOption.get, provolatile = provolatile.toOption.get, proparallel = proparallel.toOption.get, pronargs = pronargs.toOption.get, pronargdefaults = pronargdefaults.toOption.get, prorettype = prorettype.toOption.get, proargtypes = proargtypes.toOption.get, proallargtypes = proallargtypes.toOption.get, proargmodes = proargmodes.toOption.get, proargnames = proargnames.toOption.get, proargdefaults = proargdefaults.toOption.get, protrftypes = protrftypes.toOption.get, prosrc = prosrc.toOption.get, probin = probin.toOption.get, prosqlbody = prosqlbody.toOption.get, proconfig = proconfig.toOption.get, proacl = proacl.toOption.get)) + else Left(List[Either[String, Any]](oid, proname, pronamespace, proowner, prolang, procost, prorows, provariadic, prosupport, prokind, prosecdef, proleakproof, proisstrict, proretset, provolatile, proparallel, pronargs, pronargdefaults, prorettype, proargtypes, proallargtypes, proargmodes, proargnames, proargdefaults, protrftypes, prosrc, probin, prosqlbody, proconfig, proacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgProcRow] = new JsonEncoder[PgProcRow] { + override def unsafeEncode(a: PgProcRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgProcId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""proname":""") + JsonEncoder.string.unsafeEncode(a.proname, indent, out) + out.write(",") + out.write(""""pronamespace":""") + JsonEncoder.long.unsafeEncode(a.pronamespace, indent, out) + out.write(",") + out.write(""""proowner":""") + JsonEncoder.long.unsafeEncode(a.proowner, indent, out) + out.write(",") + out.write(""""prolang":""") + JsonEncoder.long.unsafeEncode(a.prolang, indent, out) + out.write(",") + out.write(""""procost":""") + JsonEncoder.float.unsafeEncode(a.procost, indent, out) + out.write(",") + out.write(""""prorows":""") + JsonEncoder.float.unsafeEncode(a.prorows, indent, out) + out.write(",") + out.write(""""provariadic":""") + JsonEncoder.long.unsafeEncode(a.provariadic, indent, out) + out.write(",") + out.write(""""prosupport":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prosupport, indent, out) + out.write(",") + out.write(""""prokind":""") + JsonEncoder.string.unsafeEncode(a.prokind, indent, out) + out.write(",") + out.write(""""prosecdef":""") + JsonEncoder.boolean.unsafeEncode(a.prosecdef, indent, out) + out.write(",") + out.write(""""proleakproof":""") + JsonEncoder.boolean.unsafeEncode(a.proleakproof, indent, out) + out.write(",") + out.write(""""proisstrict":""") + JsonEncoder.boolean.unsafeEncode(a.proisstrict, indent, out) + out.write(",") + out.write(""""proretset":""") + JsonEncoder.boolean.unsafeEncode(a.proretset, indent, out) + out.write(",") + out.write(""""provolatile":""") + JsonEncoder.string.unsafeEncode(a.provolatile, indent, out) + out.write(",") + out.write(""""proparallel":""") + JsonEncoder.string.unsafeEncode(a.proparallel, indent, out) + out.write(",") + out.write(""""pronargs":""") + TypoShort.jsonEncoder.unsafeEncode(a.pronargs, indent, out) + out.write(",") + out.write(""""pronargdefaults":""") + TypoShort.jsonEncoder.unsafeEncode(a.pronargdefaults, indent, out) + out.write(",") + out.write(""""prorettype":""") + JsonEncoder.long.unsafeEncode(a.prorettype, indent, out) + out.write(",") + out.write(""""proargtypes":""") + TypoOidVector.jsonEncoder.unsafeEncode(a.proargtypes, indent, out) + out.write(",") + out.write(""""proallargtypes":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.proallargtypes, indent, out) + out.write(",") + out.write(""""proargmodes":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.proargmodes, indent, out) + out.write(",") + out.write(""""proargnames":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.proargnames, indent, out) + out.write(",") + out.write(""""proargdefaults":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.proargdefaults, indent, out) + out.write(",") + out.write(""""protrftypes":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.protrftypes, indent, out) + out.write(",") + out.write(""""prosrc":""") + JsonEncoder.string.unsafeEncode(a.prosrc, indent, out) + out.write(",") + out.write(""""probin":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.probin, indent, out) + out.write(",") + out.write(""""prosqlbody":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.prosqlbody, indent, out) + out.write(",") + out.write(""""proconfig":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.proconfig, indent, out) + out.write(",") + out.write(""""proacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.proacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcStructure.scala new file mode 100644 index 0000000000..50275f0676 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_proc/PgProcStructure.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_proc + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgProcStructure[Row](val prefix: Option[String], val extract: Row => PgProcRow, val merge: (Row, PgProcRow) => Row) + extends Relation[PgProcFields, PgProcRow, Row] + with PgProcFields[Row] { outer => + + override val oid = new IdField[PgProcId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val proname = new Field[String, Row](prefix, "proname", None, Some("name"))(x => extract(x).proname, (row, value) => merge(row, extract(row).copy(proname = value))) + override val pronamespace = new Field[/* oid */ Long, Row](prefix, "pronamespace", None, Some("oid"))(x => extract(x).pronamespace, (row, value) => merge(row, extract(row).copy(pronamespace = value))) + override val proowner = new Field[/* oid */ Long, Row](prefix, "proowner", None, Some("oid"))(x => extract(x).proowner, (row, value) => merge(row, extract(row).copy(proowner = value))) + override val prolang = new Field[/* oid */ Long, Row](prefix, "prolang", None, Some("oid"))(x => extract(x).prolang, (row, value) => merge(row, extract(row).copy(prolang = value))) + override val procost = new Field[Float, Row](prefix, "procost", None, Some("float4"))(x => extract(x).procost, (row, value) => merge(row, extract(row).copy(procost = value))) + override val prorows = new Field[Float, Row](prefix, "prorows", None, Some("float4"))(x => extract(x).prorows, (row, value) => merge(row, extract(row).copy(prorows = value))) + override val provariadic = new Field[/* oid */ Long, Row](prefix, "provariadic", None, Some("oid"))(x => extract(x).provariadic, (row, value) => merge(row, extract(row).copy(provariadic = value))) + override val prosupport = new Field[TypoRegproc, Row](prefix, "prosupport", None, Some("regproc"))(x => extract(x).prosupport, (row, value) => merge(row, extract(row).copy(prosupport = value))) + override val prokind = new Field[String, Row](prefix, "prokind", None, Some("char"))(x => extract(x).prokind, (row, value) => merge(row, extract(row).copy(prokind = value))) + override val prosecdef = new Field[Boolean, Row](prefix, "prosecdef", None, None)(x => extract(x).prosecdef, (row, value) => merge(row, extract(row).copy(prosecdef = value))) + override val proleakproof = new Field[Boolean, Row](prefix, "proleakproof", None, None)(x => extract(x).proleakproof, (row, value) => merge(row, extract(row).copy(proleakproof = value))) + override val proisstrict = new Field[Boolean, Row](prefix, "proisstrict", None, None)(x => extract(x).proisstrict, (row, value) => merge(row, extract(row).copy(proisstrict = value))) + override val proretset = new Field[Boolean, Row](prefix, "proretset", None, None)(x => extract(x).proretset, (row, value) => merge(row, extract(row).copy(proretset = value))) + override val provolatile = new Field[String, Row](prefix, "provolatile", None, Some("char"))(x => extract(x).provolatile, (row, value) => merge(row, extract(row).copy(provolatile = value))) + override val proparallel = new Field[String, Row](prefix, "proparallel", None, Some("char"))(x => extract(x).proparallel, (row, value) => merge(row, extract(row).copy(proparallel = value))) + override val pronargs = new Field[TypoShort, Row](prefix, "pronargs", None, Some("int2"))(x => extract(x).pronargs, (row, value) => merge(row, extract(row).copy(pronargs = value))) + override val pronargdefaults = new Field[TypoShort, Row](prefix, "pronargdefaults", None, Some("int2"))(x => extract(x).pronargdefaults, (row, value) => merge(row, extract(row).copy(pronargdefaults = value))) + override val prorettype = new Field[/* oid */ Long, Row](prefix, "prorettype", None, Some("oid"))(x => extract(x).prorettype, (row, value) => merge(row, extract(row).copy(prorettype = value))) + override val proargtypes = new Field[TypoOidVector, Row](prefix, "proargtypes", None, Some("oidvector"))(x => extract(x).proargtypes, (row, value) => merge(row, extract(row).copy(proargtypes = value))) + override val proallargtypes = new OptField[Array[/* oid */ Long], Row](prefix, "proallargtypes", None, Some("_oid"))(x => extract(x).proallargtypes, (row, value) => merge(row, extract(row).copy(proallargtypes = value))) + override val proargmodes = new OptField[Array[String], Row](prefix, "proargmodes", None, Some("_char"))(x => extract(x).proargmodes, (row, value) => merge(row, extract(row).copy(proargmodes = value))) + override val proargnames = new OptField[Array[String], Row](prefix, "proargnames", None, Some("_text"))(x => extract(x).proargnames, (row, value) => merge(row, extract(row).copy(proargnames = value))) + override val proargdefaults = new OptField[TypoPgNodeTree, Row](prefix, "proargdefaults", None, Some("pg_node_tree"))(x => extract(x).proargdefaults, (row, value) => merge(row, extract(row).copy(proargdefaults = value))) + override val protrftypes = new OptField[Array[/* oid */ Long], Row](prefix, "protrftypes", None, Some("_oid"))(x => extract(x).protrftypes, (row, value) => merge(row, extract(row).copy(protrftypes = value))) + override val prosrc = new Field[String, Row](prefix, "prosrc", None, None)(x => extract(x).prosrc, (row, value) => merge(row, extract(row).copy(prosrc = value))) + override val probin = new OptField[String, Row](prefix, "probin", None, None)(x => extract(x).probin, (row, value) => merge(row, extract(row).copy(probin = value))) + override val prosqlbody = new OptField[TypoPgNodeTree, Row](prefix, "prosqlbody", None, Some("pg_node_tree"))(x => extract(x).prosqlbody, (row, value) => merge(row, extract(row).copy(prosqlbody = value))) + override val proconfig = new OptField[Array[String], Row](prefix, "proconfig", None, Some("_text"))(x => extract(x).proconfig, (row, value) => merge(row, extract(row).copy(proconfig = value))) + override val proacl = new OptField[Array[TypoAclItem], Row](prefix, "proacl", None, Some("_aclitem"))(x => extract(x).proacl, (row, value) => merge(row, extract(row).copy(proacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, proname, pronamespace, proowner, prolang, procost, prorows, provariadic, prosupport, prokind, prosecdef, proleakproof, proisstrict, proretset, provolatile, proparallel, pronargs, pronargdefaults, prorettype, proargtypes, proallargtypes, proargmodes, proargnames, proargdefaults, protrftypes, prosrc, probin, prosqlbody, proconfig, proacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgProcRow, merge: (NewRow, PgProcRow) => NewRow): PgProcStructure[NewRow] = + new PgProcStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationFields.scala new file mode 100644 index 0000000000..5ac0f03cad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgPublicationFields[Row] { + val oid: IdField[PgPublicationId, Row] + val pubname: Field[String, Row] + val pubowner: Field[/* oid */ Long, Row] + val puballtables: Field[Boolean, Row] + val pubinsert: Field[Boolean, Row] + val pubupdate: Field[Boolean, Row] + val pubdelete: Field[Boolean, Row] + val pubtruncate: Field[Boolean, Row] + val pubviaroot: Field[Boolean, Row] +} +object PgPublicationFields extends PgPublicationStructure[PgPublicationRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationId.scala new file mode 100644 index 0000000000..092dd56f45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +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 `pg_catalog.pg_publication` */ +case class PgPublicationId(value: /* oid */ Long) extends AnyVal +object PgPublicationId { + implicit lazy val arraySetter: Setter[Array[PgPublicationId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgPublicationId, /* oid */ Long] = Bijection[PgPublicationId, /* oid */ Long](_.value)(PgPublicationId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgPublicationId] = JdbcDecoder.longDecoder.map(PgPublicationId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgPublicationId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgPublicationId] = JsonDecoder.long.map(PgPublicationId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgPublicationId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgPublicationId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgPublicationId] = ParameterMetaData.instance[PgPublicationId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgPublicationId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepo.scala new file mode 100644 index 0000000000..56ab48d924 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPublicationRepo { + def delete(oid: PgPublicationId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgPublicationFields, PgPublicationRow] + def insert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, PgPublicationRow] + def select: SelectBuilder[PgPublicationFields, PgPublicationRow] + def selectAll: ZStream[ZConnection, Throwable, PgPublicationRow] + def selectById(oid: PgPublicationId): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] + def selectByIds(oids: Array[PgPublicationId]): ZStream[ZConnection, Throwable, PgPublicationRow] + def selectByUnique(pubname: String): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] + def update(row: PgPublicationRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgPublicationFields, PgPublicationRow] + def upsert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoImpl.scala new file mode 100644 index 0000000000..ebd4756203 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPublicationRepoImpl extends PgPublicationRepo { + override def delete(oid: PgPublicationId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_publication where "oid" = ${Segment.paramSegment(oid)(PgPublicationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgPublicationFields, PgPublicationRow] = { + DeleteBuilder("pg_catalog.pg_publication", PgPublicationFields) + } + override def insert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, PgPublicationRow] = { + sql"""insert into pg_catalog.pg_publication("oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot") + values (${Segment.paramSegment(unsaved.oid)(PgPublicationId.setter)}::oid, ${Segment.paramSegment(unsaved.pubname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.pubowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.puballtables)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.pubinsert)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.pubupdate)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.pubdelete)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.pubtruncate)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.pubviaroot)(Setter.booleanSetter)}) + returning "oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot" + """.insertReturning(PgPublicationRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgPublicationFields, PgPublicationRow] = { + SelectBuilderSql("pg_catalog.pg_publication", PgPublicationFields, PgPublicationRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPublicationRow] = { + sql"""select "oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot" from pg_catalog.pg_publication""".query(PgPublicationRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgPublicationId): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] = { + sql"""select "oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot" from pg_catalog.pg_publication where "oid" = ${Segment.paramSegment(oid)(PgPublicationId.setter)}""".query(PgPublicationRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgPublicationId]): ZStream[ZConnection, Throwable, PgPublicationRow] = { + sql"""select "oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot" from pg_catalog.pg_publication where "oid" = ANY(${Segment.paramSegment(oids)(PgPublicationId.arraySetter)})""".query(PgPublicationRow.jdbcDecoder).selectStream + } + override def selectByUnique(pubname: String): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] = { + sql"""select "pubname" + from pg_catalog.pg_publication + where "pubname" = ${Segment.paramSegment(pubname)(Setter.stringSetter)} + """.query(PgPublicationRow.jdbcDecoder).selectOne + } + override def update(row: PgPublicationRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_publication + set "pubname" = ${Segment.paramSegment(row.pubname)(Setter.stringSetter)}::name, + "pubowner" = ${Segment.paramSegment(row.pubowner)(Setter.longSetter)}::oid, + "puballtables" = ${Segment.paramSegment(row.puballtables)(Setter.booleanSetter)}, + "pubinsert" = ${Segment.paramSegment(row.pubinsert)(Setter.booleanSetter)}, + "pubupdate" = ${Segment.paramSegment(row.pubupdate)(Setter.booleanSetter)}, + "pubdelete" = ${Segment.paramSegment(row.pubdelete)(Setter.booleanSetter)}, + "pubtruncate" = ${Segment.paramSegment(row.pubtruncate)(Setter.booleanSetter)}, + "pubviaroot" = ${Segment.paramSegment(row.pubviaroot)(Setter.booleanSetter)} + where "oid" = ${Segment.paramSegment(oid)(PgPublicationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgPublicationFields, PgPublicationRow] = { + UpdateBuilder("pg_catalog.pg_publication", PgPublicationFields, PgPublicationRow.jdbcDecoder) + } + override def upsert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRow]] = { + sql"""insert into pg_catalog.pg_publication("oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot") + values ( + ${Segment.paramSegment(unsaved.oid)(PgPublicationId.setter)}::oid, + ${Segment.paramSegment(unsaved.pubname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.pubowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.puballtables)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.pubinsert)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.pubupdate)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.pubdelete)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.pubtruncate)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.pubviaroot)(Setter.booleanSetter)} + ) + on conflict ("oid") + do update set + "pubname" = EXCLUDED."pubname", + "pubowner" = EXCLUDED."pubowner", + "puballtables" = EXCLUDED."puballtables", + "pubinsert" = EXCLUDED."pubinsert", + "pubupdate" = EXCLUDED."pubupdate", + "pubdelete" = EXCLUDED."pubdelete", + "pubtruncate" = EXCLUDED."pubtruncate", + "pubviaroot" = EXCLUDED."pubviaroot" + returning "oid", "pubname", "pubowner", "puballtables", "pubinsert", "pubupdate", "pubdelete", "pubtruncate", "pubviaroot"""".insertReturning(PgPublicationRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoMock.scala new file mode 100644 index 0000000000..35e94b984b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgPublicationRepoMock(map: scala.collection.mutable.Map[PgPublicationId, PgPublicationRow] = scala.collection.mutable.Map.empty) extends PgPublicationRepo { + override def delete(oid: PgPublicationId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgPublicationFields, PgPublicationRow] = { + DeleteBuilderMock(DeleteParams.empty, PgPublicationFields, map) + } + override def insert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, PgPublicationRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgPublicationFields, PgPublicationRow] = { + SelectBuilderMock(PgPublicationFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPublicationRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgPublicationId): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgPublicationId]): ZStream[ZConnection, Throwable, PgPublicationRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(pubname: String): ZIO[ZConnection, Throwable, Option[PgPublicationRow]] = { + ZIO.succeed(map.values.find(v => pubname == v.pubname)) + } + override def update(row: PgPublicationRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgPublicationFields, PgPublicationRow] = { + UpdateBuilderMock(UpdateParams.empty, PgPublicationFields, map) + } + override def upsert(unsaved: PgPublicationRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRow.scala new file mode 100644 index 0000000000..1311fcc493 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPublicationRow( + oid: PgPublicationId, + pubname: String, + pubowner: /* oid */ Long, + puballtables: Boolean, + pubinsert: Boolean, + pubupdate: Boolean, + pubdelete: Boolean, + pubtruncate: Boolean, + pubviaroot: Boolean +) + +object PgPublicationRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPublicationRow] = new JdbcDecoder[PgPublicationRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPublicationRow) = + columIndex + 8 -> + PgPublicationRow( + oid = PgPublicationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + pubname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + pubowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + puballtables = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + pubinsert = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + pubupdate = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + pubdelete = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + pubtruncate = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + pubviaroot = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPublicationRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgPublicationId.jsonDecoder)) + val pubname = jsonObj.get("pubname").toRight("Missing field 'pubname'").flatMap(_.as(JsonDecoder.string)) + val pubowner = jsonObj.get("pubowner").toRight("Missing field 'pubowner'").flatMap(_.as(JsonDecoder.long)) + val puballtables = jsonObj.get("puballtables").toRight("Missing field 'puballtables'").flatMap(_.as(JsonDecoder.boolean)) + val pubinsert = jsonObj.get("pubinsert").toRight("Missing field 'pubinsert'").flatMap(_.as(JsonDecoder.boolean)) + val pubupdate = jsonObj.get("pubupdate").toRight("Missing field 'pubupdate'").flatMap(_.as(JsonDecoder.boolean)) + val pubdelete = jsonObj.get("pubdelete").toRight("Missing field 'pubdelete'").flatMap(_.as(JsonDecoder.boolean)) + val pubtruncate = jsonObj.get("pubtruncate").toRight("Missing field 'pubtruncate'").flatMap(_.as(JsonDecoder.boolean)) + val pubviaroot = jsonObj.get("pubviaroot").toRight("Missing field 'pubviaroot'").flatMap(_.as(JsonDecoder.boolean)) + if (oid.isRight && pubname.isRight && pubowner.isRight && puballtables.isRight && pubinsert.isRight && pubupdate.isRight && pubdelete.isRight && pubtruncate.isRight && pubviaroot.isRight) + Right(PgPublicationRow(oid = oid.toOption.get, pubname = pubname.toOption.get, pubowner = pubowner.toOption.get, puballtables = puballtables.toOption.get, pubinsert = pubinsert.toOption.get, pubupdate = pubupdate.toOption.get, pubdelete = pubdelete.toOption.get, pubtruncate = pubtruncate.toOption.get, pubviaroot = pubviaroot.toOption.get)) + else Left(List[Either[String, Any]](oid, pubname, pubowner, puballtables, pubinsert, pubupdate, pubdelete, pubtruncate, pubviaroot).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPublicationRow] = new JsonEncoder[PgPublicationRow] { + override def unsafeEncode(a: PgPublicationRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgPublicationId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""pubname":""") + JsonEncoder.string.unsafeEncode(a.pubname, indent, out) + out.write(",") + out.write(""""pubowner":""") + JsonEncoder.long.unsafeEncode(a.pubowner, indent, out) + out.write(",") + out.write(""""puballtables":""") + JsonEncoder.boolean.unsafeEncode(a.puballtables, indent, out) + out.write(",") + out.write(""""pubinsert":""") + JsonEncoder.boolean.unsafeEncode(a.pubinsert, indent, out) + out.write(",") + out.write(""""pubupdate":""") + JsonEncoder.boolean.unsafeEncode(a.pubupdate, indent, out) + out.write(",") + out.write(""""pubdelete":""") + JsonEncoder.boolean.unsafeEncode(a.pubdelete, indent, out) + out.write(",") + out.write(""""pubtruncate":""") + JsonEncoder.boolean.unsafeEncode(a.pubtruncate, indent, out) + out.write(",") + out.write(""""pubviaroot":""") + JsonEncoder.boolean.unsafeEncode(a.pubviaroot, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationStructure.scala new file mode 100644 index 0000000000..4c58ab5117 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication/PgPublicationStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgPublicationStructure[Row](val prefix: Option[String], val extract: Row => PgPublicationRow, val merge: (Row, PgPublicationRow) => Row) + extends Relation[PgPublicationFields, PgPublicationRow, Row] + with PgPublicationFields[Row] { outer => + + override val oid = new IdField[PgPublicationId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val pubname = new Field[String, Row](prefix, "pubname", None, Some("name"))(x => extract(x).pubname, (row, value) => merge(row, extract(row).copy(pubname = value))) + override val pubowner = new Field[/* oid */ Long, Row](prefix, "pubowner", None, Some("oid"))(x => extract(x).pubowner, (row, value) => merge(row, extract(row).copy(pubowner = value))) + override val puballtables = new Field[Boolean, Row](prefix, "puballtables", None, None)(x => extract(x).puballtables, (row, value) => merge(row, extract(row).copy(puballtables = value))) + override val pubinsert = new Field[Boolean, Row](prefix, "pubinsert", None, None)(x => extract(x).pubinsert, (row, value) => merge(row, extract(row).copy(pubinsert = value))) + override val pubupdate = new Field[Boolean, Row](prefix, "pubupdate", None, None)(x => extract(x).pubupdate, (row, value) => merge(row, extract(row).copy(pubupdate = value))) + override val pubdelete = new Field[Boolean, Row](prefix, "pubdelete", None, None)(x => extract(x).pubdelete, (row, value) => merge(row, extract(row).copy(pubdelete = value))) + override val pubtruncate = new Field[Boolean, Row](prefix, "pubtruncate", None, None)(x => extract(x).pubtruncate, (row, value) => merge(row, extract(row).copy(pubtruncate = value))) + override val pubviaroot = new Field[Boolean, Row](prefix, "pubviaroot", None, None)(x => extract(x).pubviaroot, (row, value) => merge(row, extract(row).copy(pubviaroot = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, pubname, pubowner, puballtables, pubinsert, pubupdate, pubdelete, pubtruncate, pubviaroot) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPublicationRow, merge: (NewRow, PgPublicationRow) => NewRow): PgPublicationStructure[NewRow] = + new PgPublicationStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelFields.scala new file mode 100644 index 0000000000..4ff4f558f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgPublicationRelFields[Row] { + val oid: IdField[PgPublicationRelId, Row] + val prpubid: Field[/* oid */ Long, Row] + val prrelid: Field[/* oid */ Long, Row] +} +object PgPublicationRelFields extends PgPublicationRelStructure[PgPublicationRelRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelId.scala new file mode 100644 index 0000000000..969d89be7e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +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 `pg_catalog.pg_publication_rel` */ +case class PgPublicationRelId(value: /* oid */ Long) extends AnyVal +object PgPublicationRelId { + implicit lazy val arraySetter: Setter[Array[PgPublicationRelId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgPublicationRelId, /* oid */ Long] = Bijection[PgPublicationRelId, /* oid */ Long](_.value)(PgPublicationRelId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgPublicationRelId] = JdbcDecoder.longDecoder.map(PgPublicationRelId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgPublicationRelId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgPublicationRelId] = JsonDecoder.long.map(PgPublicationRelId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgPublicationRelId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgPublicationRelId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgPublicationRelId] = ParameterMetaData.instance[PgPublicationRelId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgPublicationRelId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepo.scala new file mode 100644 index 0000000000..28aafe81e5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPublicationRelRepo { + def delete(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgPublicationRelFields, PgPublicationRelRow] + def insert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, PgPublicationRelRow] + def select: SelectBuilder[PgPublicationRelFields, PgPublicationRelRow] + def selectAll: ZStream[ZConnection, Throwable, PgPublicationRelRow] + def selectById(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] + def selectByIds(oids: Array[PgPublicationRelId]): ZStream[ZConnection, Throwable, PgPublicationRelRow] + def selectByUnique(prrelid: /* oid */ Long, prpubid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] + def update(row: PgPublicationRelRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgPublicationRelFields, PgPublicationRelRow] + def upsert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRelRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoImpl.scala new file mode 100644 index 0000000000..b565df06d9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoImpl.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPublicationRelRepoImpl extends PgPublicationRelRepo { + override def delete(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_publication_rel where "oid" = ${Segment.paramSegment(oid)(PgPublicationRelId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + DeleteBuilder("pg_catalog.pg_publication_rel", PgPublicationRelFields) + } + override def insert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, PgPublicationRelRow] = { + sql"""insert into pg_catalog.pg_publication_rel("oid", "prpubid", "prrelid") + values (${Segment.paramSegment(unsaved.oid)(PgPublicationRelId.setter)}::oid, ${Segment.paramSegment(unsaved.prpubid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.prrelid)(Setter.longSetter)}::oid) + returning "oid", "prpubid", "prrelid" + """.insertReturning(PgPublicationRelRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + SelectBuilderSql("pg_catalog.pg_publication_rel", PgPublicationRelFields, PgPublicationRelRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPublicationRelRow] = { + sql"""select "oid", "prpubid", "prrelid" from pg_catalog.pg_publication_rel""".query(PgPublicationRelRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] = { + sql"""select "oid", "prpubid", "prrelid" from pg_catalog.pg_publication_rel where "oid" = ${Segment.paramSegment(oid)(PgPublicationRelId.setter)}""".query(PgPublicationRelRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgPublicationRelId]): ZStream[ZConnection, Throwable, PgPublicationRelRow] = { + sql"""select "oid", "prpubid", "prrelid" from pg_catalog.pg_publication_rel where "oid" = ANY(${Segment.paramSegment(oids)(PgPublicationRelId.arraySetter)})""".query(PgPublicationRelRow.jdbcDecoder).selectStream + } + override def selectByUnique(prrelid: /* oid */ Long, prpubid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] = { + sql"""select "prrelid", "prpubid" + from pg_catalog.pg_publication_rel + where "prrelid" = ${Segment.paramSegment(prrelid)(Setter.longSetter)} AND "prpubid" = ${Segment.paramSegment(prpubid)(Setter.longSetter)} + """.query(PgPublicationRelRow.jdbcDecoder).selectOne + } + override def update(row: PgPublicationRelRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_publication_rel + set "prpubid" = ${Segment.paramSegment(row.prpubid)(Setter.longSetter)}::oid, + "prrelid" = ${Segment.paramSegment(row.prrelid)(Setter.longSetter)}::oid + where "oid" = ${Segment.paramSegment(oid)(PgPublicationRelId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + UpdateBuilder("pg_catalog.pg_publication_rel", PgPublicationRelFields, PgPublicationRelRow.jdbcDecoder) + } + override def upsert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRelRow]] = { + sql"""insert into pg_catalog.pg_publication_rel("oid", "prpubid", "prrelid") + values ( + ${Segment.paramSegment(unsaved.oid)(PgPublicationRelId.setter)}::oid, + ${Segment.paramSegment(unsaved.prpubid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.prrelid)(Setter.longSetter)}::oid + ) + on conflict ("oid") + do update set + "prpubid" = EXCLUDED."prpubid", + "prrelid" = EXCLUDED."prrelid" + returning "oid", "prpubid", "prrelid"""".insertReturning(PgPublicationRelRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoMock.scala new file mode 100644 index 0000000000..9745f7dd79 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgPublicationRelRepoMock(map: scala.collection.mutable.Map[PgPublicationRelId, PgPublicationRelRow] = scala.collection.mutable.Map.empty) extends PgPublicationRelRepo { + override def delete(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + DeleteBuilderMock(DeleteParams.empty, PgPublicationRelFields, map) + } + override def insert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, PgPublicationRelRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + SelectBuilderMock(PgPublicationRelFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPublicationRelRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgPublicationRelId): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgPublicationRelId]): ZStream[ZConnection, Throwable, PgPublicationRelRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(prrelid: /* oid */ Long, prpubid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgPublicationRelRow]] = { + ZIO.succeed(map.values.find(v => prrelid == v.prrelid && prpubid == v.prpubid)) + } + override def update(row: PgPublicationRelRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgPublicationRelFields, PgPublicationRelRow] = { + UpdateBuilderMock(UpdateParams.empty, PgPublicationRelFields, map) + } + override def upsert(unsaved: PgPublicationRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgPublicationRelRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRow.scala new file mode 100644 index 0000000000..ded0f0e499 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelRow.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPublicationRelRow( + oid: PgPublicationRelId, + prpubid: /* oid */ Long, + prrelid: /* oid */ Long +) + +object PgPublicationRelRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPublicationRelRow] = new JdbcDecoder[PgPublicationRelRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPublicationRelRow) = + columIndex + 2 -> + PgPublicationRelRow( + oid = PgPublicationRelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + prpubid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + prrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPublicationRelRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgPublicationRelId.jsonDecoder)) + val prpubid = jsonObj.get("prpubid").toRight("Missing field 'prpubid'").flatMap(_.as(JsonDecoder.long)) + val prrelid = jsonObj.get("prrelid").toRight("Missing field 'prrelid'").flatMap(_.as(JsonDecoder.long)) + if (oid.isRight && prpubid.isRight && prrelid.isRight) + Right(PgPublicationRelRow(oid = oid.toOption.get, prpubid = prpubid.toOption.get, prrelid = prrelid.toOption.get)) + else Left(List[Either[String, Any]](oid, prpubid, prrelid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPublicationRelRow] = new JsonEncoder[PgPublicationRelRow] { + override def unsafeEncode(a: PgPublicationRelRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgPublicationRelId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""prpubid":""") + JsonEncoder.long.unsafeEncode(a.prpubid, indent, out) + out.write(",") + out.write(""""prrelid":""") + JsonEncoder.long.unsafeEncode(a.prrelid, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelStructure.scala new file mode 100644 index 0000000000..ea64204f42 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_rel/PgPublicationRelStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_rel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgPublicationRelStructure[Row](val prefix: Option[String], val extract: Row => PgPublicationRelRow, val merge: (Row, PgPublicationRelRow) => Row) + extends Relation[PgPublicationRelFields, PgPublicationRelRow, Row] + with PgPublicationRelFields[Row] { outer => + + override val oid = new IdField[PgPublicationRelId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val prpubid = new Field[/* oid */ Long, Row](prefix, "prpubid", None, Some("oid"))(x => extract(x).prpubid, (row, value) => merge(row, extract(row).copy(prpubid = value))) + override val prrelid = new Field[/* oid */ Long, Row](prefix, "prrelid", None, Some("oid"))(x => extract(x).prrelid, (row, value) => merge(row, extract(row).copy(prrelid = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, prpubid, prrelid) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPublicationRelRow, merge: (NewRow, PgPublicationRelRow) => NewRow): PgPublicationRelStructure[NewRow] = + new PgPublicationRelStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewFields.scala new file mode 100644 index 0000000000..53748b39ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewFields.scala @@ -0,0 +1,18 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_tables + +import typo.dsl.SqlExpr.Field + +trait PgPublicationTablesViewFields[Row] { + val pubname: Field[String, Row] + val schemaname: Field[String, Row] + val tablename: Field[String, Row] +} +object PgPublicationTablesViewFields extends PgPublicationTablesViewStructure[PgPublicationTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepo.scala new file mode 100644 index 0000000000..5ec9f5d8ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgPublicationTablesViewRepo { + def select: SelectBuilder[PgPublicationTablesViewFields, PgPublicationTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgPublicationTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepoImpl.scala new file mode 100644 index 0000000000..d78c622992 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgPublicationTablesViewRepoImpl extends PgPublicationTablesViewRepo { + override def select: SelectBuilder[PgPublicationTablesViewFields, PgPublicationTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_publication_tables", PgPublicationTablesViewFields, PgPublicationTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgPublicationTablesViewRow] = { + sql"""select "pubname", "schemaname", "tablename" from pg_catalog.pg_publication_tables""".query(PgPublicationTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRow.scala new file mode 100644 index 0000000000..7cc4d39355 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewRow.scala @@ -0,0 +1,58 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_tables + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgPublicationTablesViewRow( + /** Points to [[pg_publication.PgPublicationRow.pubname]] */ + pubname: String, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String +) + +object PgPublicationTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgPublicationTablesViewRow] = new JdbcDecoder[PgPublicationTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgPublicationTablesViewRow) = + columIndex + 2 -> + PgPublicationTablesViewRow( + pubname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgPublicationTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pubname = jsonObj.get("pubname").toRight("Missing field 'pubname'").flatMap(_.as(JsonDecoder.string)) + val schemaname = jsonObj.get("schemaname").toRight("Missing field 'schemaname'").flatMap(_.as(JsonDecoder.string)) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + if (pubname.isRight && schemaname.isRight && tablename.isRight) + Right(PgPublicationTablesViewRow(pubname = pubname.toOption.get, schemaname = schemaname.toOption.get, tablename = tablename.toOption.get)) + else Left(List[Either[String, Any]](pubname, schemaname, tablename).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgPublicationTablesViewRow] = new JsonEncoder[PgPublicationTablesViewRow] { + override def unsafeEncode(a: PgPublicationTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pubname":""") + JsonEncoder.string.unsafeEncode(a.pubname, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.string.unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewStructure.scala new file mode 100644 index 0000000000..067e0b865c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_publication_tables/PgPublicationTablesViewStructure.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_publication_tables + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PgPublicationTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgPublicationTablesViewRow, val merge: (Row, PgPublicationTablesViewRow) => Row) + extends Relation[PgPublicationTablesViewFields, PgPublicationTablesViewRow, Row] + with PgPublicationTablesViewFields[Row] { outer => + + override val pubname = new Field[String, Row](prefix, "pubname", None, None)(x => extract(x).pubname, (row, value) => merge(row, extract(row).copy(pubname = value))) + override val schemaname = new Field[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pubname, schemaname, tablename) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgPublicationTablesViewRow, merge: (NewRow, PgPublicationTablesViewRow) => NewRow): PgPublicationTablesViewStructure[NewRow] = + new PgPublicationTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeFields.scala new file mode 100644 index 0000000000..39db7a10f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgRangeFields[Row] { + val rngtypid: IdField[PgRangeId, Row] + val rngsubtype: Field[/* oid */ Long, Row] + val rngmultitypid: Field[/* oid */ Long, Row] + val rngcollation: Field[/* oid */ Long, Row] + val rngsubopc: Field[/* oid */ Long, Row] + val rngcanonical: Field[TypoRegproc, Row] + val rngsubdiff: Field[TypoRegproc, Row] +} +object PgRangeFields extends PgRangeStructure[PgRangeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeId.scala new file mode 100644 index 0000000000..fbca10e799 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +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 `pg_catalog.pg_range` */ +case class PgRangeId(value: /* oid */ Long) extends AnyVal +object PgRangeId { + implicit lazy val arraySetter: Setter[Array[PgRangeId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgRangeId, /* oid */ Long] = Bijection[PgRangeId, /* oid */ Long](_.value)(PgRangeId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgRangeId] = JdbcDecoder.longDecoder.map(PgRangeId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgRangeId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgRangeId] = JsonDecoder.long.map(PgRangeId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgRangeId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgRangeId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgRangeId] = ParameterMetaData.instance[PgRangeId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgRangeId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepo.scala new file mode 100644 index 0000000000..72b157f83d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgRangeRepo { + def delete(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgRangeFields, PgRangeRow] + def insert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, PgRangeRow] + def select: SelectBuilder[PgRangeFields, PgRangeRow] + def selectAll: ZStream[ZConnection, Throwable, PgRangeRow] + def selectById(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Option[PgRangeRow]] + def selectByIds(rngtypids: Array[PgRangeId]): ZStream[ZConnection, Throwable, PgRangeRow] + def selectByUnique(rngmultitypid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgRangeRow]] + def update(row: PgRangeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgRangeFields, PgRangeRow] + def upsert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, UpdateResult[PgRangeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoImpl.scala new file mode 100644 index 0000000000..c821c1da32 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoImpl.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgRangeRepoImpl extends PgRangeRepo { + override def delete(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_range where "rngtypid" = ${Segment.paramSegment(rngtypid)(PgRangeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgRangeFields, PgRangeRow] = { + DeleteBuilder("pg_catalog.pg_range", PgRangeFields) + } + override def insert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, PgRangeRow] = { + sql"""insert into pg_catalog.pg_range("rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff") + values (${Segment.paramSegment(unsaved.rngtypid)(PgRangeId.setter)}::oid, ${Segment.paramSegment(unsaved.rngsubtype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.rngmultitypid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.rngcollation)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.rngsubopc)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.rngcanonical)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.rngsubdiff)(TypoRegproc.setter)}::regproc) + returning "rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff" + """.insertReturning(PgRangeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgRangeFields, PgRangeRow] = { + SelectBuilderSql("pg_catalog.pg_range", PgRangeFields, PgRangeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRangeRow] = { + sql"""select "rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff" from pg_catalog.pg_range""".query(PgRangeRow.jdbcDecoder).selectStream + } + override def selectById(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Option[PgRangeRow]] = { + sql"""select "rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff" from pg_catalog.pg_range where "rngtypid" = ${Segment.paramSegment(rngtypid)(PgRangeId.setter)}""".query(PgRangeRow.jdbcDecoder).selectOne + } + override def selectByIds(rngtypids: Array[PgRangeId]): ZStream[ZConnection, Throwable, PgRangeRow] = { + sql"""select "rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff" from pg_catalog.pg_range where "rngtypid" = ANY(${Segment.paramSegment(rngtypids)(PgRangeId.arraySetter)})""".query(PgRangeRow.jdbcDecoder).selectStream + } + override def selectByUnique(rngmultitypid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgRangeRow]] = { + sql"""select "rngmultitypid" + from pg_catalog.pg_range + where "rngmultitypid" = ${Segment.paramSegment(rngmultitypid)(Setter.longSetter)} + """.query(PgRangeRow.jdbcDecoder).selectOne + } + override def update(row: PgRangeRow): ZIO[ZConnection, Throwable, Boolean] = { + val rngtypid = row.rngtypid + sql"""update pg_catalog.pg_range + set "rngsubtype" = ${Segment.paramSegment(row.rngsubtype)(Setter.longSetter)}::oid, + "rngmultitypid" = ${Segment.paramSegment(row.rngmultitypid)(Setter.longSetter)}::oid, + "rngcollation" = ${Segment.paramSegment(row.rngcollation)(Setter.longSetter)}::oid, + "rngsubopc" = ${Segment.paramSegment(row.rngsubopc)(Setter.longSetter)}::oid, + "rngcanonical" = ${Segment.paramSegment(row.rngcanonical)(TypoRegproc.setter)}::regproc, + "rngsubdiff" = ${Segment.paramSegment(row.rngsubdiff)(TypoRegproc.setter)}::regproc + where "rngtypid" = ${Segment.paramSegment(rngtypid)(PgRangeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgRangeFields, PgRangeRow] = { + UpdateBuilder("pg_catalog.pg_range", PgRangeFields, PgRangeRow.jdbcDecoder) + } + override def upsert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, UpdateResult[PgRangeRow]] = { + sql"""insert into pg_catalog.pg_range("rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff") + values ( + ${Segment.paramSegment(unsaved.rngtypid)(PgRangeId.setter)}::oid, + ${Segment.paramSegment(unsaved.rngsubtype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.rngmultitypid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.rngcollation)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.rngsubopc)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.rngcanonical)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.rngsubdiff)(TypoRegproc.setter)}::regproc + ) + on conflict ("rngtypid") + do update set + "rngsubtype" = EXCLUDED."rngsubtype", + "rngmultitypid" = EXCLUDED."rngmultitypid", + "rngcollation" = EXCLUDED."rngcollation", + "rngsubopc" = EXCLUDED."rngsubopc", + "rngcanonical" = EXCLUDED."rngcanonical", + "rngsubdiff" = EXCLUDED."rngsubdiff" + returning "rngtypid", "rngsubtype", "rngmultitypid", "rngcollation", "rngsubopc", "rngcanonical", "rngsubdiff"""".insertReturning(PgRangeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoMock.scala new file mode 100644 index 0000000000..a988880935 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgRangeRepoMock(map: scala.collection.mutable.Map[PgRangeId, PgRangeRow] = scala.collection.mutable.Map.empty) extends PgRangeRepo { + override def delete(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(rngtypid).isDefined) + } + override def delete: DeleteBuilder[PgRangeFields, PgRangeRow] = { + DeleteBuilderMock(DeleteParams.empty, PgRangeFields, map) + } + override def insert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, PgRangeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.rngtypid)) + sys.error(s"id ${unsaved.rngtypid} already exists") + else + map.put(unsaved.rngtypid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgRangeFields, PgRangeRow] = { + SelectBuilderMock(PgRangeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRangeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(rngtypid: PgRangeId): ZIO[ZConnection, Throwable, Option[PgRangeRow]] = { + ZIO.succeed(map.get(rngtypid)) + } + override def selectByIds(rngtypids: Array[PgRangeId]): ZStream[ZConnection, Throwable, PgRangeRow] = { + ZStream.fromIterable(rngtypids.flatMap(map.get)) + } + override def selectByUnique(rngmultitypid: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgRangeRow]] = { + ZIO.succeed(map.values.find(v => rngmultitypid == v.rngmultitypid)) + } + override def update(row: PgRangeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.rngtypid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.rngtypid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgRangeFields, PgRangeRow] = { + UpdateBuilderMock(UpdateParams.empty, PgRangeFields, map) + } + override def upsert(unsaved: PgRangeRow): ZIO[ZConnection, Throwable, UpdateResult[PgRangeRow]] = { + ZIO.succeed { + map.put(unsaved.rngtypid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRow.scala new file mode 100644 index 0000000000..b6ac0272ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgRangeRow( + rngtypid: PgRangeId, + rngsubtype: /* oid */ Long, + rngmultitypid: /* oid */ Long, + rngcollation: /* oid */ Long, + rngsubopc: /* oid */ Long, + rngcanonical: TypoRegproc, + rngsubdiff: TypoRegproc +) + +object PgRangeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgRangeRow] = new JdbcDecoder[PgRangeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgRangeRow) = + columIndex + 6 -> + PgRangeRow( + rngtypid = PgRangeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + rngsubtype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + rngmultitypid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + rngcollation = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + rngsubopc = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + rngcanonical = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + rngsubdiff = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgRangeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val rngtypid = jsonObj.get("rngtypid").toRight("Missing field 'rngtypid'").flatMap(_.as(PgRangeId.jsonDecoder)) + val rngsubtype = jsonObj.get("rngsubtype").toRight("Missing field 'rngsubtype'").flatMap(_.as(JsonDecoder.long)) + val rngmultitypid = jsonObj.get("rngmultitypid").toRight("Missing field 'rngmultitypid'").flatMap(_.as(JsonDecoder.long)) + val rngcollation = jsonObj.get("rngcollation").toRight("Missing field 'rngcollation'").flatMap(_.as(JsonDecoder.long)) + val rngsubopc = jsonObj.get("rngsubopc").toRight("Missing field 'rngsubopc'").flatMap(_.as(JsonDecoder.long)) + val rngcanonical = jsonObj.get("rngcanonical").toRight("Missing field 'rngcanonical'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val rngsubdiff = jsonObj.get("rngsubdiff").toRight("Missing field 'rngsubdiff'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (rngtypid.isRight && rngsubtype.isRight && rngmultitypid.isRight && rngcollation.isRight && rngsubopc.isRight && rngcanonical.isRight && rngsubdiff.isRight) + Right(PgRangeRow(rngtypid = rngtypid.toOption.get, rngsubtype = rngsubtype.toOption.get, rngmultitypid = rngmultitypid.toOption.get, rngcollation = rngcollation.toOption.get, rngsubopc = rngsubopc.toOption.get, rngcanonical = rngcanonical.toOption.get, rngsubdiff = rngsubdiff.toOption.get)) + else Left(List[Either[String, Any]](rngtypid, rngsubtype, rngmultitypid, rngcollation, rngsubopc, rngcanonical, rngsubdiff).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgRangeRow] = new JsonEncoder[PgRangeRow] { + override def unsafeEncode(a: PgRangeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""rngtypid":""") + PgRangeId.jsonEncoder.unsafeEncode(a.rngtypid, indent, out) + out.write(",") + out.write(""""rngsubtype":""") + JsonEncoder.long.unsafeEncode(a.rngsubtype, indent, out) + out.write(",") + out.write(""""rngmultitypid":""") + JsonEncoder.long.unsafeEncode(a.rngmultitypid, indent, out) + out.write(",") + out.write(""""rngcollation":""") + JsonEncoder.long.unsafeEncode(a.rngcollation, indent, out) + out.write(",") + out.write(""""rngsubopc":""") + JsonEncoder.long.unsafeEncode(a.rngsubopc, indent, out) + out.write(",") + out.write(""""rngcanonical":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.rngcanonical, indent, out) + out.write(",") + out.write(""""rngsubdiff":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.rngsubdiff, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeStructure.scala new file mode 100644 index 0000000000..289c72c737 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_range/PgRangeStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_range + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgRangeStructure[Row](val prefix: Option[String], val extract: Row => PgRangeRow, val merge: (Row, PgRangeRow) => Row) + extends Relation[PgRangeFields, PgRangeRow, Row] + with PgRangeFields[Row] { outer => + + override val rngtypid = new IdField[PgRangeId, Row](prefix, "rngtypid", None, Some("oid"))(x => extract(x).rngtypid, (row, value) => merge(row, extract(row).copy(rngtypid = value))) + override val rngsubtype = new Field[/* oid */ Long, Row](prefix, "rngsubtype", None, Some("oid"))(x => extract(x).rngsubtype, (row, value) => merge(row, extract(row).copy(rngsubtype = value))) + override val rngmultitypid = new Field[/* oid */ Long, Row](prefix, "rngmultitypid", None, Some("oid"))(x => extract(x).rngmultitypid, (row, value) => merge(row, extract(row).copy(rngmultitypid = value))) + override val rngcollation = new Field[/* oid */ Long, Row](prefix, "rngcollation", None, Some("oid"))(x => extract(x).rngcollation, (row, value) => merge(row, extract(row).copy(rngcollation = value))) + override val rngsubopc = new Field[/* oid */ Long, Row](prefix, "rngsubopc", None, Some("oid"))(x => extract(x).rngsubopc, (row, value) => merge(row, extract(row).copy(rngsubopc = value))) + override val rngcanonical = new Field[TypoRegproc, Row](prefix, "rngcanonical", None, Some("regproc"))(x => extract(x).rngcanonical, (row, value) => merge(row, extract(row).copy(rngcanonical = value))) + override val rngsubdiff = new Field[TypoRegproc, Row](prefix, "rngsubdiff", None, Some("regproc"))(x => extract(x).rngsubdiff, (row, value) => merge(row, extract(row).copy(rngsubdiff = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](rngtypid, rngsubtype, rngmultitypid, rngcollation, rngsubopc, rngcanonical, rngsubdiff) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgRangeRow, merge: (NewRow, PgRangeRow) => NewRow): PgRangeStructure[NewRow] = + new PgRangeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginFields.scala new file mode 100644 index 0000000000..343a445e5e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginFields.scala @@ -0,0 +1,18 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgReplicationOriginFields[Row] { + val roident: IdField[PgReplicationOriginId, Row] + val roname: Field[String, Row] +} +object PgReplicationOriginFields extends PgReplicationOriginStructure[PgReplicationOriginRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginId.scala new file mode 100644 index 0000000000..3a79163d1b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +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 `pg_catalog.pg_replication_origin` */ +case class PgReplicationOriginId(value: /* oid */ Long) extends AnyVal +object PgReplicationOriginId { + implicit lazy val arraySetter: Setter[Array[PgReplicationOriginId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgReplicationOriginId, /* oid */ Long] = Bijection[PgReplicationOriginId, /* oid */ Long](_.value)(PgReplicationOriginId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgReplicationOriginId] = JdbcDecoder.longDecoder.map(PgReplicationOriginId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgReplicationOriginId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgReplicationOriginId] = JsonDecoder.long.map(PgReplicationOriginId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgReplicationOriginId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgReplicationOriginId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgReplicationOriginId] = ParameterMetaData.instance[PgReplicationOriginId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgReplicationOriginId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepo.scala new file mode 100644 index 0000000000..a19104d12b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgReplicationOriginRepo { + def delete(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgReplicationOriginFields, PgReplicationOriginRow] + def insert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, PgReplicationOriginRow] + def select: SelectBuilder[PgReplicationOriginFields, PgReplicationOriginRow] + def selectAll: ZStream[ZConnection, Throwable, PgReplicationOriginRow] + def selectById(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] + def selectByIds(roidents: Array[PgReplicationOriginId]): ZStream[ZConnection, Throwable, PgReplicationOriginRow] + def selectByUnique(roname: String): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] + def update(row: PgReplicationOriginRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgReplicationOriginFields, PgReplicationOriginRow] + def upsert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, UpdateResult[PgReplicationOriginRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoImpl.scala new file mode 100644 index 0000000000..c93a5b4848 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoImpl.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgReplicationOriginRepoImpl extends PgReplicationOriginRepo { + override def delete(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_replication_origin where "roident" = ${Segment.paramSegment(roident)(PgReplicationOriginId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + DeleteBuilder("pg_catalog.pg_replication_origin", PgReplicationOriginFields) + } + override def insert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, PgReplicationOriginRow] = { + sql"""insert into pg_catalog.pg_replication_origin("roident", "roname") + values (${Segment.paramSegment(unsaved.roident)(PgReplicationOriginId.setter)}::oid, ${Segment.paramSegment(unsaved.roname)(Setter.stringSetter)}) + returning "roident", "roname" + """.insertReturning(PgReplicationOriginRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + SelectBuilderSql("pg_catalog.pg_replication_origin", PgReplicationOriginFields, PgReplicationOriginRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgReplicationOriginRow] = { + sql"""select "roident", "roname" from pg_catalog.pg_replication_origin""".query(PgReplicationOriginRow.jdbcDecoder).selectStream + } + override def selectById(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] = { + sql"""select "roident", "roname" from pg_catalog.pg_replication_origin where "roident" = ${Segment.paramSegment(roident)(PgReplicationOriginId.setter)}""".query(PgReplicationOriginRow.jdbcDecoder).selectOne + } + override def selectByIds(roidents: Array[PgReplicationOriginId]): ZStream[ZConnection, Throwable, PgReplicationOriginRow] = { + sql"""select "roident", "roname" from pg_catalog.pg_replication_origin where "roident" = ANY(${Segment.paramSegment(roidents)(PgReplicationOriginId.arraySetter)})""".query(PgReplicationOriginRow.jdbcDecoder).selectStream + } + override def selectByUnique(roname: String): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] = { + sql"""select "roname" + from pg_catalog.pg_replication_origin + where "roname" = ${Segment.paramSegment(roname)(Setter.stringSetter)} + """.query(PgReplicationOriginRow.jdbcDecoder).selectOne + } + override def update(row: PgReplicationOriginRow): ZIO[ZConnection, Throwable, Boolean] = { + val roident = row.roident + sql"""update pg_catalog.pg_replication_origin + set "roname" = ${Segment.paramSegment(row.roname)(Setter.stringSetter)} + where "roident" = ${Segment.paramSegment(roident)(PgReplicationOriginId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + UpdateBuilder("pg_catalog.pg_replication_origin", PgReplicationOriginFields, PgReplicationOriginRow.jdbcDecoder) + } + override def upsert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, UpdateResult[PgReplicationOriginRow]] = { + sql"""insert into pg_catalog.pg_replication_origin("roident", "roname") + values ( + ${Segment.paramSegment(unsaved.roident)(PgReplicationOriginId.setter)}::oid, + ${Segment.paramSegment(unsaved.roname)(Setter.stringSetter)} + ) + on conflict ("roident") + do update set + "roname" = EXCLUDED."roname" + returning "roident", "roname"""".insertReturning(PgReplicationOriginRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoMock.scala new file mode 100644 index 0000000000..5fdb69c147 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgReplicationOriginRepoMock(map: scala.collection.mutable.Map[PgReplicationOriginId, PgReplicationOriginRow] = scala.collection.mutable.Map.empty) extends PgReplicationOriginRepo { + override def delete(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(roident).isDefined) + } + override def delete: DeleteBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + DeleteBuilderMock(DeleteParams.empty, PgReplicationOriginFields, map) + } + override def insert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, PgReplicationOriginRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.roident)) + sys.error(s"id ${unsaved.roident} already exists") + else + map.put(unsaved.roident, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + SelectBuilderMock(PgReplicationOriginFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgReplicationOriginRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(roident: PgReplicationOriginId): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] = { + ZIO.succeed(map.get(roident)) + } + override def selectByIds(roidents: Array[PgReplicationOriginId]): ZStream[ZConnection, Throwable, PgReplicationOriginRow] = { + ZStream.fromIterable(roidents.flatMap(map.get)) + } + override def selectByUnique(roname: String): ZIO[ZConnection, Throwable, Option[PgReplicationOriginRow]] = { + ZIO.succeed(map.values.find(v => roname == v.roname)) + } + override def update(row: PgReplicationOriginRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.roident) match { + case Some(`row`) => false + case Some(_) => + map.put(row.roident, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgReplicationOriginFields, PgReplicationOriginRow] = { + UpdateBuilderMock(UpdateParams.empty, PgReplicationOriginFields, map) + } + override def upsert(unsaved: PgReplicationOriginRow): ZIO[ZConnection, Throwable, UpdateResult[PgReplicationOriginRow]] = { + ZIO.succeed { + map.put(unsaved.roident, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRow.scala new file mode 100644 index 0000000000..d704adfee8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginRow.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgReplicationOriginRow( + roident: PgReplicationOriginId, + roname: String +) + +object PgReplicationOriginRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgReplicationOriginRow] = new JdbcDecoder[PgReplicationOriginRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgReplicationOriginRow) = + columIndex + 1 -> + PgReplicationOriginRow( + roident = PgReplicationOriginId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + roname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgReplicationOriginRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val roident = jsonObj.get("roident").toRight("Missing field 'roident'").flatMap(_.as(PgReplicationOriginId.jsonDecoder)) + val roname = jsonObj.get("roname").toRight("Missing field 'roname'").flatMap(_.as(JsonDecoder.string)) + if (roident.isRight && roname.isRight) + Right(PgReplicationOriginRow(roident = roident.toOption.get, roname = roname.toOption.get)) + else Left(List[Either[String, Any]](roident, roname).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgReplicationOriginRow] = new JsonEncoder[PgReplicationOriginRow] { + override def unsafeEncode(a: PgReplicationOriginRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""roident":""") + PgReplicationOriginId.jsonEncoder.unsafeEncode(a.roident, indent, out) + out.write(",") + out.write(""""roname":""") + JsonEncoder.string.unsafeEncode(a.roname, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginStructure.scala new file mode 100644 index 0000000000..a94470a17d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin/PgReplicationOriginStructure.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgReplicationOriginStructure[Row](val prefix: Option[String], val extract: Row => PgReplicationOriginRow, val merge: (Row, PgReplicationOriginRow) => Row) + extends Relation[PgReplicationOriginFields, PgReplicationOriginRow, Row] + with PgReplicationOriginFields[Row] { outer => + + override val roident = new IdField[PgReplicationOriginId, Row](prefix, "roident", None, Some("oid"))(x => extract(x).roident, (row, value) => merge(row, extract(row).copy(roident = value))) + override val roname = new Field[String, Row](prefix, "roname", None, None)(x => extract(x).roname, (row, value) => merge(row, extract(row).copy(roname = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](roident, roname) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgReplicationOriginRow, merge: (NewRow, PgReplicationOriginRow) => NewRow): PgReplicationOriginStructure[NewRow] = + new PgReplicationOriginStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewFields.scala new file mode 100644 index 0000000000..2b8e9175e6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin_status + +import typo.dsl.SqlExpr.OptField + +trait PgReplicationOriginStatusViewFields[Row] { + val localId: OptField[/* oid */ Long, Row] + val externalId: OptField[String, Row] + val remoteLsn: OptField[/* pg_lsn */ Long, Row] + val localLsn: OptField[/* pg_lsn */ Long, Row] +} +object PgReplicationOriginStatusViewFields extends PgReplicationOriginStatusViewStructure[PgReplicationOriginStatusViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepo.scala new file mode 100644 index 0000000000..d8dcefe5d1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin_status + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgReplicationOriginStatusViewRepo { + def select: SelectBuilder[PgReplicationOriginStatusViewFields, PgReplicationOriginStatusViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgReplicationOriginStatusViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepoImpl.scala new file mode 100644 index 0000000000..9f5606d6f6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin_status + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgReplicationOriginStatusViewRepoImpl extends PgReplicationOriginStatusViewRepo { + override def select: SelectBuilder[PgReplicationOriginStatusViewFields, PgReplicationOriginStatusViewRow] = { + SelectBuilderSql("pg_catalog.pg_replication_origin_status", PgReplicationOriginStatusViewFields, PgReplicationOriginStatusViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgReplicationOriginStatusViewRow] = { + sql"""select "local_id", "external_id", "remote_lsn", "local_lsn" from pg_catalog.pg_replication_origin_status""".query(PgReplicationOriginStatusViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRow.scala new file mode 100644 index 0000000000..d5dbec0864 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin_status + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgReplicationOriginStatusViewRow( + localId: /* nullability unknown */ Option[/* oid */ Long], + externalId: /* nullability unknown */ Option[String], + remoteLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + localLsn: /* nullability unknown */ Option[/* pg_lsn */ Long] +) + +object PgReplicationOriginStatusViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgReplicationOriginStatusViewRow] = new JdbcDecoder[PgReplicationOriginStatusViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgReplicationOriginStatusViewRow) = + columIndex + 3 -> + PgReplicationOriginStatusViewRow( + localId = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + externalId = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + remoteLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + localLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgReplicationOriginStatusViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val localId = jsonObj.get("local_id").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val externalId = jsonObj.get("external_id").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val remoteLsn = jsonObj.get("remote_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val localLsn = jsonObj.get("local_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (localId.isRight && externalId.isRight && remoteLsn.isRight && localLsn.isRight) + Right(PgReplicationOriginStatusViewRow(localId = localId.toOption.get, externalId = externalId.toOption.get, remoteLsn = remoteLsn.toOption.get, localLsn = localLsn.toOption.get)) + else Left(List[Either[String, Any]](localId, externalId, remoteLsn, localLsn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgReplicationOriginStatusViewRow] = new JsonEncoder[PgReplicationOriginStatusViewRow] { + override def unsafeEncode(a: PgReplicationOriginStatusViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""local_id":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.localId, indent, out) + out.write(",") + out.write(""""external_id":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.externalId, indent, out) + out.write(",") + out.write(""""remote_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.remoteLsn, indent, out) + out.write(",") + out.write(""""local_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.localLsn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewStructure.scala new file mode 100644 index 0000000000..8b4b8e27c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_origin_status/PgReplicationOriginStatusViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_origin_status + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgReplicationOriginStatusViewStructure[Row](val prefix: Option[String], val extract: Row => PgReplicationOriginStatusViewRow, val merge: (Row, PgReplicationOriginStatusViewRow) => Row) + extends Relation[PgReplicationOriginStatusViewFields, PgReplicationOriginStatusViewRow, Row] + with PgReplicationOriginStatusViewFields[Row] { outer => + + override val localId = new OptField[/* oid */ Long, Row](prefix, "local_id", None, None)(x => extract(x).localId, (row, value) => merge(row, extract(row).copy(localId = value))) + override val externalId = new OptField[String, Row](prefix, "external_id", None, None)(x => extract(x).externalId, (row, value) => merge(row, extract(row).copy(externalId = value))) + override val remoteLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "remote_lsn", None, None)(x => extract(x).remoteLsn, (row, value) => merge(row, extract(row).copy(remoteLsn = value))) + override val localLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "local_lsn", None, None)(x => extract(x).localLsn, (row, value) => merge(row, extract(row).copy(localLsn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](localId, externalId, remoteLsn, localLsn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgReplicationOriginStatusViewRow, merge: (NewRow, PgReplicationOriginStatusViewRow) => NewRow): PgReplicationOriginStatusViewStructure[NewRow] = + new PgReplicationOriginStatusViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewFields.scala new file mode 100644 index 0000000000..ffe6a8455b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_slots + +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.OptField + +trait PgReplicationSlotsViewFields[Row] { + val slotName: OptField[String, Row] + val plugin: OptField[String, Row] + val slotType: OptField[String, Row] + val datoid: OptField[/* oid */ Long, Row] + val database: OptField[String, Row] + val temporary: OptField[Boolean, Row] + val active: OptField[Boolean, Row] + val activePid: OptField[Int, Row] + val xmin: OptField[TypoXid, Row] + val catalogXmin: OptField[TypoXid, Row] + val restartLsn: OptField[/* pg_lsn */ Long, Row] + val confirmedFlushLsn: OptField[/* pg_lsn */ Long, Row] + val walStatus: OptField[String, Row] + val safeWalSize: OptField[Long, Row] + val twoPhase: OptField[Boolean, Row] +} +object PgReplicationSlotsViewFields extends PgReplicationSlotsViewStructure[PgReplicationSlotsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepo.scala new file mode 100644 index 0000000000..c941dd85ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_slots + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgReplicationSlotsViewRepo { + def select: SelectBuilder[PgReplicationSlotsViewFields, PgReplicationSlotsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgReplicationSlotsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepoImpl.scala new file mode 100644 index 0000000000..ae1be2ac22 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_slots + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgReplicationSlotsViewRepoImpl extends PgReplicationSlotsViewRepo { + override def select: SelectBuilder[PgReplicationSlotsViewFields, PgReplicationSlotsViewRow] = { + SelectBuilderSql("pg_catalog.pg_replication_slots", PgReplicationSlotsViewFields, PgReplicationSlotsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgReplicationSlotsViewRow] = { + sql"""select "slot_name", "plugin", "slot_type", "datoid", "database", "temporary", "active", "active_pid", "xmin", "catalog_xmin", "restart_lsn", "confirmed_flush_lsn", "wal_status", "safe_wal_size", "two_phase" from pg_catalog.pg_replication_slots""".query(PgReplicationSlotsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRow.scala new file mode 100644 index 0000000000..59ce097cf7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewRow.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_slots + +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgReplicationSlotsViewRow( + slotName: /* nullability unknown */ Option[String], + plugin: /* nullability unknown */ Option[String], + slotType: /* nullability unknown */ Option[String], + datoid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + database: Option[String], + temporary: /* nullability unknown */ Option[Boolean], + active: /* nullability unknown */ Option[Boolean], + activePid: /* nullability unknown */ Option[Int], + xmin: /* nullability unknown */ Option[TypoXid], + catalogXmin: /* nullability unknown */ Option[TypoXid], + restartLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + confirmedFlushLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + walStatus: /* nullability unknown */ Option[String], + safeWalSize: /* nullability unknown */ Option[Long], + twoPhase: /* nullability unknown */ Option[Boolean] +) + +object PgReplicationSlotsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgReplicationSlotsViewRow] = new JdbcDecoder[PgReplicationSlotsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgReplicationSlotsViewRow) = + columIndex + 14 -> + PgReplicationSlotsViewRow( + slotName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + plugin = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + slotType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + datoid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + database = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + temporary = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 5, rs)._2, + active = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 6, rs)._2, + activePid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + xmin = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + catalogXmin = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + restartLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + confirmedFlushLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + walStatus = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + safeWalSize = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + twoPhase = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 14, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgReplicationSlotsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val slotName = jsonObj.get("slot_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val plugin = jsonObj.get("plugin").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val slotType = jsonObj.get("slot_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val datoid = jsonObj.get("datoid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val database = jsonObj.get("database").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val temporary = jsonObj.get("temporary").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val active = jsonObj.get("active").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val activePid = jsonObj.get("active_pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val xmin = jsonObj.get("xmin").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val catalogXmin = jsonObj.get("catalog_xmin").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val restartLsn = jsonObj.get("restart_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val confirmedFlushLsn = jsonObj.get("confirmed_flush_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walStatus = jsonObj.get("wal_status").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val safeWalSize = jsonObj.get("safe_wal_size").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val twoPhase = jsonObj.get("two_phase").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + if (slotName.isRight && plugin.isRight && slotType.isRight && datoid.isRight && database.isRight && temporary.isRight && active.isRight && activePid.isRight && xmin.isRight && catalogXmin.isRight && restartLsn.isRight && confirmedFlushLsn.isRight && walStatus.isRight && safeWalSize.isRight && twoPhase.isRight) + Right(PgReplicationSlotsViewRow(slotName = slotName.toOption.get, plugin = plugin.toOption.get, slotType = slotType.toOption.get, datoid = datoid.toOption.get, database = database.toOption.get, temporary = temporary.toOption.get, active = active.toOption.get, activePid = activePid.toOption.get, xmin = xmin.toOption.get, catalogXmin = catalogXmin.toOption.get, restartLsn = restartLsn.toOption.get, confirmedFlushLsn = confirmedFlushLsn.toOption.get, walStatus = walStatus.toOption.get, safeWalSize = safeWalSize.toOption.get, twoPhase = twoPhase.toOption.get)) + else Left(List[Either[String, Any]](slotName, plugin, slotType, datoid, database, temporary, active, activePid, xmin, catalogXmin, restartLsn, confirmedFlushLsn, walStatus, safeWalSize, twoPhase).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgReplicationSlotsViewRow] = new JsonEncoder[PgReplicationSlotsViewRow] { + override def unsafeEncode(a: PgReplicationSlotsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""slot_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.slotName, indent, out) + out.write(",") + out.write(""""plugin":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.plugin, indent, out) + out.write(",") + out.write(""""slot_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.slotType, indent, out) + out.write(",") + out.write(""""datoid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datoid, indent, out) + out.write(",") + out.write(""""database":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.database, indent, out) + out.write(",") + out.write(""""temporary":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.temporary, indent, out) + out.write(",") + out.write(""""active":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.active, indent, out) + out.write(",") + out.write(""""active_pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.activePid, indent, out) + out.write(",") + out.write(""""xmin":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.xmin, indent, out) + out.write(",") + out.write(""""catalog_xmin":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.catalogXmin, indent, out) + out.write(",") + out.write(""""restart_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.restartLsn, indent, out) + out.write(",") + out.write(""""confirmed_flush_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.confirmedFlushLsn, indent, out) + out.write(",") + out.write(""""wal_status":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.walStatus, indent, out) + out.write(",") + out.write(""""safe_wal_size":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.safeWalSize, indent, out) + out.write(",") + out.write(""""two_phase":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.twoPhase, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewStructure.scala new file mode 100644 index 0000000000..6d01eba660 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_replication_slots/PgReplicationSlotsViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_replication_slots + +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgReplicationSlotsViewStructure[Row](val prefix: Option[String], val extract: Row => PgReplicationSlotsViewRow, val merge: (Row, PgReplicationSlotsViewRow) => Row) + extends Relation[PgReplicationSlotsViewFields, PgReplicationSlotsViewRow, Row] + with PgReplicationSlotsViewFields[Row] { outer => + + override val slotName = new OptField[String, Row](prefix, "slot_name", None, None)(x => extract(x).slotName, (row, value) => merge(row, extract(row).copy(slotName = value))) + override val plugin = new OptField[String, Row](prefix, "plugin", None, None)(x => extract(x).plugin, (row, value) => merge(row, extract(row).copy(plugin = value))) + override val slotType = new OptField[String, Row](prefix, "slot_type", None, None)(x => extract(x).slotType, (row, value) => merge(row, extract(row).copy(slotType = value))) + override val datoid = new OptField[/* oid */ Long, Row](prefix, "datoid", None, None)(x => extract(x).datoid, (row, value) => merge(row, extract(row).copy(datoid = value))) + override val database = new OptField[String, Row](prefix, "database", None, None)(x => extract(x).database, (row, value) => merge(row, extract(row).copy(database = value))) + override val temporary = new OptField[Boolean, Row](prefix, "temporary", None, None)(x => extract(x).temporary, (row, value) => merge(row, extract(row).copy(temporary = value))) + override val active = new OptField[Boolean, Row](prefix, "active", None, None)(x => extract(x).active, (row, value) => merge(row, extract(row).copy(active = value))) + override val activePid = new OptField[Int, Row](prefix, "active_pid", None, None)(x => extract(x).activePid, (row, value) => merge(row, extract(row).copy(activePid = value))) + override val xmin = new OptField[TypoXid, Row](prefix, "xmin", None, None)(x => extract(x).xmin, (row, value) => merge(row, extract(row).copy(xmin = value))) + override val catalogXmin = new OptField[TypoXid, Row](prefix, "catalog_xmin", None, None)(x => extract(x).catalogXmin, (row, value) => merge(row, extract(row).copy(catalogXmin = value))) + override val restartLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "restart_lsn", None, None)(x => extract(x).restartLsn, (row, value) => merge(row, extract(row).copy(restartLsn = value))) + override val confirmedFlushLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "confirmed_flush_lsn", None, None)(x => extract(x).confirmedFlushLsn, (row, value) => merge(row, extract(row).copy(confirmedFlushLsn = value))) + override val walStatus = new OptField[String, Row](prefix, "wal_status", None, None)(x => extract(x).walStatus, (row, value) => merge(row, extract(row).copy(walStatus = value))) + override val safeWalSize = new OptField[Long, Row](prefix, "safe_wal_size", None, None)(x => extract(x).safeWalSize, (row, value) => merge(row, extract(row).copy(safeWalSize = value))) + override val twoPhase = new OptField[Boolean, Row](prefix, "two_phase", None, None)(x => extract(x).twoPhase, (row, value) => merge(row, extract(row).copy(twoPhase = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](slotName, plugin, slotType, datoid, database, temporary, active, activePid, xmin, catalogXmin, restartLsn, confirmedFlushLsn, walStatus, safeWalSize, twoPhase) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgReplicationSlotsViewRow, merge: (NewRow, PgReplicationSlotsViewRow) => NewRow): PgReplicationSlotsViewStructure[NewRow] = + new PgReplicationSlotsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteFields.scala new file mode 100644 index 0000000000..71f745e6be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgRewriteFields[Row] { + val oid: IdField[PgRewriteId, Row] + val rulename: Field[String, Row] + val evClass: Field[/* oid */ Long, Row] + val evType: Field[String, Row] + val evEnabled: Field[String, Row] + val isInstead: Field[Boolean, Row] + val evQual: Field[TypoPgNodeTree, Row] + val evAction: Field[TypoPgNodeTree, Row] +} +object PgRewriteFields extends PgRewriteStructure[PgRewriteRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteId.scala new file mode 100644 index 0000000000..b5206bb09e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +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 `pg_catalog.pg_rewrite` */ +case class PgRewriteId(value: /* oid */ Long) extends AnyVal +object PgRewriteId { + implicit lazy val arraySetter: Setter[Array[PgRewriteId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgRewriteId, /* oid */ Long] = Bijection[PgRewriteId, /* oid */ Long](_.value)(PgRewriteId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgRewriteId] = JdbcDecoder.longDecoder.map(PgRewriteId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgRewriteId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgRewriteId] = JsonDecoder.long.map(PgRewriteId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgRewriteId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgRewriteId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgRewriteId] = ParameterMetaData.instance[PgRewriteId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgRewriteId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepo.scala new file mode 100644 index 0000000000..7e820ed569 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgRewriteRepo { + def delete(oid: PgRewriteId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgRewriteFields, PgRewriteRow] + def insert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, PgRewriteRow] + def select: SelectBuilder[PgRewriteFields, PgRewriteRow] + def selectAll: ZStream[ZConnection, Throwable, PgRewriteRow] + def selectById(oid: PgRewriteId): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] + def selectByIds(oids: Array[PgRewriteId]): ZStream[ZConnection, Throwable, PgRewriteRow] + def selectByUnique(evClass: /* oid */ Long, rulename: String): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] + def update(row: PgRewriteRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgRewriteFields, PgRewriteRow] + def upsert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, UpdateResult[PgRewriteRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoImpl.scala new file mode 100644 index 0000000000..424155df88 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoImpl.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgRewriteRepoImpl extends PgRewriteRepo { + override def delete(oid: PgRewriteId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_rewrite where "oid" = ${Segment.paramSegment(oid)(PgRewriteId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgRewriteFields, PgRewriteRow] = { + DeleteBuilder("pg_catalog.pg_rewrite", PgRewriteFields) + } + override def insert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, PgRewriteRow] = { + sql"""insert into pg_catalog.pg_rewrite("oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action") + values (${Segment.paramSegment(unsaved.oid)(PgRewriteId.setter)}::oid, ${Segment.paramSegment(unsaved.rulename)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.evClass)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.evType)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.evEnabled)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.isInstead)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.evQual)(TypoPgNodeTree.setter)}::pg_node_tree, ${Segment.paramSegment(unsaved.evAction)(TypoPgNodeTree.setter)}::pg_node_tree) + returning "oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action" + """.insertReturning(PgRewriteRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgRewriteFields, PgRewriteRow] = { + SelectBuilderSql("pg_catalog.pg_rewrite", PgRewriteFields, PgRewriteRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRewriteRow] = { + sql"""select "oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action" from pg_catalog.pg_rewrite""".query(PgRewriteRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgRewriteId): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] = { + sql"""select "oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action" from pg_catalog.pg_rewrite where "oid" = ${Segment.paramSegment(oid)(PgRewriteId.setter)}""".query(PgRewriteRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgRewriteId]): ZStream[ZConnection, Throwable, PgRewriteRow] = { + sql"""select "oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action" from pg_catalog.pg_rewrite where "oid" = ANY(${Segment.paramSegment(oids)(PgRewriteId.arraySetter)})""".query(PgRewriteRow.jdbcDecoder).selectStream + } + override def selectByUnique(evClass: /* oid */ Long, rulename: String): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] = { + sql"""select "ev_class", "rulename" + from pg_catalog.pg_rewrite + where "ev_class" = ${Segment.paramSegment(evClass)(Setter.longSetter)} AND "rulename" = ${Segment.paramSegment(rulename)(Setter.stringSetter)} + """.query(PgRewriteRow.jdbcDecoder).selectOne + } + override def update(row: PgRewriteRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_rewrite + set "rulename" = ${Segment.paramSegment(row.rulename)(Setter.stringSetter)}::name, + "ev_class" = ${Segment.paramSegment(row.evClass)(Setter.longSetter)}::oid, + "ev_type" = ${Segment.paramSegment(row.evType)(Setter.stringSetter)}::char, + "ev_enabled" = ${Segment.paramSegment(row.evEnabled)(Setter.stringSetter)}::char, + "is_instead" = ${Segment.paramSegment(row.isInstead)(Setter.booleanSetter)}, + "ev_qual" = ${Segment.paramSegment(row.evQual)(TypoPgNodeTree.setter)}::pg_node_tree, + "ev_action" = ${Segment.paramSegment(row.evAction)(TypoPgNodeTree.setter)}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgRewriteId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgRewriteFields, PgRewriteRow] = { + UpdateBuilder("pg_catalog.pg_rewrite", PgRewriteFields, PgRewriteRow.jdbcDecoder) + } + override def upsert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, UpdateResult[PgRewriteRow]] = { + sql"""insert into pg_catalog.pg_rewrite("oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action") + values ( + ${Segment.paramSegment(unsaved.oid)(PgRewriteId.setter)}::oid, + ${Segment.paramSegment(unsaved.rulename)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.evClass)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.evType)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.evEnabled)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.isInstead)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.evQual)(TypoPgNodeTree.setter)}::pg_node_tree, + ${Segment.paramSegment(unsaved.evAction)(TypoPgNodeTree.setter)}::pg_node_tree + ) + on conflict ("oid") + do update set + "rulename" = EXCLUDED."rulename", + "ev_class" = EXCLUDED."ev_class", + "ev_type" = EXCLUDED."ev_type", + "ev_enabled" = EXCLUDED."ev_enabled", + "is_instead" = EXCLUDED."is_instead", + "ev_qual" = EXCLUDED."ev_qual", + "ev_action" = EXCLUDED."ev_action" + returning "oid", "rulename", "ev_class", "ev_type", "ev_enabled", "is_instead", "ev_qual", "ev_action"""".insertReturning(PgRewriteRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoMock.scala new file mode 100644 index 0000000000..dd4ff5860a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgRewriteRepoMock(map: scala.collection.mutable.Map[PgRewriteId, PgRewriteRow] = scala.collection.mutable.Map.empty) extends PgRewriteRepo { + override def delete(oid: PgRewriteId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgRewriteFields, PgRewriteRow] = { + DeleteBuilderMock(DeleteParams.empty, PgRewriteFields, map) + } + override def insert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, PgRewriteRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgRewriteFields, PgRewriteRow] = { + SelectBuilderMock(PgRewriteFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRewriteRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgRewriteId): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgRewriteId]): ZStream[ZConnection, Throwable, PgRewriteRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(evClass: /* oid */ Long, rulename: String): ZIO[ZConnection, Throwable, Option[PgRewriteRow]] = { + ZIO.succeed(map.values.find(v => evClass == v.evClass && rulename == v.rulename)) + } + override def update(row: PgRewriteRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgRewriteFields, PgRewriteRow] = { + UpdateBuilderMock(UpdateParams.empty, PgRewriteFields, map) + } + override def upsert(unsaved: PgRewriteRow): ZIO[ZConnection, Throwable, UpdateResult[PgRewriteRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRow.scala new file mode 100644 index 0000000000..5cddffdc90 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import adventureworks.customtypes.TypoPgNodeTree +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgRewriteRow( + oid: PgRewriteId, + rulename: String, + evClass: /* oid */ Long, + evType: String, + evEnabled: String, + isInstead: Boolean, + evQual: TypoPgNodeTree, + evAction: TypoPgNodeTree +) + +object PgRewriteRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgRewriteRow] = new JdbcDecoder[PgRewriteRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgRewriteRow) = + columIndex + 7 -> + PgRewriteRow( + oid = PgRewriteId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + rulename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + evClass = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + evType = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + evEnabled = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + isInstead = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + evQual = TypoPgNodeTree.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + evAction = TypoPgNodeTree.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgRewriteRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgRewriteId.jsonDecoder)) + val rulename = jsonObj.get("rulename").toRight("Missing field 'rulename'").flatMap(_.as(JsonDecoder.string)) + val evClass = jsonObj.get("ev_class").toRight("Missing field 'ev_class'").flatMap(_.as(JsonDecoder.long)) + val evType = jsonObj.get("ev_type").toRight("Missing field 'ev_type'").flatMap(_.as(JsonDecoder.string)) + val evEnabled = jsonObj.get("ev_enabled").toRight("Missing field 'ev_enabled'").flatMap(_.as(JsonDecoder.string)) + val isInstead = jsonObj.get("is_instead").toRight("Missing field 'is_instead'").flatMap(_.as(JsonDecoder.boolean)) + val evQual = jsonObj.get("ev_qual").toRight("Missing field 'ev_qual'").flatMap(_.as(TypoPgNodeTree.jsonDecoder)) + val evAction = jsonObj.get("ev_action").toRight("Missing field 'ev_action'").flatMap(_.as(TypoPgNodeTree.jsonDecoder)) + if (oid.isRight && rulename.isRight && evClass.isRight && evType.isRight && evEnabled.isRight && isInstead.isRight && evQual.isRight && evAction.isRight) + Right(PgRewriteRow(oid = oid.toOption.get, rulename = rulename.toOption.get, evClass = evClass.toOption.get, evType = evType.toOption.get, evEnabled = evEnabled.toOption.get, isInstead = isInstead.toOption.get, evQual = evQual.toOption.get, evAction = evAction.toOption.get)) + else Left(List[Either[String, Any]](oid, rulename, evClass, evType, evEnabled, isInstead, evQual, evAction).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgRewriteRow] = new JsonEncoder[PgRewriteRow] { + override def unsafeEncode(a: PgRewriteRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgRewriteId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""rulename":""") + JsonEncoder.string.unsafeEncode(a.rulename, indent, out) + out.write(",") + out.write(""""ev_class":""") + JsonEncoder.long.unsafeEncode(a.evClass, indent, out) + out.write(",") + out.write(""""ev_type":""") + JsonEncoder.string.unsafeEncode(a.evType, indent, out) + out.write(",") + out.write(""""ev_enabled":""") + JsonEncoder.string.unsafeEncode(a.evEnabled, indent, out) + out.write(",") + out.write(""""is_instead":""") + JsonEncoder.boolean.unsafeEncode(a.isInstead, indent, out) + out.write(",") + out.write(""""ev_qual":""") + TypoPgNodeTree.jsonEncoder.unsafeEncode(a.evQual, indent, out) + out.write(",") + out.write(""""ev_action":""") + TypoPgNodeTree.jsonEncoder.unsafeEncode(a.evAction, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteStructure.scala new file mode 100644 index 0000000000..44aaea4acc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rewrite/PgRewriteStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rewrite + +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgRewriteStructure[Row](val prefix: Option[String], val extract: Row => PgRewriteRow, val merge: (Row, PgRewriteRow) => Row) + extends Relation[PgRewriteFields, PgRewriteRow, Row] + with PgRewriteFields[Row] { outer => + + override val oid = new IdField[PgRewriteId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val rulename = new Field[String, Row](prefix, "rulename", None, Some("name"))(x => extract(x).rulename, (row, value) => merge(row, extract(row).copy(rulename = value))) + override val evClass = new Field[/* oid */ Long, Row](prefix, "ev_class", None, Some("oid"))(x => extract(x).evClass, (row, value) => merge(row, extract(row).copy(evClass = value))) + override val evType = new Field[String, Row](prefix, "ev_type", None, Some("char"))(x => extract(x).evType, (row, value) => merge(row, extract(row).copy(evType = value))) + override val evEnabled = new Field[String, Row](prefix, "ev_enabled", None, Some("char"))(x => extract(x).evEnabled, (row, value) => merge(row, extract(row).copy(evEnabled = value))) + override val isInstead = new Field[Boolean, Row](prefix, "is_instead", None, None)(x => extract(x).isInstead, (row, value) => merge(row, extract(row).copy(isInstead = value))) + override val evQual = new Field[TypoPgNodeTree, Row](prefix, "ev_qual", None, Some("pg_node_tree"))(x => extract(x).evQual, (row, value) => merge(row, extract(row).copy(evQual = value))) + override val evAction = new Field[TypoPgNodeTree, Row](prefix, "ev_action", None, Some("pg_node_tree"))(x => extract(x).evAction, (row, value) => merge(row, extract(row).copy(evAction = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, rulename, evClass, evType, evEnabled, isInstead, evQual, evAction) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgRewriteRow, merge: (NewRow, PgRewriteRow) => NewRow): PgRewriteStructure[NewRow] = + new PgRewriteStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewFields.scala new file mode 100644 index 0000000000..c1adb72fcf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_roles + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgRolesViewFields[Row] { + val rolname: Field[String, Row] + val rolsuper: Field[Boolean, Row] + val rolinherit: Field[Boolean, Row] + val rolcreaterole: Field[Boolean, Row] + val rolcreatedb: Field[Boolean, Row] + val rolcanlogin: Field[Boolean, Row] + val rolreplication: Field[Boolean, Row] + val rolconnlimit: Field[Int, Row] + val rolpassword: OptField[String, Row] + val rolvaliduntil: OptField[TypoInstant, Row] + val rolbypassrls: Field[Boolean, Row] + val rolconfig: OptField[Array[String], Row] + val oid: Field[PgAuthidId, Row] +} +object PgRolesViewFields extends PgRolesViewStructure[PgRolesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepo.scala new file mode 100644 index 0000000000..650b8f6183 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_roles + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgRolesViewRepo { + def select: SelectBuilder[PgRolesViewFields, PgRolesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgRolesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepoImpl.scala new file mode 100644 index 0000000000..44c5a12307 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_roles + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgRolesViewRepoImpl extends PgRolesViewRepo { + override def select: SelectBuilder[PgRolesViewFields, PgRolesViewRow] = { + SelectBuilderSql("pg_catalog.pg_roles", PgRolesViewFields, PgRolesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRolesViewRow] = { + sql"""select "rolname", "rolsuper", "rolinherit", "rolcreaterole", "rolcreatedb", "rolcanlogin", "rolreplication", "rolconnlimit", "rolpassword", "rolvaliduntil"::text, "rolbypassrls", "rolconfig", "oid" from pg_catalog.pg_roles""".query(PgRolesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRow.scala new file mode 100644 index 0000000000..4ea2f7c013 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewRow.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_roles + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgRolesViewRow( + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + rolname: String, + /** Points to [[pg_authid.PgAuthidRow.rolsuper]] */ + rolsuper: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolinherit]] */ + rolinherit: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolcreaterole]] */ + rolcreaterole: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolcreatedb]] */ + rolcreatedb: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolcanlogin]] */ + rolcanlogin: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolreplication]] */ + rolreplication: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolconnlimit]] */ + rolconnlimit: Int, + rolpassword: /* nullability unknown */ Option[String], + /** Points to [[pg_authid.PgAuthidRow.rolvaliduntil]] */ + rolvaliduntil: Option[TypoInstant], + /** Points to [[pg_authid.PgAuthidRow.rolbypassrls]] */ + rolbypassrls: Boolean, + /** Points to [[pg_db_role_setting.PgDbRoleSettingRow.setconfig]] */ + rolconfig: Option[Array[String]], + /** Points to [[pg_authid.PgAuthidRow.oid]] */ + oid: PgAuthidId +) + +object PgRolesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgRolesViewRow] = new JdbcDecoder[PgRolesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgRolesViewRow) = + columIndex + 12 -> + PgRolesViewRow( + rolname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + rolsuper = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 1, rs)._2, + rolinherit = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 2, rs)._2, + rolcreaterole = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + rolcreatedb = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + rolcanlogin = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + rolreplication = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + rolconnlimit = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + rolpassword = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + rolvaliduntil = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + rolbypassrls = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 10, rs)._2, + rolconfig = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 11, rs)._2, + oid = PgAuthidId.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgRolesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val rolname = jsonObj.get("rolname").toRight("Missing field 'rolname'").flatMap(_.as(JsonDecoder.string)) + val rolsuper = jsonObj.get("rolsuper").toRight("Missing field 'rolsuper'").flatMap(_.as(JsonDecoder.boolean)) + val rolinherit = jsonObj.get("rolinherit").toRight("Missing field 'rolinherit'").flatMap(_.as(JsonDecoder.boolean)) + val rolcreaterole = jsonObj.get("rolcreaterole").toRight("Missing field 'rolcreaterole'").flatMap(_.as(JsonDecoder.boolean)) + val rolcreatedb = jsonObj.get("rolcreatedb").toRight("Missing field 'rolcreatedb'").flatMap(_.as(JsonDecoder.boolean)) + val rolcanlogin = jsonObj.get("rolcanlogin").toRight("Missing field 'rolcanlogin'").flatMap(_.as(JsonDecoder.boolean)) + val rolreplication = jsonObj.get("rolreplication").toRight("Missing field 'rolreplication'").flatMap(_.as(JsonDecoder.boolean)) + val rolconnlimit = jsonObj.get("rolconnlimit").toRight("Missing field 'rolconnlimit'").flatMap(_.as(JsonDecoder.int)) + val rolpassword = jsonObj.get("rolpassword").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rolvaliduntil = jsonObj.get("rolvaliduntil").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val rolbypassrls = jsonObj.get("rolbypassrls").toRight("Missing field 'rolbypassrls'").flatMap(_.as(JsonDecoder.boolean)) + val rolconfig = jsonObj.get("rolconfig").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgAuthidId.jsonDecoder)) + if (rolname.isRight && rolsuper.isRight && rolinherit.isRight && rolcreaterole.isRight && rolcreatedb.isRight && rolcanlogin.isRight && rolreplication.isRight && rolconnlimit.isRight && rolpassword.isRight && rolvaliduntil.isRight && rolbypassrls.isRight && rolconfig.isRight && oid.isRight) + Right(PgRolesViewRow(rolname = rolname.toOption.get, rolsuper = rolsuper.toOption.get, rolinherit = rolinherit.toOption.get, rolcreaterole = rolcreaterole.toOption.get, rolcreatedb = rolcreatedb.toOption.get, rolcanlogin = rolcanlogin.toOption.get, rolreplication = rolreplication.toOption.get, rolconnlimit = rolconnlimit.toOption.get, rolpassword = rolpassword.toOption.get, rolvaliduntil = rolvaliduntil.toOption.get, rolbypassrls = rolbypassrls.toOption.get, rolconfig = rolconfig.toOption.get, oid = oid.toOption.get)) + else Left(List[Either[String, Any]](rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolconnlimit, rolpassword, rolvaliduntil, rolbypassrls, rolconfig, oid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgRolesViewRow] = new JsonEncoder[PgRolesViewRow] { + override def unsafeEncode(a: PgRolesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""rolname":""") + JsonEncoder.string.unsafeEncode(a.rolname, indent, out) + out.write(",") + out.write(""""rolsuper":""") + JsonEncoder.boolean.unsafeEncode(a.rolsuper, indent, out) + out.write(",") + out.write(""""rolinherit":""") + JsonEncoder.boolean.unsafeEncode(a.rolinherit, indent, out) + out.write(",") + out.write(""""rolcreaterole":""") + JsonEncoder.boolean.unsafeEncode(a.rolcreaterole, indent, out) + out.write(",") + out.write(""""rolcreatedb":""") + JsonEncoder.boolean.unsafeEncode(a.rolcreatedb, indent, out) + out.write(",") + out.write(""""rolcanlogin":""") + JsonEncoder.boolean.unsafeEncode(a.rolcanlogin, indent, out) + out.write(",") + out.write(""""rolreplication":""") + JsonEncoder.boolean.unsafeEncode(a.rolreplication, indent, out) + out.write(",") + out.write(""""rolconnlimit":""") + JsonEncoder.int.unsafeEncode(a.rolconnlimit, indent, out) + out.write(",") + out.write(""""rolpassword":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.rolpassword, indent, out) + out.write(",") + out.write(""""rolvaliduntil":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.rolvaliduntil, indent, out) + out.write(",") + out.write(""""rolbypassrls":""") + JsonEncoder.boolean.unsafeEncode(a.rolbypassrls, indent, out) + out.write(",") + out.write(""""rolconfig":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.rolconfig, indent, out) + out.write(",") + out.write(""""oid":""") + PgAuthidId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewStructure.scala new file mode 100644 index 0000000000..019781ad9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_roles/PgRolesViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_roles + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgRolesViewStructure[Row](val prefix: Option[String], val extract: Row => PgRolesViewRow, val merge: (Row, PgRolesViewRow) => Row) + extends Relation[PgRolesViewFields, PgRolesViewRow, Row] + with PgRolesViewFields[Row] { outer => + + override val rolname = new Field[String, Row](prefix, "rolname", None, None)(x => extract(x).rolname, (row, value) => merge(row, extract(row).copy(rolname = value))) + override val rolsuper = new Field[Boolean, Row](prefix, "rolsuper", None, None)(x => extract(x).rolsuper, (row, value) => merge(row, extract(row).copy(rolsuper = value))) + override val rolinherit = new Field[Boolean, Row](prefix, "rolinherit", None, None)(x => extract(x).rolinherit, (row, value) => merge(row, extract(row).copy(rolinherit = value))) + override val rolcreaterole = new Field[Boolean, Row](prefix, "rolcreaterole", None, None)(x => extract(x).rolcreaterole, (row, value) => merge(row, extract(row).copy(rolcreaterole = value))) + override val rolcreatedb = new Field[Boolean, Row](prefix, "rolcreatedb", None, None)(x => extract(x).rolcreatedb, (row, value) => merge(row, extract(row).copy(rolcreatedb = value))) + override val rolcanlogin = new Field[Boolean, Row](prefix, "rolcanlogin", None, None)(x => extract(x).rolcanlogin, (row, value) => merge(row, extract(row).copy(rolcanlogin = value))) + override val rolreplication = new Field[Boolean, Row](prefix, "rolreplication", None, None)(x => extract(x).rolreplication, (row, value) => merge(row, extract(row).copy(rolreplication = value))) + override val rolconnlimit = new Field[Int, Row](prefix, "rolconnlimit", None, None)(x => extract(x).rolconnlimit, (row, value) => merge(row, extract(row).copy(rolconnlimit = value))) + override val rolpassword = new OptField[String, Row](prefix, "rolpassword", None, None)(x => extract(x).rolpassword, (row, value) => merge(row, extract(row).copy(rolpassword = value))) + override val rolvaliduntil = new OptField[TypoInstant, Row](prefix, "rolvaliduntil", Some("text"), None)(x => extract(x).rolvaliduntil, (row, value) => merge(row, extract(row).copy(rolvaliduntil = value))) + override val rolbypassrls = new Field[Boolean, Row](prefix, "rolbypassrls", None, None)(x => extract(x).rolbypassrls, (row, value) => merge(row, extract(row).copy(rolbypassrls = value))) + override val rolconfig = new OptField[Array[String], Row](prefix, "rolconfig", None, None)(x => extract(x).rolconfig, (row, value) => merge(row, extract(row).copy(rolconfig = value))) + override val oid = new Field[PgAuthidId, Row](prefix, "oid", None, None)(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](rolname, rolsuper, rolinherit, rolcreaterole, rolcreatedb, rolcanlogin, rolreplication, rolconnlimit, rolpassword, rolvaliduntil, rolbypassrls, rolconfig, oid) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgRolesViewRow, merge: (NewRow, PgRolesViewRow) => NewRow): PgRolesViewStructure[NewRow] = + new PgRolesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewFields.scala new file mode 100644 index 0000000000..010bccef45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rules + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgRulesViewFields[Row] { + val schemaname: OptField[String, Row] + val tablename: Field[String, Row] + val rulename: Field[String, Row] + val definition: OptField[String, Row] +} +object PgRulesViewFields extends PgRulesViewStructure[PgRulesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepo.scala new file mode 100644 index 0000000000..5b9fa67952 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rules + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgRulesViewRepo { + def select: SelectBuilder[PgRulesViewFields, PgRulesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgRulesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepoImpl.scala new file mode 100644 index 0000000000..c2796f64bc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rules + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgRulesViewRepoImpl extends PgRulesViewRepo { + override def select: SelectBuilder[PgRulesViewFields, PgRulesViewRow] = { + SelectBuilderSql("pg_catalog.pg_rules", PgRulesViewFields, PgRulesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgRulesViewRow] = { + sql"""select "schemaname", "tablename", "rulename", "definition" from pg_catalog.pg_rules""".query(PgRulesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRow.scala new file mode 100644 index 0000000000..a4ff2b339d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rules + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgRulesViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_rewrite.PgRewriteRow.rulename]] */ + rulename: String, + definition: /* nullability unknown */ Option[String] +) + +object PgRulesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgRulesViewRow] = new JdbcDecoder[PgRulesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgRulesViewRow) = + columIndex + 3 -> + PgRulesViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + rulename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + definition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgRulesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val rulename = jsonObj.get("rulename").toRight("Missing field 'rulename'").flatMap(_.as(JsonDecoder.string)) + val definition = jsonObj.get("definition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (schemaname.isRight && tablename.isRight && rulename.isRight && definition.isRight) + Right(PgRulesViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, rulename = rulename.toOption.get, definition = definition.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, rulename, definition).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgRulesViewRow] = new JsonEncoder[PgRulesViewRow] { + override def unsafeEncode(a: PgRulesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""rulename":""") + JsonEncoder.string.unsafeEncode(a.rulename, indent, out) + out.write(",") + out.write(""""definition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.definition, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewStructure.scala new file mode 100644 index 0000000000..f93e9820d1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_rules/PgRulesViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_rules + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgRulesViewStructure[Row](val prefix: Option[String], val extract: Row => PgRulesViewRow, val merge: (Row, PgRulesViewRow) => Row) + extends Relation[PgRulesViewFields, PgRulesViewRow, Row] + with PgRulesViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val rulename = new Field[String, Row](prefix, "rulename", None, None)(x => extract(x).rulename, (row, value) => merge(row, extract(row).copy(rulename = value))) + override val definition = new OptField[String, Row](prefix, "definition", None, None)(x => extract(x).definition, (row, value) => merge(row, extract(row).copy(definition = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, rulename, definition) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgRulesViewRow, merge: (NewRow, PgRulesViewRow) => NewRow): PgRulesViewStructure[NewRow] = + new PgRulesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelFields.scala new file mode 100644 index 0000000000..4157fa8cfa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgSeclabelFields[Row] { + val objoid: IdField[/* oid */ Long, Row] + val classoid: IdField[/* oid */ Long, Row] + val objsubid: IdField[Int, Row] + val provider: IdField[String, Row] + val label: Field[String, Row] +} +object PgSeclabelFields extends PgSeclabelStructure[PgSeclabelRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelId.scala new file mode 100644 index 0000000000..56ceaa39a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelId.scala @@ -0,0 +1,45 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_seclabel` */ +case class PgSeclabelId(objoid: /* oid */ Long, classoid: /* oid */ Long, objsubid: Int, provider: String) +object PgSeclabelId { + implicit lazy val jsonDecoder: JsonDecoder[PgSeclabelId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val provider = jsonObj.get("provider").toRight("Missing field 'provider'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && objsubid.isRight && provider.isRight) + Right(PgSeclabelId(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get, provider = provider.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid, provider).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSeclabelId] = new JsonEncoder[PgSeclabelId] { + override def unsafeEncode(a: PgSeclabelId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""provider":""") + JsonEncoder.string.unsafeEncode(a.provider, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgSeclabelId] = Ordering.by(x => (x.objoid, x.classoid, x.objsubid, x.provider)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepo.scala new file mode 100644 index 0000000000..4b23d9dafc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSeclabelRepo { + def delete(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgSeclabelFields, PgSeclabelRow] + def insert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, PgSeclabelRow] + def select: SelectBuilder[PgSeclabelFields, PgSeclabelRow] + def selectAll: ZStream[ZConnection, Throwable, PgSeclabelRow] + def selectById(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Option[PgSeclabelRow]] + def update(row: PgSeclabelRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgSeclabelFields, PgSeclabelRow] + def upsert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSeclabelRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoImpl.scala new file mode 100644 index 0000000000..4314acbe40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoImpl.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSeclabelRepoImpl extends PgSeclabelRepo { + override def delete(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_seclabel where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgSeclabelFields, PgSeclabelRow] = { + DeleteBuilder("pg_catalog.pg_seclabel", PgSeclabelFields) + } + override def insert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, PgSeclabelRow] = { + sql"""insert into pg_catalog.pg_seclabel("objoid", "classoid", "objsubid", "provider", "label") + values (${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.provider)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.label)(Setter.stringSetter)}) + returning "objoid", "classoid", "objsubid", "provider", "label" + """.insertReturning(PgSeclabelRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgSeclabelFields, PgSeclabelRow] = { + SelectBuilderSql("pg_catalog.pg_seclabel", PgSeclabelFields, PgSeclabelRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSeclabelRow] = { + sql"""select "objoid", "classoid", "objsubid", "provider", "label" from pg_catalog.pg_seclabel""".query(PgSeclabelRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Option[PgSeclabelRow]] = { + sql"""select "objoid", "classoid", "objsubid", "provider", "label" from pg_catalog.pg_seclabel where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".query(PgSeclabelRow.jdbcDecoder).selectOne + } + override def update(row: PgSeclabelRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_seclabel + set "label" = ${Segment.paramSegment(row.label)(Setter.stringSetter)} + where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "objsubid" = ${Segment.paramSegment(compositeId.objsubid)(Setter.intSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgSeclabelFields, PgSeclabelRow] = { + UpdateBuilder("pg_catalog.pg_seclabel", PgSeclabelFields, PgSeclabelRow.jdbcDecoder) + } + override def upsert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSeclabelRow]] = { + sql"""insert into pg_catalog.pg_seclabel("objoid", "classoid", "objsubid", "provider", "label") + values ( + ${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.provider)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.label)(Setter.stringSetter)} + ) + on conflict ("objoid", "classoid", "objsubid", "provider") + do update set + "label" = EXCLUDED."label" + returning "objoid", "classoid", "objsubid", "provider", "label"""".insertReturning(PgSeclabelRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoMock.scala new file mode 100644 index 0000000000..0caeb916f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgSeclabelRepoMock(map: scala.collection.mutable.Map[PgSeclabelId, PgSeclabelRow] = scala.collection.mutable.Map.empty) extends PgSeclabelRepo { + override def delete(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgSeclabelFields, PgSeclabelRow] = { + DeleteBuilderMock(DeleteParams.empty, PgSeclabelFields, map) + } + override def insert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, PgSeclabelRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgSeclabelFields, PgSeclabelRow] = { + SelectBuilderMock(PgSeclabelFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSeclabelRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgSeclabelId): ZIO[ZConnection, Throwable, Option[PgSeclabelRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgSeclabelRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgSeclabelFields, PgSeclabelRow] = { + UpdateBuilderMock(UpdateParams.empty, PgSeclabelFields, map) + } + override def upsert(unsaved: PgSeclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSeclabelRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRow.scala new file mode 100644 index 0000000000..9535c29290 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelRow.scala @@ -0,0 +1,69 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSeclabelRow( + objoid: /* oid */ Long, + classoid: /* oid */ Long, + objsubid: Int, + provider: String, + label: String +){ + val compositeId: PgSeclabelId = PgSeclabelId(objoid, classoid, objsubid, provider) + } + +object PgSeclabelRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSeclabelRow] = new JdbcDecoder[PgSeclabelRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSeclabelRow) = + columIndex + 4 -> + PgSeclabelRow( + objoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + objsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + provider = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + label = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSeclabelRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val provider = jsonObj.get("provider").toRight("Missing field 'provider'").flatMap(_.as(JsonDecoder.string)) + val label = jsonObj.get("label").toRight("Missing field 'label'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && objsubid.isRight && provider.isRight && label.isRight) + Right(PgSeclabelRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get, provider = provider.toOption.get, label = label.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid, provider, label).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSeclabelRow] = new JsonEncoder[PgSeclabelRow] { + override def unsafeEncode(a: PgSeclabelRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""provider":""") + JsonEncoder.string.unsafeEncode(a.provider, indent, out) + out.write(",") + out.write(""""label":""") + JsonEncoder.string.unsafeEncode(a.label, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelStructure.scala new file mode 100644 index 0000000000..fc7f9032f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabel/PgSeclabelStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgSeclabelStructure[Row](val prefix: Option[String], val extract: Row => PgSeclabelRow, val merge: (Row, PgSeclabelRow) => Row) + extends Relation[PgSeclabelFields, PgSeclabelRow, Row] + with PgSeclabelFields[Row] { outer => + + override val objoid = new IdField[/* oid */ Long, Row](prefix, "objoid", None, Some("oid"))(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new IdField[/* oid */ Long, Row](prefix, "classoid", None, Some("oid"))(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val objsubid = new IdField[Int, Row](prefix, "objsubid", None, Some("int4"))(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val provider = new IdField[String, Row](prefix, "provider", None, None)(x => extract(x).provider, (row, value) => merge(row, extract(row).copy(provider = value))) + override val label = new Field[String, Row](prefix, "label", None, None)(x => extract(x).label, (row, value) => merge(row, extract(row).copy(label = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, objsubid, provider, label) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSeclabelRow, merge: (NewRow, PgSeclabelRow) => NewRow): PgSeclabelStructure[NewRow] = + new PgSeclabelStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewFields.scala new file mode 100644 index 0000000000..bba2cd17dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabels + +import typo.dsl.SqlExpr.OptField + +trait PgSeclabelsViewFields[Row] { + val objoid: OptField[/* oid */ Long, Row] + val classoid: OptField[/* oid */ Long, Row] + val objsubid: OptField[Int, Row] + val objtype: OptField[String, Row] + val objnamespace: OptField[/* oid */ Long, Row] + val objname: OptField[String, Row] + val provider: OptField[String, Row] + val label: OptField[String, Row] +} +object PgSeclabelsViewFields extends PgSeclabelsViewStructure[PgSeclabelsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepo.scala new file mode 100644 index 0000000000..ad90907f41 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabels + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSeclabelsViewRepo { + def select: SelectBuilder[PgSeclabelsViewFields, PgSeclabelsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgSeclabelsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepoImpl.scala new file mode 100644 index 0000000000..6f4f1d2830 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabels + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSeclabelsViewRepoImpl extends PgSeclabelsViewRepo { + override def select: SelectBuilder[PgSeclabelsViewFields, PgSeclabelsViewRow] = { + SelectBuilderSql("pg_catalog.pg_seclabels", PgSeclabelsViewFields, PgSeclabelsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSeclabelsViewRow] = { + sql"""select "objoid", "classoid", "objsubid", "objtype", "objnamespace", "objname", "provider", "label" from pg_catalog.pg_seclabels""".query(PgSeclabelsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRow.scala new file mode 100644 index 0000000000..90517962ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabels + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSeclabelsViewRow( + objoid: /* nullability unknown */ Option[/* oid */ Long], + classoid: /* nullability unknown */ Option[/* oid */ Long], + objsubid: /* nullability unknown */ Option[Int], + objtype: /* nullability unknown */ Option[String], + objnamespace: /* nullability unknown */ Option[/* oid */ Long], + objname: /* nullability unknown */ Option[String], + provider: /* nullability unknown */ Option[String], + label: /* nullability unknown */ Option[String] +) + +object PgSeclabelsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSeclabelsViewRow] = new JdbcDecoder[PgSeclabelsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSeclabelsViewRow) = + columIndex + 7 -> + PgSeclabelsViewRow( + objoid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + objsubid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 2, rs)._2, + objtype = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + objnamespace = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + objname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + provider = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + label = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSeclabelsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val classoid = jsonObj.get("classoid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val objsubid = jsonObj.get("objsubid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val objtype = jsonObj.get("objtype").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val objnamespace = jsonObj.get("objnamespace").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val objname = jsonObj.get("objname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val provider = jsonObj.get("provider").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val label = jsonObj.get("label").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (objoid.isRight && classoid.isRight && objsubid.isRight && objtype.isRight && objnamespace.isRight && objname.isRight && provider.isRight && label.isRight) + Right(PgSeclabelsViewRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, objsubid = objsubid.toOption.get, objtype = objtype.toOption.get, objnamespace = objnamespace.toOption.get, objname = objname.toOption.get, provider = provider.toOption.get, label = label.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, objsubid, objtype, objnamespace, objname, provider, label).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSeclabelsViewRow] = new JsonEncoder[PgSeclabelsViewRow] { + override def unsafeEncode(a: PgSeclabelsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""objtype":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objtype, indent, out) + out.write(",") + out.write(""""objnamespace":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.objnamespace, indent, out) + out.write(",") + out.write(""""objname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.objname, indent, out) + out.write(",") + out.write(""""provider":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.provider, indent, out) + out.write(",") + out.write(""""label":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.label, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewStructure.scala new file mode 100644 index 0000000000..5a510c08d1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_seclabels/PgSeclabelsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_seclabels + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgSeclabelsViewStructure[Row](val prefix: Option[String], val extract: Row => PgSeclabelsViewRow, val merge: (Row, PgSeclabelsViewRow) => Row) + extends Relation[PgSeclabelsViewFields, PgSeclabelsViewRow, Row] + with PgSeclabelsViewFields[Row] { outer => + + override val objoid = new OptField[/* oid */ Long, Row](prefix, "objoid", None, None)(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new OptField[/* oid */ Long, Row](prefix, "classoid", None, None)(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val objsubid = new OptField[Int, Row](prefix, "objsubid", None, None)(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val objtype = new OptField[String, Row](prefix, "objtype", None, None)(x => extract(x).objtype, (row, value) => merge(row, extract(row).copy(objtype = value))) + override val objnamespace = new OptField[/* oid */ Long, Row](prefix, "objnamespace", None, None)(x => extract(x).objnamespace, (row, value) => merge(row, extract(row).copy(objnamespace = value))) + override val objname = new OptField[String, Row](prefix, "objname", None, None)(x => extract(x).objname, (row, value) => merge(row, extract(row).copy(objname = value))) + override val provider = new OptField[String, Row](prefix, "provider", None, None)(x => extract(x).provider, (row, value) => merge(row, extract(row).copy(provider = value))) + override val label = new OptField[String, Row](prefix, "label", None, None)(x => extract(x).label, (row, value) => merge(row, extract(row).copy(label = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, objsubid, objtype, objnamespace, objname, provider, label) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSeclabelsViewRow, merge: (NewRow, PgSeclabelsViewRow) => NewRow): PgSeclabelsViewStructure[NewRow] = + new PgSeclabelsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceFields.scala new file mode 100644 index 0000000000..dd2bdd3ba7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgSequenceFields[Row] { + val seqrelid: IdField[PgSequenceId, Row] + val seqtypid: Field[/* oid */ Long, Row] + val seqstart: Field[Long, Row] + val seqincrement: Field[Long, Row] + val seqmax: Field[Long, Row] + val seqmin: Field[Long, Row] + val seqcache: Field[Long, Row] + val seqcycle: Field[Boolean, Row] +} +object PgSequenceFields extends PgSequenceStructure[PgSequenceRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceId.scala new file mode 100644 index 0000000000..8b0273ff4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +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 `pg_catalog.pg_sequence` */ +case class PgSequenceId(value: /* oid */ Long) extends AnyVal +object PgSequenceId { + implicit lazy val arraySetter: Setter[Array[PgSequenceId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgSequenceId, /* oid */ Long] = Bijection[PgSequenceId, /* oid */ Long](_.value)(PgSequenceId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgSequenceId] = JdbcDecoder.longDecoder.map(PgSequenceId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgSequenceId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgSequenceId] = JsonDecoder.long.map(PgSequenceId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgSequenceId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgSequenceId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgSequenceId] = ParameterMetaData.instance[PgSequenceId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgSequenceId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepo.scala new file mode 100644 index 0000000000..ab669fbc51 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSequenceRepo { + def delete(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgSequenceFields, PgSequenceRow] + def insert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, PgSequenceRow] + def select: SelectBuilder[PgSequenceFields, PgSequenceRow] + def selectAll: ZStream[ZConnection, Throwable, PgSequenceRow] + def selectById(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Option[PgSequenceRow]] + def selectByIds(seqrelids: Array[PgSequenceId]): ZStream[ZConnection, Throwable, PgSequenceRow] + def update(row: PgSequenceRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgSequenceFields, PgSequenceRow] + def upsert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, UpdateResult[PgSequenceRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoImpl.scala new file mode 100644 index 0000000000..b714f3494d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoImpl.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSequenceRepoImpl extends PgSequenceRepo { + override def delete(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_sequence where "seqrelid" = ${Segment.paramSegment(seqrelid)(PgSequenceId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgSequenceFields, PgSequenceRow] = { + DeleteBuilder("pg_catalog.pg_sequence", PgSequenceFields) + } + override def insert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, PgSequenceRow] = { + sql"""insert into pg_catalog.pg_sequence("seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle") + values (${Segment.paramSegment(unsaved.seqrelid)(PgSequenceId.setter)}::oid, ${Segment.paramSegment(unsaved.seqtypid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.seqstart)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.seqincrement)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.seqmax)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.seqmin)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.seqcache)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.seqcycle)(Setter.booleanSetter)}) + returning "seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle" + """.insertReturning(PgSequenceRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgSequenceFields, PgSequenceRow] = { + SelectBuilderSql("pg_catalog.pg_sequence", PgSequenceFields, PgSequenceRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSequenceRow] = { + sql"""select "seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle" from pg_catalog.pg_sequence""".query(PgSequenceRow.jdbcDecoder).selectStream + } + override def selectById(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Option[PgSequenceRow]] = { + sql"""select "seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle" from pg_catalog.pg_sequence where "seqrelid" = ${Segment.paramSegment(seqrelid)(PgSequenceId.setter)}""".query(PgSequenceRow.jdbcDecoder).selectOne + } + override def selectByIds(seqrelids: Array[PgSequenceId]): ZStream[ZConnection, Throwable, PgSequenceRow] = { + sql"""select "seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle" from pg_catalog.pg_sequence where "seqrelid" = ANY(${Segment.paramSegment(seqrelids)(PgSequenceId.arraySetter)})""".query(PgSequenceRow.jdbcDecoder).selectStream + } + override def update(row: PgSequenceRow): ZIO[ZConnection, Throwable, Boolean] = { + val seqrelid = row.seqrelid + sql"""update pg_catalog.pg_sequence + set "seqtypid" = ${Segment.paramSegment(row.seqtypid)(Setter.longSetter)}::oid, + "seqstart" = ${Segment.paramSegment(row.seqstart)(Setter.longSetter)}::int8, + "seqincrement" = ${Segment.paramSegment(row.seqincrement)(Setter.longSetter)}::int8, + "seqmax" = ${Segment.paramSegment(row.seqmax)(Setter.longSetter)}::int8, + "seqmin" = ${Segment.paramSegment(row.seqmin)(Setter.longSetter)}::int8, + "seqcache" = ${Segment.paramSegment(row.seqcache)(Setter.longSetter)}::int8, + "seqcycle" = ${Segment.paramSegment(row.seqcycle)(Setter.booleanSetter)} + where "seqrelid" = ${Segment.paramSegment(seqrelid)(PgSequenceId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgSequenceFields, PgSequenceRow] = { + UpdateBuilder("pg_catalog.pg_sequence", PgSequenceFields, PgSequenceRow.jdbcDecoder) + } + override def upsert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, UpdateResult[PgSequenceRow]] = { + sql"""insert into pg_catalog.pg_sequence("seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle") + values ( + ${Segment.paramSegment(unsaved.seqrelid)(PgSequenceId.setter)}::oid, + ${Segment.paramSegment(unsaved.seqtypid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.seqstart)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.seqincrement)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.seqmax)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.seqmin)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.seqcache)(Setter.longSetter)}::int8, + ${Segment.paramSegment(unsaved.seqcycle)(Setter.booleanSetter)} + ) + on conflict ("seqrelid") + do update set + "seqtypid" = EXCLUDED."seqtypid", + "seqstart" = EXCLUDED."seqstart", + "seqincrement" = EXCLUDED."seqincrement", + "seqmax" = EXCLUDED."seqmax", + "seqmin" = EXCLUDED."seqmin", + "seqcache" = EXCLUDED."seqcache", + "seqcycle" = EXCLUDED."seqcycle" + returning "seqrelid", "seqtypid", "seqstart", "seqincrement", "seqmax", "seqmin", "seqcache", "seqcycle"""".insertReturning(PgSequenceRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoMock.scala new file mode 100644 index 0000000000..b55cfc4a36 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgSequenceRepoMock(map: scala.collection.mutable.Map[PgSequenceId, PgSequenceRow] = scala.collection.mutable.Map.empty) extends PgSequenceRepo { + override def delete(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(seqrelid).isDefined) + } + override def delete: DeleteBuilder[PgSequenceFields, PgSequenceRow] = { + DeleteBuilderMock(DeleteParams.empty, PgSequenceFields, map) + } + override def insert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, PgSequenceRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.seqrelid)) + sys.error(s"id ${unsaved.seqrelid} already exists") + else + map.put(unsaved.seqrelid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgSequenceFields, PgSequenceRow] = { + SelectBuilderMock(PgSequenceFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSequenceRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(seqrelid: PgSequenceId): ZIO[ZConnection, Throwable, Option[PgSequenceRow]] = { + ZIO.succeed(map.get(seqrelid)) + } + override def selectByIds(seqrelids: Array[PgSequenceId]): ZStream[ZConnection, Throwable, PgSequenceRow] = { + ZStream.fromIterable(seqrelids.flatMap(map.get)) + } + override def update(row: PgSequenceRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.seqrelid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.seqrelid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgSequenceFields, PgSequenceRow] = { + UpdateBuilderMock(UpdateParams.empty, PgSequenceFields, map) + } + override def upsert(unsaved: PgSequenceRow): ZIO[ZConnection, Throwable, UpdateResult[PgSequenceRow]] = { + ZIO.succeed { + map.put(unsaved.seqrelid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRow.scala new file mode 100644 index 0000000000..58f5a1e400 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSequenceRow( + seqrelid: PgSequenceId, + seqtypid: /* oid */ Long, + seqstart: Long, + seqincrement: Long, + seqmax: Long, + seqmin: Long, + seqcache: Long, + seqcycle: Boolean +) + +object PgSequenceRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSequenceRow] = new JdbcDecoder[PgSequenceRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSequenceRow) = + columIndex + 7 -> + PgSequenceRow( + seqrelid = PgSequenceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + seqtypid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + seqstart = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + seqincrement = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + seqmax = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + seqmin = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + seqcache = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + seqcycle = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSequenceRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val seqrelid = jsonObj.get("seqrelid").toRight("Missing field 'seqrelid'").flatMap(_.as(PgSequenceId.jsonDecoder)) + val seqtypid = jsonObj.get("seqtypid").toRight("Missing field 'seqtypid'").flatMap(_.as(JsonDecoder.long)) + val seqstart = jsonObj.get("seqstart").toRight("Missing field 'seqstart'").flatMap(_.as(JsonDecoder.long)) + val seqincrement = jsonObj.get("seqincrement").toRight("Missing field 'seqincrement'").flatMap(_.as(JsonDecoder.long)) + val seqmax = jsonObj.get("seqmax").toRight("Missing field 'seqmax'").flatMap(_.as(JsonDecoder.long)) + val seqmin = jsonObj.get("seqmin").toRight("Missing field 'seqmin'").flatMap(_.as(JsonDecoder.long)) + val seqcache = jsonObj.get("seqcache").toRight("Missing field 'seqcache'").flatMap(_.as(JsonDecoder.long)) + val seqcycle = jsonObj.get("seqcycle").toRight("Missing field 'seqcycle'").flatMap(_.as(JsonDecoder.boolean)) + if (seqrelid.isRight && seqtypid.isRight && seqstart.isRight && seqincrement.isRight && seqmax.isRight && seqmin.isRight && seqcache.isRight && seqcycle.isRight) + Right(PgSequenceRow(seqrelid = seqrelid.toOption.get, seqtypid = seqtypid.toOption.get, seqstart = seqstart.toOption.get, seqincrement = seqincrement.toOption.get, seqmax = seqmax.toOption.get, seqmin = seqmin.toOption.get, seqcache = seqcache.toOption.get, seqcycle = seqcycle.toOption.get)) + else Left(List[Either[String, Any]](seqrelid, seqtypid, seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSequenceRow] = new JsonEncoder[PgSequenceRow] { + override def unsafeEncode(a: PgSequenceRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""seqrelid":""") + PgSequenceId.jsonEncoder.unsafeEncode(a.seqrelid, indent, out) + out.write(",") + out.write(""""seqtypid":""") + JsonEncoder.long.unsafeEncode(a.seqtypid, indent, out) + out.write(",") + out.write(""""seqstart":""") + JsonEncoder.long.unsafeEncode(a.seqstart, indent, out) + out.write(",") + out.write(""""seqincrement":""") + JsonEncoder.long.unsafeEncode(a.seqincrement, indent, out) + out.write(",") + out.write(""""seqmax":""") + JsonEncoder.long.unsafeEncode(a.seqmax, indent, out) + out.write(",") + out.write(""""seqmin":""") + JsonEncoder.long.unsafeEncode(a.seqmin, indent, out) + out.write(",") + out.write(""""seqcache":""") + JsonEncoder.long.unsafeEncode(a.seqcache, indent, out) + out.write(",") + out.write(""""seqcycle":""") + JsonEncoder.boolean.unsafeEncode(a.seqcycle, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceStructure.scala new file mode 100644 index 0000000000..5d4a00498a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequence/PgSequenceStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequence + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgSequenceStructure[Row](val prefix: Option[String], val extract: Row => PgSequenceRow, val merge: (Row, PgSequenceRow) => Row) + extends Relation[PgSequenceFields, PgSequenceRow, Row] + with PgSequenceFields[Row] { outer => + + override val seqrelid = new IdField[PgSequenceId, Row](prefix, "seqrelid", None, Some("oid"))(x => extract(x).seqrelid, (row, value) => merge(row, extract(row).copy(seqrelid = value))) + override val seqtypid = new Field[/* oid */ Long, Row](prefix, "seqtypid", None, Some("oid"))(x => extract(x).seqtypid, (row, value) => merge(row, extract(row).copy(seqtypid = value))) + override val seqstart = new Field[Long, Row](prefix, "seqstart", None, Some("int8"))(x => extract(x).seqstart, (row, value) => merge(row, extract(row).copy(seqstart = value))) + override val seqincrement = new Field[Long, Row](prefix, "seqincrement", None, Some("int8"))(x => extract(x).seqincrement, (row, value) => merge(row, extract(row).copy(seqincrement = value))) + override val seqmax = new Field[Long, Row](prefix, "seqmax", None, Some("int8"))(x => extract(x).seqmax, (row, value) => merge(row, extract(row).copy(seqmax = value))) + override val seqmin = new Field[Long, Row](prefix, "seqmin", None, Some("int8"))(x => extract(x).seqmin, (row, value) => merge(row, extract(row).copy(seqmin = value))) + override val seqcache = new Field[Long, Row](prefix, "seqcache", None, Some("int8"))(x => extract(x).seqcache, (row, value) => merge(row, extract(row).copy(seqcache = value))) + override val seqcycle = new Field[Boolean, Row](prefix, "seqcycle", None, None)(x => extract(x).seqcycle, (row, value) => merge(row, extract(row).copy(seqcycle = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](seqrelid, seqtypid, seqstart, seqincrement, seqmax, seqmin, seqcache, seqcycle) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSequenceRow, merge: (NewRow, PgSequenceRow) => NewRow): PgSequenceStructure[NewRow] = + new PgSequenceStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewFields.scala new file mode 100644 index 0000000000..ba7f7dcc69 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequences + +import adventureworks.customtypes.TypoRegtype +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgSequencesViewFields[Row] { + val schemaname: Field[String, Row] + val sequencename: Field[String, Row] + val sequenceowner: OptField[String, Row] + val dataType: OptField[TypoRegtype, Row] + val startValue: Field[Long, Row] + val minValue: Field[Long, Row] + val maxValue: Field[Long, Row] + val incrementBy: Field[Long, Row] + val cycle: Field[Boolean, Row] + val cacheSize: Field[Long, Row] + val lastValue: OptField[Long, Row] +} +object PgSequencesViewFields extends PgSequencesViewStructure[PgSequencesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepo.scala new file mode 100644 index 0000000000..a4f5d62d31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequences + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSequencesViewRepo { + def select: SelectBuilder[PgSequencesViewFields, PgSequencesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgSequencesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepoImpl.scala new file mode 100644 index 0000000000..b0e24750ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequences + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSequencesViewRepoImpl extends PgSequencesViewRepo { + override def select: SelectBuilder[PgSequencesViewFields, PgSequencesViewRow] = { + SelectBuilderSql("pg_catalog.pg_sequences", PgSequencesViewFields, PgSequencesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSequencesViewRow] = { + sql"""select "schemaname", "sequencename", "sequenceowner", "data_type", "start_value", "min_value", "max_value", "increment_by", "cycle", "cache_size", "last_value" from pg_catalog.pg_sequences""".query(PgSequencesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRow.scala new file mode 100644 index 0000000000..4972fb7f52 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewRow.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequences + +import adventureworks.customtypes.TypoRegtype +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSequencesViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + sequencename: String, + sequenceowner: /* nullability unknown */ Option[String], + dataType: /* nullability unknown */ Option[TypoRegtype], + /** Points to [[pg_sequence.PgSequenceRow.seqstart]] */ + startValue: Long, + /** Points to [[pg_sequence.PgSequenceRow.seqmin]] */ + minValue: Long, + /** Points to [[pg_sequence.PgSequenceRow.seqmax]] */ + maxValue: Long, + /** Points to [[pg_sequence.PgSequenceRow.seqincrement]] */ + incrementBy: Long, + /** Points to [[pg_sequence.PgSequenceRow.seqcycle]] */ + cycle: Boolean, + /** Points to [[pg_sequence.PgSequenceRow.seqcache]] */ + cacheSize: Long, + lastValue: /* nullability unknown */ Option[Long] +) + +object PgSequencesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSequencesViewRow] = new JdbcDecoder[PgSequencesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSequencesViewRow) = + columIndex + 10 -> + PgSequencesViewRow( + schemaname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + sequencename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + sequenceowner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + dataType = JdbcDecoder.optionDecoder(TypoRegtype.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + startValue = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + minValue = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + maxValue = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 6, rs)._2, + incrementBy = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 7, rs)._2, + cycle = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 8, rs)._2, + cacheSize = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 9, rs)._2, + lastValue = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSequencesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").toRight("Missing field 'schemaname'").flatMap(_.as(JsonDecoder.string)) + val sequencename = jsonObj.get("sequencename").toRight("Missing field 'sequencename'").flatMap(_.as(JsonDecoder.string)) + val sequenceowner = jsonObj.get("sequenceowner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val dataType = jsonObj.get("data_type").fold[Either[String, Option[TypoRegtype]]](Right(None))(_.as(JsonDecoder.option(TypoRegtype.jsonDecoder))) + val startValue = jsonObj.get("start_value").toRight("Missing field 'start_value'").flatMap(_.as(JsonDecoder.long)) + val minValue = jsonObj.get("min_value").toRight("Missing field 'min_value'").flatMap(_.as(JsonDecoder.long)) + val maxValue = jsonObj.get("max_value").toRight("Missing field 'max_value'").flatMap(_.as(JsonDecoder.long)) + val incrementBy = jsonObj.get("increment_by").toRight("Missing field 'increment_by'").flatMap(_.as(JsonDecoder.long)) + val cycle = jsonObj.get("cycle").toRight("Missing field 'cycle'").flatMap(_.as(JsonDecoder.boolean)) + val cacheSize = jsonObj.get("cache_size").toRight("Missing field 'cache_size'").flatMap(_.as(JsonDecoder.long)) + val lastValue = jsonObj.get("last_value").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (schemaname.isRight && sequencename.isRight && sequenceowner.isRight && dataType.isRight && startValue.isRight && minValue.isRight && maxValue.isRight && incrementBy.isRight && cycle.isRight && cacheSize.isRight && lastValue.isRight) + Right(PgSequencesViewRow(schemaname = schemaname.toOption.get, sequencename = sequencename.toOption.get, sequenceowner = sequenceowner.toOption.get, dataType = dataType.toOption.get, startValue = startValue.toOption.get, minValue = minValue.toOption.get, maxValue = maxValue.toOption.get, incrementBy = incrementBy.toOption.get, cycle = cycle.toOption.get, cacheSize = cacheSize.toOption.get, lastValue = lastValue.toOption.get)) + else Left(List[Either[String, Any]](schemaname, sequencename, sequenceowner, dataType, startValue, minValue, maxValue, incrementBy, cycle, cacheSize, lastValue).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSequencesViewRow] = new JsonEncoder[PgSequencesViewRow] { + override def unsafeEncode(a: PgSequencesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.string.unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""sequencename":""") + JsonEncoder.string.unsafeEncode(a.sequencename, indent, out) + out.write(",") + out.write(""""sequenceowner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sequenceowner, indent, out) + out.write(",") + out.write(""""data_type":""") + JsonEncoder.option(TypoRegtype.jsonEncoder).unsafeEncode(a.dataType, indent, out) + out.write(",") + out.write(""""start_value":""") + JsonEncoder.long.unsafeEncode(a.startValue, indent, out) + out.write(",") + out.write(""""min_value":""") + JsonEncoder.long.unsafeEncode(a.minValue, indent, out) + out.write(",") + out.write(""""max_value":""") + JsonEncoder.long.unsafeEncode(a.maxValue, indent, out) + out.write(",") + out.write(""""increment_by":""") + JsonEncoder.long.unsafeEncode(a.incrementBy, indent, out) + out.write(",") + out.write(""""cycle":""") + JsonEncoder.boolean.unsafeEncode(a.cycle, indent, out) + out.write(",") + out.write(""""cache_size":""") + JsonEncoder.long.unsafeEncode(a.cacheSize, indent, out) + out.write(",") + out.write(""""last_value":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.lastValue, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewStructure.scala new file mode 100644 index 0000000000..aea836f8ef --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_sequences/PgSequencesViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_sequences + +import adventureworks.customtypes.TypoRegtype +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgSequencesViewStructure[Row](val prefix: Option[String], val extract: Row => PgSequencesViewRow, val merge: (Row, PgSequencesViewRow) => Row) + extends Relation[PgSequencesViewFields, PgSequencesViewRow, Row] + with PgSequencesViewFields[Row] { outer => + + override val schemaname = new Field[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val sequencename = new Field[String, Row](prefix, "sequencename", None, None)(x => extract(x).sequencename, (row, value) => merge(row, extract(row).copy(sequencename = value))) + override val sequenceowner = new OptField[String, Row](prefix, "sequenceowner", None, None)(x => extract(x).sequenceowner, (row, value) => merge(row, extract(row).copy(sequenceowner = value))) + override val dataType = new OptField[TypoRegtype, Row](prefix, "data_type", None, None)(x => extract(x).dataType, (row, value) => merge(row, extract(row).copy(dataType = value))) + override val startValue = new Field[Long, Row](prefix, "start_value", None, None)(x => extract(x).startValue, (row, value) => merge(row, extract(row).copy(startValue = value))) + override val minValue = new Field[Long, Row](prefix, "min_value", None, None)(x => extract(x).minValue, (row, value) => merge(row, extract(row).copy(minValue = value))) + override val maxValue = new Field[Long, Row](prefix, "max_value", None, None)(x => extract(x).maxValue, (row, value) => merge(row, extract(row).copy(maxValue = value))) + override val incrementBy = new Field[Long, Row](prefix, "increment_by", None, None)(x => extract(x).incrementBy, (row, value) => merge(row, extract(row).copy(incrementBy = value))) + override val cycle = new Field[Boolean, Row](prefix, "cycle", None, None)(x => extract(x).cycle, (row, value) => merge(row, extract(row).copy(cycle = value))) + override val cacheSize = new Field[Long, Row](prefix, "cache_size", None, None)(x => extract(x).cacheSize, (row, value) => merge(row, extract(row).copy(cacheSize = value))) + override val lastValue = new OptField[Long, Row](prefix, "last_value", None, None)(x => extract(x).lastValue, (row, value) => merge(row, extract(row).copy(lastValue = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, sequencename, sequenceowner, dataType, startValue, minValue, maxValue, incrementBy, cycle, cacheSize, lastValue) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSequencesViewRow, merge: (NewRow, PgSequencesViewRow) => NewRow): PgSequencesViewStructure[NewRow] = + new PgSequencesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewFields.scala new file mode 100644 index 0000000000..29892ff71f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_settings + +import typo.dsl.SqlExpr.OptField + +trait PgSettingsViewFields[Row] { + val name: OptField[String, Row] + val setting: OptField[String, Row] + val unit: OptField[String, Row] + val category: OptField[String, Row] + val shortDesc: OptField[String, Row] + val extraDesc: OptField[String, Row] + val context: OptField[String, Row] + val vartype: OptField[String, Row] + val source: OptField[String, Row] + val minVal: OptField[String, Row] + val maxVal: OptField[String, Row] + val enumvals: OptField[Array[String], Row] + val bootVal: OptField[String, Row] + val resetVal: OptField[String, Row] + val sourcefile: OptField[String, Row] + val sourceline: OptField[Int, Row] + val pendingRestart: OptField[Boolean, Row] +} +object PgSettingsViewFields extends PgSettingsViewStructure[PgSettingsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepo.scala new file mode 100644 index 0000000000..17a19db62b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_settings + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSettingsViewRepo { + def select: SelectBuilder[PgSettingsViewFields, PgSettingsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgSettingsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepoImpl.scala new file mode 100644 index 0000000000..6712570482 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_settings + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSettingsViewRepoImpl extends PgSettingsViewRepo { + override def select: SelectBuilder[PgSettingsViewFields, PgSettingsViewRow] = { + SelectBuilderSql("pg_catalog.pg_settings", PgSettingsViewFields, PgSettingsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSettingsViewRow] = { + sql"""select "name", "setting", "unit", "category", "short_desc", "extra_desc", "context", "vartype", "source", "min_val", "max_val", "enumvals", "boot_val", "reset_val", "sourcefile", "sourceline", "pending_restart" from pg_catalog.pg_settings""".query(PgSettingsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRow.scala new file mode 100644 index 0000000000..f7eccec043 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewRow.scala @@ -0,0 +1,139 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_settings + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSettingsViewRow( + name: /* nullability unknown */ Option[String], + setting: /* nullability unknown */ Option[String], + unit: /* nullability unknown */ Option[String], + category: /* nullability unknown */ Option[String], + shortDesc: /* nullability unknown */ Option[String], + extraDesc: /* nullability unknown */ Option[String], + context: /* nullability unknown */ Option[String], + vartype: /* nullability unknown */ Option[String], + source: /* nullability unknown */ Option[String], + minVal: /* nullability unknown */ Option[String], + maxVal: /* nullability unknown */ Option[String], + enumvals: /* nullability unknown */ Option[Array[String]], + bootVal: /* nullability unknown */ Option[String], + resetVal: /* nullability unknown */ Option[String], + sourcefile: /* nullability unknown */ Option[String], + sourceline: /* nullability unknown */ Option[Int], + pendingRestart: /* nullability unknown */ Option[Boolean] +) + +object PgSettingsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSettingsViewRow] = new JdbcDecoder[PgSettingsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSettingsViewRow) = + columIndex + 16 -> + PgSettingsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + setting = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + unit = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + category = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + shortDesc = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + extraDesc = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + context = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + vartype = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + source = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + minVal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + maxVal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + enumvals = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 11, rs)._2, + bootVal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + resetVal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + sourcefile = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + sourceline = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 15, rs)._2, + pendingRestart = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 16, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSettingsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val setting = jsonObj.get("setting").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val unit = jsonObj.get("unit").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val category = jsonObj.get("category").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val shortDesc = jsonObj.get("short_desc").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val extraDesc = jsonObj.get("extra_desc").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val context = jsonObj.get("context").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val vartype = jsonObj.get("vartype").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val source = jsonObj.get("source").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val minVal = jsonObj.get("min_val").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maxVal = jsonObj.get("max_val").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val enumvals = jsonObj.get("enumvals").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val bootVal = jsonObj.get("boot_val").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val resetVal = jsonObj.get("reset_val").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sourcefile = jsonObj.get("sourcefile").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sourceline = jsonObj.get("sourceline").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val pendingRestart = jsonObj.get("pending_restart").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + if (name.isRight && setting.isRight && unit.isRight && category.isRight && shortDesc.isRight && extraDesc.isRight && context.isRight && vartype.isRight && source.isRight && minVal.isRight && maxVal.isRight && enumvals.isRight && bootVal.isRight && resetVal.isRight && sourcefile.isRight && sourceline.isRight && pendingRestart.isRight) + Right(PgSettingsViewRow(name = name.toOption.get, setting = setting.toOption.get, unit = unit.toOption.get, category = category.toOption.get, shortDesc = shortDesc.toOption.get, extraDesc = extraDesc.toOption.get, context = context.toOption.get, vartype = vartype.toOption.get, source = source.toOption.get, minVal = minVal.toOption.get, maxVal = maxVal.toOption.get, enumvals = enumvals.toOption.get, bootVal = bootVal.toOption.get, resetVal = resetVal.toOption.get, sourcefile = sourcefile.toOption.get, sourceline = sourceline.toOption.get, pendingRestart = pendingRestart.toOption.get)) + else Left(List[Either[String, Any]](name, setting, unit, category, shortDesc, extraDesc, context, vartype, source, minVal, maxVal, enumvals, bootVal, resetVal, sourcefile, sourceline, pendingRestart).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSettingsViewRow] = new JsonEncoder[PgSettingsViewRow] { + override def unsafeEncode(a: PgSettingsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""setting":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.setting, indent, out) + out.write(",") + out.write(""""unit":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.unit, indent, out) + out.write(",") + out.write(""""category":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.category, indent, out) + out.write(",") + out.write(""""short_desc":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.shortDesc, indent, out) + out.write(",") + out.write(""""extra_desc":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.extraDesc, indent, out) + out.write(",") + out.write(""""context":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.context, indent, out) + out.write(",") + out.write(""""vartype":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.vartype, indent, out) + out.write(",") + out.write(""""source":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.source, indent, out) + out.write(",") + out.write(""""min_val":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.minVal, indent, out) + out.write(",") + out.write(""""max_val":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.maxVal, indent, out) + out.write(",") + out.write(""""enumvals":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.enumvals, indent, out) + out.write(",") + out.write(""""boot_val":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.bootVal, indent, out) + out.write(",") + out.write(""""reset_val":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.resetVal, indent, out) + out.write(",") + out.write(""""sourcefile":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.sourcefile, indent, out) + out.write(",") + out.write(""""sourceline":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.sourceline, indent, out) + out.write(",") + out.write(""""pending_restart":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.pendingRestart, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewStructure.scala new file mode 100644 index 0000000000..3e2a13970a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_settings/PgSettingsViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_settings + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgSettingsViewStructure[Row](val prefix: Option[String], val extract: Row => PgSettingsViewRow, val merge: (Row, PgSettingsViewRow) => Row) + extends Relation[PgSettingsViewFields, PgSettingsViewRow, Row] + with PgSettingsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val setting = new OptField[String, Row](prefix, "setting", None, None)(x => extract(x).setting, (row, value) => merge(row, extract(row).copy(setting = value))) + override val unit = new OptField[String, Row](prefix, "unit", None, None)(x => extract(x).unit, (row, value) => merge(row, extract(row).copy(unit = value))) + override val category = new OptField[String, Row](prefix, "category", None, None)(x => extract(x).category, (row, value) => merge(row, extract(row).copy(category = value))) + override val shortDesc = new OptField[String, Row](prefix, "short_desc", None, None)(x => extract(x).shortDesc, (row, value) => merge(row, extract(row).copy(shortDesc = value))) + override val extraDesc = new OptField[String, Row](prefix, "extra_desc", None, None)(x => extract(x).extraDesc, (row, value) => merge(row, extract(row).copy(extraDesc = value))) + override val context = new OptField[String, Row](prefix, "context", None, None)(x => extract(x).context, (row, value) => merge(row, extract(row).copy(context = value))) + override val vartype = new OptField[String, Row](prefix, "vartype", None, None)(x => extract(x).vartype, (row, value) => merge(row, extract(row).copy(vartype = value))) + override val source = new OptField[String, Row](prefix, "source", None, None)(x => extract(x).source, (row, value) => merge(row, extract(row).copy(source = value))) + override val minVal = new OptField[String, Row](prefix, "min_val", None, None)(x => extract(x).minVal, (row, value) => merge(row, extract(row).copy(minVal = value))) + override val maxVal = new OptField[String, Row](prefix, "max_val", None, None)(x => extract(x).maxVal, (row, value) => merge(row, extract(row).copy(maxVal = value))) + override val enumvals = new OptField[Array[String], Row](prefix, "enumvals", None, None)(x => extract(x).enumvals, (row, value) => merge(row, extract(row).copy(enumvals = value))) + override val bootVal = new OptField[String, Row](prefix, "boot_val", None, None)(x => extract(x).bootVal, (row, value) => merge(row, extract(row).copy(bootVal = value))) + override val resetVal = new OptField[String, Row](prefix, "reset_val", None, None)(x => extract(x).resetVal, (row, value) => merge(row, extract(row).copy(resetVal = value))) + override val sourcefile = new OptField[String, Row](prefix, "sourcefile", None, None)(x => extract(x).sourcefile, (row, value) => merge(row, extract(row).copy(sourcefile = value))) + override val sourceline = new OptField[Int, Row](prefix, "sourceline", None, None)(x => extract(x).sourceline, (row, value) => merge(row, extract(row).copy(sourceline = value))) + override val pendingRestart = new OptField[Boolean, Row](prefix, "pending_restart", None, None)(x => extract(x).pendingRestart, (row, value) => merge(row, extract(row).copy(pendingRestart = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, setting, unit, category, shortDesc, extraDesc, context, vartype, source, minVal, maxVal, enumvals, bootVal, resetVal, sourcefile, sourceline, pendingRestart) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSettingsViewRow, merge: (NewRow, PgSettingsViewRow) => NewRow): PgSettingsViewStructure[NewRow] = + new PgSettingsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewFields.scala new file mode 100644 index 0000000000..4058f75b01 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shadow + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgShadowViewFields[Row] { + val usename: Field[String, Row] + val usesysid: Field[PgAuthidId, Row] + val usecreatedb: Field[Boolean, Row] + val usesuper: Field[Boolean, Row] + val userepl: Field[Boolean, Row] + val usebypassrls: Field[Boolean, Row] + val passwd: OptField[String, Row] + val valuntil: OptField[TypoInstant, Row] + val useconfig: OptField[Array[String], Row] +} +object PgShadowViewFields extends PgShadowViewStructure[PgShadowViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepo.scala new file mode 100644 index 0000000000..127bab4731 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shadow + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgShadowViewRepo { + def select: SelectBuilder[PgShadowViewFields, PgShadowViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgShadowViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepoImpl.scala new file mode 100644 index 0000000000..779ec1bbe5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shadow + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgShadowViewRepoImpl extends PgShadowViewRepo { + override def select: SelectBuilder[PgShadowViewFields, PgShadowViewRow] = { + SelectBuilderSql("pg_catalog.pg_shadow", PgShadowViewFields, PgShadowViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShadowViewRow] = { + sql"""select "usename", "usesysid", "usecreatedb", "usesuper", "userepl", "usebypassrls", "passwd", "valuntil"::text, "useconfig" from pg_catalog.pg_shadow""".query(PgShadowViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRow.scala new file mode 100644 index 0000000000..57654df1ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewRow.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shadow + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgShadowViewRow( + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + usename: String, + /** Points to [[pg_authid.PgAuthidRow.oid]] */ + usesysid: PgAuthidId, + /** Points to [[pg_authid.PgAuthidRow.rolcreatedb]] */ + usecreatedb: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolsuper]] */ + usesuper: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolreplication]] */ + userepl: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolbypassrls]] */ + usebypassrls: Boolean, + /** Points to [[pg_authid.PgAuthidRow.rolpassword]] */ + passwd: Option[String], + /** Points to [[pg_authid.PgAuthidRow.rolvaliduntil]] */ + valuntil: Option[TypoInstant], + /** Points to [[pg_db_role_setting.PgDbRoleSettingRow.setconfig]] */ + useconfig: Option[Array[String]] +) + +object PgShadowViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgShadowViewRow] = new JdbcDecoder[PgShadowViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgShadowViewRow) = + columIndex + 8 -> + PgShadowViewRow( + usename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + usesysid = PgAuthidId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + usecreatedb = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 2, rs)._2, + usesuper = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + userepl = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + usebypassrls = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + passwd = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + valuntil = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + useconfig = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgShadowViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val usename = jsonObj.get("usename").toRight("Missing field 'usename'").flatMap(_.as(JsonDecoder.string)) + val usesysid = jsonObj.get("usesysid").toRight("Missing field 'usesysid'").flatMap(_.as(PgAuthidId.jsonDecoder)) + val usecreatedb = jsonObj.get("usecreatedb").toRight("Missing field 'usecreatedb'").flatMap(_.as(JsonDecoder.boolean)) + val usesuper = jsonObj.get("usesuper").toRight("Missing field 'usesuper'").flatMap(_.as(JsonDecoder.boolean)) + val userepl = jsonObj.get("userepl").toRight("Missing field 'userepl'").flatMap(_.as(JsonDecoder.boolean)) + val usebypassrls = jsonObj.get("usebypassrls").toRight("Missing field 'usebypassrls'").flatMap(_.as(JsonDecoder.boolean)) + val passwd = jsonObj.get("passwd").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val valuntil = jsonObj.get("valuntil").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val useconfig = jsonObj.get("useconfig").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (usename.isRight && usesysid.isRight && usecreatedb.isRight && usesuper.isRight && userepl.isRight && usebypassrls.isRight && passwd.isRight && valuntil.isRight && useconfig.isRight) + Right(PgShadowViewRow(usename = usename.toOption.get, usesysid = usesysid.toOption.get, usecreatedb = usecreatedb.toOption.get, usesuper = usesuper.toOption.get, userepl = userepl.toOption.get, usebypassrls = usebypassrls.toOption.get, passwd = passwd.toOption.get, valuntil = valuntil.toOption.get, useconfig = useconfig.toOption.get)) + else Left(List[Either[String, Any]](usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShadowViewRow] = new JsonEncoder[PgShadowViewRow] { + override def unsafeEncode(a: PgShadowViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""usename":""") + JsonEncoder.string.unsafeEncode(a.usename, indent, out) + out.write(",") + out.write(""""usesysid":""") + PgAuthidId.jsonEncoder.unsafeEncode(a.usesysid, indent, out) + out.write(",") + out.write(""""usecreatedb":""") + JsonEncoder.boolean.unsafeEncode(a.usecreatedb, indent, out) + out.write(",") + out.write(""""usesuper":""") + JsonEncoder.boolean.unsafeEncode(a.usesuper, indent, out) + out.write(",") + out.write(""""userepl":""") + JsonEncoder.boolean.unsafeEncode(a.userepl, indent, out) + out.write(",") + out.write(""""usebypassrls":""") + JsonEncoder.boolean.unsafeEncode(a.usebypassrls, indent, out) + out.write(",") + out.write(""""passwd":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.passwd, indent, out) + out.write(",") + out.write(""""valuntil":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.valuntil, indent, out) + out.write(",") + out.write(""""useconfig":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.useconfig, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewStructure.scala new file mode 100644 index 0000000000..1d18282a79 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shadow/PgShadowViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shadow + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgShadowViewStructure[Row](val prefix: Option[String], val extract: Row => PgShadowViewRow, val merge: (Row, PgShadowViewRow) => Row) + extends Relation[PgShadowViewFields, PgShadowViewRow, Row] + with PgShadowViewFields[Row] { outer => + + override val usename = new Field[String, Row](prefix, "usename", None, None)(x => extract(x).usename, (row, value) => merge(row, extract(row).copy(usename = value))) + override val usesysid = new Field[PgAuthidId, Row](prefix, "usesysid", None, None)(x => extract(x).usesysid, (row, value) => merge(row, extract(row).copy(usesysid = value))) + override val usecreatedb = new Field[Boolean, Row](prefix, "usecreatedb", None, None)(x => extract(x).usecreatedb, (row, value) => merge(row, extract(row).copy(usecreatedb = value))) + override val usesuper = new Field[Boolean, Row](prefix, "usesuper", None, None)(x => extract(x).usesuper, (row, value) => merge(row, extract(row).copy(usesuper = value))) + override val userepl = new Field[Boolean, Row](prefix, "userepl", None, None)(x => extract(x).userepl, (row, value) => merge(row, extract(row).copy(userepl = value))) + override val usebypassrls = new Field[Boolean, Row](prefix, "usebypassrls", None, None)(x => extract(x).usebypassrls, (row, value) => merge(row, extract(row).copy(usebypassrls = value))) + override val passwd = new OptField[String, Row](prefix, "passwd", None, None)(x => extract(x).passwd, (row, value) => merge(row, extract(row).copy(passwd = value))) + override val valuntil = new OptField[TypoInstant, Row](prefix, "valuntil", Some("text"), None)(x => extract(x).valuntil, (row, value) => merge(row, extract(row).copy(valuntil = value))) + override val useconfig = new OptField[Array[String], Row](prefix, "useconfig", None, None)(x => extract(x).useconfig, (row, value) => merge(row, extract(row).copy(useconfig = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgShadowViewRow, merge: (NewRow, PgShadowViewRow) => NewRow): PgShadowViewStructure[NewRow] = + new PgShadowViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependFields.scala new file mode 100644 index 0000000000..10244bf12f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdepend + +import typo.dsl.SqlExpr.Field + +trait PgShdependFields[Row] { + val dbid: Field[/* oid */ Long, Row] + val classid: Field[/* oid */ Long, Row] + val objid: Field[/* oid */ Long, Row] + val objsubid: Field[Int, Row] + val refclassid: Field[/* oid */ Long, Row] + val refobjid: Field[/* oid */ Long, Row] + val deptype: Field[String, Row] +} +object PgShdependFields extends PgShdependStructure[PgShdependRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepo.scala new file mode 100644 index 0000000000..01fac5da69 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdepend + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgShdependRepo { + def delete: DeleteBuilder[PgShdependFields, PgShdependRow] + def insert(unsaved: PgShdependRow): ZIO[ZConnection, Throwable, PgShdependRow] + def select: SelectBuilder[PgShdependFields, PgShdependRow] + def selectAll: ZStream[ZConnection, Throwable, PgShdependRow] + def update: UpdateBuilder[PgShdependFields, PgShdependRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepoImpl.scala new file mode 100644 index 0000000000..2c652876a0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRepoImpl.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdepend + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgShdependRepoImpl extends PgShdependRepo { + override def delete: DeleteBuilder[PgShdependFields, PgShdependRow] = { + DeleteBuilder("pg_catalog.pg_shdepend", PgShdependFields) + } + override def insert(unsaved: PgShdependRow): ZIO[ZConnection, Throwable, PgShdependRow] = { + sql"""insert into pg_catalog.pg_shdepend("dbid", "classid", "objid", "objsubid", "refclassid", "refobjid", "deptype") + values (${Segment.paramSegment(unsaved.dbid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.objsubid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.refclassid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.refobjid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.deptype)(Setter.stringSetter)}::char) + returning "dbid", "classid", "objid", "objsubid", "refclassid", "refobjid", "deptype" + """.insertReturning(PgShdependRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgShdependFields, PgShdependRow] = { + SelectBuilderSql("pg_catalog.pg_shdepend", PgShdependFields, PgShdependRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShdependRow] = { + sql"""select "dbid", "classid", "objid", "objsubid", "refclassid", "refobjid", "deptype" from pg_catalog.pg_shdepend""".query(PgShdependRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[PgShdependFields, PgShdependRow] = { + UpdateBuilder("pg_catalog.pg_shdepend", PgShdependFields, PgShdependRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRow.scala new file mode 100644 index 0000000000..d63d43550d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdepend + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgShdependRow( + dbid: /* oid */ Long, + classid: /* oid */ Long, + objid: /* oid */ Long, + objsubid: Int, + refclassid: /* oid */ Long, + refobjid: /* oid */ Long, + deptype: String +) + +object PgShdependRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgShdependRow] = new JdbcDecoder[PgShdependRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgShdependRow) = + columIndex + 6 -> + PgShdependRow( + dbid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + objid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + objsubid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + refclassid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + refobjid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 5, rs)._2, + deptype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgShdependRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val dbid = jsonObj.get("dbid").toRight("Missing field 'dbid'").flatMap(_.as(JsonDecoder.long)) + val classid = jsonObj.get("classid").toRight("Missing field 'classid'").flatMap(_.as(JsonDecoder.long)) + val objid = jsonObj.get("objid").toRight("Missing field 'objid'").flatMap(_.as(JsonDecoder.long)) + val objsubid = jsonObj.get("objsubid").toRight("Missing field 'objsubid'").flatMap(_.as(JsonDecoder.int)) + val refclassid = jsonObj.get("refclassid").toRight("Missing field 'refclassid'").flatMap(_.as(JsonDecoder.long)) + val refobjid = jsonObj.get("refobjid").toRight("Missing field 'refobjid'").flatMap(_.as(JsonDecoder.long)) + val deptype = jsonObj.get("deptype").toRight("Missing field 'deptype'").flatMap(_.as(JsonDecoder.string)) + if (dbid.isRight && classid.isRight && objid.isRight && objsubid.isRight && refclassid.isRight && refobjid.isRight && deptype.isRight) + Right(PgShdependRow(dbid = dbid.toOption.get, classid = classid.toOption.get, objid = objid.toOption.get, objsubid = objsubid.toOption.get, refclassid = refclassid.toOption.get, refobjid = refobjid.toOption.get, deptype = deptype.toOption.get)) + else Left(List[Either[String, Any]](dbid, classid, objid, objsubid, refclassid, refobjid, deptype).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShdependRow] = new JsonEncoder[PgShdependRow] { + override def unsafeEncode(a: PgShdependRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""dbid":""") + JsonEncoder.long.unsafeEncode(a.dbid, indent, out) + out.write(",") + out.write(""""classid":""") + JsonEncoder.long.unsafeEncode(a.classid, indent, out) + out.write(",") + out.write(""""objid":""") + JsonEncoder.long.unsafeEncode(a.objid, indent, out) + out.write(",") + out.write(""""objsubid":""") + JsonEncoder.int.unsafeEncode(a.objsubid, indent, out) + out.write(",") + out.write(""""refclassid":""") + JsonEncoder.long.unsafeEncode(a.refclassid, indent, out) + out.write(",") + out.write(""""refobjid":""") + JsonEncoder.long.unsafeEncode(a.refobjid, indent, out) + out.write(",") + out.write(""""deptype":""") + JsonEncoder.string.unsafeEncode(a.deptype, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependStructure.scala new file mode 100644 index 0000000000..324cb2395e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdepend/PgShdependStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdepend + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PgShdependStructure[Row](val prefix: Option[String], val extract: Row => PgShdependRow, val merge: (Row, PgShdependRow) => Row) + extends Relation[PgShdependFields, PgShdependRow, Row] + with PgShdependFields[Row] { outer => + + override val dbid = new Field[/* oid */ Long, Row](prefix, "dbid", None, Some("oid"))(x => extract(x).dbid, (row, value) => merge(row, extract(row).copy(dbid = value))) + override val classid = new Field[/* oid */ Long, Row](prefix, "classid", None, Some("oid"))(x => extract(x).classid, (row, value) => merge(row, extract(row).copy(classid = value))) + override val objid = new Field[/* oid */ Long, Row](prefix, "objid", None, Some("oid"))(x => extract(x).objid, (row, value) => merge(row, extract(row).copy(objid = value))) + override val objsubid = new Field[Int, Row](prefix, "objsubid", None, Some("int4"))(x => extract(x).objsubid, (row, value) => merge(row, extract(row).copy(objsubid = value))) + override val refclassid = new Field[/* oid */ Long, Row](prefix, "refclassid", None, Some("oid"))(x => extract(x).refclassid, (row, value) => merge(row, extract(row).copy(refclassid = value))) + override val refobjid = new Field[/* oid */ Long, Row](prefix, "refobjid", None, Some("oid"))(x => extract(x).refobjid, (row, value) => merge(row, extract(row).copy(refobjid = value))) + override val deptype = new Field[String, Row](prefix, "deptype", None, Some("char"))(x => extract(x).deptype, (row, value) => merge(row, extract(row).copy(deptype = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](dbid, classid, objid, objsubid, refclassid, refobjid, deptype) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgShdependRow, merge: (NewRow, PgShdependRow) => NewRow): PgShdependStructure[NewRow] = + new PgShdependStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionFields.scala new file mode 100644 index 0000000000..435e9968b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgShdescriptionFields[Row] { + val objoid: IdField[/* oid */ Long, Row] + val classoid: IdField[/* oid */ Long, Row] + val description: Field[String, Row] +} +object PgShdescriptionFields extends PgShdescriptionStructure[PgShdescriptionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionId.scala new file mode 100644 index 0000000000..9e598813e2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_shdescription` */ +case class PgShdescriptionId(objoid: /* oid */ Long, classoid: /* oid */ Long) +object PgShdescriptionId { + implicit lazy val jsonDecoder: JsonDecoder[PgShdescriptionId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + if (objoid.isRight && classoid.isRight) + Right(PgShdescriptionId(objoid = objoid.toOption.get, classoid = classoid.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShdescriptionId] = new JsonEncoder[PgShdescriptionId] { + override def unsafeEncode(a: PgShdescriptionId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgShdescriptionId] = Ordering.by(x => (x.objoid, x.classoid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepo.scala new file mode 100644 index 0000000000..d88c79f4f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgShdescriptionRepo { + def delete(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgShdescriptionFields, PgShdescriptionRow] + def insert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, PgShdescriptionRow] + def select: SelectBuilder[PgShdescriptionFields, PgShdescriptionRow] + def selectAll: ZStream[ZConnection, Throwable, PgShdescriptionRow] + def selectById(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Option[PgShdescriptionRow]] + def update(row: PgShdescriptionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgShdescriptionFields, PgShdescriptionRow] + def upsert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgShdescriptionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoImpl.scala new file mode 100644 index 0000000000..12400ab857 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoImpl.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgShdescriptionRepoImpl extends PgShdescriptionRepo { + override def delete(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_shdescription where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + DeleteBuilder("pg_catalog.pg_shdescription", PgShdescriptionFields) + } + override def insert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, PgShdescriptionRow] = { + sql"""insert into pg_catalog.pg_shdescription("objoid", "classoid", "description") + values (${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}) + returning "objoid", "classoid", "description" + """.insertReturning(PgShdescriptionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + SelectBuilderSql("pg_catalog.pg_shdescription", PgShdescriptionFields, PgShdescriptionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShdescriptionRow] = { + sql"""select "objoid", "classoid", "description" from pg_catalog.pg_shdescription""".query(PgShdescriptionRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Option[PgShdescriptionRow]] = { + sql"""select "objoid", "classoid", "description" from pg_catalog.pg_shdescription where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)}""".query(PgShdescriptionRow.jdbcDecoder).selectOne + } + override def update(row: PgShdescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_shdescription + set "description" = ${Segment.paramSegment(row.description)(Setter.stringSetter)} + where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + UpdateBuilder("pg_catalog.pg_shdescription", PgShdescriptionFields, PgShdescriptionRow.jdbcDecoder) + } + override def upsert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgShdescriptionRow]] = { + sql"""insert into pg_catalog.pg_shdescription("objoid", "classoid", "description") + values ( + ${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)} + ) + on conflict ("objoid", "classoid") + do update set + "description" = EXCLUDED."description" + returning "objoid", "classoid", "description"""".insertReturning(PgShdescriptionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoMock.scala new file mode 100644 index 0000000000..8ece1a4cbf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgShdescriptionRepoMock(map: scala.collection.mutable.Map[PgShdescriptionId, PgShdescriptionRow] = scala.collection.mutable.Map.empty) extends PgShdescriptionRepo { + override def delete(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + DeleteBuilderMock(DeleteParams.empty, PgShdescriptionFields, map) + } + override def insert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, PgShdescriptionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + SelectBuilderMock(PgShdescriptionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShdescriptionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgShdescriptionId): ZIO[ZConnection, Throwable, Option[PgShdescriptionRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgShdescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgShdescriptionFields, PgShdescriptionRow] = { + UpdateBuilderMock(UpdateParams.empty, PgShdescriptionFields, map) + } + override def upsert(unsaved: PgShdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgShdescriptionRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRow.scala new file mode 100644 index 0000000000..0fee7f4d18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionRow.scala @@ -0,0 +1,57 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgShdescriptionRow( + objoid: /* oid */ Long, + classoid: /* oid */ Long, + description: String +){ + val compositeId: PgShdescriptionId = PgShdescriptionId(objoid, classoid) + } + +object PgShdescriptionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgShdescriptionRow] = new JdbcDecoder[PgShdescriptionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgShdescriptionRow) = + columIndex + 2 -> + PgShdescriptionRow( + objoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgShdescriptionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && description.isRight) + Right(PgShdescriptionRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, description = description.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, description).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShdescriptionRow] = new JsonEncoder[PgShdescriptionRow] { + override def unsafeEncode(a: PgShdescriptionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionStructure.scala new file mode 100644 index 0000000000..5e78025aec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shdescription/PgShdescriptionStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shdescription + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgShdescriptionStructure[Row](val prefix: Option[String], val extract: Row => PgShdescriptionRow, val merge: (Row, PgShdescriptionRow) => Row) + extends Relation[PgShdescriptionFields, PgShdescriptionRow, Row] + with PgShdescriptionFields[Row] { outer => + + override val objoid = new IdField[/* oid */ Long, Row](prefix, "objoid", None, Some("oid"))(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new IdField[/* oid */ Long, Row](prefix, "classoid", None, Some("oid"))(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val description = new Field[String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, description) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgShdescriptionRow, merge: (NewRow, PgShdescriptionRow) => NewRow): PgShdescriptionStructure[NewRow] = + new PgShdescriptionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewFields.scala new file mode 100644 index 0000000000..7ef92f1d50 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shmem_allocations + +import typo.dsl.SqlExpr.OptField + +trait PgShmemAllocationsViewFields[Row] { + val name: OptField[String, Row] + val off: OptField[Long, Row] + val size: OptField[Long, Row] + val allocatedSize: OptField[Long, Row] +} +object PgShmemAllocationsViewFields extends PgShmemAllocationsViewStructure[PgShmemAllocationsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepo.scala new file mode 100644 index 0000000000..440ff9e10d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shmem_allocations + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgShmemAllocationsViewRepo { + def select: SelectBuilder[PgShmemAllocationsViewFields, PgShmemAllocationsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgShmemAllocationsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepoImpl.scala new file mode 100644 index 0000000000..3d981f4919 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shmem_allocations + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgShmemAllocationsViewRepoImpl extends PgShmemAllocationsViewRepo { + override def select: SelectBuilder[PgShmemAllocationsViewFields, PgShmemAllocationsViewRow] = { + SelectBuilderSql("pg_catalog.pg_shmem_allocations", PgShmemAllocationsViewFields, PgShmemAllocationsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShmemAllocationsViewRow] = { + sql"""select "name", "off", "size", "allocated_size" from pg_catalog.pg_shmem_allocations""".query(PgShmemAllocationsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRow.scala new file mode 100644 index 0000000000..fdf938abb8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shmem_allocations + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgShmemAllocationsViewRow( + name: /* nullability unknown */ Option[String], + off: /* nullability unknown */ Option[Long], + size: /* nullability unknown */ Option[Long], + allocatedSize: /* nullability unknown */ Option[Long] +) + +object PgShmemAllocationsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgShmemAllocationsViewRow] = new JdbcDecoder[PgShmemAllocationsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgShmemAllocationsViewRow) = + columIndex + 3 -> + PgShmemAllocationsViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + off = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + size = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + allocatedSize = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgShmemAllocationsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val off = jsonObj.get("off").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val size = jsonObj.get("size").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val allocatedSize = jsonObj.get("allocated_size").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (name.isRight && off.isRight && size.isRight && allocatedSize.isRight) + Right(PgShmemAllocationsViewRow(name = name.toOption.get, off = off.toOption.get, size = size.toOption.get, allocatedSize = allocatedSize.toOption.get)) + else Left(List[Either[String, Any]](name, off, size, allocatedSize).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShmemAllocationsViewRow] = new JsonEncoder[PgShmemAllocationsViewRow] { + override def unsafeEncode(a: PgShmemAllocationsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""off":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.off, indent, out) + out.write(",") + out.write(""""size":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.size, indent, out) + out.write(",") + out.write(""""allocated_size":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.allocatedSize, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewStructure.scala new file mode 100644 index 0000000000..2e1b7669ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shmem_allocations/PgShmemAllocationsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shmem_allocations + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgShmemAllocationsViewStructure[Row](val prefix: Option[String], val extract: Row => PgShmemAllocationsViewRow, val merge: (Row, PgShmemAllocationsViewRow) => Row) + extends Relation[PgShmemAllocationsViewFields, PgShmemAllocationsViewRow, Row] + with PgShmemAllocationsViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val off = new OptField[Long, Row](prefix, "off", None, None)(x => extract(x).off, (row, value) => merge(row, extract(row).copy(off = value))) + override val size = new OptField[Long, Row](prefix, "size", None, None)(x => extract(x).size, (row, value) => merge(row, extract(row).copy(size = value))) + override val allocatedSize = new OptField[Long, Row](prefix, "allocated_size", None, None)(x => extract(x).allocatedSize, (row, value) => merge(row, extract(row).copy(allocatedSize = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, off, size, allocatedSize) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgShmemAllocationsViewRow, merge: (NewRow, PgShmemAllocationsViewRow) => NewRow): PgShmemAllocationsViewStructure[NewRow] = + new PgShmemAllocationsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelFields.scala new file mode 100644 index 0000000000..658c172d5b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgShseclabelFields[Row] { + val objoid: IdField[/* oid */ Long, Row] + val classoid: IdField[/* oid */ Long, Row] + val provider: IdField[String, Row] + val label: Field[String, Row] +} +object PgShseclabelFields extends PgShseclabelStructure[PgShseclabelRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelId.scala new file mode 100644 index 0000000000..a8cde7745f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelId.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_shseclabel` */ +case class PgShseclabelId(objoid: /* oid */ Long, classoid: /* oid */ Long, provider: String) +object PgShseclabelId { + implicit lazy val jsonDecoder: JsonDecoder[PgShseclabelId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val provider = jsonObj.get("provider").toRight("Missing field 'provider'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && provider.isRight) + Right(PgShseclabelId(objoid = objoid.toOption.get, classoid = classoid.toOption.get, provider = provider.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, provider).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShseclabelId] = new JsonEncoder[PgShseclabelId] { + override def unsafeEncode(a: PgShseclabelId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""provider":""") + JsonEncoder.string.unsafeEncode(a.provider, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgShseclabelId] = Ordering.by(x => (x.objoid, x.classoid, x.provider)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepo.scala new file mode 100644 index 0000000000..ad28f07b53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgShseclabelRepo { + def delete(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgShseclabelFields, PgShseclabelRow] + def insert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, PgShseclabelRow] + def select: SelectBuilder[PgShseclabelFields, PgShseclabelRow] + def selectAll: ZStream[ZConnection, Throwable, PgShseclabelRow] + def selectById(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Option[PgShseclabelRow]] + def update(row: PgShseclabelRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgShseclabelFields, PgShseclabelRow] + def upsert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgShseclabelRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoImpl.scala new file mode 100644 index 0000000000..42b4a0dba9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgShseclabelRepoImpl extends PgShseclabelRepo { + override def delete(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_shseclabel where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgShseclabelFields, PgShseclabelRow] = { + DeleteBuilder("pg_catalog.pg_shseclabel", PgShseclabelFields) + } + override def insert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, PgShseclabelRow] = { + sql"""insert into pg_catalog.pg_shseclabel("objoid", "classoid", "provider", "label") + values (${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.provider)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.label)(Setter.stringSetter)}) + returning "objoid", "classoid", "provider", "label" + """.insertReturning(PgShseclabelRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgShseclabelFields, PgShseclabelRow] = { + SelectBuilderSql("pg_catalog.pg_shseclabel", PgShseclabelFields, PgShseclabelRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShseclabelRow] = { + sql"""select "objoid", "classoid", "provider", "label" from pg_catalog.pg_shseclabel""".query(PgShseclabelRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Option[PgShseclabelRow]] = { + sql"""select "objoid", "classoid", "provider", "label" from pg_catalog.pg_shseclabel where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".query(PgShseclabelRow.jdbcDecoder).selectOne + } + override def update(row: PgShseclabelRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_shseclabel + set "label" = ${Segment.paramSegment(row.label)(Setter.stringSetter)} + where "objoid" = ${Segment.paramSegment(compositeId.objoid)(Setter.longSetter)} AND "classoid" = ${Segment.paramSegment(compositeId.classoid)(Setter.longSetter)} AND "provider" = ${Segment.paramSegment(compositeId.provider)(Setter.stringSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgShseclabelFields, PgShseclabelRow] = { + UpdateBuilder("pg_catalog.pg_shseclabel", PgShseclabelFields, PgShseclabelRow.jdbcDecoder) + } + override def upsert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgShseclabelRow]] = { + sql"""insert into pg_catalog.pg_shseclabel("objoid", "classoid", "provider", "label") + values ( + ${Segment.paramSegment(unsaved.objoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.classoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.provider)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.label)(Setter.stringSetter)} + ) + on conflict ("objoid", "classoid", "provider") + do update set + "label" = EXCLUDED."label" + returning "objoid", "classoid", "provider", "label"""".insertReturning(PgShseclabelRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoMock.scala new file mode 100644 index 0000000000..535873dc83 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgShseclabelRepoMock(map: scala.collection.mutable.Map[PgShseclabelId, PgShseclabelRow] = scala.collection.mutable.Map.empty) extends PgShseclabelRepo { + override def delete(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgShseclabelFields, PgShseclabelRow] = { + DeleteBuilderMock(DeleteParams.empty, PgShseclabelFields, map) + } + override def insert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, PgShseclabelRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgShseclabelFields, PgShseclabelRow] = { + SelectBuilderMock(PgShseclabelFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgShseclabelRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgShseclabelId): ZIO[ZConnection, Throwable, Option[PgShseclabelRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgShseclabelRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgShseclabelFields, PgShseclabelRow] = { + UpdateBuilderMock(UpdateParams.empty, PgShseclabelFields, map) + } + override def upsert(unsaved: PgShseclabelRow): ZIO[ZConnection, Throwable, UpdateResult[PgShseclabelRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRow.scala new file mode 100644 index 0000000000..2fdad334db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgShseclabelRow( + objoid: /* oid */ Long, + classoid: /* oid */ Long, + provider: String, + label: String +){ + val compositeId: PgShseclabelId = PgShseclabelId(objoid, classoid, provider) + } + +object PgShseclabelRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgShseclabelRow] = new JdbcDecoder[PgShseclabelRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgShseclabelRow) = + columIndex + 3 -> + PgShseclabelRow( + objoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + classoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + provider = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + label = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgShseclabelRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val objoid = jsonObj.get("objoid").toRight("Missing field 'objoid'").flatMap(_.as(JsonDecoder.long)) + val classoid = jsonObj.get("classoid").toRight("Missing field 'classoid'").flatMap(_.as(JsonDecoder.long)) + val provider = jsonObj.get("provider").toRight("Missing field 'provider'").flatMap(_.as(JsonDecoder.string)) + val label = jsonObj.get("label").toRight("Missing field 'label'").flatMap(_.as(JsonDecoder.string)) + if (objoid.isRight && classoid.isRight && provider.isRight && label.isRight) + Right(PgShseclabelRow(objoid = objoid.toOption.get, classoid = classoid.toOption.get, provider = provider.toOption.get, label = label.toOption.get)) + else Left(List[Either[String, Any]](objoid, classoid, provider, label).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgShseclabelRow] = new JsonEncoder[PgShseclabelRow] { + override def unsafeEncode(a: PgShseclabelRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""objoid":""") + JsonEncoder.long.unsafeEncode(a.objoid, indent, out) + out.write(",") + out.write(""""classoid":""") + JsonEncoder.long.unsafeEncode(a.classoid, indent, out) + out.write(",") + out.write(""""provider":""") + JsonEncoder.string.unsafeEncode(a.provider, indent, out) + out.write(",") + out.write(""""label":""") + JsonEncoder.string.unsafeEncode(a.label, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelStructure.scala new file mode 100644 index 0000000000..c037268c84 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_shseclabel/PgShseclabelStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_shseclabel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgShseclabelStructure[Row](val prefix: Option[String], val extract: Row => PgShseclabelRow, val merge: (Row, PgShseclabelRow) => Row) + extends Relation[PgShseclabelFields, PgShseclabelRow, Row] + with PgShseclabelFields[Row] { outer => + + override val objoid = new IdField[/* oid */ Long, Row](prefix, "objoid", None, Some("oid"))(x => extract(x).objoid, (row, value) => merge(row, extract(row).copy(objoid = value))) + override val classoid = new IdField[/* oid */ Long, Row](prefix, "classoid", None, Some("oid"))(x => extract(x).classoid, (row, value) => merge(row, extract(row).copy(classoid = value))) + override val provider = new IdField[String, Row](prefix, "provider", None, None)(x => extract(x).provider, (row, value) => merge(row, extract(row).copy(provider = value))) + override val label = new Field[String, Row](prefix, "label", None, None)(x => extract(x).label, (row, value) => merge(row, extract(row).copy(label = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](objoid, classoid, provider, label) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgShseclabelRow, merge: (NewRow, PgShseclabelRow) => NewRow): PgShseclabelStructure[NewRow] = + new PgShseclabelStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewFields.scala new file mode 100644 index 0000000000..97a23c677e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewFields.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_activity + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.OptField + +trait PgStatActivityViewFields[Row] { + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val pid: OptField[Int, Row] + val leaderPid: OptField[Int, Row] + val usesysid: OptField[/* oid */ Long, Row] + val usename: OptField[String, Row] + val applicationName: OptField[String, Row] + val clientAddr: OptField[TypoInet, Row] + val clientHostname: OptField[String, Row] + val clientPort: OptField[Int, Row] + val backendStart: OptField[TypoInstant, Row] + val xactStart: OptField[TypoInstant, Row] + val queryStart: OptField[TypoInstant, Row] + val stateChange: OptField[TypoInstant, Row] + val waitEventType: OptField[String, Row] + val waitEvent: OptField[String, Row] + val state: OptField[String, Row] + val backendXid: OptField[TypoXid, Row] + val backendXmin: OptField[TypoXid, Row] + val queryId: OptField[Long, Row] + val query: OptField[String, Row] + val backendType: OptField[String, Row] +} +object PgStatActivityViewFields extends PgStatActivityViewStructure[PgStatActivityViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepo.scala new file mode 100644 index 0000000000..2464e31733 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_activity + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatActivityViewRepo { + def select: SelectBuilder[PgStatActivityViewFields, PgStatActivityViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatActivityViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepoImpl.scala new file mode 100644 index 0000000000..866f4a4818 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_activity + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatActivityViewRepoImpl extends PgStatActivityViewRepo { + override def select: SelectBuilder[PgStatActivityViewFields, PgStatActivityViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_activity", PgStatActivityViewFields, PgStatActivityViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatActivityViewRow] = { + sql"""select "datid", "datname", "pid", "leader_pid", "usesysid", "usename", "application_name", "client_addr", "client_hostname", "client_port", "backend_start"::text, "xact_start"::text, "query_start"::text, "state_change"::text, "wait_event_type", "wait_event", "state", "backend_xid", "backend_xmin", "query_id", "query", "backend_type" from pg_catalog.pg_stat_activity""".query(PgStatActivityViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRow.scala new file mode 100644 index 0000000000..09187b565a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewRow.scala @@ -0,0 +1,174 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_activity + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatActivityViewRow( + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + pid: /* nullability unknown */ Option[Int], + leaderPid: /* nullability unknown */ Option[Int], + usesysid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + usename: Option[String], + applicationName: /* nullability unknown */ Option[String], + clientAddr: /* nullability unknown */ Option[TypoInet], + clientHostname: /* nullability unknown */ Option[String], + clientPort: /* nullability unknown */ Option[Int], + backendStart: /* nullability unknown */ Option[TypoInstant], + xactStart: /* nullability unknown */ Option[TypoInstant], + queryStart: /* nullability unknown */ Option[TypoInstant], + stateChange: /* nullability unknown */ Option[TypoInstant], + waitEventType: /* nullability unknown */ Option[String], + waitEvent: /* nullability unknown */ Option[String], + state: /* nullability unknown */ Option[String], + backendXid: /* nullability unknown */ Option[TypoXid], + backendXmin: /* nullability unknown */ Option[TypoXid], + queryId: /* nullability unknown */ Option[Long], + query: /* nullability unknown */ Option[String], + backendType: /* nullability unknown */ Option[String] +) + +object PgStatActivityViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatActivityViewRow] = new JdbcDecoder[PgStatActivityViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatActivityViewRow) = + columIndex + 21 -> + PgStatActivityViewRow( + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 2, rs)._2, + leaderPid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + usesysid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + usename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + applicationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + clientAddr = JdbcDecoder.optionDecoder(TypoInet.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + clientHostname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + clientPort = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + backendStart = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + xactStart = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + queryStart = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + stateChange = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 13, rs)._2, + waitEventType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + waitEvent = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + state = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + backendXid = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + backendXmin = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + queryId = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 19, rs)._2, + query = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + backendType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatActivityViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val leaderPid = jsonObj.get("leader_pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val usesysid = jsonObj.get("usesysid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val usename = jsonObj.get("usename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val applicationName = jsonObj.get("application_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clientAddr = jsonObj.get("client_addr").fold[Either[String, Option[TypoInet]]](Right(None))(_.as(JsonDecoder.option(TypoInet.jsonDecoder))) + val clientHostname = jsonObj.get("client_hostname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clientPort = jsonObj.get("client_port").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val backendStart = jsonObj.get("backend_start").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val xactStart = jsonObj.get("xact_start").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val queryStart = jsonObj.get("query_start").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val stateChange = jsonObj.get("state_change").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val waitEventType = jsonObj.get("wait_event_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val waitEvent = jsonObj.get("wait_event").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val state = jsonObj.get("state").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val backendXid = jsonObj.get("backend_xid").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val backendXmin = jsonObj.get("backend_xmin").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val queryId = jsonObj.get("query_id").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val query = jsonObj.get("query").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val backendType = jsonObj.get("backend_type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (datid.isRight && datname.isRight && pid.isRight && leaderPid.isRight && usesysid.isRight && usename.isRight && applicationName.isRight && clientAddr.isRight && clientHostname.isRight && clientPort.isRight && backendStart.isRight && xactStart.isRight && queryStart.isRight && stateChange.isRight && waitEventType.isRight && waitEvent.isRight && state.isRight && backendXid.isRight && backendXmin.isRight && queryId.isRight && query.isRight && backendType.isRight) + Right(PgStatActivityViewRow(datid = datid.toOption.get, datname = datname.toOption.get, pid = pid.toOption.get, leaderPid = leaderPid.toOption.get, usesysid = usesysid.toOption.get, usename = usename.toOption.get, applicationName = applicationName.toOption.get, clientAddr = clientAddr.toOption.get, clientHostname = clientHostname.toOption.get, clientPort = clientPort.toOption.get, backendStart = backendStart.toOption.get, xactStart = xactStart.toOption.get, queryStart = queryStart.toOption.get, stateChange = stateChange.toOption.get, waitEventType = waitEventType.toOption.get, waitEvent = waitEvent.toOption.get, state = state.toOption.get, backendXid = backendXid.toOption.get, backendXmin = backendXmin.toOption.get, queryId = queryId.toOption.get, query = query.toOption.get, backendType = backendType.toOption.get)) + else Left(List[Either[String, Any]](datid, datname, pid, leaderPid, usesysid, usename, applicationName, clientAddr, clientHostname, clientPort, backendStart, xactStart, queryStart, stateChange, waitEventType, waitEvent, state, backendXid, backendXmin, queryId, query, backendType).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatActivityViewRow] = new JsonEncoder[PgStatActivityViewRow] { + override def unsafeEncode(a: PgStatActivityViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""leader_pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.leaderPid, indent, out) + out.write(",") + out.write(""""usesysid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.usesysid, indent, out) + out.write(",") + out.write(""""usename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.usename, indent, out) + out.write(",") + out.write(""""application_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.applicationName, indent, out) + out.write(",") + out.write(""""client_addr":""") + JsonEncoder.option(TypoInet.jsonEncoder).unsafeEncode(a.clientAddr, indent, out) + out.write(",") + out.write(""""client_hostname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.clientHostname, indent, out) + out.write(",") + out.write(""""client_port":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.clientPort, indent, out) + out.write(",") + out.write(""""backend_start":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.backendStart, indent, out) + out.write(",") + out.write(""""xact_start":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.xactStart, indent, out) + out.write(",") + out.write(""""query_start":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.queryStart, indent, out) + out.write(",") + out.write(""""state_change":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.stateChange, indent, out) + out.write(",") + out.write(""""wait_event_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.waitEventType, indent, out) + out.write(",") + out.write(""""wait_event":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.waitEvent, indent, out) + out.write(",") + out.write(""""state":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.state, indent, out) + out.write(",") + out.write(""""backend_xid":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.backendXid, indent, out) + out.write(",") + out.write(""""backend_xmin":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.backendXmin, indent, out) + out.write(",") + out.write(""""query_id":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.queryId, indent, out) + out.write(",") + out.write(""""query":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.query, indent, out) + out.write(",") + out.write(""""backend_type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.backendType, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewStructure.scala new file mode 100644 index 0000000000..db5039a491 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_activity/PgStatActivityViewStructure.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_activity + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatActivityViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatActivityViewRow, val merge: (Row, PgStatActivityViewRow) => Row) + extends Relation[PgStatActivityViewFields, PgStatActivityViewRow, Row] + with PgStatActivityViewFields[Row] { outer => + + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val leaderPid = new OptField[Int, Row](prefix, "leader_pid", None, None)(x => extract(x).leaderPid, (row, value) => merge(row, extract(row).copy(leaderPid = value))) + override val usesysid = new OptField[/* oid */ Long, Row](prefix, "usesysid", None, None)(x => extract(x).usesysid, (row, value) => merge(row, extract(row).copy(usesysid = value))) + override val usename = new OptField[String, Row](prefix, "usename", None, None)(x => extract(x).usename, (row, value) => merge(row, extract(row).copy(usename = value))) + override val applicationName = new OptField[String, Row](prefix, "application_name", None, None)(x => extract(x).applicationName, (row, value) => merge(row, extract(row).copy(applicationName = value))) + override val clientAddr = new OptField[TypoInet, Row](prefix, "client_addr", None, None)(x => extract(x).clientAddr, (row, value) => merge(row, extract(row).copy(clientAddr = value))) + override val clientHostname = new OptField[String, Row](prefix, "client_hostname", None, None)(x => extract(x).clientHostname, (row, value) => merge(row, extract(row).copy(clientHostname = value))) + override val clientPort = new OptField[Int, Row](prefix, "client_port", None, None)(x => extract(x).clientPort, (row, value) => merge(row, extract(row).copy(clientPort = value))) + override val backendStart = new OptField[TypoInstant, Row](prefix, "backend_start", Some("text"), None)(x => extract(x).backendStart, (row, value) => merge(row, extract(row).copy(backendStart = value))) + override val xactStart = new OptField[TypoInstant, Row](prefix, "xact_start", Some("text"), None)(x => extract(x).xactStart, (row, value) => merge(row, extract(row).copy(xactStart = value))) + override val queryStart = new OptField[TypoInstant, Row](prefix, "query_start", Some("text"), None)(x => extract(x).queryStart, (row, value) => merge(row, extract(row).copy(queryStart = value))) + override val stateChange = new OptField[TypoInstant, Row](prefix, "state_change", Some("text"), None)(x => extract(x).stateChange, (row, value) => merge(row, extract(row).copy(stateChange = value))) + override val waitEventType = new OptField[String, Row](prefix, "wait_event_type", None, None)(x => extract(x).waitEventType, (row, value) => merge(row, extract(row).copy(waitEventType = value))) + override val waitEvent = new OptField[String, Row](prefix, "wait_event", None, None)(x => extract(x).waitEvent, (row, value) => merge(row, extract(row).copy(waitEvent = value))) + override val state = new OptField[String, Row](prefix, "state", None, None)(x => extract(x).state, (row, value) => merge(row, extract(row).copy(state = value))) + override val backendXid = new OptField[TypoXid, Row](prefix, "backend_xid", None, None)(x => extract(x).backendXid, (row, value) => merge(row, extract(row).copy(backendXid = value))) + override val backendXmin = new OptField[TypoXid, Row](prefix, "backend_xmin", None, None)(x => extract(x).backendXmin, (row, value) => merge(row, extract(row).copy(backendXmin = value))) + override val queryId = new OptField[Long, Row](prefix, "query_id", None, None)(x => extract(x).queryId, (row, value) => merge(row, extract(row).copy(queryId = value))) + override val query = new OptField[String, Row](prefix, "query", None, None)(x => extract(x).query, (row, value) => merge(row, extract(row).copy(query = value))) + override val backendType = new OptField[String, Row](prefix, "backend_type", None, None)(x => extract(x).backendType, (row, value) => merge(row, extract(row).copy(backendType = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](datid, datname, pid, leaderPid, usesysid, usename, applicationName, clientAddr, clientHostname, clientPort, backendStart, xactStart, queryStart, stateChange, waitEventType, waitEvent, state, backendXid, backendXmin, queryId, query, backendType) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatActivityViewRow, merge: (NewRow, PgStatActivityViewRow) => NewRow): PgStatActivityViewStructure[NewRow] = + new PgStatActivityViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewFields.scala new file mode 100644 index 0000000000..71c85dde88 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatAllIndexesViewFields[Row] { + val relid: Field[PgClassId, Row] + val indexrelid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val indexrelname: Field[String, Row] + val idxScan: OptField[Long, Row] + val idxTupRead: OptField[Long, Row] + val idxTupFetch: OptField[Long, Row] +} +object PgStatAllIndexesViewFields extends PgStatAllIndexesViewStructure[PgStatAllIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepo.scala new file mode 100644 index 0000000000..31af885035 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatAllIndexesViewRepo { + def select: SelectBuilder[PgStatAllIndexesViewFields, PgStatAllIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatAllIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..8143037c49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatAllIndexesViewRepoImpl extends PgStatAllIndexesViewRepo { + override def select: SelectBuilder[PgStatAllIndexesViewFields, PgStatAllIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_all_indexes", PgStatAllIndexesViewFields, PgStatAllIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatAllIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_scan", "idx_tup_read", "idx_tup_fetch" from pg_catalog.pg_stat_all_indexes""".query(PgStatAllIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRow.scala new file mode 100644 index 0000000000..0cfcee1e9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatAllIndexesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_class.PgClassRow.oid]] */ + indexrelid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + indexrelname: String, + idxScan: /* nullability unknown */ Option[Long], + idxTupRead: /* nullability unknown */ Option[Long], + idxTupFetch: /* nullability unknown */ Option[Long] +) + +object PgStatAllIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatAllIndexesViewRow] = new JdbcDecoder[PgStatAllIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatAllIndexesViewRow) = + columIndex + 7 -> + PgStatAllIndexesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + indexrelid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatAllIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val indexrelid = jsonObj.get("indexrelid").toRight("Missing field 'indexrelid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val indexrelname = jsonObj.get("indexrelname").toRight("Missing field 'indexrelname'").flatMap(_.as(JsonDecoder.string)) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupRead = jsonObj.get("idx_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxScan.isRight && idxTupRead.isRight && idxTupFetch.isRight) + Right(PgStatAllIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxScan = idxScan.toOption.get, idxTupRead = idxTupRead.toOption.get, idxTupFetch = idxTupFetch.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatAllIndexesViewRow] = new JsonEncoder[PgStatAllIndexesViewRow] { + override def unsafeEncode(a: PgStatAllIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + PgClassId.jsonEncoder.unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.string.unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupRead, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewStructure.scala new file mode 100644 index 0000000000..636298d65b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_indexes/PgStatAllIndexesViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatAllIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatAllIndexesViewRow, val merge: (Row, PgStatAllIndexesViewRow) => Row) + extends Relation[PgStatAllIndexesViewFields, PgStatAllIndexesViewRow, Row] + with PgStatAllIndexesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new Field[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new Field[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxScan = new OptField[Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupRead = new OptField[Long, Row](prefix, "idx_tup_read", None, None)(x => extract(x).idxTupRead, (row, value) => merge(row, extract(row).copy(idxTupRead = value))) + override val idxTupFetch = new OptField[Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatAllIndexesViewRow, merge: (NewRow, PgStatAllIndexesViewRow) => NewRow): PgStatAllIndexesViewStructure[NewRow] = + new PgStatAllIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewFields.scala new file mode 100644 index 0000000000..d34e73e05e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewFields.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatAllTablesViewFields[Row] { + val relid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val seqScan: OptField[Long, Row] + val seqTupRead: OptField[Long, Row] + val idxScan: OptField[Long, Row] + val idxTupFetch: OptField[Long, Row] + val nTupIns: OptField[Long, Row] + val nTupUpd: OptField[Long, Row] + val nTupDel: OptField[Long, Row] + val nTupHotUpd: OptField[Long, Row] + val nLiveTup: OptField[Long, Row] + val nDeadTup: OptField[Long, Row] + val nModSinceAnalyze: OptField[Long, Row] + val nInsSinceVacuum: OptField[Long, Row] + val lastVacuum: OptField[TypoInstant, Row] + val lastAutovacuum: OptField[TypoInstant, Row] + val lastAnalyze: OptField[TypoInstant, Row] + val lastAutoanalyze: OptField[TypoInstant, Row] + val vacuumCount: OptField[Long, Row] + val autovacuumCount: OptField[Long, Row] + val analyzeCount: OptField[Long, Row] + val autoanalyzeCount: OptField[Long, Row] +} +object PgStatAllTablesViewFields extends PgStatAllTablesViewStructure[PgStatAllTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepo.scala new file mode 100644 index 0000000000..96875bdabf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatAllTablesViewRepo { + def select: SelectBuilder[PgStatAllTablesViewFields, PgStatAllTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatAllTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepoImpl.scala new file mode 100644 index 0000000000..d28fc4da67 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatAllTablesViewRepoImpl extends PgStatAllTablesViewRepo { + override def select: SelectBuilder[PgStatAllTablesViewFields, PgStatAllTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_all_tables", PgStatAllTablesViewFields, PgStatAllTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatAllTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd", "n_live_tup", "n_dead_tup", "n_mod_since_analyze", "n_ins_since_vacuum", "last_vacuum"::text, "last_autovacuum"::text, "last_analyze"::text, "last_autoanalyze"::text, "vacuum_count", "autovacuum_count", "analyze_count", "autoanalyze_count" from pg_catalog.pg_stat_all_tables""".query(PgStatAllTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRow.scala new file mode 100644 index 0000000000..3cb8f9b5df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewRow.scala @@ -0,0 +1,180 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatAllTablesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + seqScan: /* nullability unknown */ Option[Long], + seqTupRead: /* nullability unknown */ Option[Long], + idxScan: /* nullability unknown */ Option[Long], + idxTupFetch: /* nullability unknown */ Option[Long], + nTupIns: /* nullability unknown */ Option[Long], + nTupUpd: /* nullability unknown */ Option[Long], + nTupDel: /* nullability unknown */ Option[Long], + nTupHotUpd: /* nullability unknown */ Option[Long], + nLiveTup: /* nullability unknown */ Option[Long], + nDeadTup: /* nullability unknown */ Option[Long], + nModSinceAnalyze: /* nullability unknown */ Option[Long], + nInsSinceVacuum: /* nullability unknown */ Option[Long], + lastVacuum: /* nullability unknown */ Option[TypoInstant], + lastAutovacuum: /* nullability unknown */ Option[TypoInstant], + lastAnalyze: /* nullability unknown */ Option[TypoInstant], + lastAutoanalyze: /* nullability unknown */ Option[TypoInstant], + vacuumCount: /* nullability unknown */ Option[Long], + autovacuumCount: /* nullability unknown */ Option[Long], + analyzeCount: /* nullability unknown */ Option[Long], + autoanalyzeCount: /* nullability unknown */ Option[Long] +) + +object PgStatAllTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatAllTablesViewRow] = new JdbcDecoder[PgStatAllTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatAllTablesViewRow) = + columIndex + 22 -> + PgStatAllTablesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + nLiveTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + nDeadTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + nModSinceAnalyze = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + nInsSinceVacuum = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + lastVacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + lastAutovacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + lastAnalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + lastAutoanalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + vacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 19, rs)._2, + autovacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 20, rs)._2, + analyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 21, rs)._2, + autoanalyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 22, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatAllTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nLiveTup = jsonObj.get("n_live_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nDeadTup = jsonObj.get("n_dead_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nModSinceAnalyze = jsonObj.get("n_mod_since_analyze").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nInsSinceVacuum = jsonObj.get("n_ins_since_vacuum").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastVacuum = jsonObj.get("last_vacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutovacuum = jsonObj.get("last_autovacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAnalyze = jsonObj.get("last_analyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutoanalyze = jsonObj.get("last_autoanalyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val vacuumCount = jsonObj.get("vacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autovacuumCount = jsonObj.get("autovacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val analyzeCount = jsonObj.get("analyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autoanalyzeCount = jsonObj.get("autoanalyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight && nLiveTup.isRight && nDeadTup.isRight && nModSinceAnalyze.isRight && nInsSinceVacuum.isRight && lastVacuum.isRight && lastAutovacuum.isRight && lastAnalyze.isRight && lastAutoanalyze.isRight && vacuumCount.isRight && autovacuumCount.isRight && analyzeCount.isRight && autoanalyzeCount.isRight) + Right(PgStatAllTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get, nLiveTup = nLiveTup.toOption.get, nDeadTup = nDeadTup.toOption.get, nModSinceAnalyze = nModSinceAnalyze.toOption.get, nInsSinceVacuum = nInsSinceVacuum.toOption.get, lastVacuum = lastVacuum.toOption.get, lastAutovacuum = lastAutovacuum.toOption.get, lastAnalyze = lastAnalyze.toOption.get, lastAutoanalyze = lastAutoanalyze.toOption.get, vacuumCount = vacuumCount.toOption.get, autovacuumCount = autovacuumCount.toOption.get, analyzeCount = analyzeCount.toOption.get, autoanalyzeCount = autoanalyzeCount.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatAllTablesViewRow] = new JsonEncoder[PgStatAllTablesViewRow] { + override def unsafeEncode(a: PgStatAllTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write(",") + out.write(""""n_live_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nLiveTup, indent, out) + out.write(",") + out.write(""""n_dead_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nDeadTup, indent, out) + out.write(",") + out.write(""""n_mod_since_analyze":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nModSinceAnalyze, indent, out) + out.write(",") + out.write(""""n_ins_since_vacuum":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nInsSinceVacuum, indent, out) + out.write(",") + out.write(""""last_vacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastVacuum, indent, out) + out.write(",") + out.write(""""last_autovacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutovacuum, indent, out) + out.write(",") + out.write(""""last_analyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAnalyze, indent, out) + out.write(",") + out.write(""""last_autoanalyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutoanalyze, indent, out) + out.write(",") + out.write(""""vacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.vacuumCount, indent, out) + out.write(",") + out.write(""""autovacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autovacuumCount, indent, out) + out.write(",") + out.write(""""analyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.analyzeCount, indent, out) + out.write(",") + out.write(""""autoanalyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autoanalyzeCount, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewStructure.scala new file mode 100644 index 0000000000..8695b1ef89 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_all_tables/PgStatAllTablesViewStructure.scala @@ -0,0 +1,50 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_all_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatAllTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatAllTablesViewRow, val merge: (Row, PgStatAllTablesViewRow) => Row) + extends Relation[PgStatAllTablesViewFields, PgStatAllTablesViewRow, Row] + with PgStatAllTablesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + override val nLiveTup = new OptField[Long, Row](prefix, "n_live_tup", None, None)(x => extract(x).nLiveTup, (row, value) => merge(row, extract(row).copy(nLiveTup = value))) + override val nDeadTup = new OptField[Long, Row](prefix, "n_dead_tup", None, None)(x => extract(x).nDeadTup, (row, value) => merge(row, extract(row).copy(nDeadTup = value))) + override val nModSinceAnalyze = new OptField[Long, Row](prefix, "n_mod_since_analyze", None, None)(x => extract(x).nModSinceAnalyze, (row, value) => merge(row, extract(row).copy(nModSinceAnalyze = value))) + override val nInsSinceVacuum = new OptField[Long, Row](prefix, "n_ins_since_vacuum", None, None)(x => extract(x).nInsSinceVacuum, (row, value) => merge(row, extract(row).copy(nInsSinceVacuum = value))) + override val lastVacuum = new OptField[TypoInstant, Row](prefix, "last_vacuum", Some("text"), None)(x => extract(x).lastVacuum, (row, value) => merge(row, extract(row).copy(lastVacuum = value))) + override val lastAutovacuum = new OptField[TypoInstant, Row](prefix, "last_autovacuum", Some("text"), None)(x => extract(x).lastAutovacuum, (row, value) => merge(row, extract(row).copy(lastAutovacuum = value))) + override val lastAnalyze = new OptField[TypoInstant, Row](prefix, "last_analyze", Some("text"), None)(x => extract(x).lastAnalyze, (row, value) => merge(row, extract(row).copy(lastAnalyze = value))) + override val lastAutoanalyze = new OptField[TypoInstant, Row](prefix, "last_autoanalyze", Some("text"), None)(x => extract(x).lastAutoanalyze, (row, value) => merge(row, extract(row).copy(lastAutoanalyze = value))) + override val vacuumCount = new OptField[Long, Row](prefix, "vacuum_count", None, None)(x => extract(x).vacuumCount, (row, value) => merge(row, extract(row).copy(vacuumCount = value))) + override val autovacuumCount = new OptField[Long, Row](prefix, "autovacuum_count", None, None)(x => extract(x).autovacuumCount, (row, value) => merge(row, extract(row).copy(autovacuumCount = value))) + override val analyzeCount = new OptField[Long, Row](prefix, "analyze_count", None, None)(x => extract(x).analyzeCount, (row, value) => merge(row, extract(row).copy(analyzeCount = value))) + override val autoanalyzeCount = new OptField[Long, Row](prefix, "autoanalyze_count", None, None)(x => extract(x).autoanalyzeCount, (row, value) => merge(row, extract(row).copy(autoanalyzeCount = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatAllTablesViewRow, merge: (NewRow, PgStatAllTablesViewRow) => NewRow): PgStatAllTablesViewStructure[NewRow] = + new PgStatAllTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewFields.scala new file mode 100644 index 0000000000..0e004c16e9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_archiver + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatArchiverViewFields[Row] { + val archivedCount: OptField[Long, Row] + val lastArchivedWal: OptField[String, Row] + val lastArchivedTime: OptField[TypoInstant, Row] + val failedCount: OptField[Long, Row] + val lastFailedWal: OptField[String, Row] + val lastFailedTime: OptField[TypoInstant, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatArchiverViewFields extends PgStatArchiverViewStructure[PgStatArchiverViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepo.scala new file mode 100644 index 0000000000..f283b77f2e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_archiver + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatArchiverViewRepo { + def select: SelectBuilder[PgStatArchiverViewFields, PgStatArchiverViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatArchiverViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepoImpl.scala new file mode 100644 index 0000000000..cc0b188555 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_archiver + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatArchiverViewRepoImpl extends PgStatArchiverViewRepo { + override def select: SelectBuilder[PgStatArchiverViewFields, PgStatArchiverViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_archiver", PgStatArchiverViewFields, PgStatArchiverViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatArchiverViewRow] = { + sql"""select "archived_count", "last_archived_wal", "last_archived_time"::text, "failed_count", "last_failed_wal", "last_failed_time"::text, "stats_reset"::text from pg_catalog.pg_stat_archiver""".query(PgStatArchiverViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRow.scala new file mode 100644 index 0000000000..57e99c714b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_archiver + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatArchiverViewRow( + archivedCount: /* nullability unknown */ Option[Long], + lastArchivedWal: /* nullability unknown */ Option[String], + lastArchivedTime: /* nullability unknown */ Option[TypoInstant], + failedCount: /* nullability unknown */ Option[Long], + lastFailedWal: /* nullability unknown */ Option[String], + lastFailedTime: /* nullability unknown */ Option[TypoInstant], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatArchiverViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatArchiverViewRow] = new JdbcDecoder[PgStatArchiverViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatArchiverViewRow) = + columIndex + 6 -> + PgStatArchiverViewRow( + archivedCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + lastArchivedWal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + lastArchivedTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + failedCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastFailedWal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + lastFailedTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatArchiverViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val archivedCount = jsonObj.get("archived_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastArchivedWal = jsonObj.get("last_archived_wal").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val lastArchivedTime = jsonObj.get("last_archived_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val failedCount = jsonObj.get("failed_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastFailedWal = jsonObj.get("last_failed_wal").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val lastFailedTime = jsonObj.get("last_failed_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (archivedCount.isRight && lastArchivedWal.isRight && lastArchivedTime.isRight && failedCount.isRight && lastFailedWal.isRight && lastFailedTime.isRight && statsReset.isRight) + Right(PgStatArchiverViewRow(archivedCount = archivedCount.toOption.get, lastArchivedWal = lastArchivedWal.toOption.get, lastArchivedTime = lastArchivedTime.toOption.get, failedCount = failedCount.toOption.get, lastFailedWal = lastFailedWal.toOption.get, lastFailedTime = lastFailedTime.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](archivedCount, lastArchivedWal, lastArchivedTime, failedCount, lastFailedWal, lastFailedTime, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatArchiverViewRow] = new JsonEncoder[PgStatArchiverViewRow] { + override def unsafeEncode(a: PgStatArchiverViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""archived_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.archivedCount, indent, out) + out.write(",") + out.write(""""last_archived_wal":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.lastArchivedWal, indent, out) + out.write(",") + out.write(""""last_archived_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastArchivedTime, indent, out) + out.write(",") + out.write(""""failed_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.failedCount, indent, out) + out.write(",") + out.write(""""last_failed_wal":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.lastFailedWal, indent, out) + out.write(",") + out.write(""""last_failed_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastFailedTime, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewStructure.scala new file mode 100644 index 0000000000..52ce2e8990 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_archiver/PgStatArchiverViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_archiver + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatArchiverViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatArchiverViewRow, val merge: (Row, PgStatArchiverViewRow) => Row) + extends Relation[PgStatArchiverViewFields, PgStatArchiverViewRow, Row] + with PgStatArchiverViewFields[Row] { outer => + + override val archivedCount = new OptField[Long, Row](prefix, "archived_count", None, None)(x => extract(x).archivedCount, (row, value) => merge(row, extract(row).copy(archivedCount = value))) + override val lastArchivedWal = new OptField[String, Row](prefix, "last_archived_wal", None, None)(x => extract(x).lastArchivedWal, (row, value) => merge(row, extract(row).copy(lastArchivedWal = value))) + override val lastArchivedTime = new OptField[TypoInstant, Row](prefix, "last_archived_time", Some("text"), None)(x => extract(x).lastArchivedTime, (row, value) => merge(row, extract(row).copy(lastArchivedTime = value))) + override val failedCount = new OptField[Long, Row](prefix, "failed_count", None, None)(x => extract(x).failedCount, (row, value) => merge(row, extract(row).copy(failedCount = value))) + override val lastFailedWal = new OptField[String, Row](prefix, "last_failed_wal", None, None)(x => extract(x).lastFailedWal, (row, value) => merge(row, extract(row).copy(lastFailedWal = value))) + override val lastFailedTime = new OptField[TypoInstant, Row](prefix, "last_failed_time", Some("text"), None)(x => extract(x).lastFailedTime, (row, value) => merge(row, extract(row).copy(lastFailedTime = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](archivedCount, lastArchivedWal, lastArchivedTime, failedCount, lastFailedWal, lastFailedTime, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatArchiverViewRow, merge: (NewRow, PgStatArchiverViewRow) => NewRow): PgStatArchiverViewStructure[NewRow] = + new PgStatArchiverViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewFields.scala new file mode 100644 index 0000000000..ae71f73a09 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_bgwriter + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatBgwriterViewFields[Row] { + val checkpointsTimed: OptField[Long, Row] + val checkpointsReq: OptField[Long, Row] + val checkpointWriteTime: OptField[Double, Row] + val checkpointSyncTime: OptField[Double, Row] + val buffersCheckpoint: OptField[Long, Row] + val buffersClean: OptField[Long, Row] + val maxwrittenClean: OptField[Long, Row] + val buffersBackend: OptField[Long, Row] + val buffersBackendFsync: OptField[Long, Row] + val buffersAlloc: OptField[Long, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatBgwriterViewFields extends PgStatBgwriterViewStructure[PgStatBgwriterViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepo.scala new file mode 100644 index 0000000000..19fb7d94fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_bgwriter + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatBgwriterViewRepo { + def select: SelectBuilder[PgStatBgwriterViewFields, PgStatBgwriterViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatBgwriterViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepoImpl.scala new file mode 100644 index 0000000000..3bff799aeb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_bgwriter + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatBgwriterViewRepoImpl extends PgStatBgwriterViewRepo { + override def select: SelectBuilder[PgStatBgwriterViewFields, PgStatBgwriterViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_bgwriter", PgStatBgwriterViewFields, PgStatBgwriterViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatBgwriterViewRow] = { + sql"""select "checkpoints_timed", "checkpoints_req", "checkpoint_write_time", "checkpoint_sync_time", "buffers_checkpoint", "buffers_clean", "maxwritten_clean", "buffers_backend", "buffers_backend_fsync", "buffers_alloc", "stats_reset"::text from pg_catalog.pg_stat_bgwriter""".query(PgStatBgwriterViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRow.scala new file mode 100644 index 0000000000..e91e11ba91 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewRow.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_bgwriter + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatBgwriterViewRow( + checkpointsTimed: /* nullability unknown */ Option[Long], + checkpointsReq: /* nullability unknown */ Option[Long], + checkpointWriteTime: /* nullability unknown */ Option[Double], + checkpointSyncTime: /* nullability unknown */ Option[Double], + buffersCheckpoint: /* nullability unknown */ Option[Long], + buffersClean: /* nullability unknown */ Option[Long], + maxwrittenClean: /* nullability unknown */ Option[Long], + buffersBackend: /* nullability unknown */ Option[Long], + buffersBackendFsync: /* nullability unknown */ Option[Long], + buffersAlloc: /* nullability unknown */ Option[Long], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatBgwriterViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatBgwriterViewRow] = new JdbcDecoder[PgStatBgwriterViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatBgwriterViewRow) = + columIndex + 10 -> + PgStatBgwriterViewRow( + checkpointsTimed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + checkpointsReq = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + checkpointWriteTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 2, rs)._2, + checkpointSyncTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 3, rs)._2, + buffersCheckpoint = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + buffersClean = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + maxwrittenClean = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + buffersBackend = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + buffersBackendFsync = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + buffersAlloc = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatBgwriterViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val checkpointsTimed = jsonObj.get("checkpoints_timed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val checkpointsReq = jsonObj.get("checkpoints_req").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val checkpointWriteTime = jsonObj.get("checkpoint_write_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val checkpointSyncTime = jsonObj.get("checkpoint_sync_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val buffersCheckpoint = jsonObj.get("buffers_checkpoint").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val buffersClean = jsonObj.get("buffers_clean").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val maxwrittenClean = jsonObj.get("maxwritten_clean").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val buffersBackend = jsonObj.get("buffers_backend").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val buffersBackendFsync = jsonObj.get("buffers_backend_fsync").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val buffersAlloc = jsonObj.get("buffers_alloc").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (checkpointsTimed.isRight && checkpointsReq.isRight && checkpointWriteTime.isRight && checkpointSyncTime.isRight && buffersCheckpoint.isRight && buffersClean.isRight && maxwrittenClean.isRight && buffersBackend.isRight && buffersBackendFsync.isRight && buffersAlloc.isRight && statsReset.isRight) + Right(PgStatBgwriterViewRow(checkpointsTimed = checkpointsTimed.toOption.get, checkpointsReq = checkpointsReq.toOption.get, checkpointWriteTime = checkpointWriteTime.toOption.get, checkpointSyncTime = checkpointSyncTime.toOption.get, buffersCheckpoint = buffersCheckpoint.toOption.get, buffersClean = buffersClean.toOption.get, maxwrittenClean = maxwrittenClean.toOption.get, buffersBackend = buffersBackend.toOption.get, buffersBackendFsync = buffersBackendFsync.toOption.get, buffersAlloc = buffersAlloc.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](checkpointsTimed, checkpointsReq, checkpointWriteTime, checkpointSyncTime, buffersCheckpoint, buffersClean, maxwrittenClean, buffersBackend, buffersBackendFsync, buffersAlloc, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatBgwriterViewRow] = new JsonEncoder[PgStatBgwriterViewRow] { + override def unsafeEncode(a: PgStatBgwriterViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""checkpoints_timed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.checkpointsTimed, indent, out) + out.write(",") + out.write(""""checkpoints_req":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.checkpointsReq, indent, out) + out.write(",") + out.write(""""checkpoint_write_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.checkpointWriteTime, indent, out) + out.write(",") + out.write(""""checkpoint_sync_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.checkpointSyncTime, indent, out) + out.write(",") + out.write(""""buffers_checkpoint":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.buffersCheckpoint, indent, out) + out.write(",") + out.write(""""buffers_clean":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.buffersClean, indent, out) + out.write(",") + out.write(""""maxwritten_clean":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.maxwrittenClean, indent, out) + out.write(",") + out.write(""""buffers_backend":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.buffersBackend, indent, out) + out.write(",") + out.write(""""buffers_backend_fsync":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.buffersBackendFsync, indent, out) + out.write(",") + out.write(""""buffers_alloc":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.buffersAlloc, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewStructure.scala new file mode 100644 index 0000000000..a5c0ed1177 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_bgwriter/PgStatBgwriterViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_bgwriter + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatBgwriterViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatBgwriterViewRow, val merge: (Row, PgStatBgwriterViewRow) => Row) + extends Relation[PgStatBgwriterViewFields, PgStatBgwriterViewRow, Row] + with PgStatBgwriterViewFields[Row] { outer => + + override val checkpointsTimed = new OptField[Long, Row](prefix, "checkpoints_timed", None, None)(x => extract(x).checkpointsTimed, (row, value) => merge(row, extract(row).copy(checkpointsTimed = value))) + override val checkpointsReq = new OptField[Long, Row](prefix, "checkpoints_req", None, None)(x => extract(x).checkpointsReq, (row, value) => merge(row, extract(row).copy(checkpointsReq = value))) + override val checkpointWriteTime = new OptField[Double, Row](prefix, "checkpoint_write_time", None, None)(x => extract(x).checkpointWriteTime, (row, value) => merge(row, extract(row).copy(checkpointWriteTime = value))) + override val checkpointSyncTime = new OptField[Double, Row](prefix, "checkpoint_sync_time", None, None)(x => extract(x).checkpointSyncTime, (row, value) => merge(row, extract(row).copy(checkpointSyncTime = value))) + override val buffersCheckpoint = new OptField[Long, Row](prefix, "buffers_checkpoint", None, None)(x => extract(x).buffersCheckpoint, (row, value) => merge(row, extract(row).copy(buffersCheckpoint = value))) + override val buffersClean = new OptField[Long, Row](prefix, "buffers_clean", None, None)(x => extract(x).buffersClean, (row, value) => merge(row, extract(row).copy(buffersClean = value))) + override val maxwrittenClean = new OptField[Long, Row](prefix, "maxwritten_clean", None, None)(x => extract(x).maxwrittenClean, (row, value) => merge(row, extract(row).copy(maxwrittenClean = value))) + override val buffersBackend = new OptField[Long, Row](prefix, "buffers_backend", None, None)(x => extract(x).buffersBackend, (row, value) => merge(row, extract(row).copy(buffersBackend = value))) + override val buffersBackendFsync = new OptField[Long, Row](prefix, "buffers_backend_fsync", None, None)(x => extract(x).buffersBackendFsync, (row, value) => merge(row, extract(row).copy(buffersBackendFsync = value))) + override val buffersAlloc = new OptField[Long, Row](prefix, "buffers_alloc", None, None)(x => extract(x).buffersAlloc, (row, value) => merge(row, extract(row).copy(buffersAlloc = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](checkpointsTimed, checkpointsReq, checkpointWriteTime, checkpointSyncTime, buffersCheckpoint, buffersClean, maxwrittenClean, buffersBackend, buffersBackendFsync, buffersAlloc, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatBgwriterViewRow, merge: (NewRow, PgStatBgwriterViewRow) => NewRow): PgStatBgwriterViewStructure[NewRow] = + new PgStatBgwriterViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewFields.scala new file mode 100644 index 0000000000..37966a20f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewFields.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatDatabaseViewFields[Row] { + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val numbackends: OptField[Int, Row] + val xactCommit: OptField[Long, Row] + val xactRollback: OptField[Long, Row] + val blksRead: OptField[Long, Row] + val blksHit: OptField[Long, Row] + val tupReturned: OptField[Long, Row] + val tupFetched: OptField[Long, Row] + val tupInserted: OptField[Long, Row] + val tupUpdated: OptField[Long, Row] + val tupDeleted: OptField[Long, Row] + val conflicts: OptField[Long, Row] + val tempFiles: OptField[Long, Row] + val tempBytes: OptField[Long, Row] + val deadlocks: OptField[Long, Row] + val checksumFailures: OptField[Long, Row] + val checksumLastFailure: OptField[TypoInstant, Row] + val blkReadTime: OptField[Double, Row] + val blkWriteTime: OptField[Double, Row] + val sessionTime: OptField[Double, Row] + val activeTime: OptField[Double, Row] + val idleInTransactionTime: OptField[Double, Row] + val sessions: OptField[Long, Row] + val sessionsAbandoned: OptField[Long, Row] + val sessionsFatal: OptField[Long, Row] + val sessionsKilled: OptField[Long, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatDatabaseViewFields extends PgStatDatabaseViewStructure[PgStatDatabaseViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepo.scala new file mode 100644 index 0000000000..88dac79d11 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatDatabaseViewRepo { + def select: SelectBuilder[PgStatDatabaseViewFields, PgStatDatabaseViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatDatabaseViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepoImpl.scala new file mode 100644 index 0000000000..ae31027fd2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatDatabaseViewRepoImpl extends PgStatDatabaseViewRepo { + override def select: SelectBuilder[PgStatDatabaseViewFields, PgStatDatabaseViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_database", PgStatDatabaseViewFields, PgStatDatabaseViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatDatabaseViewRow] = { + sql"""select "datid", "datname", "numbackends", "xact_commit", "xact_rollback", "blks_read", "blks_hit", "tup_returned", "tup_fetched", "tup_inserted", "tup_updated", "tup_deleted", "conflicts", "temp_files", "temp_bytes", "deadlocks", "checksum_failures", "checksum_last_failure"::text, "blk_read_time", "blk_write_time", "session_time", "active_time", "idle_in_transaction_time", "sessions", "sessions_abandoned", "sessions_fatal", "sessions_killed", "stats_reset"::text from pg_catalog.pg_stat_database""".query(PgStatDatabaseViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRow.scala new file mode 100644 index 0000000000..d53bf1c6b5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewRow.scala @@ -0,0 +1,206 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatDatabaseViewRow( + datid: /* nullability unknown */ Option[/* oid */ Long], + datname: /* nullability unknown */ Option[String], + numbackends: /* nullability unknown */ Option[Int], + xactCommit: /* nullability unknown */ Option[Long], + xactRollback: /* nullability unknown */ Option[Long], + blksRead: /* nullability unknown */ Option[Long], + blksHit: /* nullability unknown */ Option[Long], + tupReturned: /* nullability unknown */ Option[Long], + tupFetched: /* nullability unknown */ Option[Long], + tupInserted: /* nullability unknown */ Option[Long], + tupUpdated: /* nullability unknown */ Option[Long], + tupDeleted: /* nullability unknown */ Option[Long], + conflicts: /* nullability unknown */ Option[Long], + tempFiles: /* nullability unknown */ Option[Long], + tempBytes: /* nullability unknown */ Option[Long], + deadlocks: /* nullability unknown */ Option[Long], + checksumFailures: /* nullability unknown */ Option[Long], + checksumLastFailure: /* nullability unknown */ Option[TypoInstant], + blkReadTime: /* nullability unknown */ Option[Double], + blkWriteTime: /* nullability unknown */ Option[Double], + sessionTime: /* nullability unknown */ Option[Double], + activeTime: /* nullability unknown */ Option[Double], + idleInTransactionTime: /* nullability unknown */ Option[Double], + sessions: /* nullability unknown */ Option[Long], + sessionsAbandoned: /* nullability unknown */ Option[Long], + sessionsFatal: /* nullability unknown */ Option[Long], + sessionsKilled: /* nullability unknown */ Option[Long], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatDatabaseViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatDatabaseViewRow] = new JdbcDecoder[PgStatDatabaseViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatDatabaseViewRow) = + columIndex + 27 -> + PgStatDatabaseViewRow( + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + numbackends = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 2, rs)._2, + xactCommit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + xactRollback = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + blksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + blksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + tupReturned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + tupFetched = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + tupInserted = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + tupUpdated = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + tupDeleted = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + conflicts = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + tempFiles = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + tempBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + deadlocks = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 15, rs)._2, + checksumFailures = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 16, rs)._2, + checksumLastFailure = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + blkReadTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 18, rs)._2, + blkWriteTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 19, rs)._2, + sessionTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 20, rs)._2, + activeTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 21, rs)._2, + idleInTransactionTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 22, rs)._2, + sessions = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 23, rs)._2, + sessionsAbandoned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 24, rs)._2, + sessionsFatal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 25, rs)._2, + sessionsKilled = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 26, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 27, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatDatabaseViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numbackends = jsonObj.get("numbackends").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val xactCommit = jsonObj.get("xact_commit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val xactRollback = jsonObj.get("xact_rollback").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksRead = jsonObj.get("blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksHit = jsonObj.get("blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tupReturned = jsonObj.get("tup_returned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tupFetched = jsonObj.get("tup_fetched").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tupInserted = jsonObj.get("tup_inserted").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tupUpdated = jsonObj.get("tup_updated").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tupDeleted = jsonObj.get("tup_deleted").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val conflicts = jsonObj.get("conflicts").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tempFiles = jsonObj.get("temp_files").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tempBytes = jsonObj.get("temp_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val deadlocks = jsonObj.get("deadlocks").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val checksumFailures = jsonObj.get("checksum_failures").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val checksumLastFailure = jsonObj.get("checksum_last_failure").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val blkReadTime = jsonObj.get("blk_read_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val blkWriteTime = jsonObj.get("blk_write_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val sessionTime = jsonObj.get("session_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val activeTime = jsonObj.get("active_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val idleInTransactionTime = jsonObj.get("idle_in_transaction_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val sessions = jsonObj.get("sessions").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val sessionsAbandoned = jsonObj.get("sessions_abandoned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val sessionsFatal = jsonObj.get("sessions_fatal").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val sessionsKilled = jsonObj.get("sessions_killed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (datid.isRight && datname.isRight && numbackends.isRight && xactCommit.isRight && xactRollback.isRight && blksRead.isRight && blksHit.isRight && tupReturned.isRight && tupFetched.isRight && tupInserted.isRight && tupUpdated.isRight && tupDeleted.isRight && conflicts.isRight && tempFiles.isRight && tempBytes.isRight && deadlocks.isRight && checksumFailures.isRight && checksumLastFailure.isRight && blkReadTime.isRight && blkWriteTime.isRight && sessionTime.isRight && activeTime.isRight && idleInTransactionTime.isRight && sessions.isRight && sessionsAbandoned.isRight && sessionsFatal.isRight && sessionsKilled.isRight && statsReset.isRight) + Right(PgStatDatabaseViewRow(datid = datid.toOption.get, datname = datname.toOption.get, numbackends = numbackends.toOption.get, xactCommit = xactCommit.toOption.get, xactRollback = xactRollback.toOption.get, blksRead = blksRead.toOption.get, blksHit = blksHit.toOption.get, tupReturned = tupReturned.toOption.get, tupFetched = tupFetched.toOption.get, tupInserted = tupInserted.toOption.get, tupUpdated = tupUpdated.toOption.get, tupDeleted = tupDeleted.toOption.get, conflicts = conflicts.toOption.get, tempFiles = tempFiles.toOption.get, tempBytes = tempBytes.toOption.get, deadlocks = deadlocks.toOption.get, checksumFailures = checksumFailures.toOption.get, checksumLastFailure = checksumLastFailure.toOption.get, blkReadTime = blkReadTime.toOption.get, blkWriteTime = blkWriteTime.toOption.get, sessionTime = sessionTime.toOption.get, activeTime = activeTime.toOption.get, idleInTransactionTime = idleInTransactionTime.toOption.get, sessions = sessions.toOption.get, sessionsAbandoned = sessionsAbandoned.toOption.get, sessionsFatal = sessionsFatal.toOption.get, sessionsKilled = sessionsKilled.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](datid, datname, numbackends, xactCommit, xactRollback, blksRead, blksHit, tupReturned, tupFetched, tupInserted, tupUpdated, tupDeleted, conflicts, tempFiles, tempBytes, deadlocks, checksumFailures, checksumLastFailure, blkReadTime, blkWriteTime, sessionTime, activeTime, idleInTransactionTime, sessions, sessionsAbandoned, sessionsFatal, sessionsKilled, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatDatabaseViewRow] = new JsonEncoder[PgStatDatabaseViewRow] { + override def unsafeEncode(a: PgStatDatabaseViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""numbackends":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numbackends, indent, out) + out.write(",") + out.write(""""xact_commit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.xactCommit, indent, out) + out.write(",") + out.write(""""xact_rollback":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.xactRollback, indent, out) + out.write(",") + out.write(""""blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksRead, indent, out) + out.write(",") + out.write(""""blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksHit, indent, out) + out.write(",") + out.write(""""tup_returned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tupReturned, indent, out) + out.write(",") + out.write(""""tup_fetched":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tupFetched, indent, out) + out.write(",") + out.write(""""tup_inserted":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tupInserted, indent, out) + out.write(",") + out.write(""""tup_updated":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tupUpdated, indent, out) + out.write(",") + out.write(""""tup_deleted":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tupDeleted, indent, out) + out.write(",") + out.write(""""conflicts":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflicts, indent, out) + out.write(",") + out.write(""""temp_files":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tempFiles, indent, out) + out.write(",") + out.write(""""temp_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tempBytes, indent, out) + out.write(",") + out.write(""""deadlocks":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.deadlocks, indent, out) + out.write(",") + out.write(""""checksum_failures":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.checksumFailures, indent, out) + out.write(",") + out.write(""""checksum_last_failure":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.checksumLastFailure, indent, out) + out.write(",") + out.write(""""blk_read_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.blkReadTime, indent, out) + out.write(",") + out.write(""""blk_write_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.blkWriteTime, indent, out) + out.write(",") + out.write(""""session_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.sessionTime, indent, out) + out.write(",") + out.write(""""active_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.activeTime, indent, out) + out.write(",") + out.write(""""idle_in_transaction_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.idleInTransactionTime, indent, out) + out.write(",") + out.write(""""sessions":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sessions, indent, out) + out.write(",") + out.write(""""sessions_abandoned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sessionsAbandoned, indent, out) + out.write(",") + out.write(""""sessions_fatal":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sessionsFatal, indent, out) + out.write(",") + out.write(""""sessions_killed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sessionsKilled, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewStructure.scala new file mode 100644 index 0000000000..c7b2640999 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database/PgStatDatabaseViewStructure.scala @@ -0,0 +1,53 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatDatabaseViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatDatabaseViewRow, val merge: (Row, PgStatDatabaseViewRow) => Row) + extends Relation[PgStatDatabaseViewFields, PgStatDatabaseViewRow, Row] + with PgStatDatabaseViewFields[Row] { outer => + + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val numbackends = new OptField[Int, Row](prefix, "numbackends", None, None)(x => extract(x).numbackends, (row, value) => merge(row, extract(row).copy(numbackends = value))) + override val xactCommit = new OptField[Long, Row](prefix, "xact_commit", None, None)(x => extract(x).xactCommit, (row, value) => merge(row, extract(row).copy(xactCommit = value))) + override val xactRollback = new OptField[Long, Row](prefix, "xact_rollback", None, None)(x => extract(x).xactRollback, (row, value) => merge(row, extract(row).copy(xactRollback = value))) + override val blksRead = new OptField[Long, Row](prefix, "blks_read", None, None)(x => extract(x).blksRead, (row, value) => merge(row, extract(row).copy(blksRead = value))) + override val blksHit = new OptField[Long, Row](prefix, "blks_hit", None, None)(x => extract(x).blksHit, (row, value) => merge(row, extract(row).copy(blksHit = value))) + override val tupReturned = new OptField[Long, Row](prefix, "tup_returned", None, None)(x => extract(x).tupReturned, (row, value) => merge(row, extract(row).copy(tupReturned = value))) + override val tupFetched = new OptField[Long, Row](prefix, "tup_fetched", None, None)(x => extract(x).tupFetched, (row, value) => merge(row, extract(row).copy(tupFetched = value))) + override val tupInserted = new OptField[Long, Row](prefix, "tup_inserted", None, None)(x => extract(x).tupInserted, (row, value) => merge(row, extract(row).copy(tupInserted = value))) + override val tupUpdated = new OptField[Long, Row](prefix, "tup_updated", None, None)(x => extract(x).tupUpdated, (row, value) => merge(row, extract(row).copy(tupUpdated = value))) + override val tupDeleted = new OptField[Long, Row](prefix, "tup_deleted", None, None)(x => extract(x).tupDeleted, (row, value) => merge(row, extract(row).copy(tupDeleted = value))) + override val conflicts = new OptField[Long, Row](prefix, "conflicts", None, None)(x => extract(x).conflicts, (row, value) => merge(row, extract(row).copy(conflicts = value))) + override val tempFiles = new OptField[Long, Row](prefix, "temp_files", None, None)(x => extract(x).tempFiles, (row, value) => merge(row, extract(row).copy(tempFiles = value))) + override val tempBytes = new OptField[Long, Row](prefix, "temp_bytes", None, None)(x => extract(x).tempBytes, (row, value) => merge(row, extract(row).copy(tempBytes = value))) + override val deadlocks = new OptField[Long, Row](prefix, "deadlocks", None, None)(x => extract(x).deadlocks, (row, value) => merge(row, extract(row).copy(deadlocks = value))) + override val checksumFailures = new OptField[Long, Row](prefix, "checksum_failures", None, None)(x => extract(x).checksumFailures, (row, value) => merge(row, extract(row).copy(checksumFailures = value))) + override val checksumLastFailure = new OptField[TypoInstant, Row](prefix, "checksum_last_failure", Some("text"), None)(x => extract(x).checksumLastFailure, (row, value) => merge(row, extract(row).copy(checksumLastFailure = value))) + override val blkReadTime = new OptField[Double, Row](prefix, "blk_read_time", None, None)(x => extract(x).blkReadTime, (row, value) => merge(row, extract(row).copy(blkReadTime = value))) + override val blkWriteTime = new OptField[Double, Row](prefix, "blk_write_time", None, None)(x => extract(x).blkWriteTime, (row, value) => merge(row, extract(row).copy(blkWriteTime = value))) + override val sessionTime = new OptField[Double, Row](prefix, "session_time", None, None)(x => extract(x).sessionTime, (row, value) => merge(row, extract(row).copy(sessionTime = value))) + override val activeTime = new OptField[Double, Row](prefix, "active_time", None, None)(x => extract(x).activeTime, (row, value) => merge(row, extract(row).copy(activeTime = value))) + override val idleInTransactionTime = new OptField[Double, Row](prefix, "idle_in_transaction_time", None, None)(x => extract(x).idleInTransactionTime, (row, value) => merge(row, extract(row).copy(idleInTransactionTime = value))) + override val sessions = new OptField[Long, Row](prefix, "sessions", None, None)(x => extract(x).sessions, (row, value) => merge(row, extract(row).copy(sessions = value))) + override val sessionsAbandoned = new OptField[Long, Row](prefix, "sessions_abandoned", None, None)(x => extract(x).sessionsAbandoned, (row, value) => merge(row, extract(row).copy(sessionsAbandoned = value))) + override val sessionsFatal = new OptField[Long, Row](prefix, "sessions_fatal", None, None)(x => extract(x).sessionsFatal, (row, value) => merge(row, extract(row).copy(sessionsFatal = value))) + override val sessionsKilled = new OptField[Long, Row](prefix, "sessions_killed", None, None)(x => extract(x).sessionsKilled, (row, value) => merge(row, extract(row).copy(sessionsKilled = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](datid, datname, numbackends, xactCommit, xactRollback, blksRead, blksHit, tupReturned, tupFetched, tupInserted, tupUpdated, tupDeleted, conflicts, tempFiles, tempBytes, deadlocks, checksumFailures, checksumLastFailure, blkReadTime, blkWriteTime, sessionTime, activeTime, idleInTransactionTime, sessions, sessionsAbandoned, sessionsFatal, sessionsKilled, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatDatabaseViewRow, merge: (NewRow, PgStatDatabaseViewRow) => NewRow): PgStatDatabaseViewStructure[NewRow] = + new PgStatDatabaseViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewFields.scala new file mode 100644 index 0000000000..c19028e1c0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database_conflicts + +import adventureworks.pg_catalog.pg_database.PgDatabaseId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatDatabaseConflictsViewFields[Row] { + val datid: Field[PgDatabaseId, Row] + val datname: Field[String, Row] + val conflTablespace: OptField[Long, Row] + val conflLock: OptField[Long, Row] + val conflSnapshot: OptField[Long, Row] + val conflBufferpin: OptField[Long, Row] + val conflDeadlock: OptField[Long, Row] +} +object PgStatDatabaseConflictsViewFields extends PgStatDatabaseConflictsViewStructure[PgStatDatabaseConflictsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepo.scala new file mode 100644 index 0000000000..188b05c863 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database_conflicts + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatDatabaseConflictsViewRepo { + def select: SelectBuilder[PgStatDatabaseConflictsViewFields, PgStatDatabaseConflictsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatDatabaseConflictsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepoImpl.scala new file mode 100644 index 0000000000..64e44daf96 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database_conflicts + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatDatabaseConflictsViewRepoImpl extends PgStatDatabaseConflictsViewRepo { + override def select: SelectBuilder[PgStatDatabaseConflictsViewFields, PgStatDatabaseConflictsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_database_conflicts", PgStatDatabaseConflictsViewFields, PgStatDatabaseConflictsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatDatabaseConflictsViewRow] = { + sql"""select "datid", "datname", "confl_tablespace", "confl_lock", "confl_snapshot", "confl_bufferpin", "confl_deadlock" from pg_catalog.pg_stat_database_conflicts""".query(PgStatDatabaseConflictsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRow.scala new file mode 100644 index 0000000000..6893d0c8c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database_conflicts + +import adventureworks.pg_catalog.pg_database.PgDatabaseId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatDatabaseConflictsViewRow( + /** Points to [[pg_database.PgDatabaseRow.oid]] */ + datid: PgDatabaseId, + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: String, + conflTablespace: /* nullability unknown */ Option[Long], + conflLock: /* nullability unknown */ Option[Long], + conflSnapshot: /* nullability unknown */ Option[Long], + conflBufferpin: /* nullability unknown */ Option[Long], + conflDeadlock: /* nullability unknown */ Option[Long] +) + +object PgStatDatabaseConflictsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatDatabaseConflictsViewRow] = new JdbcDecoder[PgStatDatabaseConflictsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatDatabaseConflictsViewRow) = + columIndex + 6 -> + PgStatDatabaseConflictsViewRow( + datid = PgDatabaseId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + datname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + conflTablespace = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + conflLock = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + conflSnapshot = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + conflBufferpin = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + conflDeadlock = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatDatabaseConflictsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val datid = jsonObj.get("datid").toRight("Missing field 'datid'").flatMap(_.as(PgDatabaseId.jsonDecoder)) + val datname = jsonObj.get("datname").toRight("Missing field 'datname'").flatMap(_.as(JsonDecoder.string)) + val conflTablespace = jsonObj.get("confl_tablespace").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val conflLock = jsonObj.get("confl_lock").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val conflSnapshot = jsonObj.get("confl_snapshot").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val conflBufferpin = jsonObj.get("confl_bufferpin").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val conflDeadlock = jsonObj.get("confl_deadlock").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (datid.isRight && datname.isRight && conflTablespace.isRight && conflLock.isRight && conflSnapshot.isRight && conflBufferpin.isRight && conflDeadlock.isRight) + Right(PgStatDatabaseConflictsViewRow(datid = datid.toOption.get, datname = datname.toOption.get, conflTablespace = conflTablespace.toOption.get, conflLock = conflLock.toOption.get, conflSnapshot = conflSnapshot.toOption.get, conflBufferpin = conflBufferpin.toOption.get, conflDeadlock = conflDeadlock.toOption.get)) + else Left(List[Either[String, Any]](datid, datname, conflTablespace, conflLock, conflSnapshot, conflBufferpin, conflDeadlock).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatDatabaseConflictsViewRow] = new JsonEncoder[PgStatDatabaseConflictsViewRow] { + override def unsafeEncode(a: PgStatDatabaseConflictsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""datid":""") + PgDatabaseId.jsonEncoder.unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.string.unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""confl_tablespace":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflTablespace, indent, out) + out.write(",") + out.write(""""confl_lock":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflLock, indent, out) + out.write(",") + out.write(""""confl_snapshot":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflSnapshot, indent, out) + out.write(",") + out.write(""""confl_bufferpin":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflBufferpin, indent, out) + out.write(",") + out.write(""""confl_deadlock":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.conflDeadlock, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewStructure.scala new file mode 100644 index 0000000000..d1b0d68b27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_database_conflicts/PgStatDatabaseConflictsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_database_conflicts + +import adventureworks.pg_catalog.pg_database.PgDatabaseId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatDatabaseConflictsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatDatabaseConflictsViewRow, val merge: (Row, PgStatDatabaseConflictsViewRow) => Row) + extends Relation[PgStatDatabaseConflictsViewFields, PgStatDatabaseConflictsViewRow, Row] + with PgStatDatabaseConflictsViewFields[Row] { outer => + + override val datid = new Field[PgDatabaseId, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new Field[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val conflTablespace = new OptField[Long, Row](prefix, "confl_tablespace", None, None)(x => extract(x).conflTablespace, (row, value) => merge(row, extract(row).copy(conflTablespace = value))) + override val conflLock = new OptField[Long, Row](prefix, "confl_lock", None, None)(x => extract(x).conflLock, (row, value) => merge(row, extract(row).copy(conflLock = value))) + override val conflSnapshot = new OptField[Long, Row](prefix, "confl_snapshot", None, None)(x => extract(x).conflSnapshot, (row, value) => merge(row, extract(row).copy(conflSnapshot = value))) + override val conflBufferpin = new OptField[Long, Row](prefix, "confl_bufferpin", None, None)(x => extract(x).conflBufferpin, (row, value) => merge(row, extract(row).copy(conflBufferpin = value))) + override val conflDeadlock = new OptField[Long, Row](prefix, "confl_deadlock", None, None)(x => extract(x).conflDeadlock, (row, value) => merge(row, extract(row).copy(conflDeadlock = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](datid, datname, conflTablespace, conflLock, conflSnapshot, conflBufferpin, conflDeadlock) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatDatabaseConflictsViewRow, merge: (NewRow, PgStatDatabaseConflictsViewRow) => NewRow): PgStatDatabaseConflictsViewStructure[NewRow] = + new PgStatDatabaseConflictsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewFields.scala new file mode 100644 index 0000000000..5af5629fb4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_gssapi + +import typo.dsl.SqlExpr.OptField + +trait PgStatGssapiViewFields[Row] { + val pid: OptField[Int, Row] + val gssAuthenticated: OptField[Boolean, Row] + val principal: OptField[String, Row] + val encrypted: OptField[Boolean, Row] +} +object PgStatGssapiViewFields extends PgStatGssapiViewStructure[PgStatGssapiViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepo.scala new file mode 100644 index 0000000000..3ab5da8bd5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_gssapi + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatGssapiViewRepo { + def select: SelectBuilder[PgStatGssapiViewFields, PgStatGssapiViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatGssapiViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepoImpl.scala new file mode 100644 index 0000000000..9075b4f19b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_gssapi + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatGssapiViewRepoImpl extends PgStatGssapiViewRepo { + override def select: SelectBuilder[PgStatGssapiViewFields, PgStatGssapiViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_gssapi", PgStatGssapiViewFields, PgStatGssapiViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatGssapiViewRow] = { + sql"""select "pid", "gss_authenticated", "principal", "encrypted" from pg_catalog.pg_stat_gssapi""".query(PgStatGssapiViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRow.scala new file mode 100644 index 0000000000..58f01e5390 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_gssapi + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatGssapiViewRow( + pid: /* nullability unknown */ Option[Int], + gssAuthenticated: /* nullability unknown */ Option[Boolean], + principal: /* nullability unknown */ Option[String], + encrypted: /* nullability unknown */ Option[Boolean] +) + +object PgStatGssapiViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatGssapiViewRow] = new JdbcDecoder[PgStatGssapiViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatGssapiViewRow) = + columIndex + 3 -> + PgStatGssapiViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + gssAuthenticated = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 1, rs)._2, + principal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + encrypted = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatGssapiViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val gssAuthenticated = jsonObj.get("gss_authenticated").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val principal = jsonObj.get("principal").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val encrypted = jsonObj.get("encrypted").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + if (pid.isRight && gssAuthenticated.isRight && principal.isRight && encrypted.isRight) + Right(PgStatGssapiViewRow(pid = pid.toOption.get, gssAuthenticated = gssAuthenticated.toOption.get, principal = principal.toOption.get, encrypted = encrypted.toOption.get)) + else Left(List[Either[String, Any]](pid, gssAuthenticated, principal, encrypted).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatGssapiViewRow] = new JsonEncoder[PgStatGssapiViewRow] { + override def unsafeEncode(a: PgStatGssapiViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""gss_authenticated":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.gssAuthenticated, indent, out) + out.write(",") + out.write(""""principal":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.principal, indent, out) + out.write(",") + out.write(""""encrypted":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.encrypted, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewStructure.scala new file mode 100644 index 0000000000..6047e9fedf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_gssapi/PgStatGssapiViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_gssapi + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatGssapiViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatGssapiViewRow, val merge: (Row, PgStatGssapiViewRow) => Row) + extends Relation[PgStatGssapiViewFields, PgStatGssapiViewRow, Row] + with PgStatGssapiViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val gssAuthenticated = new OptField[Boolean, Row](prefix, "gss_authenticated", None, None)(x => extract(x).gssAuthenticated, (row, value) => merge(row, extract(row).copy(gssAuthenticated = value))) + override val principal = new OptField[String, Row](prefix, "principal", None, None)(x => extract(x).principal, (row, value) => merge(row, extract(row).copy(principal = value))) + override val encrypted = new OptField[Boolean, Row](prefix, "encrypted", None, None)(x => extract(x).encrypted, (row, value) => merge(row, extract(row).copy(encrypted = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, gssAuthenticated, principal, encrypted) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatGssapiViewRow, merge: (NewRow, PgStatGssapiViewRow) => NewRow): PgStatGssapiViewStructure[NewRow] = + new PgStatGssapiViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewFields.scala new file mode 100644 index 0000000000..ef8c794725 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_analyze + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressAnalyzeViewFields[Row] { + val pid: OptField[Int, Row] + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val relid: OptField[/* oid */ Long, Row] + val phase: OptField[String, Row] + val sampleBlksTotal: OptField[Long, Row] + val sampleBlksScanned: OptField[Long, Row] + val extStatsTotal: OptField[Long, Row] + val extStatsComputed: OptField[Long, Row] + val childTablesTotal: OptField[Long, Row] + val childTablesDone: OptField[Long, Row] + val currentChildTableRelid: OptField[/* oid */ Long, Row] +} +object PgStatProgressAnalyzeViewFields extends PgStatProgressAnalyzeViewStructure[PgStatProgressAnalyzeViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepo.scala new file mode 100644 index 0000000000..1443aaa83f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_analyze + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressAnalyzeViewRepo { + def select: SelectBuilder[PgStatProgressAnalyzeViewFields, PgStatProgressAnalyzeViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressAnalyzeViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepoImpl.scala new file mode 100644 index 0000000000..4278702773 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_analyze + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressAnalyzeViewRepoImpl extends PgStatProgressAnalyzeViewRepo { + override def select: SelectBuilder[PgStatProgressAnalyzeViewFields, PgStatProgressAnalyzeViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_analyze", PgStatProgressAnalyzeViewFields, PgStatProgressAnalyzeViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressAnalyzeViewRow] = { + sql"""select "pid", "datid", "datname", "relid", "phase", "sample_blks_total", "sample_blks_scanned", "ext_stats_total", "ext_stats_computed", "child_tables_total", "child_tables_done", "current_child_table_relid" from pg_catalog.pg_stat_progress_analyze""".query(PgStatProgressAnalyzeViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRow.scala new file mode 100644 index 0000000000..d100aa3ff7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewRow.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_analyze + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressAnalyzeViewRow( + pid: /* nullability unknown */ Option[Int], + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + relid: /* nullability unknown */ Option[/* oid */ Long], + phase: /* nullability unknown */ Option[String], + sampleBlksTotal: /* nullability unknown */ Option[Long], + sampleBlksScanned: /* nullability unknown */ Option[Long], + extStatsTotal: /* nullability unknown */ Option[Long], + extStatsComputed: /* nullability unknown */ Option[Long], + childTablesTotal: /* nullability unknown */ Option[Long], + childTablesDone: /* nullability unknown */ Option[Long], + currentChildTableRelid: /* nullability unknown */ Option[/* oid */ Long] +) + +object PgStatProgressAnalyzeViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressAnalyzeViewRow] = new JdbcDecoder[PgStatProgressAnalyzeViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressAnalyzeViewRow) = + columIndex + 11 -> + PgStatProgressAnalyzeViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + phase = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + sampleBlksTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + sampleBlksScanned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + extStatsTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + extStatsComputed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + childTablesTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + childTablesDone = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + currentChildTableRelid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressAnalyzeViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val phase = jsonObj.get("phase").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sampleBlksTotal = jsonObj.get("sample_blks_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val sampleBlksScanned = jsonObj.get("sample_blks_scanned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val extStatsTotal = jsonObj.get("ext_stats_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val extStatsComputed = jsonObj.get("ext_stats_computed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val childTablesTotal = jsonObj.get("child_tables_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val childTablesDone = jsonObj.get("child_tables_done").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val currentChildTableRelid = jsonObj.get("current_child_table_relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && datid.isRight && datname.isRight && relid.isRight && phase.isRight && sampleBlksTotal.isRight && sampleBlksScanned.isRight && extStatsTotal.isRight && extStatsComputed.isRight && childTablesTotal.isRight && childTablesDone.isRight && currentChildTableRelid.isRight) + Right(PgStatProgressAnalyzeViewRow(pid = pid.toOption.get, datid = datid.toOption.get, datname = datname.toOption.get, relid = relid.toOption.get, phase = phase.toOption.get, sampleBlksTotal = sampleBlksTotal.toOption.get, sampleBlksScanned = sampleBlksScanned.toOption.get, extStatsTotal = extStatsTotal.toOption.get, extStatsComputed = extStatsComputed.toOption.get, childTablesTotal = childTablesTotal.toOption.get, childTablesDone = childTablesDone.toOption.get, currentChildTableRelid = currentChildTableRelid.toOption.get)) + else Left(List[Either[String, Any]](pid, datid, datname, relid, phase, sampleBlksTotal, sampleBlksScanned, extStatsTotal, extStatsComputed, childTablesTotal, childTablesDone, currentChildTableRelid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressAnalyzeViewRow] = new JsonEncoder[PgStatProgressAnalyzeViewRow] { + override def unsafeEncode(a: PgStatProgressAnalyzeViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""phase":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.phase, indent, out) + out.write(",") + out.write(""""sample_blks_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sampleBlksTotal, indent, out) + out.write(",") + out.write(""""sample_blks_scanned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sampleBlksScanned, indent, out) + out.write(",") + out.write(""""ext_stats_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.extStatsTotal, indent, out) + out.write(",") + out.write(""""ext_stats_computed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.extStatsComputed, indent, out) + out.write(",") + out.write(""""child_tables_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.childTablesTotal, indent, out) + out.write(",") + out.write(""""child_tables_done":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.childTablesDone, indent, out) + out.write(",") + out.write(""""current_child_table_relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.currentChildTableRelid, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewStructure.scala new file mode 100644 index 0000000000..90a758378e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_analyze/PgStatProgressAnalyzeViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_analyze + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressAnalyzeViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressAnalyzeViewRow, val merge: (Row, PgStatProgressAnalyzeViewRow) => Row) + extends Relation[PgStatProgressAnalyzeViewFields, PgStatProgressAnalyzeViewRow, Row] + with PgStatProgressAnalyzeViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val phase = new OptField[String, Row](prefix, "phase", None, None)(x => extract(x).phase, (row, value) => merge(row, extract(row).copy(phase = value))) + override val sampleBlksTotal = new OptField[Long, Row](prefix, "sample_blks_total", None, None)(x => extract(x).sampleBlksTotal, (row, value) => merge(row, extract(row).copy(sampleBlksTotal = value))) + override val sampleBlksScanned = new OptField[Long, Row](prefix, "sample_blks_scanned", None, None)(x => extract(x).sampleBlksScanned, (row, value) => merge(row, extract(row).copy(sampleBlksScanned = value))) + override val extStatsTotal = new OptField[Long, Row](prefix, "ext_stats_total", None, None)(x => extract(x).extStatsTotal, (row, value) => merge(row, extract(row).copy(extStatsTotal = value))) + override val extStatsComputed = new OptField[Long, Row](prefix, "ext_stats_computed", None, None)(x => extract(x).extStatsComputed, (row, value) => merge(row, extract(row).copy(extStatsComputed = value))) + override val childTablesTotal = new OptField[Long, Row](prefix, "child_tables_total", None, None)(x => extract(x).childTablesTotal, (row, value) => merge(row, extract(row).copy(childTablesTotal = value))) + override val childTablesDone = new OptField[Long, Row](prefix, "child_tables_done", None, None)(x => extract(x).childTablesDone, (row, value) => merge(row, extract(row).copy(childTablesDone = value))) + override val currentChildTableRelid = new OptField[/* oid */ Long, Row](prefix, "current_child_table_relid", None, None)(x => extract(x).currentChildTableRelid, (row, value) => merge(row, extract(row).copy(currentChildTableRelid = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, datid, datname, relid, phase, sampleBlksTotal, sampleBlksScanned, extStatsTotal, extStatsComputed, childTablesTotal, childTablesDone, currentChildTableRelid) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressAnalyzeViewRow, merge: (NewRow, PgStatProgressAnalyzeViewRow) => NewRow): PgStatProgressAnalyzeViewStructure[NewRow] = + new PgStatProgressAnalyzeViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewFields.scala new file mode 100644 index 0000000000..6fced3f78d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_basebackup + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressBasebackupViewFields[Row] { + val pid: OptField[Int, Row] + val phase: OptField[String, Row] + val backupTotal: OptField[Long, Row] + val backupStreamed: OptField[Long, Row] + val tablespacesTotal: OptField[Long, Row] + val tablespacesStreamed: OptField[Long, Row] +} +object PgStatProgressBasebackupViewFields extends PgStatProgressBasebackupViewStructure[PgStatProgressBasebackupViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepo.scala new file mode 100644 index 0000000000..f13039a303 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_basebackup + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressBasebackupViewRepo { + def select: SelectBuilder[PgStatProgressBasebackupViewFields, PgStatProgressBasebackupViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressBasebackupViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepoImpl.scala new file mode 100644 index 0000000000..d09833588d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_basebackup + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressBasebackupViewRepoImpl extends PgStatProgressBasebackupViewRepo { + override def select: SelectBuilder[PgStatProgressBasebackupViewFields, PgStatProgressBasebackupViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_basebackup", PgStatProgressBasebackupViewFields, PgStatProgressBasebackupViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressBasebackupViewRow] = { + sql"""select "pid", "phase", "backup_total", "backup_streamed", "tablespaces_total", "tablespaces_streamed" from pg_catalog.pg_stat_progress_basebackup""".query(PgStatProgressBasebackupViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRow.scala new file mode 100644 index 0000000000..ae13c8e08a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_basebackup + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressBasebackupViewRow( + pid: /* nullability unknown */ Option[Int], + phase: /* nullability unknown */ Option[String], + backupTotal: /* nullability unknown */ Option[Long], + backupStreamed: /* nullability unknown */ Option[Long], + tablespacesTotal: /* nullability unknown */ Option[Long], + tablespacesStreamed: /* nullability unknown */ Option[Long] +) + +object PgStatProgressBasebackupViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressBasebackupViewRow] = new JdbcDecoder[PgStatProgressBasebackupViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressBasebackupViewRow) = + columIndex + 5 -> + PgStatProgressBasebackupViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + phase = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + backupTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + backupStreamed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + tablespacesTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + tablespacesStreamed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressBasebackupViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val phase = jsonObj.get("phase").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val backupTotal = jsonObj.get("backup_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val backupStreamed = jsonObj.get("backup_streamed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tablespacesTotal = jsonObj.get("tablespaces_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tablespacesStreamed = jsonObj.get("tablespaces_streamed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && phase.isRight && backupTotal.isRight && backupStreamed.isRight && tablespacesTotal.isRight && tablespacesStreamed.isRight) + Right(PgStatProgressBasebackupViewRow(pid = pid.toOption.get, phase = phase.toOption.get, backupTotal = backupTotal.toOption.get, backupStreamed = backupStreamed.toOption.get, tablespacesTotal = tablespacesTotal.toOption.get, tablespacesStreamed = tablespacesStreamed.toOption.get)) + else Left(List[Either[String, Any]](pid, phase, backupTotal, backupStreamed, tablespacesTotal, tablespacesStreamed).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressBasebackupViewRow] = new JsonEncoder[PgStatProgressBasebackupViewRow] { + override def unsafeEncode(a: PgStatProgressBasebackupViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""phase":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.phase, indent, out) + out.write(",") + out.write(""""backup_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.backupTotal, indent, out) + out.write(",") + out.write(""""backup_streamed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.backupStreamed, indent, out) + out.write(",") + out.write(""""tablespaces_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tablespacesTotal, indent, out) + out.write(",") + out.write(""""tablespaces_streamed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tablespacesStreamed, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewStructure.scala new file mode 100644 index 0000000000..786347b721 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_basebackup/PgStatProgressBasebackupViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_basebackup + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressBasebackupViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressBasebackupViewRow, val merge: (Row, PgStatProgressBasebackupViewRow) => Row) + extends Relation[PgStatProgressBasebackupViewFields, PgStatProgressBasebackupViewRow, Row] + with PgStatProgressBasebackupViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val phase = new OptField[String, Row](prefix, "phase", None, None)(x => extract(x).phase, (row, value) => merge(row, extract(row).copy(phase = value))) + override val backupTotal = new OptField[Long, Row](prefix, "backup_total", None, None)(x => extract(x).backupTotal, (row, value) => merge(row, extract(row).copy(backupTotal = value))) + override val backupStreamed = new OptField[Long, Row](prefix, "backup_streamed", None, None)(x => extract(x).backupStreamed, (row, value) => merge(row, extract(row).copy(backupStreamed = value))) + override val tablespacesTotal = new OptField[Long, Row](prefix, "tablespaces_total", None, None)(x => extract(x).tablespacesTotal, (row, value) => merge(row, extract(row).copy(tablespacesTotal = value))) + override val tablespacesStreamed = new OptField[Long, Row](prefix, "tablespaces_streamed", None, None)(x => extract(x).tablespacesStreamed, (row, value) => merge(row, extract(row).copy(tablespacesStreamed = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, phase, backupTotal, backupStreamed, tablespacesTotal, tablespacesStreamed) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressBasebackupViewRow, merge: (NewRow, PgStatProgressBasebackupViewRow) => NewRow): PgStatProgressBasebackupViewStructure[NewRow] = + new PgStatProgressBasebackupViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewFields.scala new file mode 100644 index 0000000000..4a79c92e66 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_cluster + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressClusterViewFields[Row] { + val pid: OptField[Int, Row] + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val relid: OptField[/* oid */ Long, Row] + val command: OptField[String, Row] + val phase: OptField[String, Row] + val clusterIndexRelid: OptField[/* oid */ Long, Row] + val heapTuplesScanned: OptField[Long, Row] + val heapTuplesWritten: OptField[Long, Row] + val heapBlksTotal: OptField[Long, Row] + val heapBlksScanned: OptField[Long, Row] + val indexRebuildCount: OptField[Long, Row] +} +object PgStatProgressClusterViewFields extends PgStatProgressClusterViewStructure[PgStatProgressClusterViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepo.scala new file mode 100644 index 0000000000..89dbd35da6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_cluster + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressClusterViewRepo { + def select: SelectBuilder[PgStatProgressClusterViewFields, PgStatProgressClusterViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressClusterViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepoImpl.scala new file mode 100644 index 0000000000..e6d69c9510 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_cluster + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressClusterViewRepoImpl extends PgStatProgressClusterViewRepo { + override def select: SelectBuilder[PgStatProgressClusterViewFields, PgStatProgressClusterViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_cluster", PgStatProgressClusterViewFields, PgStatProgressClusterViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressClusterViewRow] = { + sql"""select "pid", "datid", "datname", "relid", "command", "phase", "cluster_index_relid", "heap_tuples_scanned", "heap_tuples_written", "heap_blks_total", "heap_blks_scanned", "index_rebuild_count" from pg_catalog.pg_stat_progress_cluster""".query(PgStatProgressClusterViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRow.scala new file mode 100644 index 0000000000..11ae7be877 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewRow.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_cluster + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressClusterViewRow( + pid: /* nullability unknown */ Option[Int], + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + relid: /* nullability unknown */ Option[/* oid */ Long], + command: /* nullability unknown */ Option[String], + phase: /* nullability unknown */ Option[String], + clusterIndexRelid: /* nullability unknown */ Option[/* oid */ Long], + heapTuplesScanned: /* nullability unknown */ Option[Long], + heapTuplesWritten: /* nullability unknown */ Option[Long], + heapBlksTotal: /* nullability unknown */ Option[Long], + heapBlksScanned: /* nullability unknown */ Option[Long], + indexRebuildCount: /* nullability unknown */ Option[Long] +) + +object PgStatProgressClusterViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressClusterViewRow] = new JdbcDecoder[PgStatProgressClusterViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressClusterViewRow) = + columIndex + 11 -> + PgStatProgressClusterViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + command = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + phase = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + clusterIndexRelid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + heapTuplesScanned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + heapTuplesWritten = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + heapBlksTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + heapBlksScanned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + indexRebuildCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressClusterViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val command = jsonObj.get("command").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val phase = jsonObj.get("phase").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clusterIndexRelid = jsonObj.get("cluster_index_relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapTuplesScanned = jsonObj.get("heap_tuples_scanned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapTuplesWritten = jsonObj.get("heap_tuples_written").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksTotal = jsonObj.get("heap_blks_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksScanned = jsonObj.get("heap_blks_scanned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val indexRebuildCount = jsonObj.get("index_rebuild_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && datid.isRight && datname.isRight && relid.isRight && command.isRight && phase.isRight && clusterIndexRelid.isRight && heapTuplesScanned.isRight && heapTuplesWritten.isRight && heapBlksTotal.isRight && heapBlksScanned.isRight && indexRebuildCount.isRight) + Right(PgStatProgressClusterViewRow(pid = pid.toOption.get, datid = datid.toOption.get, datname = datname.toOption.get, relid = relid.toOption.get, command = command.toOption.get, phase = phase.toOption.get, clusterIndexRelid = clusterIndexRelid.toOption.get, heapTuplesScanned = heapTuplesScanned.toOption.get, heapTuplesWritten = heapTuplesWritten.toOption.get, heapBlksTotal = heapBlksTotal.toOption.get, heapBlksScanned = heapBlksScanned.toOption.get, indexRebuildCount = indexRebuildCount.toOption.get)) + else Left(List[Either[String, Any]](pid, datid, datname, relid, command, phase, clusterIndexRelid, heapTuplesScanned, heapTuplesWritten, heapBlksTotal, heapBlksScanned, indexRebuildCount).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressClusterViewRow] = new JsonEncoder[PgStatProgressClusterViewRow] { + override def unsafeEncode(a: PgStatProgressClusterViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""command":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.command, indent, out) + out.write(",") + out.write(""""phase":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.phase, indent, out) + out.write(",") + out.write(""""cluster_index_relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.clusterIndexRelid, indent, out) + out.write(",") + out.write(""""heap_tuples_scanned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapTuplesScanned, indent, out) + out.write(",") + out.write(""""heap_tuples_written":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapTuplesWritten, indent, out) + out.write(",") + out.write(""""heap_blks_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksTotal, indent, out) + out.write(",") + out.write(""""heap_blks_scanned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksScanned, indent, out) + out.write(",") + out.write(""""index_rebuild_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.indexRebuildCount, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewStructure.scala new file mode 100644 index 0000000000..d6c432ad6e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_cluster/PgStatProgressClusterViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_cluster + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressClusterViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressClusterViewRow, val merge: (Row, PgStatProgressClusterViewRow) => Row) + extends Relation[PgStatProgressClusterViewFields, PgStatProgressClusterViewRow, Row] + with PgStatProgressClusterViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val command = new OptField[String, Row](prefix, "command", None, None)(x => extract(x).command, (row, value) => merge(row, extract(row).copy(command = value))) + override val phase = new OptField[String, Row](prefix, "phase", None, None)(x => extract(x).phase, (row, value) => merge(row, extract(row).copy(phase = value))) + override val clusterIndexRelid = new OptField[/* oid */ Long, Row](prefix, "cluster_index_relid", None, None)(x => extract(x).clusterIndexRelid, (row, value) => merge(row, extract(row).copy(clusterIndexRelid = value))) + override val heapTuplesScanned = new OptField[Long, Row](prefix, "heap_tuples_scanned", None, None)(x => extract(x).heapTuplesScanned, (row, value) => merge(row, extract(row).copy(heapTuplesScanned = value))) + override val heapTuplesWritten = new OptField[Long, Row](prefix, "heap_tuples_written", None, None)(x => extract(x).heapTuplesWritten, (row, value) => merge(row, extract(row).copy(heapTuplesWritten = value))) + override val heapBlksTotal = new OptField[Long, Row](prefix, "heap_blks_total", None, None)(x => extract(x).heapBlksTotal, (row, value) => merge(row, extract(row).copy(heapBlksTotal = value))) + override val heapBlksScanned = new OptField[Long, Row](prefix, "heap_blks_scanned", None, None)(x => extract(x).heapBlksScanned, (row, value) => merge(row, extract(row).copy(heapBlksScanned = value))) + override val indexRebuildCount = new OptField[Long, Row](prefix, "index_rebuild_count", None, None)(x => extract(x).indexRebuildCount, (row, value) => merge(row, extract(row).copy(indexRebuildCount = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, datid, datname, relid, command, phase, clusterIndexRelid, heapTuplesScanned, heapTuplesWritten, heapBlksTotal, heapBlksScanned, indexRebuildCount) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressClusterViewRow, merge: (NewRow, PgStatProgressClusterViewRow) => NewRow): PgStatProgressClusterViewStructure[NewRow] = + new PgStatProgressClusterViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewFields.scala new file mode 100644 index 0000000000..59fbc47f74 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_copy + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressCopyViewFields[Row] { + val pid: OptField[Int, Row] + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val relid: OptField[/* oid */ Long, Row] + val command: OptField[String, Row] + val `type`: OptField[String, Row] + val bytesProcessed: OptField[Long, Row] + val bytesTotal: OptField[Long, Row] + val tuplesProcessed: OptField[Long, Row] + val tuplesExcluded: OptField[Long, Row] +} +object PgStatProgressCopyViewFields extends PgStatProgressCopyViewStructure[PgStatProgressCopyViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepo.scala new file mode 100644 index 0000000000..1818c64a80 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_copy + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressCopyViewRepo { + def select: SelectBuilder[PgStatProgressCopyViewFields, PgStatProgressCopyViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressCopyViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepoImpl.scala new file mode 100644 index 0000000000..2399b11ca4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_copy + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressCopyViewRepoImpl extends PgStatProgressCopyViewRepo { + override def select: SelectBuilder[PgStatProgressCopyViewFields, PgStatProgressCopyViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_copy", PgStatProgressCopyViewFields, PgStatProgressCopyViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressCopyViewRow] = { + sql"""select "pid", "datid", "datname", "relid", "command", "type", "bytes_processed", "bytes_total", "tuples_processed", "tuples_excluded" from pg_catalog.pg_stat_progress_copy""".query(PgStatProgressCopyViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRow.scala new file mode 100644 index 0000000000..388d7701ba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewRow.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_copy + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressCopyViewRow( + pid: /* nullability unknown */ Option[Int], + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + relid: /* nullability unknown */ Option[/* oid */ Long], + command: /* nullability unknown */ Option[String], + `type`: /* nullability unknown */ Option[String], + bytesProcessed: /* nullability unknown */ Option[Long], + bytesTotal: /* nullability unknown */ Option[Long], + tuplesProcessed: /* nullability unknown */ Option[Long], + tuplesExcluded: /* nullability unknown */ Option[Long] +) + +object PgStatProgressCopyViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressCopyViewRow] = new JdbcDecoder[PgStatProgressCopyViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressCopyViewRow) = + columIndex + 9 -> + PgStatProgressCopyViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + command = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + `type` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + bytesProcessed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + bytesTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + tuplesProcessed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + tuplesExcluded = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressCopyViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val command = jsonObj.get("command").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `type` = jsonObj.get("type").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val bytesProcessed = jsonObj.get("bytes_processed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val bytesTotal = jsonObj.get("bytes_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tuplesProcessed = jsonObj.get("tuples_processed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tuplesExcluded = jsonObj.get("tuples_excluded").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && datid.isRight && datname.isRight && relid.isRight && command.isRight && `type`.isRight && bytesProcessed.isRight && bytesTotal.isRight && tuplesProcessed.isRight && tuplesExcluded.isRight) + Right(PgStatProgressCopyViewRow(pid = pid.toOption.get, datid = datid.toOption.get, datname = datname.toOption.get, relid = relid.toOption.get, command = command.toOption.get, `type` = `type`.toOption.get, bytesProcessed = bytesProcessed.toOption.get, bytesTotal = bytesTotal.toOption.get, tuplesProcessed = tuplesProcessed.toOption.get, tuplesExcluded = tuplesExcluded.toOption.get)) + else Left(List[Either[String, Any]](pid, datid, datname, relid, command, `type`, bytesProcessed, bytesTotal, tuplesProcessed, tuplesExcluded).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressCopyViewRow] = new JsonEncoder[PgStatProgressCopyViewRow] { + override def unsafeEncode(a: PgStatProgressCopyViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""command":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.command, indent, out) + out.write(",") + out.write(""""type":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`type`, indent, out) + out.write(",") + out.write(""""bytes_processed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.bytesProcessed, indent, out) + out.write(",") + out.write(""""bytes_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.bytesTotal, indent, out) + out.write(",") + out.write(""""tuples_processed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tuplesProcessed, indent, out) + out.write(",") + out.write(""""tuples_excluded":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tuplesExcluded, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewStructure.scala new file mode 100644 index 0000000000..95ffbd8e46 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_copy/PgStatProgressCopyViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_copy + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressCopyViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressCopyViewRow, val merge: (Row, PgStatProgressCopyViewRow) => Row) + extends Relation[PgStatProgressCopyViewFields, PgStatProgressCopyViewRow, Row] + with PgStatProgressCopyViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val command = new OptField[String, Row](prefix, "command", None, None)(x => extract(x).command, (row, value) => merge(row, extract(row).copy(command = value))) + override val `type` = new OptField[String, Row](prefix, "type", None, None)(x => extract(x).`type`, (row, value) => merge(row, extract(row).copy(`type` = value))) + override val bytesProcessed = new OptField[Long, Row](prefix, "bytes_processed", None, None)(x => extract(x).bytesProcessed, (row, value) => merge(row, extract(row).copy(bytesProcessed = value))) + override val bytesTotal = new OptField[Long, Row](prefix, "bytes_total", None, None)(x => extract(x).bytesTotal, (row, value) => merge(row, extract(row).copy(bytesTotal = value))) + override val tuplesProcessed = new OptField[Long, Row](prefix, "tuples_processed", None, None)(x => extract(x).tuplesProcessed, (row, value) => merge(row, extract(row).copy(tuplesProcessed = value))) + override val tuplesExcluded = new OptField[Long, Row](prefix, "tuples_excluded", None, None)(x => extract(x).tuplesExcluded, (row, value) => merge(row, extract(row).copy(tuplesExcluded = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, datid, datname, relid, command, `type`, bytesProcessed, bytesTotal, tuplesProcessed, tuplesExcluded) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressCopyViewRow, merge: (NewRow, PgStatProgressCopyViewRow) => NewRow): PgStatProgressCopyViewStructure[NewRow] = + new PgStatProgressCopyViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewFields.scala new file mode 100644 index 0000000000..699a1a289f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_create_index + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressCreateIndexViewFields[Row] { + val pid: OptField[Int, Row] + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val relid: OptField[/* oid */ Long, Row] + val indexRelid: OptField[/* oid */ Long, Row] + val command: OptField[String, Row] + val phase: OptField[String, Row] + val lockersTotal: OptField[Long, Row] + val lockersDone: OptField[Long, Row] + val currentLockerPid: OptField[Long, Row] + val blocksTotal: OptField[Long, Row] + val blocksDone: OptField[Long, Row] + val tuplesTotal: OptField[Long, Row] + val tuplesDone: OptField[Long, Row] + val partitionsTotal: OptField[Long, Row] + val partitionsDone: OptField[Long, Row] +} +object PgStatProgressCreateIndexViewFields extends PgStatProgressCreateIndexViewStructure[PgStatProgressCreateIndexViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepo.scala new file mode 100644 index 0000000000..23ab322c53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_create_index + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressCreateIndexViewRepo { + def select: SelectBuilder[PgStatProgressCreateIndexViewFields, PgStatProgressCreateIndexViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressCreateIndexViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepoImpl.scala new file mode 100644 index 0000000000..d5538ff243 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_create_index + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressCreateIndexViewRepoImpl extends PgStatProgressCreateIndexViewRepo { + override def select: SelectBuilder[PgStatProgressCreateIndexViewFields, PgStatProgressCreateIndexViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_create_index", PgStatProgressCreateIndexViewFields, PgStatProgressCreateIndexViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressCreateIndexViewRow] = { + sql"""select "pid", "datid", "datname", "relid", "index_relid", "command", "phase", "lockers_total", "lockers_done", "current_locker_pid", "blocks_total", "blocks_done", "tuples_total", "tuples_done", "partitions_total", "partitions_done" from pg_catalog.pg_stat_progress_create_index""".query(PgStatProgressCreateIndexViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRow.scala new file mode 100644 index 0000000000..828430847a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewRow.scala @@ -0,0 +1,134 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_create_index + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressCreateIndexViewRow( + pid: /* nullability unknown */ Option[Int], + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + relid: /* nullability unknown */ Option[/* oid */ Long], + indexRelid: /* nullability unknown */ Option[/* oid */ Long], + command: /* nullability unknown */ Option[String], + phase: /* nullability unknown */ Option[String], + lockersTotal: /* nullability unknown */ Option[Long], + lockersDone: /* nullability unknown */ Option[Long], + currentLockerPid: /* nullability unknown */ Option[Long], + blocksTotal: /* nullability unknown */ Option[Long], + blocksDone: /* nullability unknown */ Option[Long], + tuplesTotal: /* nullability unknown */ Option[Long], + tuplesDone: /* nullability unknown */ Option[Long], + partitionsTotal: /* nullability unknown */ Option[Long], + partitionsDone: /* nullability unknown */ Option[Long] +) + +object PgStatProgressCreateIndexViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressCreateIndexViewRow] = new JdbcDecoder[PgStatProgressCreateIndexViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressCreateIndexViewRow) = + columIndex + 15 -> + PgStatProgressCreateIndexViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexRelid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + command = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + phase = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + lockersTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + lockersDone = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + currentLockerPid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + blocksTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + blocksDone = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + tuplesTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + tuplesDone = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + partitionsTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + partitionsDone = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 15, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressCreateIndexViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val indexRelid = jsonObj.get("index_relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val command = jsonObj.get("command").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val phase = jsonObj.get("phase").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val lockersTotal = jsonObj.get("lockers_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lockersDone = jsonObj.get("lockers_done").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val currentLockerPid = jsonObj.get("current_locker_pid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blocksTotal = jsonObj.get("blocks_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blocksDone = jsonObj.get("blocks_done").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tuplesTotal = jsonObj.get("tuples_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tuplesDone = jsonObj.get("tuples_done").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val partitionsTotal = jsonObj.get("partitions_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val partitionsDone = jsonObj.get("partitions_done").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && datid.isRight && datname.isRight && relid.isRight && indexRelid.isRight && command.isRight && phase.isRight && lockersTotal.isRight && lockersDone.isRight && currentLockerPid.isRight && blocksTotal.isRight && blocksDone.isRight && tuplesTotal.isRight && tuplesDone.isRight && partitionsTotal.isRight && partitionsDone.isRight) + Right(PgStatProgressCreateIndexViewRow(pid = pid.toOption.get, datid = datid.toOption.get, datname = datname.toOption.get, relid = relid.toOption.get, indexRelid = indexRelid.toOption.get, command = command.toOption.get, phase = phase.toOption.get, lockersTotal = lockersTotal.toOption.get, lockersDone = lockersDone.toOption.get, currentLockerPid = currentLockerPid.toOption.get, blocksTotal = blocksTotal.toOption.get, blocksDone = blocksDone.toOption.get, tuplesTotal = tuplesTotal.toOption.get, tuplesDone = tuplesDone.toOption.get, partitionsTotal = partitionsTotal.toOption.get, partitionsDone = partitionsDone.toOption.get)) + else Left(List[Either[String, Any]](pid, datid, datname, relid, indexRelid, command, phase, lockersTotal, lockersDone, currentLockerPid, blocksTotal, blocksDone, tuplesTotal, tuplesDone, partitionsTotal, partitionsDone).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressCreateIndexViewRow] = new JsonEncoder[PgStatProgressCreateIndexViewRow] { + override def unsafeEncode(a: PgStatProgressCreateIndexViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""index_relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.indexRelid, indent, out) + out.write(",") + out.write(""""command":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.command, indent, out) + out.write(",") + out.write(""""phase":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.phase, indent, out) + out.write(",") + out.write(""""lockers_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.lockersTotal, indent, out) + out.write(",") + out.write(""""lockers_done":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.lockersDone, indent, out) + out.write(",") + out.write(""""current_locker_pid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.currentLockerPid, indent, out) + out.write(",") + out.write(""""blocks_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blocksTotal, indent, out) + out.write(",") + out.write(""""blocks_done":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blocksDone, indent, out) + out.write(",") + out.write(""""tuples_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tuplesTotal, indent, out) + out.write(",") + out.write(""""tuples_done":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tuplesDone, indent, out) + out.write(",") + out.write(""""partitions_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.partitionsTotal, indent, out) + out.write(",") + out.write(""""partitions_done":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.partitionsDone, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewStructure.scala new file mode 100644 index 0000000000..89770ef1af --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_create_index/PgStatProgressCreateIndexViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_create_index + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressCreateIndexViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressCreateIndexViewRow, val merge: (Row, PgStatProgressCreateIndexViewRow) => Row) + extends Relation[PgStatProgressCreateIndexViewFields, PgStatProgressCreateIndexViewRow, Row] + with PgStatProgressCreateIndexViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexRelid = new OptField[/* oid */ Long, Row](prefix, "index_relid", None, None)(x => extract(x).indexRelid, (row, value) => merge(row, extract(row).copy(indexRelid = value))) + override val command = new OptField[String, Row](prefix, "command", None, None)(x => extract(x).command, (row, value) => merge(row, extract(row).copy(command = value))) + override val phase = new OptField[String, Row](prefix, "phase", None, None)(x => extract(x).phase, (row, value) => merge(row, extract(row).copy(phase = value))) + override val lockersTotal = new OptField[Long, Row](prefix, "lockers_total", None, None)(x => extract(x).lockersTotal, (row, value) => merge(row, extract(row).copy(lockersTotal = value))) + override val lockersDone = new OptField[Long, Row](prefix, "lockers_done", None, None)(x => extract(x).lockersDone, (row, value) => merge(row, extract(row).copy(lockersDone = value))) + override val currentLockerPid = new OptField[Long, Row](prefix, "current_locker_pid", None, None)(x => extract(x).currentLockerPid, (row, value) => merge(row, extract(row).copy(currentLockerPid = value))) + override val blocksTotal = new OptField[Long, Row](prefix, "blocks_total", None, None)(x => extract(x).blocksTotal, (row, value) => merge(row, extract(row).copy(blocksTotal = value))) + override val blocksDone = new OptField[Long, Row](prefix, "blocks_done", None, None)(x => extract(x).blocksDone, (row, value) => merge(row, extract(row).copy(blocksDone = value))) + override val tuplesTotal = new OptField[Long, Row](prefix, "tuples_total", None, None)(x => extract(x).tuplesTotal, (row, value) => merge(row, extract(row).copy(tuplesTotal = value))) + override val tuplesDone = new OptField[Long, Row](prefix, "tuples_done", None, None)(x => extract(x).tuplesDone, (row, value) => merge(row, extract(row).copy(tuplesDone = value))) + override val partitionsTotal = new OptField[Long, Row](prefix, "partitions_total", None, None)(x => extract(x).partitionsTotal, (row, value) => merge(row, extract(row).copy(partitionsTotal = value))) + override val partitionsDone = new OptField[Long, Row](prefix, "partitions_done", None, None)(x => extract(x).partitionsDone, (row, value) => merge(row, extract(row).copy(partitionsDone = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, datid, datname, relid, indexRelid, command, phase, lockersTotal, lockersDone, currentLockerPid, blocksTotal, blocksDone, tuplesTotal, tuplesDone, partitionsTotal, partitionsDone) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressCreateIndexViewRow, merge: (NewRow, PgStatProgressCreateIndexViewRow) => NewRow): PgStatProgressCreateIndexViewStructure[NewRow] = + new PgStatProgressCreateIndexViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewFields.scala new file mode 100644 index 0000000000..908d5423db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_vacuum + +import typo.dsl.SqlExpr.OptField + +trait PgStatProgressVacuumViewFields[Row] { + val pid: OptField[Int, Row] + val datid: OptField[/* oid */ Long, Row] + val datname: OptField[String, Row] + val relid: OptField[/* oid */ Long, Row] + val phase: OptField[String, Row] + val heapBlksTotal: OptField[Long, Row] + val heapBlksScanned: OptField[Long, Row] + val heapBlksVacuumed: OptField[Long, Row] + val indexVacuumCount: OptField[Long, Row] + val maxDeadTuples: OptField[Long, Row] + val numDeadTuples: OptField[Long, Row] +} +object PgStatProgressVacuumViewFields extends PgStatProgressVacuumViewStructure[PgStatProgressVacuumViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepo.scala new file mode 100644 index 0000000000..71e82b58e5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_vacuum + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatProgressVacuumViewRepo { + def select: SelectBuilder[PgStatProgressVacuumViewFields, PgStatProgressVacuumViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatProgressVacuumViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepoImpl.scala new file mode 100644 index 0000000000..c3c0fafef5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_vacuum + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatProgressVacuumViewRepoImpl extends PgStatProgressVacuumViewRepo { + override def select: SelectBuilder[PgStatProgressVacuumViewFields, PgStatProgressVacuumViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_progress_vacuum", PgStatProgressVacuumViewFields, PgStatProgressVacuumViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatProgressVacuumViewRow] = { + sql"""select "pid", "datid", "datname", "relid", "phase", "heap_blks_total", "heap_blks_scanned", "heap_blks_vacuumed", "index_vacuum_count", "max_dead_tuples", "num_dead_tuples" from pg_catalog.pg_stat_progress_vacuum""".query(PgStatProgressVacuumViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRow.scala new file mode 100644 index 0000000000..107ef6be02 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewRow.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_vacuum + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatProgressVacuumViewRow( + pid: /* nullability unknown */ Option[Int], + datid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_database.PgDatabaseRow.datname]] */ + datname: Option[String], + relid: /* nullability unknown */ Option[/* oid */ Long], + phase: /* nullability unknown */ Option[String], + heapBlksTotal: /* nullability unknown */ Option[Long], + heapBlksScanned: /* nullability unknown */ Option[Long], + heapBlksVacuumed: /* nullability unknown */ Option[Long], + indexVacuumCount: /* nullability unknown */ Option[Long], + maxDeadTuples: /* nullability unknown */ Option[Long], + numDeadTuples: /* nullability unknown */ Option[Long] +) + +object PgStatProgressVacuumViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatProgressVacuumViewRow] = new JdbcDecoder[PgStatProgressVacuumViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatProgressVacuumViewRow) = + columIndex + 10 -> + PgStatProgressVacuumViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + datid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + datname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + phase = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + heapBlksTotal = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + heapBlksScanned = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + heapBlksVacuumed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + indexVacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + maxDeadTuples = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + numDeadTuples = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatProgressVacuumViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val datid = jsonObj.get("datid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val datname = jsonObj.get("datname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val phase = jsonObj.get("phase").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val heapBlksTotal = jsonObj.get("heap_blks_total").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksScanned = jsonObj.get("heap_blks_scanned").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksVacuumed = jsonObj.get("heap_blks_vacuumed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val indexVacuumCount = jsonObj.get("index_vacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val maxDeadTuples = jsonObj.get("max_dead_tuples").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val numDeadTuples = jsonObj.get("num_dead_tuples").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (pid.isRight && datid.isRight && datname.isRight && relid.isRight && phase.isRight && heapBlksTotal.isRight && heapBlksScanned.isRight && heapBlksVacuumed.isRight && indexVacuumCount.isRight && maxDeadTuples.isRight && numDeadTuples.isRight) + Right(PgStatProgressVacuumViewRow(pid = pid.toOption.get, datid = datid.toOption.get, datname = datname.toOption.get, relid = relid.toOption.get, phase = phase.toOption.get, heapBlksTotal = heapBlksTotal.toOption.get, heapBlksScanned = heapBlksScanned.toOption.get, heapBlksVacuumed = heapBlksVacuumed.toOption.get, indexVacuumCount = indexVacuumCount.toOption.get, maxDeadTuples = maxDeadTuples.toOption.get, numDeadTuples = numDeadTuples.toOption.get)) + else Left(List[Either[String, Any]](pid, datid, datname, relid, phase, heapBlksTotal, heapBlksScanned, heapBlksVacuumed, indexVacuumCount, maxDeadTuples, numDeadTuples).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatProgressVacuumViewRow] = new JsonEncoder[PgStatProgressVacuumViewRow] { + override def unsafeEncode(a: PgStatProgressVacuumViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""datid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.datid, indent, out) + out.write(",") + out.write(""""datname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.datname, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""phase":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.phase, indent, out) + out.write(",") + out.write(""""heap_blks_total":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksTotal, indent, out) + out.write(",") + out.write(""""heap_blks_scanned":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksScanned, indent, out) + out.write(",") + out.write(""""heap_blks_vacuumed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksVacuumed, indent, out) + out.write(",") + out.write(""""index_vacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.indexVacuumCount, indent, out) + out.write(",") + out.write(""""max_dead_tuples":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.maxDeadTuples, indent, out) + out.write(",") + out.write(""""num_dead_tuples":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.numDeadTuples, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewStructure.scala new file mode 100644 index 0000000000..15cd23ff67 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_progress_vacuum/PgStatProgressVacuumViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_progress_vacuum + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatProgressVacuumViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatProgressVacuumViewRow, val merge: (Row, PgStatProgressVacuumViewRow) => Row) + extends Relation[PgStatProgressVacuumViewFields, PgStatProgressVacuumViewRow, Row] + with PgStatProgressVacuumViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val datid = new OptField[/* oid */ Long, Row](prefix, "datid", None, None)(x => extract(x).datid, (row, value) => merge(row, extract(row).copy(datid = value))) + override val datname = new OptField[String, Row](prefix, "datname", None, None)(x => extract(x).datname, (row, value) => merge(row, extract(row).copy(datname = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val phase = new OptField[String, Row](prefix, "phase", None, None)(x => extract(x).phase, (row, value) => merge(row, extract(row).copy(phase = value))) + override val heapBlksTotal = new OptField[Long, Row](prefix, "heap_blks_total", None, None)(x => extract(x).heapBlksTotal, (row, value) => merge(row, extract(row).copy(heapBlksTotal = value))) + override val heapBlksScanned = new OptField[Long, Row](prefix, "heap_blks_scanned", None, None)(x => extract(x).heapBlksScanned, (row, value) => merge(row, extract(row).copy(heapBlksScanned = value))) + override val heapBlksVacuumed = new OptField[Long, Row](prefix, "heap_blks_vacuumed", None, None)(x => extract(x).heapBlksVacuumed, (row, value) => merge(row, extract(row).copy(heapBlksVacuumed = value))) + override val indexVacuumCount = new OptField[Long, Row](prefix, "index_vacuum_count", None, None)(x => extract(x).indexVacuumCount, (row, value) => merge(row, extract(row).copy(indexVacuumCount = value))) + override val maxDeadTuples = new OptField[Long, Row](prefix, "max_dead_tuples", None, None)(x => extract(x).maxDeadTuples, (row, value) => merge(row, extract(row).copy(maxDeadTuples = value))) + override val numDeadTuples = new OptField[Long, Row](prefix, "num_dead_tuples", None, None)(x => extract(x).numDeadTuples, (row, value) => merge(row, extract(row).copy(numDeadTuples = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, datid, datname, relid, phase, heapBlksTotal, heapBlksScanned, heapBlksVacuumed, indexVacuumCount, maxDeadTuples, numDeadTuples) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatProgressVacuumViewRow, merge: (NewRow, PgStatProgressVacuumViewRow) => NewRow): PgStatProgressVacuumViewStructure[NewRow] = + new PgStatProgressVacuumViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewFields.scala new file mode 100644 index 0000000000..130fee01e7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewFields.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.OptField + +trait PgStatReplicationViewFields[Row] { + val pid: OptField[Int, Row] + val usesysid: OptField[/* oid */ Long, Row] + val usename: OptField[String, Row] + val applicationName: OptField[String, Row] + val clientAddr: OptField[TypoInet, Row] + val clientHostname: OptField[String, Row] + val clientPort: OptField[Int, Row] + val backendStart: OptField[TypoInstant, Row] + val backendXmin: OptField[TypoXid, Row] + val state: OptField[String, Row] + val sentLsn: OptField[/* pg_lsn */ Long, Row] + val writeLsn: OptField[/* pg_lsn */ Long, Row] + val flushLsn: OptField[/* pg_lsn */ Long, Row] + val replayLsn: OptField[/* pg_lsn */ Long, Row] + val writeLag: OptField[TypoInterval, Row] + val flushLag: OptField[TypoInterval, Row] + val replayLag: OptField[TypoInterval, Row] + val syncPriority: OptField[Int, Row] + val syncState: OptField[String, Row] + val replyTime: OptField[TypoInstant, Row] +} +object PgStatReplicationViewFields extends PgStatReplicationViewStructure[PgStatReplicationViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepo.scala new file mode 100644 index 0000000000..1e7a1fcccf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatReplicationViewRepo { + def select: SelectBuilder[PgStatReplicationViewFields, PgStatReplicationViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatReplicationViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepoImpl.scala new file mode 100644 index 0000000000..66d376127e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatReplicationViewRepoImpl extends PgStatReplicationViewRepo { + override def select: SelectBuilder[PgStatReplicationViewFields, PgStatReplicationViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_replication", PgStatReplicationViewFields, PgStatReplicationViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatReplicationViewRow] = { + sql"""select "pid", "usesysid", "usename", "application_name", "client_addr", "client_hostname", "client_port", "backend_start"::text, "backend_xmin", "state", "sent_lsn", "write_lsn", "flush_lsn", "replay_lsn", "write_lag", "flush_lag", "replay_lag", "sync_priority", "sync_state", "reply_time"::text from pg_catalog.pg_stat_replication""".query(PgStatReplicationViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRow.scala new file mode 100644 index 0000000000..454d46c1be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewRow.scala @@ -0,0 +1,162 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoXid +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatReplicationViewRow( + pid: /* nullability unknown */ Option[Int], + usesysid: /* nullability unknown */ Option[/* oid */ Long], + /** Points to [[pg_authid.PgAuthidRow.rolname]] */ + usename: Option[String], + applicationName: /* nullability unknown */ Option[String], + clientAddr: /* nullability unknown */ Option[TypoInet], + clientHostname: /* nullability unknown */ Option[String], + clientPort: /* nullability unknown */ Option[Int], + backendStart: /* nullability unknown */ Option[TypoInstant], + backendXmin: /* nullability unknown */ Option[TypoXid], + state: /* nullability unknown */ Option[String], + sentLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + writeLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + flushLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + replayLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + writeLag: /* nullability unknown */ Option[TypoInterval], + flushLag: /* nullability unknown */ Option[TypoInterval], + replayLag: /* nullability unknown */ Option[TypoInterval], + syncPriority: /* nullability unknown */ Option[Int], + syncState: /* nullability unknown */ Option[String], + replyTime: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatReplicationViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatReplicationViewRow] = new JdbcDecoder[PgStatReplicationViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatReplicationViewRow) = + columIndex + 19 -> + PgStatReplicationViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + usesysid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + usename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + applicationName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + clientAddr = JdbcDecoder.optionDecoder(TypoInet.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + clientHostname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + clientPort = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 6, rs)._2, + backendStart = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + backendXmin = JdbcDecoder.optionDecoder(TypoXid.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + state = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + sentLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + writeLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + flushLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + replayLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + writeLag = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 14, rs)._2, + flushLag = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + replayLag = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + syncPriority = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 17, rs)._2, + syncState = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + replyTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 19, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatReplicationViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val usesysid = jsonObj.get("usesysid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val usename = jsonObj.get("usename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val applicationName = jsonObj.get("application_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clientAddr = jsonObj.get("client_addr").fold[Either[String, Option[TypoInet]]](Right(None))(_.as(JsonDecoder.option(TypoInet.jsonDecoder))) + val clientHostname = jsonObj.get("client_hostname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clientPort = jsonObj.get("client_port").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val backendStart = jsonObj.get("backend_start").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val backendXmin = jsonObj.get("backend_xmin").fold[Either[String, Option[TypoXid]]](Right(None))(_.as(JsonDecoder.option(TypoXid.jsonDecoder))) + val state = jsonObj.get("state").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sentLsn = jsonObj.get("sent_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val writeLsn = jsonObj.get("write_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val flushLsn = jsonObj.get("flush_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val replayLsn = jsonObj.get("replay_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val writeLag = jsonObj.get("write_lag").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val flushLag = jsonObj.get("flush_lag").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val replayLag = jsonObj.get("replay_lag").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val syncPriority = jsonObj.get("sync_priority").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val syncState = jsonObj.get("sync_state").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val replyTime = jsonObj.get("reply_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (pid.isRight && usesysid.isRight && usename.isRight && applicationName.isRight && clientAddr.isRight && clientHostname.isRight && clientPort.isRight && backendStart.isRight && backendXmin.isRight && state.isRight && sentLsn.isRight && writeLsn.isRight && flushLsn.isRight && replayLsn.isRight && writeLag.isRight && flushLag.isRight && replayLag.isRight && syncPriority.isRight && syncState.isRight && replyTime.isRight) + Right(PgStatReplicationViewRow(pid = pid.toOption.get, usesysid = usesysid.toOption.get, usename = usename.toOption.get, applicationName = applicationName.toOption.get, clientAddr = clientAddr.toOption.get, clientHostname = clientHostname.toOption.get, clientPort = clientPort.toOption.get, backendStart = backendStart.toOption.get, backendXmin = backendXmin.toOption.get, state = state.toOption.get, sentLsn = sentLsn.toOption.get, writeLsn = writeLsn.toOption.get, flushLsn = flushLsn.toOption.get, replayLsn = replayLsn.toOption.get, writeLag = writeLag.toOption.get, flushLag = flushLag.toOption.get, replayLag = replayLag.toOption.get, syncPriority = syncPriority.toOption.get, syncState = syncState.toOption.get, replyTime = replyTime.toOption.get)) + else Left(List[Either[String, Any]](pid, usesysid, usename, applicationName, clientAddr, clientHostname, clientPort, backendStart, backendXmin, state, sentLsn, writeLsn, flushLsn, replayLsn, writeLag, flushLag, replayLag, syncPriority, syncState, replyTime).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatReplicationViewRow] = new JsonEncoder[PgStatReplicationViewRow] { + override def unsafeEncode(a: PgStatReplicationViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""usesysid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.usesysid, indent, out) + out.write(",") + out.write(""""usename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.usename, indent, out) + out.write(",") + out.write(""""application_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.applicationName, indent, out) + out.write(",") + out.write(""""client_addr":""") + JsonEncoder.option(TypoInet.jsonEncoder).unsafeEncode(a.clientAddr, indent, out) + out.write(",") + out.write(""""client_hostname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.clientHostname, indent, out) + out.write(",") + out.write(""""client_port":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.clientPort, indent, out) + out.write(",") + out.write(""""backend_start":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.backendStart, indent, out) + out.write(",") + out.write(""""backend_xmin":""") + JsonEncoder.option(TypoXid.jsonEncoder).unsafeEncode(a.backendXmin, indent, out) + out.write(",") + out.write(""""state":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.state, indent, out) + out.write(",") + out.write(""""sent_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.sentLsn, indent, out) + out.write(",") + out.write(""""write_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.writeLsn, indent, out) + out.write(",") + out.write(""""flush_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.flushLsn, indent, out) + out.write(",") + out.write(""""replay_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.replayLsn, indent, out) + out.write(",") + out.write(""""write_lag":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.writeLag, indent, out) + out.write(",") + out.write(""""flush_lag":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.flushLag, indent, out) + out.write(",") + out.write(""""replay_lag":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.replayLag, indent, out) + out.write(",") + out.write(""""sync_priority":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.syncPriority, indent, out) + out.write(",") + out.write(""""sync_state":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.syncState, indent, out) + out.write(",") + out.write(""""reply_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.replyTime, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewStructure.scala new file mode 100644 index 0000000000..546ae834ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication/PgStatReplicationViewStructure.scala @@ -0,0 +1,48 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication + +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoXid +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatReplicationViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatReplicationViewRow, val merge: (Row, PgStatReplicationViewRow) => Row) + extends Relation[PgStatReplicationViewFields, PgStatReplicationViewRow, Row] + with PgStatReplicationViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val usesysid = new OptField[/* oid */ Long, Row](prefix, "usesysid", None, None)(x => extract(x).usesysid, (row, value) => merge(row, extract(row).copy(usesysid = value))) + override val usename = new OptField[String, Row](prefix, "usename", None, None)(x => extract(x).usename, (row, value) => merge(row, extract(row).copy(usename = value))) + override val applicationName = new OptField[String, Row](prefix, "application_name", None, None)(x => extract(x).applicationName, (row, value) => merge(row, extract(row).copy(applicationName = value))) + override val clientAddr = new OptField[TypoInet, Row](prefix, "client_addr", None, None)(x => extract(x).clientAddr, (row, value) => merge(row, extract(row).copy(clientAddr = value))) + override val clientHostname = new OptField[String, Row](prefix, "client_hostname", None, None)(x => extract(x).clientHostname, (row, value) => merge(row, extract(row).copy(clientHostname = value))) + override val clientPort = new OptField[Int, Row](prefix, "client_port", None, None)(x => extract(x).clientPort, (row, value) => merge(row, extract(row).copy(clientPort = value))) + override val backendStart = new OptField[TypoInstant, Row](prefix, "backend_start", Some("text"), None)(x => extract(x).backendStart, (row, value) => merge(row, extract(row).copy(backendStart = value))) + override val backendXmin = new OptField[TypoXid, Row](prefix, "backend_xmin", None, None)(x => extract(x).backendXmin, (row, value) => merge(row, extract(row).copy(backendXmin = value))) + override val state = new OptField[String, Row](prefix, "state", None, None)(x => extract(x).state, (row, value) => merge(row, extract(row).copy(state = value))) + override val sentLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "sent_lsn", None, None)(x => extract(x).sentLsn, (row, value) => merge(row, extract(row).copy(sentLsn = value))) + override val writeLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "write_lsn", None, None)(x => extract(x).writeLsn, (row, value) => merge(row, extract(row).copy(writeLsn = value))) + override val flushLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "flush_lsn", None, None)(x => extract(x).flushLsn, (row, value) => merge(row, extract(row).copy(flushLsn = value))) + override val replayLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "replay_lsn", None, None)(x => extract(x).replayLsn, (row, value) => merge(row, extract(row).copy(replayLsn = value))) + override val writeLag = new OptField[TypoInterval, Row](prefix, "write_lag", None, None)(x => extract(x).writeLag, (row, value) => merge(row, extract(row).copy(writeLag = value))) + override val flushLag = new OptField[TypoInterval, Row](prefix, "flush_lag", None, None)(x => extract(x).flushLag, (row, value) => merge(row, extract(row).copy(flushLag = value))) + override val replayLag = new OptField[TypoInterval, Row](prefix, "replay_lag", None, None)(x => extract(x).replayLag, (row, value) => merge(row, extract(row).copy(replayLag = value))) + override val syncPriority = new OptField[Int, Row](prefix, "sync_priority", None, None)(x => extract(x).syncPriority, (row, value) => merge(row, extract(row).copy(syncPriority = value))) + override val syncState = new OptField[String, Row](prefix, "sync_state", None, None)(x => extract(x).syncState, (row, value) => merge(row, extract(row).copy(syncState = value))) + override val replyTime = new OptField[TypoInstant, Row](prefix, "reply_time", Some("text"), None)(x => extract(x).replyTime, (row, value) => merge(row, extract(row).copy(replyTime = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, usesysid, usename, applicationName, clientAddr, clientHostname, clientPort, backendStart, backendXmin, state, sentLsn, writeLsn, flushLsn, replayLsn, writeLag, flushLag, replayLag, syncPriority, syncState, replyTime) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatReplicationViewRow, merge: (NewRow, PgStatReplicationViewRow) => NewRow): PgStatReplicationViewStructure[NewRow] = + new PgStatReplicationViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewFields.scala new file mode 100644 index 0000000000..7f43e3ca40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication_slots + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatReplicationSlotsViewFields[Row] { + val slotName: OptField[String, Row] + val spillTxns: OptField[Long, Row] + val spillCount: OptField[Long, Row] + val spillBytes: OptField[Long, Row] + val streamTxns: OptField[Long, Row] + val streamCount: OptField[Long, Row] + val streamBytes: OptField[Long, Row] + val totalTxns: OptField[Long, Row] + val totalBytes: OptField[Long, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatReplicationSlotsViewFields extends PgStatReplicationSlotsViewStructure[PgStatReplicationSlotsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepo.scala new file mode 100644 index 0000000000..f7d92d9ae0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication_slots + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatReplicationSlotsViewRepo { + def select: SelectBuilder[PgStatReplicationSlotsViewFields, PgStatReplicationSlotsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatReplicationSlotsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepoImpl.scala new file mode 100644 index 0000000000..d349ecb620 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication_slots + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatReplicationSlotsViewRepoImpl extends PgStatReplicationSlotsViewRepo { + override def select: SelectBuilder[PgStatReplicationSlotsViewFields, PgStatReplicationSlotsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_replication_slots", PgStatReplicationSlotsViewFields, PgStatReplicationSlotsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatReplicationSlotsViewRow] = { + sql"""select "slot_name", "spill_txns", "spill_count", "spill_bytes", "stream_txns", "stream_count", "stream_bytes", "total_txns", "total_bytes", "stats_reset"::text from pg_catalog.pg_stat_replication_slots""".query(PgStatReplicationSlotsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRow.scala new file mode 100644 index 0000000000..aa2aa1cb51 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewRow.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication_slots + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatReplicationSlotsViewRow( + slotName: /* nullability unknown */ Option[String], + spillTxns: /* nullability unknown */ Option[Long], + spillCount: /* nullability unknown */ Option[Long], + spillBytes: /* nullability unknown */ Option[Long], + streamTxns: /* nullability unknown */ Option[Long], + streamCount: /* nullability unknown */ Option[Long], + streamBytes: /* nullability unknown */ Option[Long], + totalTxns: /* nullability unknown */ Option[Long], + totalBytes: /* nullability unknown */ Option[Long], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatReplicationSlotsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatReplicationSlotsViewRow] = new JdbcDecoder[PgStatReplicationSlotsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatReplicationSlotsViewRow) = + columIndex + 9 -> + PgStatReplicationSlotsViewRow( + slotName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + spillTxns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + spillCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + spillBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + streamTxns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + streamCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + streamBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + totalTxns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + totalBytes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatReplicationSlotsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val slotName = jsonObj.get("slot_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val spillTxns = jsonObj.get("spill_txns").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val spillCount = jsonObj.get("spill_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val spillBytes = jsonObj.get("spill_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val streamTxns = jsonObj.get("stream_txns").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val streamCount = jsonObj.get("stream_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val streamBytes = jsonObj.get("stream_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val totalTxns = jsonObj.get("total_txns").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val totalBytes = jsonObj.get("total_bytes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (slotName.isRight && spillTxns.isRight && spillCount.isRight && spillBytes.isRight && streamTxns.isRight && streamCount.isRight && streamBytes.isRight && totalTxns.isRight && totalBytes.isRight && statsReset.isRight) + Right(PgStatReplicationSlotsViewRow(slotName = slotName.toOption.get, spillTxns = spillTxns.toOption.get, spillCount = spillCount.toOption.get, spillBytes = spillBytes.toOption.get, streamTxns = streamTxns.toOption.get, streamCount = streamCount.toOption.get, streamBytes = streamBytes.toOption.get, totalTxns = totalTxns.toOption.get, totalBytes = totalBytes.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](slotName, spillTxns, spillCount, spillBytes, streamTxns, streamCount, streamBytes, totalTxns, totalBytes, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatReplicationSlotsViewRow] = new JsonEncoder[PgStatReplicationSlotsViewRow] { + override def unsafeEncode(a: PgStatReplicationSlotsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""slot_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.slotName, indent, out) + out.write(",") + out.write(""""spill_txns":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.spillTxns, indent, out) + out.write(",") + out.write(""""spill_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.spillCount, indent, out) + out.write(",") + out.write(""""spill_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.spillBytes, indent, out) + out.write(",") + out.write(""""stream_txns":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.streamTxns, indent, out) + out.write(",") + out.write(""""stream_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.streamCount, indent, out) + out.write(",") + out.write(""""stream_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.streamBytes, indent, out) + out.write(",") + out.write(""""total_txns":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.totalTxns, indent, out) + out.write(",") + out.write(""""total_bytes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.totalBytes, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewStructure.scala new file mode 100644 index 0000000000..22894f1264 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_replication_slots/PgStatReplicationSlotsViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_replication_slots + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatReplicationSlotsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatReplicationSlotsViewRow, val merge: (Row, PgStatReplicationSlotsViewRow) => Row) + extends Relation[PgStatReplicationSlotsViewFields, PgStatReplicationSlotsViewRow, Row] + with PgStatReplicationSlotsViewFields[Row] { outer => + + override val slotName = new OptField[String, Row](prefix, "slot_name", None, None)(x => extract(x).slotName, (row, value) => merge(row, extract(row).copy(slotName = value))) + override val spillTxns = new OptField[Long, Row](prefix, "spill_txns", None, None)(x => extract(x).spillTxns, (row, value) => merge(row, extract(row).copy(spillTxns = value))) + override val spillCount = new OptField[Long, Row](prefix, "spill_count", None, None)(x => extract(x).spillCount, (row, value) => merge(row, extract(row).copy(spillCount = value))) + override val spillBytes = new OptField[Long, Row](prefix, "spill_bytes", None, None)(x => extract(x).spillBytes, (row, value) => merge(row, extract(row).copy(spillBytes = value))) + override val streamTxns = new OptField[Long, Row](prefix, "stream_txns", None, None)(x => extract(x).streamTxns, (row, value) => merge(row, extract(row).copy(streamTxns = value))) + override val streamCount = new OptField[Long, Row](prefix, "stream_count", None, None)(x => extract(x).streamCount, (row, value) => merge(row, extract(row).copy(streamCount = value))) + override val streamBytes = new OptField[Long, Row](prefix, "stream_bytes", None, None)(x => extract(x).streamBytes, (row, value) => merge(row, extract(row).copy(streamBytes = value))) + override val totalTxns = new OptField[Long, Row](prefix, "total_txns", None, None)(x => extract(x).totalTxns, (row, value) => merge(row, extract(row).copy(totalTxns = value))) + override val totalBytes = new OptField[Long, Row](prefix, "total_bytes", None, None)(x => extract(x).totalBytes, (row, value) => merge(row, extract(row).copy(totalBytes = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](slotName, spillTxns, spillCount, spillBytes, streamTxns, streamCount, streamBytes, totalTxns, totalBytes, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatReplicationSlotsViewRow, merge: (NewRow, PgStatReplicationSlotsViewRow) => NewRow): PgStatReplicationSlotsViewStructure[NewRow] = + new PgStatReplicationSlotsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewFields.scala new file mode 100644 index 0000000000..e102b13970 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_slru + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatSlruViewFields[Row] { + val name: OptField[String, Row] + val blksZeroed: OptField[Long, Row] + val blksHit: OptField[Long, Row] + val blksRead: OptField[Long, Row] + val blksWritten: OptField[Long, Row] + val blksExists: OptField[Long, Row] + val flushes: OptField[Long, Row] + val truncates: OptField[Long, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatSlruViewFields extends PgStatSlruViewStructure[PgStatSlruViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepo.scala new file mode 100644 index 0000000000..6fff181204 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_slru + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatSlruViewRepo { + def select: SelectBuilder[PgStatSlruViewFields, PgStatSlruViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatSlruViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepoImpl.scala new file mode 100644 index 0000000000..9c33a62a26 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_slru + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatSlruViewRepoImpl extends PgStatSlruViewRepo { + override def select: SelectBuilder[PgStatSlruViewFields, PgStatSlruViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_slru", PgStatSlruViewFields, PgStatSlruViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatSlruViewRow] = { + sql"""select "name", "blks_zeroed", "blks_hit", "blks_read", "blks_written", "blks_exists", "flushes", "truncates", "stats_reset"::text from pg_catalog.pg_stat_slru""".query(PgStatSlruViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRow.scala new file mode 100644 index 0000000000..3fcf6d55e1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewRow.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_slru + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatSlruViewRow( + name: /* nullability unknown */ Option[String], + blksZeroed: /* nullability unknown */ Option[Long], + blksHit: /* nullability unknown */ Option[Long], + blksRead: /* nullability unknown */ Option[Long], + blksWritten: /* nullability unknown */ Option[Long], + blksExists: /* nullability unknown */ Option[Long], + flushes: /* nullability unknown */ Option[Long], + truncates: /* nullability unknown */ Option[Long], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatSlruViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatSlruViewRow] = new JdbcDecoder[PgStatSlruViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatSlruViewRow) = + columIndex + 8 -> + PgStatSlruViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + blksZeroed = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + blksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + blksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + blksWritten = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + blksExists = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + flushes = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + truncates = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatSlruViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blksZeroed = jsonObj.get("blks_zeroed").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksHit = jsonObj.get("blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksRead = jsonObj.get("blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksWritten = jsonObj.get("blks_written").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksExists = jsonObj.get("blks_exists").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val flushes = jsonObj.get("flushes").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val truncates = jsonObj.get("truncates").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (name.isRight && blksZeroed.isRight && blksHit.isRight && blksRead.isRight && blksWritten.isRight && blksExists.isRight && flushes.isRight && truncates.isRight && statsReset.isRight) + Right(PgStatSlruViewRow(name = name.toOption.get, blksZeroed = blksZeroed.toOption.get, blksHit = blksHit.toOption.get, blksRead = blksRead.toOption.get, blksWritten = blksWritten.toOption.get, blksExists = blksExists.toOption.get, flushes = flushes.toOption.get, truncates = truncates.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](name, blksZeroed, blksHit, blksRead, blksWritten, blksExists, flushes, truncates, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatSlruViewRow] = new JsonEncoder[PgStatSlruViewRow] { + override def unsafeEncode(a: PgStatSlruViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""blks_zeroed":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksZeroed, indent, out) + out.write(",") + out.write(""""blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksHit, indent, out) + out.write(",") + out.write(""""blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksRead, indent, out) + out.write(",") + out.write(""""blks_written":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksWritten, indent, out) + out.write(",") + out.write(""""blks_exists":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksExists, indent, out) + out.write(",") + out.write(""""flushes":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.flushes, indent, out) + out.write(",") + out.write(""""truncates":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.truncates, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewStructure.scala new file mode 100644 index 0000000000..351230f7ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_slru/PgStatSlruViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_slru + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatSlruViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatSlruViewRow, val merge: (Row, PgStatSlruViewRow) => Row) + extends Relation[PgStatSlruViewFields, PgStatSlruViewRow, Row] + with PgStatSlruViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val blksZeroed = new OptField[Long, Row](prefix, "blks_zeroed", None, None)(x => extract(x).blksZeroed, (row, value) => merge(row, extract(row).copy(blksZeroed = value))) + override val blksHit = new OptField[Long, Row](prefix, "blks_hit", None, None)(x => extract(x).blksHit, (row, value) => merge(row, extract(row).copy(blksHit = value))) + override val blksRead = new OptField[Long, Row](prefix, "blks_read", None, None)(x => extract(x).blksRead, (row, value) => merge(row, extract(row).copy(blksRead = value))) + override val blksWritten = new OptField[Long, Row](prefix, "blks_written", None, None)(x => extract(x).blksWritten, (row, value) => merge(row, extract(row).copy(blksWritten = value))) + override val blksExists = new OptField[Long, Row](prefix, "blks_exists", None, None)(x => extract(x).blksExists, (row, value) => merge(row, extract(row).copy(blksExists = value))) + override val flushes = new OptField[Long, Row](prefix, "flushes", None, None)(x => extract(x).flushes, (row, value) => merge(row, extract(row).copy(flushes = value))) + override val truncates = new OptField[Long, Row](prefix, "truncates", None, None)(x => extract(x).truncates, (row, value) => merge(row, extract(row).copy(truncates = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, blksZeroed, blksHit, blksRead, blksWritten, blksExists, flushes, truncates, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatSlruViewRow, merge: (NewRow, PgStatSlruViewRow) => NewRow): PgStatSlruViewStructure[NewRow] = + new PgStatSlruViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewFields.scala new file mode 100644 index 0000000000..c51c6f8de3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_ssl + +import typo.dsl.SqlExpr.OptField + +trait PgStatSslViewFields[Row] { + val pid: OptField[Int, Row] + val ssl: OptField[Boolean, Row] + val version: OptField[String, Row] + val cipher: OptField[String, Row] + val bits: OptField[Int, Row] + val clientDn: OptField[String, Row] + val clientSerial: OptField[BigDecimal, Row] + val issuerDn: OptField[String, Row] +} +object PgStatSslViewFields extends PgStatSslViewStructure[PgStatSslViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepo.scala new file mode 100644 index 0000000000..11efd59527 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_ssl + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatSslViewRepo { + def select: SelectBuilder[PgStatSslViewFields, PgStatSslViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatSslViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepoImpl.scala new file mode 100644 index 0000000000..8dc9b15878 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_ssl + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatSslViewRepoImpl extends PgStatSslViewRepo { + override def select: SelectBuilder[PgStatSslViewFields, PgStatSslViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_ssl", PgStatSslViewFields, PgStatSslViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatSslViewRow] = { + sql"""select "pid", "ssl", "version", "cipher", "bits", "client_dn", "client_serial", "issuer_dn" from pg_catalog.pg_stat_ssl""".query(PgStatSslViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRow.scala new file mode 100644 index 0000000000..b8b3009de3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_ssl + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatSslViewRow( + pid: /* nullability unknown */ Option[Int], + ssl: /* nullability unknown */ Option[Boolean], + version: /* nullability unknown */ Option[String], + cipher: /* nullability unknown */ Option[String], + bits: /* nullability unknown */ Option[Int], + clientDn: /* nullability unknown */ Option[String], + clientSerial: /* nullability unknown */ Option[BigDecimal], + issuerDn: /* nullability unknown */ Option[String] +) + +object PgStatSslViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatSslViewRow] = new JdbcDecoder[PgStatSslViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatSslViewRow) = + columIndex + 7 -> + PgStatSslViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + ssl = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 1, rs)._2, + version = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + cipher = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + bits = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 4, rs)._2, + clientDn = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + clientSerial = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 6, rs)._2, + issuerDn = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatSslViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val ssl = jsonObj.get("ssl").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val version = jsonObj.get("version").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val cipher = jsonObj.get("cipher").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val bits = jsonObj.get("bits").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val clientDn = jsonObj.get("client_dn").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val clientSerial = jsonObj.get("client_serial").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val issuerDn = jsonObj.get("issuer_dn").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (pid.isRight && ssl.isRight && version.isRight && cipher.isRight && bits.isRight && clientDn.isRight && clientSerial.isRight && issuerDn.isRight) + Right(PgStatSslViewRow(pid = pid.toOption.get, ssl = ssl.toOption.get, version = version.toOption.get, cipher = cipher.toOption.get, bits = bits.toOption.get, clientDn = clientDn.toOption.get, clientSerial = clientSerial.toOption.get, issuerDn = issuerDn.toOption.get)) + else Left(List[Either[String, Any]](pid, ssl, version, cipher, bits, clientDn, clientSerial, issuerDn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatSslViewRow] = new JsonEncoder[PgStatSslViewRow] { + override def unsafeEncode(a: PgStatSslViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""ssl":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.ssl, indent, out) + out.write(",") + out.write(""""version":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.version, indent, out) + out.write(",") + out.write(""""cipher":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.cipher, indent, out) + out.write(",") + out.write(""""bits":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.bits, indent, out) + out.write(",") + out.write(""""client_dn":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.clientDn, indent, out) + out.write(",") + out.write(""""client_serial":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.clientSerial, indent, out) + out.write(",") + out.write(""""issuer_dn":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.issuerDn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewStructure.scala new file mode 100644 index 0000000000..f0e9430618 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_ssl/PgStatSslViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_ssl + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatSslViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatSslViewRow, val merge: (Row, PgStatSslViewRow) => Row) + extends Relation[PgStatSslViewFields, PgStatSslViewRow, Row] + with PgStatSslViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val ssl = new OptField[Boolean, Row](prefix, "ssl", None, None)(x => extract(x).ssl, (row, value) => merge(row, extract(row).copy(ssl = value))) + override val version = new OptField[String, Row](prefix, "version", None, None)(x => extract(x).version, (row, value) => merge(row, extract(row).copy(version = value))) + override val cipher = new OptField[String, Row](prefix, "cipher", None, None)(x => extract(x).cipher, (row, value) => merge(row, extract(row).copy(cipher = value))) + override val bits = new OptField[Int, Row](prefix, "bits", None, None)(x => extract(x).bits, (row, value) => merge(row, extract(row).copy(bits = value))) + override val clientDn = new OptField[String, Row](prefix, "client_dn", None, None)(x => extract(x).clientDn, (row, value) => merge(row, extract(row).copy(clientDn = value))) + override val clientSerial = new OptField[BigDecimal, Row](prefix, "client_serial", None, None)(x => extract(x).clientSerial, (row, value) => merge(row, extract(row).copy(clientSerial = value))) + override val issuerDn = new OptField[String, Row](prefix, "issuer_dn", None, None)(x => extract(x).issuerDn, (row, value) => merge(row, extract(row).copy(issuerDn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, ssl, version, cipher, bits, clientDn, clientSerial, issuerDn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatSslViewRow, merge: (NewRow, PgStatSslViewRow) => NewRow): PgStatSslViewStructure[NewRow] = + new PgStatSslViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewFields.scala new file mode 100644 index 0000000000..7a08b7d6b7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_subscription + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatSubscriptionViewFields[Row] { + val subid: Field[PgSubscriptionId, Row] + val subname: Field[String, Row] + val pid: OptField[Int, Row] + val relid: OptField[/* oid */ Long, Row] + val receivedLsn: OptField[/* pg_lsn */ Long, Row] + val lastMsgSendTime: OptField[TypoInstant, Row] + val lastMsgReceiptTime: OptField[TypoInstant, Row] + val latestEndLsn: OptField[/* pg_lsn */ Long, Row] + val latestEndTime: OptField[TypoInstant, Row] +} +object PgStatSubscriptionViewFields extends PgStatSubscriptionViewStructure[PgStatSubscriptionViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepo.scala new file mode 100644 index 0000000000..84bae96197 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_subscription + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatSubscriptionViewRepo { + def select: SelectBuilder[PgStatSubscriptionViewFields, PgStatSubscriptionViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatSubscriptionViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepoImpl.scala new file mode 100644 index 0000000000..ebe4ff07ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_subscription + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatSubscriptionViewRepoImpl extends PgStatSubscriptionViewRepo { + override def select: SelectBuilder[PgStatSubscriptionViewFields, PgStatSubscriptionViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_subscription", PgStatSubscriptionViewFields, PgStatSubscriptionViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatSubscriptionViewRow] = { + sql"""select "subid", "subname", "pid", "relid", "received_lsn", "last_msg_send_time"::text, "last_msg_receipt_time"::text, "latest_end_lsn", "latest_end_time"::text from pg_catalog.pg_stat_subscription""".query(PgStatSubscriptionViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRow.scala new file mode 100644 index 0000000000..2f3e71c09d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewRow.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_subscription + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatSubscriptionViewRow( + /** Points to [[pg_subscription.PgSubscriptionRow.oid]] */ + subid: PgSubscriptionId, + /** Points to [[pg_subscription.PgSubscriptionRow.subname]] */ + subname: String, + pid: Option[Int], + relid: Option[/* oid */ Long], + receivedLsn: Option[/* pg_lsn */ Long], + lastMsgSendTime: Option[TypoInstant], + lastMsgReceiptTime: Option[TypoInstant], + latestEndLsn: Option[/* pg_lsn */ Long], + latestEndTime: Option[TypoInstant] +) + +object PgStatSubscriptionViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatSubscriptionViewRow] = new JdbcDecoder[PgStatSubscriptionViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatSubscriptionViewRow) = + columIndex + 8 -> + PgStatSubscriptionViewRow( + subid = PgSubscriptionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + subname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 2, rs)._2, + relid = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + receivedLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + lastMsgSendTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + lastMsgReceiptTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + latestEndLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + latestEndTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatSubscriptionViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val subid = jsonObj.get("subid").toRight("Missing field 'subid'").flatMap(_.as(PgSubscriptionId.jsonDecoder)) + val subname = jsonObj.get("subname").toRight("Missing field 'subname'").flatMap(_.as(JsonDecoder.string)) + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val relid = jsonObj.get("relid").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val receivedLsn = jsonObj.get("received_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastMsgSendTime = jsonObj.get("last_msg_send_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastMsgReceiptTime = jsonObj.get("last_msg_receipt_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val latestEndLsn = jsonObj.get("latest_end_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val latestEndTime = jsonObj.get("latest_end_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (subid.isRight && subname.isRight && pid.isRight && relid.isRight && receivedLsn.isRight && lastMsgSendTime.isRight && lastMsgReceiptTime.isRight && latestEndLsn.isRight && latestEndTime.isRight) + Right(PgStatSubscriptionViewRow(subid = subid.toOption.get, subname = subname.toOption.get, pid = pid.toOption.get, relid = relid.toOption.get, receivedLsn = receivedLsn.toOption.get, lastMsgSendTime = lastMsgSendTime.toOption.get, lastMsgReceiptTime = lastMsgReceiptTime.toOption.get, latestEndLsn = latestEndLsn.toOption.get, latestEndTime = latestEndTime.toOption.get)) + else Left(List[Either[String, Any]](subid, subname, pid, relid, receivedLsn, lastMsgSendTime, lastMsgReceiptTime, latestEndLsn, latestEndTime).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatSubscriptionViewRow] = new JsonEncoder[PgStatSubscriptionViewRow] { + override def unsafeEncode(a: PgStatSubscriptionViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""subid":""") + PgSubscriptionId.jsonEncoder.unsafeEncode(a.subid, indent, out) + out.write(",") + out.write(""""subname":""") + JsonEncoder.string.unsafeEncode(a.subname, indent, out) + out.write(",") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""relid":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""received_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.receivedLsn, indent, out) + out.write(",") + out.write(""""last_msg_send_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastMsgSendTime, indent, out) + out.write(",") + out.write(""""last_msg_receipt_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastMsgReceiptTime, indent, out) + out.write(",") + out.write(""""latest_end_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.latestEndLsn, indent, out) + out.write(",") + out.write(""""latest_end_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.latestEndTime, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewStructure.scala new file mode 100644 index 0000000000..aedaf33f8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_subscription/PgStatSubscriptionViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_subscription + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatSubscriptionViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatSubscriptionViewRow, val merge: (Row, PgStatSubscriptionViewRow) => Row) + extends Relation[PgStatSubscriptionViewFields, PgStatSubscriptionViewRow, Row] + with PgStatSubscriptionViewFields[Row] { outer => + + override val subid = new Field[PgSubscriptionId, Row](prefix, "subid", None, None)(x => extract(x).subid, (row, value) => merge(row, extract(row).copy(subid = value))) + override val subname = new Field[String, Row](prefix, "subname", None, None)(x => extract(x).subname, (row, value) => merge(row, extract(row).copy(subname = value))) + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val relid = new OptField[/* oid */ Long, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val receivedLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "received_lsn", None, None)(x => extract(x).receivedLsn, (row, value) => merge(row, extract(row).copy(receivedLsn = value))) + override val lastMsgSendTime = new OptField[TypoInstant, Row](prefix, "last_msg_send_time", Some("text"), None)(x => extract(x).lastMsgSendTime, (row, value) => merge(row, extract(row).copy(lastMsgSendTime = value))) + override val lastMsgReceiptTime = new OptField[TypoInstant, Row](prefix, "last_msg_receipt_time", Some("text"), None)(x => extract(x).lastMsgReceiptTime, (row, value) => merge(row, extract(row).copy(lastMsgReceiptTime = value))) + override val latestEndLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "latest_end_lsn", None, None)(x => extract(x).latestEndLsn, (row, value) => merge(row, extract(row).copy(latestEndLsn = value))) + override val latestEndTime = new OptField[TypoInstant, Row](prefix, "latest_end_time", Some("text"), None)(x => extract(x).latestEndTime, (row, value) => merge(row, extract(row).copy(latestEndTime = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](subid, subname, pid, relid, receivedLsn, lastMsgSendTime, lastMsgReceiptTime, latestEndLsn, latestEndTime) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatSubscriptionViewRow, merge: (NewRow, PgStatSubscriptionViewRow) => NewRow): PgStatSubscriptionViewStructure[NewRow] = + new PgStatSubscriptionViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewFields.scala new file mode 100644 index 0000000000..84da35427c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatSysIndexesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val indexrelid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val indexrelname: OptField[String, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupRead: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] +} +object PgStatSysIndexesViewFields extends PgStatSysIndexesViewStructure[PgStatSysIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepo.scala new file mode 100644 index 0000000000..8c55869b4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatSysIndexesViewRepo { + def select: SelectBuilder[PgStatSysIndexesViewFields, PgStatSysIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatSysIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..b4d0c5ac68 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatSysIndexesViewRepoImpl extends PgStatSysIndexesViewRepo { + override def select: SelectBuilder[PgStatSysIndexesViewFields, PgStatSysIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_sys_indexes", PgStatSysIndexesViewFields, PgStatSysIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatSysIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_scan", "idx_tup_read", "idx_tup_fetch" from pg_catalog.pg_stat_sys_indexes""".query(PgStatSysIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRow.scala new file mode 100644 index 0000000000..de51a4ebf4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewRow.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatSysIndexesViewRow( + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.indexrelid]] */ + indexrelid: Option[PgClassId], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.indexrelname]] */ + indexrelname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxTupRead]] */ + idxTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long] +) + +object PgStatSysIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatSysIndexesViewRow] = new JdbcDecoder[PgStatSysIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatSysIndexesViewRow) = + columIndex + 7 -> + PgStatSysIndexesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + indexrelid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatSysIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val indexrelid = jsonObj.get("indexrelid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val indexrelname = jsonObj.get("indexrelname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupRead = jsonObj.get("idx_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxScan.isRight && idxTupRead.isRight && idxTupFetch.isRight) + Right(PgStatSysIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxScan = idxScan.toOption.get, idxTupRead = idxTupRead.toOption.get, idxTupFetch = idxTupFetch.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatSysIndexesViewRow] = new JsonEncoder[PgStatSysIndexesViewRow] { + override def unsafeEncode(a: PgStatSysIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupRead, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewStructure.scala new file mode 100644 index 0000000000..554b710a39 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_indexes/PgStatSysIndexesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatSysIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatSysIndexesViewRow, val merge: (Row, PgStatSysIndexesViewRow) => Row) + extends Relation[PgStatSysIndexesViewFields, PgStatSysIndexesViewRow, Row] + with PgStatSysIndexesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new OptField[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new OptField[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_read", None, None)(x => extract(x).idxTupRead, (row, value) => merge(row, extract(row).copy(idxTupRead = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatSysIndexesViewRow, merge: (NewRow, PgStatSysIndexesViewRow) => NewRow): PgStatSysIndexesViewStructure[NewRow] = + new PgStatSysIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewFields.scala new file mode 100644 index 0000000000..46ec98a025 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewFields.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatSysTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val seqScan: OptField[/* nullability unknown */ Long, Row] + val seqTupRead: OptField[/* nullability unknown */ Long, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] + val nTupIns: OptField[/* nullability unknown */ Long, Row] + val nTupUpd: OptField[/* nullability unknown */ Long, Row] + val nTupDel: OptField[/* nullability unknown */ Long, Row] + val nTupHotUpd: OptField[/* nullability unknown */ Long, Row] + val nLiveTup: OptField[/* nullability unknown */ Long, Row] + val nDeadTup: OptField[/* nullability unknown */ Long, Row] + val nModSinceAnalyze: OptField[/* nullability unknown */ Long, Row] + val nInsSinceVacuum: OptField[/* nullability unknown */ Long, Row] + val lastVacuum: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAutovacuum: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAnalyze: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAutoanalyze: OptField[/* nullability unknown */ TypoInstant, Row] + val vacuumCount: OptField[/* nullability unknown */ Long, Row] + val autovacuumCount: OptField[/* nullability unknown */ Long, Row] + val analyzeCount: OptField[/* nullability unknown */ Long, Row] + val autoanalyzeCount: OptField[/* nullability unknown */ Long, Row] +} +object PgStatSysTablesViewFields extends PgStatSysTablesViewStructure[PgStatSysTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepo.scala new file mode 100644 index 0000000000..2e6d988319 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatSysTablesViewRepo { + def select: SelectBuilder[PgStatSysTablesViewFields, PgStatSysTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatSysTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepoImpl.scala new file mode 100644 index 0000000000..4b7c7b5cad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatSysTablesViewRepoImpl extends PgStatSysTablesViewRepo { + override def select: SelectBuilder[PgStatSysTablesViewFields, PgStatSysTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_sys_tables", PgStatSysTablesViewFields, PgStatSysTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatSysTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd", "n_live_tup", "n_dead_tup", "n_mod_since_analyze", "n_ins_since_vacuum", "last_vacuum"::text, "last_autovacuum"::text, "last_analyze"::text, "last_autoanalyze"::text, "vacuum_count", "autovacuum_count", "analyze_count", "autoanalyze_count" from pg_catalog.pg_stat_sys_tables""".query(PgStatSysTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRow.scala new file mode 100644 index 0000000000..6a8743d751 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewRow.scala @@ -0,0 +1,200 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatSysTablesViewRow( + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.seqScan]] */ + seqScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.seqTupRead]] */ + seqTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupIns]] */ + nTupIns: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupUpd]] */ + nTupUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupDel]] */ + nTupDel: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupHotUpd]] */ + nTupHotUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nLiveTup]] */ + nLiveTup: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nDeadTup]] */ + nDeadTup: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nModSinceAnalyze]] */ + nModSinceAnalyze: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nInsSinceVacuum]] */ + nInsSinceVacuum: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastVacuum]] */ + lastVacuum: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAutovacuum]] */ + lastAutovacuum: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAnalyze]] */ + lastAnalyze: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAutoanalyze]] */ + lastAutoanalyze: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.vacuumCount]] */ + vacuumCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.autovacuumCount]] */ + autovacuumCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.analyzeCount]] */ + analyzeCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.autoanalyzeCount]] */ + autoanalyzeCount: Option[/* nullability unknown */ Long] +) + +object PgStatSysTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatSysTablesViewRow] = new JdbcDecoder[PgStatSysTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatSysTablesViewRow) = + columIndex + 22 -> + PgStatSysTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + nLiveTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + nDeadTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + nModSinceAnalyze = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + nInsSinceVacuum = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + lastVacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + lastAutovacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + lastAnalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + lastAutoanalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + vacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 19, rs)._2, + autovacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 20, rs)._2, + analyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 21, rs)._2, + autoanalyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 22, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatSysTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nLiveTup = jsonObj.get("n_live_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nDeadTup = jsonObj.get("n_dead_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nModSinceAnalyze = jsonObj.get("n_mod_since_analyze").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nInsSinceVacuum = jsonObj.get("n_ins_since_vacuum").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastVacuum = jsonObj.get("last_vacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutovacuum = jsonObj.get("last_autovacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAnalyze = jsonObj.get("last_analyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutoanalyze = jsonObj.get("last_autoanalyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val vacuumCount = jsonObj.get("vacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autovacuumCount = jsonObj.get("autovacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val analyzeCount = jsonObj.get("analyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autoanalyzeCount = jsonObj.get("autoanalyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight && nLiveTup.isRight && nDeadTup.isRight && nModSinceAnalyze.isRight && nInsSinceVacuum.isRight && lastVacuum.isRight && lastAutovacuum.isRight && lastAnalyze.isRight && lastAutoanalyze.isRight && vacuumCount.isRight && autovacuumCount.isRight && analyzeCount.isRight && autoanalyzeCount.isRight) + Right(PgStatSysTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get, nLiveTup = nLiveTup.toOption.get, nDeadTup = nDeadTup.toOption.get, nModSinceAnalyze = nModSinceAnalyze.toOption.get, nInsSinceVacuum = nInsSinceVacuum.toOption.get, lastVacuum = lastVacuum.toOption.get, lastAutovacuum = lastAutovacuum.toOption.get, lastAnalyze = lastAnalyze.toOption.get, lastAutoanalyze = lastAutoanalyze.toOption.get, vacuumCount = vacuumCount.toOption.get, autovacuumCount = autovacuumCount.toOption.get, analyzeCount = analyzeCount.toOption.get, autoanalyzeCount = autoanalyzeCount.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatSysTablesViewRow] = new JsonEncoder[PgStatSysTablesViewRow] { + override def unsafeEncode(a: PgStatSysTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write(",") + out.write(""""n_live_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nLiveTup, indent, out) + out.write(",") + out.write(""""n_dead_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nDeadTup, indent, out) + out.write(",") + out.write(""""n_mod_since_analyze":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nModSinceAnalyze, indent, out) + out.write(",") + out.write(""""n_ins_since_vacuum":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nInsSinceVacuum, indent, out) + out.write(",") + out.write(""""last_vacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastVacuum, indent, out) + out.write(",") + out.write(""""last_autovacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutovacuum, indent, out) + out.write(",") + out.write(""""last_analyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAnalyze, indent, out) + out.write(",") + out.write(""""last_autoanalyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutoanalyze, indent, out) + out.write(",") + out.write(""""vacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.vacuumCount, indent, out) + out.write(",") + out.write(""""autovacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autovacuumCount, indent, out) + out.write(",") + out.write(""""analyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.analyzeCount, indent, out) + out.write(",") + out.write(""""autoanalyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autoanalyzeCount, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewStructure.scala new file mode 100644 index 0000000000..cecdf1788c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_sys_tables/PgStatSysTablesViewStructure.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_sys_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatSysTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatSysTablesViewRow, val merge: (Row, PgStatSysTablesViewRow) => Row) + extends Relation[PgStatSysTablesViewFields, PgStatSysTablesViewRow, Row] + with PgStatSysTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + override val nLiveTup = new OptField[/* nullability unknown */ Long, Row](prefix, "n_live_tup", None, None)(x => extract(x).nLiveTup, (row, value) => merge(row, extract(row).copy(nLiveTup = value))) + override val nDeadTup = new OptField[/* nullability unknown */ Long, Row](prefix, "n_dead_tup", None, None)(x => extract(x).nDeadTup, (row, value) => merge(row, extract(row).copy(nDeadTup = value))) + override val nModSinceAnalyze = new OptField[/* nullability unknown */ Long, Row](prefix, "n_mod_since_analyze", None, None)(x => extract(x).nModSinceAnalyze, (row, value) => merge(row, extract(row).copy(nModSinceAnalyze = value))) + override val nInsSinceVacuum = new OptField[/* nullability unknown */ Long, Row](prefix, "n_ins_since_vacuum", None, None)(x => extract(x).nInsSinceVacuum, (row, value) => merge(row, extract(row).copy(nInsSinceVacuum = value))) + override val lastVacuum = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_vacuum", Some("text"), None)(x => extract(x).lastVacuum, (row, value) => merge(row, extract(row).copy(lastVacuum = value))) + override val lastAutovacuum = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_autovacuum", Some("text"), None)(x => extract(x).lastAutovacuum, (row, value) => merge(row, extract(row).copy(lastAutovacuum = value))) + override val lastAnalyze = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_analyze", Some("text"), None)(x => extract(x).lastAnalyze, (row, value) => merge(row, extract(row).copy(lastAnalyze = value))) + override val lastAutoanalyze = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_autoanalyze", Some("text"), None)(x => extract(x).lastAutoanalyze, (row, value) => merge(row, extract(row).copy(lastAutoanalyze = value))) + override val vacuumCount = new OptField[/* nullability unknown */ Long, Row](prefix, "vacuum_count", None, None)(x => extract(x).vacuumCount, (row, value) => merge(row, extract(row).copy(vacuumCount = value))) + override val autovacuumCount = new OptField[/* nullability unknown */ Long, Row](prefix, "autovacuum_count", None, None)(x => extract(x).autovacuumCount, (row, value) => merge(row, extract(row).copy(autovacuumCount = value))) + override val analyzeCount = new OptField[/* nullability unknown */ Long, Row](prefix, "analyze_count", None, None)(x => extract(x).analyzeCount, (row, value) => merge(row, extract(row).copy(analyzeCount = value))) + override val autoanalyzeCount = new OptField[/* nullability unknown */ Long, Row](prefix, "autoanalyze_count", None, None)(x => extract(x).autoanalyzeCount, (row, value) => merge(row, extract(row).copy(autoanalyzeCount = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatSysTablesViewRow, merge: (NewRow, PgStatSysTablesViewRow) => NewRow): PgStatSysTablesViewStructure[NewRow] = + new PgStatSysTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewFields.scala new file mode 100644 index 0000000000..8cada6ee83 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatUserFunctionsViewFields[Row] { + val funcid: Field[PgProcId, Row] + val schemaname: OptField[String, Row] + val funcname: Field[String, Row] + val calls: OptField[Long, Row] + val totalTime: OptField[Double, Row] + val selfTime: OptField[Double, Row] +} +object PgStatUserFunctionsViewFields extends PgStatUserFunctionsViewStructure[PgStatUserFunctionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepo.scala new file mode 100644 index 0000000000..3d4086043f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_functions + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatUserFunctionsViewRepo { + def select: SelectBuilder[PgStatUserFunctionsViewFields, PgStatUserFunctionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatUserFunctionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepoImpl.scala new file mode 100644 index 0000000000..b2c290c103 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_functions + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatUserFunctionsViewRepoImpl extends PgStatUserFunctionsViewRepo { + override def select: SelectBuilder[PgStatUserFunctionsViewFields, PgStatUserFunctionsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_user_functions", PgStatUserFunctionsViewFields, PgStatUserFunctionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatUserFunctionsViewRow] = { + sql"""select "funcid", "schemaname", "funcname", "calls", "total_time", "self_time" from pg_catalog.pg_stat_user_functions""".query(PgStatUserFunctionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRow.scala new file mode 100644 index 0000000000..05fa4fde82 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewRow.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatUserFunctionsViewRow( + /** Points to [[pg_proc.PgProcRow.oid]] */ + funcid: PgProcId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_proc.PgProcRow.proname]] */ + funcname: String, + calls: /* nullability unknown */ Option[Long], + totalTime: /* nullability unknown */ Option[Double], + selfTime: /* nullability unknown */ Option[Double] +) + +object PgStatUserFunctionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatUserFunctionsViewRow] = new JdbcDecoder[PgStatUserFunctionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatUserFunctionsViewRow) = + columIndex + 5 -> + PgStatUserFunctionsViewRow( + funcid = PgProcId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + funcname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + calls = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + totalTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 4, rs)._2, + selfTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatUserFunctionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val funcid = jsonObj.get("funcid").toRight("Missing field 'funcid'").flatMap(_.as(PgProcId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val funcname = jsonObj.get("funcname").toRight("Missing field 'funcname'").flatMap(_.as(JsonDecoder.string)) + val calls = jsonObj.get("calls").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val totalTime = jsonObj.get("total_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val selfTime = jsonObj.get("self_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + if (funcid.isRight && schemaname.isRight && funcname.isRight && calls.isRight && totalTime.isRight && selfTime.isRight) + Right(PgStatUserFunctionsViewRow(funcid = funcid.toOption.get, schemaname = schemaname.toOption.get, funcname = funcname.toOption.get, calls = calls.toOption.get, totalTime = totalTime.toOption.get, selfTime = selfTime.toOption.get)) + else Left(List[Either[String, Any]](funcid, schemaname, funcname, calls, totalTime, selfTime).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatUserFunctionsViewRow] = new JsonEncoder[PgStatUserFunctionsViewRow] { + override def unsafeEncode(a: PgStatUserFunctionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""funcid":""") + PgProcId.jsonEncoder.unsafeEncode(a.funcid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""funcname":""") + JsonEncoder.string.unsafeEncode(a.funcname, indent, out) + out.write(",") + out.write(""""calls":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.calls, indent, out) + out.write(",") + out.write(""""total_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.totalTime, indent, out) + out.write(",") + out.write(""""self_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.selfTime, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewStructure.scala new file mode 100644 index 0000000000..da8396b4da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_functions/PgStatUserFunctionsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatUserFunctionsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatUserFunctionsViewRow, val merge: (Row, PgStatUserFunctionsViewRow) => Row) + extends Relation[PgStatUserFunctionsViewFields, PgStatUserFunctionsViewRow, Row] + with PgStatUserFunctionsViewFields[Row] { outer => + + override val funcid = new Field[PgProcId, Row](prefix, "funcid", None, None)(x => extract(x).funcid, (row, value) => merge(row, extract(row).copy(funcid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val funcname = new Field[String, Row](prefix, "funcname", None, None)(x => extract(x).funcname, (row, value) => merge(row, extract(row).copy(funcname = value))) + override val calls = new OptField[Long, Row](prefix, "calls", None, None)(x => extract(x).calls, (row, value) => merge(row, extract(row).copy(calls = value))) + override val totalTime = new OptField[Double, Row](prefix, "total_time", None, None)(x => extract(x).totalTime, (row, value) => merge(row, extract(row).copy(totalTime = value))) + override val selfTime = new OptField[Double, Row](prefix, "self_time", None, None)(x => extract(x).selfTime, (row, value) => merge(row, extract(row).copy(selfTime = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](funcid, schemaname, funcname, calls, totalTime, selfTime) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatUserFunctionsViewRow, merge: (NewRow, PgStatUserFunctionsViewRow) => NewRow): PgStatUserFunctionsViewStructure[NewRow] = + new PgStatUserFunctionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewFields.scala new file mode 100644 index 0000000000..6f863a1fa7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatUserIndexesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val indexrelid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val indexrelname: OptField[String, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupRead: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] +} +object PgStatUserIndexesViewFields extends PgStatUserIndexesViewStructure[PgStatUserIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepo.scala new file mode 100644 index 0000000000..d97cfc2647 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatUserIndexesViewRepo { + def select: SelectBuilder[PgStatUserIndexesViewFields, PgStatUserIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatUserIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..9275f18e15 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatUserIndexesViewRepoImpl extends PgStatUserIndexesViewRepo { + override def select: SelectBuilder[PgStatUserIndexesViewFields, PgStatUserIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_user_indexes", PgStatUserIndexesViewFields, PgStatUserIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatUserIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_scan", "idx_tup_read", "idx_tup_fetch" from pg_catalog.pg_stat_user_indexes""".query(PgStatUserIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRow.scala new file mode 100644 index 0000000000..7772c08bd3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewRow.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatUserIndexesViewRow( + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.indexrelid]] */ + indexrelid: Option[PgClassId], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.indexrelname]] */ + indexrelname: Option[String], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxTupRead]] */ + idxTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_indexes.PgStatAllIndexesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long] +) + +object PgStatUserIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatUserIndexesViewRow] = new JdbcDecoder[PgStatUserIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatUserIndexesViewRow) = + columIndex + 7 -> + PgStatUserIndexesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + indexrelid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatUserIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val indexrelid = jsonObj.get("indexrelid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val indexrelname = jsonObj.get("indexrelname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupRead = jsonObj.get("idx_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxScan.isRight && idxTupRead.isRight && idxTupFetch.isRight) + Right(PgStatUserIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxScan = idxScan.toOption.get, idxTupRead = idxTupRead.toOption.get, idxTupFetch = idxTupFetch.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatUserIndexesViewRow] = new JsonEncoder[PgStatUserIndexesViewRow] { + override def unsafeEncode(a: PgStatUserIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupRead, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewStructure.scala new file mode 100644 index 0000000000..c22f67b589 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_indexes/PgStatUserIndexesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatUserIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatUserIndexesViewRow, val merge: (Row, PgStatUserIndexesViewRow) => Row) + extends Relation[PgStatUserIndexesViewFields, PgStatUserIndexesViewRow, Row] + with PgStatUserIndexesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new OptField[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new OptField[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_read", None, None)(x => extract(x).idxTupRead, (row, value) => merge(row, extract(row).copy(idxTupRead = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxScan, idxTupRead, idxTupFetch) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatUserIndexesViewRow, merge: (NewRow, PgStatUserIndexesViewRow) => NewRow): PgStatUserIndexesViewStructure[NewRow] = + new PgStatUserIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewFields.scala new file mode 100644 index 0000000000..d4d86cc6cb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewFields.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatUserTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val seqScan: OptField[/* nullability unknown */ Long, Row] + val seqTupRead: OptField[/* nullability unknown */ Long, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] + val nTupIns: OptField[/* nullability unknown */ Long, Row] + val nTupUpd: OptField[/* nullability unknown */ Long, Row] + val nTupDel: OptField[/* nullability unknown */ Long, Row] + val nTupHotUpd: OptField[/* nullability unknown */ Long, Row] + val nLiveTup: OptField[/* nullability unknown */ Long, Row] + val nDeadTup: OptField[/* nullability unknown */ Long, Row] + val nModSinceAnalyze: OptField[/* nullability unknown */ Long, Row] + val nInsSinceVacuum: OptField[/* nullability unknown */ Long, Row] + val lastVacuum: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAutovacuum: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAnalyze: OptField[/* nullability unknown */ TypoInstant, Row] + val lastAutoanalyze: OptField[/* nullability unknown */ TypoInstant, Row] + val vacuumCount: OptField[/* nullability unknown */ Long, Row] + val autovacuumCount: OptField[/* nullability unknown */ Long, Row] + val analyzeCount: OptField[/* nullability unknown */ Long, Row] + val autoanalyzeCount: OptField[/* nullability unknown */ Long, Row] +} +object PgStatUserTablesViewFields extends PgStatUserTablesViewStructure[PgStatUserTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepo.scala new file mode 100644 index 0000000000..7ba1b63386 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatUserTablesViewRepo { + def select: SelectBuilder[PgStatUserTablesViewFields, PgStatUserTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatUserTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepoImpl.scala new file mode 100644 index 0000000000..d6996dc254 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatUserTablesViewRepoImpl extends PgStatUserTablesViewRepo { + override def select: SelectBuilder[PgStatUserTablesViewFields, PgStatUserTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_user_tables", PgStatUserTablesViewFields, PgStatUserTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatUserTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd", "n_live_tup", "n_dead_tup", "n_mod_since_analyze", "n_ins_since_vacuum", "last_vacuum"::text, "last_autovacuum"::text, "last_analyze"::text, "last_autoanalyze"::text, "vacuum_count", "autovacuum_count", "analyze_count", "autoanalyze_count" from pg_catalog.pg_stat_user_tables""".query(PgStatUserTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRow.scala new file mode 100644 index 0000000000..587df5780f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewRow.scala @@ -0,0 +1,200 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatUserTablesViewRow( + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.seqScan]] */ + seqScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.seqTupRead]] */ + seqTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupIns]] */ + nTupIns: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupUpd]] */ + nTupUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupDel]] */ + nTupDel: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nTupHotUpd]] */ + nTupHotUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nLiveTup]] */ + nLiveTup: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nDeadTup]] */ + nDeadTup: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nModSinceAnalyze]] */ + nModSinceAnalyze: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.nInsSinceVacuum]] */ + nInsSinceVacuum: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastVacuum]] */ + lastVacuum: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAutovacuum]] */ + lastAutovacuum: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAnalyze]] */ + lastAnalyze: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.lastAutoanalyze]] */ + lastAutoanalyze: Option[/* nullability unknown */ TypoInstant], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.vacuumCount]] */ + vacuumCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.autovacuumCount]] */ + autovacuumCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.analyzeCount]] */ + analyzeCount: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_all_tables.PgStatAllTablesViewRow.autoanalyzeCount]] */ + autoanalyzeCount: Option[/* nullability unknown */ Long] +) + +object PgStatUserTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatUserTablesViewRow] = new JdbcDecoder[PgStatUserTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatUserTablesViewRow) = + columIndex + 22 -> + PgStatUserTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2, + nLiveTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 11, rs)._2, + nDeadTup = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 12, rs)._2, + nModSinceAnalyze = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 13, rs)._2, + nInsSinceVacuum = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + lastVacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + lastAutovacuum = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + lastAnalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + lastAutoanalyze = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + vacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 19, rs)._2, + autovacuumCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 20, rs)._2, + analyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 21, rs)._2, + autoanalyzeCount = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 22, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatUserTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nLiveTup = jsonObj.get("n_live_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nDeadTup = jsonObj.get("n_dead_tup").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nModSinceAnalyze = jsonObj.get("n_mod_since_analyze").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nInsSinceVacuum = jsonObj.get("n_ins_since_vacuum").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val lastVacuum = jsonObj.get("last_vacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutovacuum = jsonObj.get("last_autovacuum").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAnalyze = jsonObj.get("last_analyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastAutoanalyze = jsonObj.get("last_autoanalyze").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val vacuumCount = jsonObj.get("vacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autovacuumCount = jsonObj.get("autovacuum_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val analyzeCount = jsonObj.get("analyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val autoanalyzeCount = jsonObj.get("autoanalyze_count").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight && nLiveTup.isRight && nDeadTup.isRight && nModSinceAnalyze.isRight && nInsSinceVacuum.isRight && lastVacuum.isRight && lastAutovacuum.isRight && lastAnalyze.isRight && lastAutoanalyze.isRight && vacuumCount.isRight && autovacuumCount.isRight && analyzeCount.isRight && autoanalyzeCount.isRight) + Right(PgStatUserTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get, nLiveTup = nLiveTup.toOption.get, nDeadTup = nDeadTup.toOption.get, nModSinceAnalyze = nModSinceAnalyze.toOption.get, nInsSinceVacuum = nInsSinceVacuum.toOption.get, lastVacuum = lastVacuum.toOption.get, lastAutovacuum = lastAutovacuum.toOption.get, lastAnalyze = lastAnalyze.toOption.get, lastAutoanalyze = lastAutoanalyze.toOption.get, vacuumCount = vacuumCount.toOption.get, autovacuumCount = autovacuumCount.toOption.get, analyzeCount = analyzeCount.toOption.get, autoanalyzeCount = autoanalyzeCount.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatUserTablesViewRow] = new JsonEncoder[PgStatUserTablesViewRow] { + override def unsafeEncode(a: PgStatUserTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write(",") + out.write(""""n_live_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nLiveTup, indent, out) + out.write(",") + out.write(""""n_dead_tup":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nDeadTup, indent, out) + out.write(",") + out.write(""""n_mod_since_analyze":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nModSinceAnalyze, indent, out) + out.write(",") + out.write(""""n_ins_since_vacuum":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nInsSinceVacuum, indent, out) + out.write(",") + out.write(""""last_vacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastVacuum, indent, out) + out.write(",") + out.write(""""last_autovacuum":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutovacuum, indent, out) + out.write(",") + out.write(""""last_analyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAnalyze, indent, out) + out.write(",") + out.write(""""last_autoanalyze":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastAutoanalyze, indent, out) + out.write(",") + out.write(""""vacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.vacuumCount, indent, out) + out.write(",") + out.write(""""autovacuum_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autovacuumCount, indent, out) + out.write(",") + out.write(""""analyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.analyzeCount, indent, out) + out.write(",") + out.write(""""autoanalyze_count":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.autoanalyzeCount, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewStructure.scala new file mode 100644 index 0000000000..fa33846ec8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_user_tables/PgStatUserTablesViewStructure.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_user_tables + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatUserTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatUserTablesViewRow, val merge: (Row, PgStatUserTablesViewRow) => Row) + extends Relation[PgStatUserTablesViewFields, PgStatUserTablesViewRow, Row] + with PgStatUserTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + override val nLiveTup = new OptField[/* nullability unknown */ Long, Row](prefix, "n_live_tup", None, None)(x => extract(x).nLiveTup, (row, value) => merge(row, extract(row).copy(nLiveTup = value))) + override val nDeadTup = new OptField[/* nullability unknown */ Long, Row](prefix, "n_dead_tup", None, None)(x => extract(x).nDeadTup, (row, value) => merge(row, extract(row).copy(nDeadTup = value))) + override val nModSinceAnalyze = new OptField[/* nullability unknown */ Long, Row](prefix, "n_mod_since_analyze", None, None)(x => extract(x).nModSinceAnalyze, (row, value) => merge(row, extract(row).copy(nModSinceAnalyze = value))) + override val nInsSinceVacuum = new OptField[/* nullability unknown */ Long, Row](prefix, "n_ins_since_vacuum", None, None)(x => extract(x).nInsSinceVacuum, (row, value) => merge(row, extract(row).copy(nInsSinceVacuum = value))) + override val lastVacuum = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_vacuum", Some("text"), None)(x => extract(x).lastVacuum, (row, value) => merge(row, extract(row).copy(lastVacuum = value))) + override val lastAutovacuum = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_autovacuum", Some("text"), None)(x => extract(x).lastAutovacuum, (row, value) => merge(row, extract(row).copy(lastAutovacuum = value))) + override val lastAnalyze = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_analyze", Some("text"), None)(x => extract(x).lastAnalyze, (row, value) => merge(row, extract(row).copy(lastAnalyze = value))) + override val lastAutoanalyze = new OptField[/* nullability unknown */ TypoInstant, Row](prefix, "last_autoanalyze", Some("text"), None)(x => extract(x).lastAutoanalyze, (row, value) => merge(row, extract(row).copy(lastAutoanalyze = value))) + override val vacuumCount = new OptField[/* nullability unknown */ Long, Row](prefix, "vacuum_count", None, None)(x => extract(x).vacuumCount, (row, value) => merge(row, extract(row).copy(vacuumCount = value))) + override val autovacuumCount = new OptField[/* nullability unknown */ Long, Row](prefix, "autovacuum_count", None, None)(x => extract(x).autovacuumCount, (row, value) => merge(row, extract(row).copy(autovacuumCount = value))) + override val analyzeCount = new OptField[/* nullability unknown */ Long, Row](prefix, "analyze_count", None, None)(x => extract(x).analyzeCount, (row, value) => merge(row, extract(row).copy(analyzeCount = value))) + override val autoanalyzeCount = new OptField[/* nullability unknown */ Long, Row](prefix, "autoanalyze_count", None, None)(x => extract(x).autoanalyzeCount, (row, value) => merge(row, extract(row).copy(autoanalyzeCount = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd, nLiveTup, nDeadTup, nModSinceAnalyze, nInsSinceVacuum, lastVacuum, lastAutovacuum, lastAnalyze, lastAutoanalyze, vacuumCount, autovacuumCount, analyzeCount, autoanalyzeCount) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatUserTablesViewRow, merge: (NewRow, PgStatUserTablesViewRow) => NewRow): PgStatUserTablesViewStructure[NewRow] = + new PgStatUserTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewFields.scala new file mode 100644 index 0000000000..c8eafe78a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatWalViewFields[Row] { + val walRecords: OptField[Long, Row] + val walFpi: OptField[Long, Row] + val walBytes: OptField[BigDecimal, Row] + val walBuffersFull: OptField[Long, Row] + val walWrite: OptField[Long, Row] + val walSync: OptField[Long, Row] + val walWriteTime: OptField[Double, Row] + val walSyncTime: OptField[Double, Row] + val statsReset: OptField[TypoInstant, Row] +} +object PgStatWalViewFields extends PgStatWalViewStructure[PgStatWalViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepo.scala new file mode 100644 index 0000000000..0aca22fb79 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatWalViewRepo { + def select: SelectBuilder[PgStatWalViewFields, PgStatWalViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatWalViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepoImpl.scala new file mode 100644 index 0000000000..30fa2dd9eb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatWalViewRepoImpl extends PgStatWalViewRepo { + override def select: SelectBuilder[PgStatWalViewFields, PgStatWalViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_wal", PgStatWalViewFields, PgStatWalViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatWalViewRow] = { + sql"""select "wal_records", "wal_fpi", "wal_bytes", "wal_buffers_full", "wal_write", "wal_sync", "wal_write_time", "wal_sync_time", "stats_reset"::text from pg_catalog.pg_stat_wal""".query(PgStatWalViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRow.scala new file mode 100644 index 0000000000..87bce90d08 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewRow.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatWalViewRow( + walRecords: /* nullability unknown */ Option[Long], + walFpi: /* nullability unknown */ Option[Long], + walBytes: /* nullability unknown */ Option[BigDecimal], + walBuffersFull: /* nullability unknown */ Option[Long], + walWrite: /* nullability unknown */ Option[Long], + walSync: /* nullability unknown */ Option[Long], + walWriteTime: /* nullability unknown */ Option[Double], + walSyncTime: /* nullability unknown */ Option[Double], + statsReset: /* nullability unknown */ Option[TypoInstant] +) + +object PgStatWalViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatWalViewRow] = new JdbcDecoder[PgStatWalViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatWalViewRow) = + columIndex + 8 -> + PgStatWalViewRow( + walRecords = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 0, rs)._2, + walFpi = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 1, rs)._2, + walBytes = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 2, rs)._2, + walBuffersFull = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + walWrite = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + walSync = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + walWriteTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 6, rs)._2, + walSyncTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 7, rs)._2, + statsReset = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatWalViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val walRecords = jsonObj.get("wal_records").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walFpi = jsonObj.get("wal_fpi").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walBytes = jsonObj.get("wal_bytes").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val walBuffersFull = jsonObj.get("wal_buffers_full").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walWrite = jsonObj.get("wal_write").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walSync = jsonObj.get("wal_sync").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val walWriteTime = jsonObj.get("wal_write_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val walSyncTime = jsonObj.get("wal_sync_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val statsReset = jsonObj.get("stats_reset").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (walRecords.isRight && walFpi.isRight && walBytes.isRight && walBuffersFull.isRight && walWrite.isRight && walSync.isRight && walWriteTime.isRight && walSyncTime.isRight && statsReset.isRight) + Right(PgStatWalViewRow(walRecords = walRecords.toOption.get, walFpi = walFpi.toOption.get, walBytes = walBytes.toOption.get, walBuffersFull = walBuffersFull.toOption.get, walWrite = walWrite.toOption.get, walSync = walSync.toOption.get, walWriteTime = walWriteTime.toOption.get, walSyncTime = walSyncTime.toOption.get, statsReset = statsReset.toOption.get)) + else Left(List[Either[String, Any]](walRecords, walFpi, walBytes, walBuffersFull, walWrite, walSync, walWriteTime, walSyncTime, statsReset).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatWalViewRow] = new JsonEncoder[PgStatWalViewRow] { + override def unsafeEncode(a: PgStatWalViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""wal_records":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.walRecords, indent, out) + out.write(",") + out.write(""""wal_fpi":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.walFpi, indent, out) + out.write(",") + out.write(""""wal_bytes":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.walBytes, indent, out) + out.write(",") + out.write(""""wal_buffers_full":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.walBuffersFull, indent, out) + out.write(",") + out.write(""""wal_write":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.walWrite, indent, out) + out.write(",") + out.write(""""wal_sync":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.walSync, indent, out) + out.write(",") + out.write(""""wal_write_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.walWriteTime, indent, out) + out.write(",") + out.write(""""wal_sync_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.walSyncTime, indent, out) + out.write(",") + out.write(""""stats_reset":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.statsReset, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewStructure.scala new file mode 100644 index 0000000000..2059e65fc5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal/PgStatWalViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatWalViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatWalViewRow, val merge: (Row, PgStatWalViewRow) => Row) + extends Relation[PgStatWalViewFields, PgStatWalViewRow, Row] + with PgStatWalViewFields[Row] { outer => + + override val walRecords = new OptField[Long, Row](prefix, "wal_records", None, None)(x => extract(x).walRecords, (row, value) => merge(row, extract(row).copy(walRecords = value))) + override val walFpi = new OptField[Long, Row](prefix, "wal_fpi", None, None)(x => extract(x).walFpi, (row, value) => merge(row, extract(row).copy(walFpi = value))) + override val walBytes = new OptField[BigDecimal, Row](prefix, "wal_bytes", None, None)(x => extract(x).walBytes, (row, value) => merge(row, extract(row).copy(walBytes = value))) + override val walBuffersFull = new OptField[Long, Row](prefix, "wal_buffers_full", None, None)(x => extract(x).walBuffersFull, (row, value) => merge(row, extract(row).copy(walBuffersFull = value))) + override val walWrite = new OptField[Long, Row](prefix, "wal_write", None, None)(x => extract(x).walWrite, (row, value) => merge(row, extract(row).copy(walWrite = value))) + override val walSync = new OptField[Long, Row](prefix, "wal_sync", None, None)(x => extract(x).walSync, (row, value) => merge(row, extract(row).copy(walSync = value))) + override val walWriteTime = new OptField[Double, Row](prefix, "wal_write_time", None, None)(x => extract(x).walWriteTime, (row, value) => merge(row, extract(row).copy(walWriteTime = value))) + override val walSyncTime = new OptField[Double, Row](prefix, "wal_sync_time", None, None)(x => extract(x).walSyncTime, (row, value) => merge(row, extract(row).copy(walSyncTime = value))) + override val statsReset = new OptField[TypoInstant, Row](prefix, "stats_reset", Some("text"), None)(x => extract(x).statsReset, (row, value) => merge(row, extract(row).copy(statsReset = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](walRecords, walFpi, walBytes, walBuffersFull, walWrite, walSync, walWriteTime, walSyncTime, statsReset) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatWalViewRow, merge: (NewRow, PgStatWalViewRow) => NewRow): PgStatWalViewStructure[NewRow] = + new PgStatWalViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewFields.scala new file mode 100644 index 0000000000..73b10f6758 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal_receiver + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.OptField + +trait PgStatWalReceiverViewFields[Row] { + val pid: OptField[Int, Row] + val status: OptField[String, Row] + val receiveStartLsn: OptField[/* pg_lsn */ Long, Row] + val receiveStartTli: OptField[Int, Row] + val writtenLsn: OptField[/* pg_lsn */ Long, Row] + val flushedLsn: OptField[/* pg_lsn */ Long, Row] + val receivedTli: OptField[Int, Row] + val lastMsgSendTime: OptField[TypoInstant, Row] + val lastMsgReceiptTime: OptField[TypoInstant, Row] + val latestEndLsn: OptField[/* pg_lsn */ Long, Row] + val latestEndTime: OptField[TypoInstant, Row] + val slotName: OptField[String, Row] + val senderHost: OptField[String, Row] + val senderPort: OptField[Int, Row] + val conninfo: OptField[String, Row] +} +object PgStatWalReceiverViewFields extends PgStatWalReceiverViewStructure[PgStatWalReceiverViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepo.scala new file mode 100644 index 0000000000..5adef09bfa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal_receiver + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatWalReceiverViewRepo { + def select: SelectBuilder[PgStatWalReceiverViewFields, PgStatWalReceiverViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatWalReceiverViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepoImpl.scala new file mode 100644 index 0000000000..3575b324b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal_receiver + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatWalReceiverViewRepoImpl extends PgStatWalReceiverViewRepo { + override def select: SelectBuilder[PgStatWalReceiverViewFields, PgStatWalReceiverViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_wal_receiver", PgStatWalReceiverViewFields, PgStatWalReceiverViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatWalReceiverViewRow] = { + sql"""select "pid", "status", "receive_start_lsn", "receive_start_tli", "written_lsn", "flushed_lsn", "received_tli", "last_msg_send_time"::text, "last_msg_receipt_time"::text, "latest_end_lsn", "latest_end_time"::text, "slot_name", "sender_host", "sender_port", "conninfo" from pg_catalog.pg_stat_wal_receiver""".query(PgStatWalReceiverViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRow.scala new file mode 100644 index 0000000000..99b5480de5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewRow.scala @@ -0,0 +1,128 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal_receiver + +import adventureworks.customtypes.TypoInstant +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatWalReceiverViewRow( + pid: /* nullability unknown */ Option[Int], + status: /* nullability unknown */ Option[String], + receiveStartLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + receiveStartTli: /* nullability unknown */ Option[Int], + writtenLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + flushedLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + receivedTli: /* nullability unknown */ Option[Int], + lastMsgSendTime: /* nullability unknown */ Option[TypoInstant], + lastMsgReceiptTime: /* nullability unknown */ Option[TypoInstant], + latestEndLsn: /* nullability unknown */ Option[/* pg_lsn */ Long], + latestEndTime: /* nullability unknown */ Option[TypoInstant], + slotName: /* nullability unknown */ Option[String], + senderHost: /* nullability unknown */ Option[String], + senderPort: /* nullability unknown */ Option[Int], + conninfo: /* nullability unknown */ Option[String] +) + +object PgStatWalReceiverViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatWalReceiverViewRow] = new JdbcDecoder[PgStatWalReceiverViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatWalReceiverViewRow) = + columIndex + 14 -> + PgStatWalReceiverViewRow( + pid = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + status = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + receiveStartLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 2, rs)._2, + receiveStartTli = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + writtenLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + flushedLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + receivedTli = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 6, rs)._2, + lastMsgSendTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + lastMsgReceiptTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + latestEndLsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + latestEndTime = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + slotName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + senderHost = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + senderPort = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 13, rs)._2, + conninfo = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatWalReceiverViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val pid = jsonObj.get("pid").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val status = jsonObj.get("status").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val receiveStartLsn = jsonObj.get("receive_start_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val receiveStartTli = jsonObj.get("receive_start_tli").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val writtenLsn = jsonObj.get("written_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val flushedLsn = jsonObj.get("flushed_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val receivedTli = jsonObj.get("received_tli").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val lastMsgSendTime = jsonObj.get("last_msg_send_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val lastMsgReceiptTime = jsonObj.get("last_msg_receipt_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val latestEndLsn = jsonObj.get("latest_end_lsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val latestEndTime = jsonObj.get("latest_end_time").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val slotName = jsonObj.get("slot_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val senderHost = jsonObj.get("sender_host").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val senderPort = jsonObj.get("sender_port").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val conninfo = jsonObj.get("conninfo").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (pid.isRight && status.isRight && receiveStartLsn.isRight && receiveStartTli.isRight && writtenLsn.isRight && flushedLsn.isRight && receivedTli.isRight && lastMsgSendTime.isRight && lastMsgReceiptTime.isRight && latestEndLsn.isRight && latestEndTime.isRight && slotName.isRight && senderHost.isRight && senderPort.isRight && conninfo.isRight) + Right(PgStatWalReceiverViewRow(pid = pid.toOption.get, status = status.toOption.get, receiveStartLsn = receiveStartLsn.toOption.get, receiveStartTli = receiveStartTli.toOption.get, writtenLsn = writtenLsn.toOption.get, flushedLsn = flushedLsn.toOption.get, receivedTli = receivedTli.toOption.get, lastMsgSendTime = lastMsgSendTime.toOption.get, lastMsgReceiptTime = lastMsgReceiptTime.toOption.get, latestEndLsn = latestEndLsn.toOption.get, latestEndTime = latestEndTime.toOption.get, slotName = slotName.toOption.get, senderHost = senderHost.toOption.get, senderPort = senderPort.toOption.get, conninfo = conninfo.toOption.get)) + else Left(List[Either[String, Any]](pid, status, receiveStartLsn, receiveStartTli, writtenLsn, flushedLsn, receivedTli, lastMsgSendTime, lastMsgReceiptTime, latestEndLsn, latestEndTime, slotName, senderHost, senderPort, conninfo).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatWalReceiverViewRow] = new JsonEncoder[PgStatWalReceiverViewRow] { + override def unsafeEncode(a: PgStatWalReceiverViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""pid":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.pid, indent, out) + out.write(",") + out.write(""""status":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""receive_start_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.receiveStartLsn, indent, out) + out.write(",") + out.write(""""receive_start_tli":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.receiveStartTli, indent, out) + out.write(",") + out.write(""""written_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.writtenLsn, indent, out) + out.write(",") + out.write(""""flushed_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.flushedLsn, indent, out) + out.write(",") + out.write(""""received_tli":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.receivedTli, indent, out) + out.write(",") + out.write(""""last_msg_send_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastMsgSendTime, indent, out) + out.write(",") + out.write(""""last_msg_receipt_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.lastMsgReceiptTime, indent, out) + out.write(",") + out.write(""""latest_end_lsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.latestEndLsn, indent, out) + out.write(",") + out.write(""""latest_end_time":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.latestEndTime, indent, out) + out.write(",") + out.write(""""slot_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.slotName, indent, out) + out.write(",") + out.write(""""sender_host":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.senderHost, indent, out) + out.write(",") + out.write(""""sender_port":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.senderPort, indent, out) + out.write(",") + out.write(""""conninfo":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.conninfo, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewStructure.scala new file mode 100644 index 0000000000..58271f504d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_wal_receiver/PgStatWalReceiverViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_wal_receiver + +import adventureworks.customtypes.TypoInstant +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatWalReceiverViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatWalReceiverViewRow, val merge: (Row, PgStatWalReceiverViewRow) => Row) + extends Relation[PgStatWalReceiverViewFields, PgStatWalReceiverViewRow, Row] + with PgStatWalReceiverViewFields[Row] { outer => + + override val pid = new OptField[Int, Row](prefix, "pid", None, None)(x => extract(x).pid, (row, value) => merge(row, extract(row).copy(pid = value))) + override val status = new OptField[String, Row](prefix, "status", None, None)(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val receiveStartLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "receive_start_lsn", None, None)(x => extract(x).receiveStartLsn, (row, value) => merge(row, extract(row).copy(receiveStartLsn = value))) + override val receiveStartTli = new OptField[Int, Row](prefix, "receive_start_tli", None, None)(x => extract(x).receiveStartTli, (row, value) => merge(row, extract(row).copy(receiveStartTli = value))) + override val writtenLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "written_lsn", None, None)(x => extract(x).writtenLsn, (row, value) => merge(row, extract(row).copy(writtenLsn = value))) + override val flushedLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "flushed_lsn", None, None)(x => extract(x).flushedLsn, (row, value) => merge(row, extract(row).copy(flushedLsn = value))) + override val receivedTli = new OptField[Int, Row](prefix, "received_tli", None, None)(x => extract(x).receivedTli, (row, value) => merge(row, extract(row).copy(receivedTli = value))) + override val lastMsgSendTime = new OptField[TypoInstant, Row](prefix, "last_msg_send_time", Some("text"), None)(x => extract(x).lastMsgSendTime, (row, value) => merge(row, extract(row).copy(lastMsgSendTime = value))) + override val lastMsgReceiptTime = new OptField[TypoInstant, Row](prefix, "last_msg_receipt_time", Some("text"), None)(x => extract(x).lastMsgReceiptTime, (row, value) => merge(row, extract(row).copy(lastMsgReceiptTime = value))) + override val latestEndLsn = new OptField[/* pg_lsn */ Long, Row](prefix, "latest_end_lsn", None, None)(x => extract(x).latestEndLsn, (row, value) => merge(row, extract(row).copy(latestEndLsn = value))) + override val latestEndTime = new OptField[TypoInstant, Row](prefix, "latest_end_time", Some("text"), None)(x => extract(x).latestEndTime, (row, value) => merge(row, extract(row).copy(latestEndTime = value))) + override val slotName = new OptField[String, Row](prefix, "slot_name", None, None)(x => extract(x).slotName, (row, value) => merge(row, extract(row).copy(slotName = value))) + override val senderHost = new OptField[String, Row](prefix, "sender_host", None, None)(x => extract(x).senderHost, (row, value) => merge(row, extract(row).copy(senderHost = value))) + override val senderPort = new OptField[Int, Row](prefix, "sender_port", None, None)(x => extract(x).senderPort, (row, value) => merge(row, extract(row).copy(senderPort = value))) + override val conninfo = new OptField[String, Row](prefix, "conninfo", None, None)(x => extract(x).conninfo, (row, value) => merge(row, extract(row).copy(conninfo = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](pid, status, receiveStartLsn, receiveStartTli, writtenLsn, flushedLsn, receivedTli, lastMsgSendTime, lastMsgReceiptTime, latestEndLsn, latestEndTime, slotName, senderHost, senderPort, conninfo) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatWalReceiverViewRow, merge: (NewRow, PgStatWalReceiverViewRow) => NewRow): PgStatWalReceiverViewStructure[NewRow] = + new PgStatWalReceiverViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewFields.scala new file mode 100644 index 0000000000..f6ce081029 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatXactAllTablesViewFields[Row] { + val relid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val seqScan: OptField[Long, Row] + val seqTupRead: OptField[Long, Row] + val idxScan: OptField[Long, Row] + val idxTupFetch: OptField[Long, Row] + val nTupIns: OptField[Long, Row] + val nTupUpd: OptField[Long, Row] + val nTupDel: OptField[Long, Row] + val nTupHotUpd: OptField[Long, Row] +} +object PgStatXactAllTablesViewFields extends PgStatXactAllTablesViewStructure[PgStatXactAllTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepo.scala new file mode 100644 index 0000000000..57ce122387 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_all_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatXactAllTablesViewRepo { + def select: SelectBuilder[PgStatXactAllTablesViewFields, PgStatXactAllTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatXactAllTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepoImpl.scala new file mode 100644 index 0000000000..ba350625f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_all_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatXactAllTablesViewRepoImpl extends PgStatXactAllTablesViewRepo { + override def select: SelectBuilder[PgStatXactAllTablesViewFields, PgStatXactAllTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_xact_all_tables", PgStatXactAllTablesViewFields, PgStatXactAllTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatXactAllTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd" from pg_catalog.pg_stat_xact_all_tables""".query(PgStatXactAllTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRow.scala new file mode 100644 index 0000000000..178a452a38 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewRow.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatXactAllTablesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + seqScan: /* nullability unknown */ Option[Long], + seqTupRead: /* nullability unknown */ Option[Long], + idxScan: /* nullability unknown */ Option[Long], + idxTupFetch: /* nullability unknown */ Option[Long], + nTupIns: /* nullability unknown */ Option[Long], + nTupUpd: /* nullability unknown */ Option[Long], + nTupDel: /* nullability unknown */ Option[Long], + nTupHotUpd: /* nullability unknown */ Option[Long] +) + +object PgStatXactAllTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatXactAllTablesViewRow] = new JdbcDecoder[PgStatXactAllTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatXactAllTablesViewRow) = + columIndex + 10 -> + PgStatXactAllTablesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatXactAllTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight) + Right(PgStatXactAllTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatXactAllTablesViewRow] = new JsonEncoder[PgStatXactAllTablesViewRow] { + override def unsafeEncode(a: PgStatXactAllTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewStructure.scala new file mode 100644 index 0000000000..9b0a27740e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_all_tables/PgStatXactAllTablesViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatXactAllTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatXactAllTablesViewRow, val merge: (Row, PgStatXactAllTablesViewRow) => Row) + extends Relation[PgStatXactAllTablesViewFields, PgStatXactAllTablesViewRow, Row] + with PgStatXactAllTablesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatXactAllTablesViewRow, merge: (NewRow, PgStatXactAllTablesViewRow) => NewRow): PgStatXactAllTablesViewStructure[NewRow] = + new PgStatXactAllTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewFields.scala new file mode 100644 index 0000000000..33cf48a9e7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatXactSysTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val seqScan: OptField[/* nullability unknown */ Long, Row] + val seqTupRead: OptField[/* nullability unknown */ Long, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] + val nTupIns: OptField[/* nullability unknown */ Long, Row] + val nTupUpd: OptField[/* nullability unknown */ Long, Row] + val nTupDel: OptField[/* nullability unknown */ Long, Row] + val nTupHotUpd: OptField[/* nullability unknown */ Long, Row] +} +object PgStatXactSysTablesViewFields extends PgStatXactSysTablesViewStructure[PgStatXactSysTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepo.scala new file mode 100644 index 0000000000..c07cb3e23b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_sys_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatXactSysTablesViewRepo { + def select: SelectBuilder[PgStatXactSysTablesViewFields, PgStatXactSysTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatXactSysTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepoImpl.scala new file mode 100644 index 0000000000..860591783e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_sys_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatXactSysTablesViewRepoImpl extends PgStatXactSysTablesViewRepo { + override def select: SelectBuilder[PgStatXactSysTablesViewFields, PgStatXactSysTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_xact_sys_tables", PgStatXactSysTablesViewFields, PgStatXactSysTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatXactSysTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd" from pg_catalog.pg_stat_xact_sys_tables""".query(PgStatXactSysTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRow.scala new file mode 100644 index 0000000000..b0584844ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewRow.scala @@ -0,0 +1,115 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatXactSysTablesViewRow( + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.seqScan]] */ + seqScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.seqTupRead]] */ + seqTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupIns]] */ + nTupIns: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupUpd]] */ + nTupUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupDel]] */ + nTupDel: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupHotUpd]] */ + nTupHotUpd: Option[/* nullability unknown */ Long] +) + +object PgStatXactSysTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatXactSysTablesViewRow] = new JdbcDecoder[PgStatXactSysTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatXactSysTablesViewRow) = + columIndex + 10 -> + PgStatXactSysTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatXactSysTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight) + Right(PgStatXactSysTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatXactSysTablesViewRow] = new JsonEncoder[PgStatXactSysTablesViewRow] { + override def unsafeEncode(a: PgStatXactSysTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewStructure.scala new file mode 100644 index 0000000000..2f753a4f88 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_sys_tables/PgStatXactSysTablesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatXactSysTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatXactSysTablesViewRow, val merge: (Row, PgStatXactSysTablesViewRow) => Row) + extends Relation[PgStatXactSysTablesViewFields, PgStatXactSysTablesViewRow, Row] + with PgStatXactSysTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatXactSysTablesViewRow, merge: (NewRow, PgStatXactSysTablesViewRow) => NewRow): PgStatXactSysTablesViewStructure[NewRow] = + new PgStatXactSysTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewFields.scala new file mode 100644 index 0000000000..168e734fc1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatXactUserFunctionsViewFields[Row] { + val funcid: Field[PgProcId, Row] + val schemaname: OptField[String, Row] + val funcname: Field[String, Row] + val calls: OptField[Long, Row] + val totalTime: OptField[Double, Row] + val selfTime: OptField[Double, Row] +} +object PgStatXactUserFunctionsViewFields extends PgStatXactUserFunctionsViewStructure[PgStatXactUserFunctionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepo.scala new file mode 100644 index 0000000000..9de89fdeea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_functions + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatXactUserFunctionsViewRepo { + def select: SelectBuilder[PgStatXactUserFunctionsViewFields, PgStatXactUserFunctionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatXactUserFunctionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepoImpl.scala new file mode 100644 index 0000000000..b66a018a4e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_functions + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatXactUserFunctionsViewRepoImpl extends PgStatXactUserFunctionsViewRepo { + override def select: SelectBuilder[PgStatXactUserFunctionsViewFields, PgStatXactUserFunctionsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_xact_user_functions", PgStatXactUserFunctionsViewFields, PgStatXactUserFunctionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatXactUserFunctionsViewRow] = { + sql"""select "funcid", "schemaname", "funcname", "calls", "total_time", "self_time" from pg_catalog.pg_stat_xact_user_functions""".query(PgStatXactUserFunctionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRow.scala new file mode 100644 index 0000000000..f5db995796 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewRow.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatXactUserFunctionsViewRow( + /** Points to [[pg_proc.PgProcRow.oid]] */ + funcid: PgProcId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_proc.PgProcRow.proname]] */ + funcname: String, + calls: /* nullability unknown */ Option[Long], + totalTime: /* nullability unknown */ Option[Double], + selfTime: /* nullability unknown */ Option[Double] +) + +object PgStatXactUserFunctionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatXactUserFunctionsViewRow] = new JdbcDecoder[PgStatXactUserFunctionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatXactUserFunctionsViewRow) = + columIndex + 5 -> + PgStatXactUserFunctionsViewRow( + funcid = PgProcId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + funcname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + calls = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + totalTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 4, rs)._2, + selfTime = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatXactUserFunctionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val funcid = jsonObj.get("funcid").toRight("Missing field 'funcid'").flatMap(_.as(PgProcId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val funcname = jsonObj.get("funcname").toRight("Missing field 'funcname'").flatMap(_.as(JsonDecoder.string)) + val calls = jsonObj.get("calls").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val totalTime = jsonObj.get("total_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val selfTime = jsonObj.get("self_time").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + if (funcid.isRight && schemaname.isRight && funcname.isRight && calls.isRight && totalTime.isRight && selfTime.isRight) + Right(PgStatXactUserFunctionsViewRow(funcid = funcid.toOption.get, schemaname = schemaname.toOption.get, funcname = funcname.toOption.get, calls = calls.toOption.get, totalTime = totalTime.toOption.get, selfTime = selfTime.toOption.get)) + else Left(List[Either[String, Any]](funcid, schemaname, funcname, calls, totalTime, selfTime).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatXactUserFunctionsViewRow] = new JsonEncoder[PgStatXactUserFunctionsViewRow] { + override def unsafeEncode(a: PgStatXactUserFunctionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""funcid":""") + PgProcId.jsonEncoder.unsafeEncode(a.funcid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""funcname":""") + JsonEncoder.string.unsafeEncode(a.funcname, indent, out) + out.write(",") + out.write(""""calls":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.calls, indent, out) + out.write(",") + out.write(""""total_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.totalTime, indent, out) + out.write(",") + out.write(""""self_time":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.selfTime, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewStructure.scala new file mode 100644 index 0000000000..8b73cf8f8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_functions/PgStatXactUserFunctionsViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_functions + +import adventureworks.pg_catalog.pg_proc.PgProcId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatXactUserFunctionsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatXactUserFunctionsViewRow, val merge: (Row, PgStatXactUserFunctionsViewRow) => Row) + extends Relation[PgStatXactUserFunctionsViewFields, PgStatXactUserFunctionsViewRow, Row] + with PgStatXactUserFunctionsViewFields[Row] { outer => + + override val funcid = new Field[PgProcId, Row](prefix, "funcid", None, None)(x => extract(x).funcid, (row, value) => merge(row, extract(row).copy(funcid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val funcname = new Field[String, Row](prefix, "funcname", None, None)(x => extract(x).funcname, (row, value) => merge(row, extract(row).copy(funcname = value))) + override val calls = new OptField[Long, Row](prefix, "calls", None, None)(x => extract(x).calls, (row, value) => merge(row, extract(row).copy(calls = value))) + override val totalTime = new OptField[Double, Row](prefix, "total_time", None, None)(x => extract(x).totalTime, (row, value) => merge(row, extract(row).copy(totalTime = value))) + override val selfTime = new OptField[Double, Row](prefix, "self_time", None, None)(x => extract(x).selfTime, (row, value) => merge(row, extract(row).copy(selfTime = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](funcid, schemaname, funcname, calls, totalTime, selfTime) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatXactUserFunctionsViewRow, merge: (NewRow, PgStatXactUserFunctionsViewRow) => NewRow): PgStatXactUserFunctionsViewStructure[NewRow] = + new PgStatXactUserFunctionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewFields.scala new file mode 100644 index 0000000000..deb75c4eba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatXactUserTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val seqScan: OptField[/* nullability unknown */ Long, Row] + val seqTupRead: OptField[/* nullability unknown */ Long, Row] + val idxScan: OptField[/* nullability unknown */ Long, Row] + val idxTupFetch: OptField[/* nullability unknown */ Long, Row] + val nTupIns: OptField[/* nullability unknown */ Long, Row] + val nTupUpd: OptField[/* nullability unknown */ Long, Row] + val nTupDel: OptField[/* nullability unknown */ Long, Row] + val nTupHotUpd: OptField[/* nullability unknown */ Long, Row] +} +object PgStatXactUserTablesViewFields extends PgStatXactUserTablesViewStructure[PgStatXactUserTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepo.scala new file mode 100644 index 0000000000..79d67854ef --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatXactUserTablesViewRepo { + def select: SelectBuilder[PgStatXactUserTablesViewFields, PgStatXactUserTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatXactUserTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepoImpl.scala new file mode 100644 index 0000000000..949850fda3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatXactUserTablesViewRepoImpl extends PgStatXactUserTablesViewRepo { + override def select: SelectBuilder[PgStatXactUserTablesViewFields, PgStatXactUserTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_stat_xact_user_tables", PgStatXactUserTablesViewFields, PgStatXactUserTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatXactUserTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "seq_scan", "seq_tup_read", "idx_scan", "idx_tup_fetch", "n_tup_ins", "n_tup_upd", "n_tup_del", "n_tup_hot_upd" from pg_catalog.pg_stat_xact_user_tables""".query(PgStatXactUserTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRow.scala new file mode 100644 index 0000000000..879eb6e9e1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewRow.scala @@ -0,0 +1,115 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatXactUserTablesViewRow( + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.seqScan]] */ + seqScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.seqTupRead]] */ + seqTupRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.idxScan]] */ + idxScan: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.idxTupFetch]] */ + idxTupFetch: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupIns]] */ + nTupIns: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupUpd]] */ + nTupUpd: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupDel]] */ + nTupDel: Option[/* nullability unknown */ Long], + /** Points to [[pg_stat_xact_all_tables.PgStatXactAllTablesViewRow.nTupHotUpd]] */ + nTupHotUpd: Option[/* nullability unknown */ Long] +) + +object PgStatXactUserTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatXactUserTablesViewRow] = new JdbcDecoder[PgStatXactUserTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatXactUserTablesViewRow) = + columIndex + 10 -> + PgStatXactUserTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + seqScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + seqTupRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxScan = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxTupFetch = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + nTupIns = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + nTupUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + nTupDel = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + nTupHotUpd = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatXactUserTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val seqScan = jsonObj.get("seq_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val seqTupRead = jsonObj.get("seq_tup_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxScan = jsonObj.get("idx_scan").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxTupFetch = jsonObj.get("idx_tup_fetch").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupIns = jsonObj.get("n_tup_ins").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupUpd = jsonObj.get("n_tup_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupDel = jsonObj.get("n_tup_del").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val nTupHotUpd = jsonObj.get("n_tup_hot_upd").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && seqScan.isRight && seqTupRead.isRight && idxScan.isRight && idxTupFetch.isRight && nTupIns.isRight && nTupUpd.isRight && nTupDel.isRight && nTupHotUpd.isRight) + Right(PgStatXactUserTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, seqScan = seqScan.toOption.get, seqTupRead = seqTupRead.toOption.get, idxScan = idxScan.toOption.get, idxTupFetch = idxTupFetch.toOption.get, nTupIns = nTupIns.toOption.get, nTupUpd = nTupUpd.toOption.get, nTupDel = nTupDel.toOption.get, nTupHotUpd = nTupHotUpd.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatXactUserTablesViewRow] = new JsonEncoder[PgStatXactUserTablesViewRow] { + override def unsafeEncode(a: PgStatXactUserTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""seq_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqScan, indent, out) + out.write(",") + out.write(""""seq_tup_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.seqTupRead, indent, out) + out.write(",") + out.write(""""idx_scan":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxScan, indent, out) + out.write(",") + out.write(""""idx_tup_fetch":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxTupFetch, indent, out) + out.write(",") + out.write(""""n_tup_ins":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupIns, indent, out) + out.write(",") + out.write(""""n_tup_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupUpd, indent, out) + out.write(",") + out.write(""""n_tup_del":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupDel, indent, out) + out.write(",") + out.write(""""n_tup_hot_upd":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.nTupHotUpd, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewStructure.scala new file mode 100644 index 0000000000..03650f267f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stat_xact_user_tables/PgStatXactUserTablesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stat_xact_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatXactUserTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatXactUserTablesViewRow, val merge: (Row, PgStatXactUserTablesViewRow) => Row) + extends Relation[PgStatXactUserTablesViewFields, PgStatXactUserTablesViewRow, Row] + with PgStatXactUserTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val seqScan = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_scan", None, None)(x => extract(x).seqScan, (row, value) => merge(row, extract(row).copy(seqScan = value))) + override val seqTupRead = new OptField[/* nullability unknown */ Long, Row](prefix, "seq_tup_read", None, None)(x => extract(x).seqTupRead, (row, value) => merge(row, extract(row).copy(seqTupRead = value))) + override val idxScan = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_scan", None, None)(x => extract(x).idxScan, (row, value) => merge(row, extract(row).copy(idxScan = value))) + override val idxTupFetch = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_tup_fetch", None, None)(x => extract(x).idxTupFetch, (row, value) => merge(row, extract(row).copy(idxTupFetch = value))) + override val nTupIns = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_ins", None, None)(x => extract(x).nTupIns, (row, value) => merge(row, extract(row).copy(nTupIns = value))) + override val nTupUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_upd", None, None)(x => extract(x).nTupUpd, (row, value) => merge(row, extract(row).copy(nTupUpd = value))) + override val nTupDel = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_del", None, None)(x => extract(x).nTupDel, (row, value) => merge(row, extract(row).copy(nTupDel = value))) + override val nTupHotUpd = new OptField[/* nullability unknown */ Long, Row](prefix, "n_tup_hot_upd", None, None)(x => extract(x).nTupHotUpd, (row, value) => merge(row, extract(row).copy(nTupHotUpd = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, seqScan, seqTupRead, idxScan, idxTupFetch, nTupIns, nTupUpd, nTupDel, nTupHotUpd) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatXactUserTablesViewRow, merge: (NewRow, PgStatXactUserTablesViewRow) => NewRow): PgStatXactUserTablesViewStructure[NewRow] = + new PgStatXactUserTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewFields.scala new file mode 100644 index 0000000000..1e11c043c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatioAllIndexesViewFields[Row] { + val relid: Field[PgClassId, Row] + val indexrelid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val indexrelname: Field[String, Row] + val idxBlksRead: OptField[Long, Row] + val idxBlksHit: OptField[Long, Row] +} +object PgStatioAllIndexesViewFields extends PgStatioAllIndexesViewStructure[PgStatioAllIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepo.scala new file mode 100644 index 0000000000..5b8bec3d52 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioAllIndexesViewRepo { + def select: SelectBuilder[PgStatioAllIndexesViewFields, PgStatioAllIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioAllIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..be40044ca3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioAllIndexesViewRepoImpl extends PgStatioAllIndexesViewRepo { + override def select: SelectBuilder[PgStatioAllIndexesViewFields, PgStatioAllIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_all_indexes", PgStatioAllIndexesViewFields, PgStatioAllIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioAllIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_blks_read", "idx_blks_hit" from pg_catalog.pg_statio_all_indexes""".query(PgStatioAllIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRow.scala new file mode 100644 index 0000000000..60d3a4f7e2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewRow.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioAllIndexesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_class.PgClassRow.oid]] */ + indexrelid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + indexrelname: String, + idxBlksRead: /* nullability unknown */ Option[Long], + idxBlksHit: /* nullability unknown */ Option[Long] +) + +object PgStatioAllIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioAllIndexesViewRow] = new JdbcDecoder[PgStatioAllIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioAllIndexesViewRow) = + columIndex + 6 -> + PgStatioAllIndexesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + indexrelid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioAllIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val indexrelid = jsonObj.get("indexrelid").toRight("Missing field 'indexrelid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val indexrelname = jsonObj.get("indexrelname").toRight("Missing field 'indexrelname'").flatMap(_.as(JsonDecoder.string)) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxBlksRead.isRight && idxBlksHit.isRight) + Right(PgStatioAllIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioAllIndexesViewRow] = new JsonEncoder[PgStatioAllIndexesViewRow] { + override def unsafeEncode(a: PgStatioAllIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + PgClassId.jsonEncoder.unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.string.unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewStructure.scala new file mode 100644 index 0000000000..5e07a73f57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_indexes/PgStatioAllIndexesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioAllIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioAllIndexesViewRow, val merge: (Row, PgStatioAllIndexesViewRow) => Row) + extends Relation[PgStatioAllIndexesViewFields, PgStatioAllIndexesViewRow, Row] + with PgStatioAllIndexesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new Field[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new Field[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxBlksRead = new OptField[Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioAllIndexesViewRow, merge: (NewRow, PgStatioAllIndexesViewRow) => NewRow): PgStatioAllIndexesViewStructure[NewRow] = + new PgStatioAllIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewFields.scala new file mode 100644 index 0000000000..42417f991d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatioAllSequencesViewFields[Row] { + val relid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val blksRead: OptField[Long, Row] + val blksHit: OptField[Long, Row] +} +object PgStatioAllSequencesViewFields extends PgStatioAllSequencesViewStructure[PgStatioAllSequencesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepo.scala new file mode 100644 index 0000000000..ab9484e61b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_sequences + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioAllSequencesViewRepo { + def select: SelectBuilder[PgStatioAllSequencesViewFields, PgStatioAllSequencesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioAllSequencesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepoImpl.scala new file mode 100644 index 0000000000..dbd068f146 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_sequences + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioAllSequencesViewRepoImpl extends PgStatioAllSequencesViewRepo { + override def select: SelectBuilder[PgStatioAllSequencesViewFields, PgStatioAllSequencesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_all_sequences", PgStatioAllSequencesViewFields, PgStatioAllSequencesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioAllSequencesViewRow] = { + sql"""select "relid", "schemaname", "relname", "blks_read", "blks_hit" from pg_catalog.pg_statio_all_sequences""".query(PgStatioAllSequencesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRow.scala new file mode 100644 index 0000000000..f6ff016e14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioAllSequencesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + blksRead: /* nullability unknown */ Option[Long], + blksHit: /* nullability unknown */ Option[Long] +) + +object PgStatioAllSequencesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioAllSequencesViewRow] = new JdbcDecoder[PgStatioAllSequencesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioAllSequencesViewRow) = + columIndex + 4 -> + PgStatioAllSequencesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + blksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + blksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioAllSequencesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val blksRead = jsonObj.get("blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksHit = jsonObj.get("blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && blksRead.isRight && blksHit.isRight) + Right(PgStatioAllSequencesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, blksRead = blksRead.toOption.get, blksHit = blksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, blksRead, blksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioAllSequencesViewRow] = new JsonEncoder[PgStatioAllSequencesViewRow] { + override def unsafeEncode(a: PgStatioAllSequencesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksRead, indent, out) + out.write(",") + out.write(""""blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewStructure.scala new file mode 100644 index 0000000000..8c52c65fc1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_sequences/PgStatioAllSequencesViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioAllSequencesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioAllSequencesViewRow, val merge: (Row, PgStatioAllSequencesViewRow) => Row) + extends Relation[PgStatioAllSequencesViewFields, PgStatioAllSequencesViewRow, Row] + with PgStatioAllSequencesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val blksRead = new OptField[Long, Row](prefix, "blks_read", None, None)(x => extract(x).blksRead, (row, value) => merge(row, extract(row).copy(blksRead = value))) + override val blksHit = new OptField[Long, Row](prefix, "blks_hit", None, None)(x => extract(x).blksHit, (row, value) => merge(row, extract(row).copy(blksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, blksRead, blksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioAllSequencesViewRow, merge: (NewRow, PgStatioAllSequencesViewRow) => NewRow): PgStatioAllSequencesViewStructure[NewRow] = + new PgStatioAllSequencesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewFields.scala new file mode 100644 index 0000000000..571eb2826c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatioAllTablesViewFields[Row] { + val relid: Field[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: Field[String, Row] + val heapBlksRead: OptField[Long, Row] + val heapBlksHit: OptField[Long, Row] + val idxBlksRead: OptField[Long, Row] + val idxBlksHit: OptField[Long, Row] + val toastBlksRead: OptField[Long, Row] + val toastBlksHit: OptField[Long, Row] + val tidxBlksRead: OptField[Long, Row] + val tidxBlksHit: OptField[Long, Row] +} +object PgStatioAllTablesViewFields extends PgStatioAllTablesViewStructure[PgStatioAllTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepo.scala new file mode 100644 index 0000000000..75ebbd6597 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioAllTablesViewRepo { + def select: SelectBuilder[PgStatioAllTablesViewFields, PgStatioAllTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioAllTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepoImpl.scala new file mode 100644 index 0000000000..f80726f73e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioAllTablesViewRepoImpl extends PgStatioAllTablesViewRepo { + override def select: SelectBuilder[PgStatioAllTablesViewFields, PgStatioAllTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_all_tables", PgStatioAllTablesViewFields, PgStatioAllTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioAllTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "heap_blks_read", "heap_blks_hit", "idx_blks_read", "idx_blks_hit", "toast_blks_read", "toast_blks_hit", "tidx_blks_read", "tidx_blks_hit" from pg_catalog.pg_statio_all_tables""".query(PgStatioAllTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRow.scala new file mode 100644 index 0000000000..d26b33afe6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewRow.scala @@ -0,0 +1,107 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioAllTablesViewRow( + /** Points to [[pg_class.PgClassRow.oid]] */ + relid: PgClassId, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + relname: String, + heapBlksRead: /* nullability unknown */ Option[Long], + heapBlksHit: /* nullability unknown */ Option[Long], + idxBlksRead: /* nullability unknown */ Option[Long], + idxBlksHit: /* nullability unknown */ Option[Long], + toastBlksRead: /* nullability unknown */ Option[Long], + toastBlksHit: /* nullability unknown */ Option[Long], + tidxBlksRead: /* nullability unknown */ Option[Long], + tidxBlksHit: /* nullability unknown */ Option[Long] +) + +object PgStatioAllTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioAllTablesViewRow] = new JdbcDecoder[PgStatioAllTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioAllTablesViewRow) = + columIndex + 10 -> + PgStatioAllTablesViewRow( + relid = PgClassId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + heapBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + heapBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + toastBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + toastBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + tidxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + tidxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioAllTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").toRight("Missing field 'relid'").flatMap(_.as(PgClassId.jsonDecoder)) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").toRight("Missing field 'relname'").flatMap(_.as(JsonDecoder.string)) + val heapBlksRead = jsonObj.get("heap_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksHit = jsonObj.get("heap_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksRead = jsonObj.get("toast_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksHit = jsonObj.get("toast_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksRead = jsonObj.get("tidx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksHit = jsonObj.get("tidx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && heapBlksRead.isRight && heapBlksHit.isRight && idxBlksRead.isRight && idxBlksHit.isRight && toastBlksRead.isRight && toastBlksHit.isRight && tidxBlksRead.isRight && tidxBlksHit.isRight) + Right(PgStatioAllTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, heapBlksRead = heapBlksRead.toOption.get, heapBlksHit = heapBlksHit.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get, toastBlksRead = toastBlksRead.toOption.get, toastBlksHit = toastBlksHit.toOption.get, tidxBlksRead = tidxBlksRead.toOption.get, tidxBlksHit = tidxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioAllTablesViewRow] = new JsonEncoder[PgStatioAllTablesViewRow] { + override def unsafeEncode(a: PgStatioAllTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + PgClassId.jsonEncoder.unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.string.unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""heap_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksRead, indent, out) + out.write(",") + out.write(""""heap_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksHit, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write(",") + out.write(""""toast_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksRead, indent, out) + out.write(",") + out.write(""""toast_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksHit, indent, out) + out.write(",") + out.write(""""tidx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksRead, indent, out) + out.write(",") + out.write(""""tidx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewStructure.scala new file mode 100644 index 0000000000..7393b8d5d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_all_tables/PgStatioAllTablesViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_all_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioAllTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioAllTablesViewRow, val merge: (Row, PgStatioAllTablesViewRow) => Row) + extends Relation[PgStatioAllTablesViewFields, PgStatioAllTablesViewRow, Row] + with PgStatioAllTablesViewFields[Row] { outer => + + override val relid = new Field[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new Field[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val heapBlksRead = new OptField[Long, Row](prefix, "heap_blks_read", None, None)(x => extract(x).heapBlksRead, (row, value) => merge(row, extract(row).copy(heapBlksRead = value))) + override val heapBlksHit = new OptField[Long, Row](prefix, "heap_blks_hit", None, None)(x => extract(x).heapBlksHit, (row, value) => merge(row, extract(row).copy(heapBlksHit = value))) + override val idxBlksRead = new OptField[Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + override val toastBlksRead = new OptField[Long, Row](prefix, "toast_blks_read", None, None)(x => extract(x).toastBlksRead, (row, value) => merge(row, extract(row).copy(toastBlksRead = value))) + override val toastBlksHit = new OptField[Long, Row](prefix, "toast_blks_hit", None, None)(x => extract(x).toastBlksHit, (row, value) => merge(row, extract(row).copy(toastBlksHit = value))) + override val tidxBlksRead = new OptField[Long, Row](prefix, "tidx_blks_read", None, None)(x => extract(x).tidxBlksRead, (row, value) => merge(row, extract(row).copy(tidxBlksRead = value))) + override val tidxBlksHit = new OptField[Long, Row](prefix, "tidx_blks_hit", None, None)(x => extract(x).tidxBlksHit, (row, value) => merge(row, extract(row).copy(tidxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioAllTablesViewRow, merge: (NewRow, PgStatioAllTablesViewRow) => NewRow): PgStatioAllTablesViewStructure[NewRow] = + new PgStatioAllTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewFields.scala new file mode 100644 index 0000000000..29f160189d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioSysIndexesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val indexrelid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val indexrelname: OptField[String, Row] + val idxBlksRead: OptField[/* nullability unknown */ Long, Row] + val idxBlksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioSysIndexesViewFields extends PgStatioSysIndexesViewStructure[PgStatioSysIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepo.scala new file mode 100644 index 0000000000..aa60a91672 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioSysIndexesViewRepo { + def select: SelectBuilder[PgStatioSysIndexesViewFields, PgStatioSysIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioSysIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..68ec10160d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioSysIndexesViewRepoImpl extends PgStatioSysIndexesViewRepo { + override def select: SelectBuilder[PgStatioSysIndexesViewFields, PgStatioSysIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_sys_indexes", PgStatioSysIndexesViewFields, PgStatioSysIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioSysIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_blks_read", "idx_blks_hit" from pg_catalog.pg_statio_sys_indexes""".query(PgStatioSysIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRow.scala new file mode 100644 index 0000000000..9a06c0957b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewRow.scala @@ -0,0 +1,87 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioSysIndexesViewRow( + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.indexrelid]] */ + indexrelid: Option[PgClassId], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.indexrelname]] */ + indexrelname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.idxBlksRead]] */ + idxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.idxBlksHit]] */ + idxBlksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioSysIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioSysIndexesViewRow] = new JdbcDecoder[PgStatioSysIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioSysIndexesViewRow) = + columIndex + 6 -> + PgStatioSysIndexesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + indexrelid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioSysIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val indexrelid = jsonObj.get("indexrelid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val indexrelname = jsonObj.get("indexrelname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxBlksRead.isRight && idxBlksHit.isRight) + Right(PgStatioSysIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioSysIndexesViewRow] = new JsonEncoder[PgStatioSysIndexesViewRow] { + override def unsafeEncode(a: PgStatioSysIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewStructure.scala new file mode 100644 index 0000000000..ec2f3b70b7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_indexes/PgStatioSysIndexesViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioSysIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioSysIndexesViewRow, val merge: (Row, PgStatioSysIndexesViewRow) => Row) + extends Relation[PgStatioSysIndexesViewFields, PgStatioSysIndexesViewRow, Row] + with PgStatioSysIndexesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new OptField[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new OptField[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioSysIndexesViewRow, merge: (NewRow, PgStatioSysIndexesViewRow) => NewRow): PgStatioSysIndexesViewStructure[NewRow] = + new PgStatioSysIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewFields.scala new file mode 100644 index 0000000000..addbb40c4b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioSysSequencesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val blksRead: OptField[/* nullability unknown */ Long, Row] + val blksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioSysSequencesViewFields extends PgStatioSysSequencesViewStructure[PgStatioSysSequencesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepo.scala new file mode 100644 index 0000000000..4ace183dab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_sequences + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioSysSequencesViewRepo { + def select: SelectBuilder[PgStatioSysSequencesViewFields, PgStatioSysSequencesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioSysSequencesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepoImpl.scala new file mode 100644 index 0000000000..2eefa03f3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_sequences + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioSysSequencesViewRepoImpl extends PgStatioSysSequencesViewRepo { + override def select: SelectBuilder[PgStatioSysSequencesViewFields, PgStatioSysSequencesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_sys_sequences", PgStatioSysSequencesViewFields, PgStatioSysSequencesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioSysSequencesViewRow] = { + sql"""select "relid", "schemaname", "relname", "blks_read", "blks_hit" from pg_catalog.pg_statio_sys_sequences""".query(PgStatioSysSequencesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRow.scala new file mode 100644 index 0000000000..f3016da6d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioSysSequencesViewRow( + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.blksRead]] */ + blksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.blksHit]] */ + blksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioSysSequencesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioSysSequencesViewRow] = new JdbcDecoder[PgStatioSysSequencesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioSysSequencesViewRow) = + columIndex + 4 -> + PgStatioSysSequencesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + blksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + blksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioSysSequencesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blksRead = jsonObj.get("blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksHit = jsonObj.get("blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && blksRead.isRight && blksHit.isRight) + Right(PgStatioSysSequencesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, blksRead = blksRead.toOption.get, blksHit = blksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, blksRead, blksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioSysSequencesViewRow] = new JsonEncoder[PgStatioSysSequencesViewRow] { + override def unsafeEncode(a: PgStatioSysSequencesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksRead, indent, out) + out.write(",") + out.write(""""blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewStructure.scala new file mode 100644 index 0000000000..e53819613a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_sequences/PgStatioSysSequencesViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioSysSequencesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioSysSequencesViewRow, val merge: (Row, PgStatioSysSequencesViewRow) => Row) + extends Relation[PgStatioSysSequencesViewFields, PgStatioSysSequencesViewRow, Row] + with PgStatioSysSequencesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val blksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "blks_read", None, None)(x => extract(x).blksRead, (row, value) => merge(row, extract(row).copy(blksRead = value))) + override val blksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "blks_hit", None, None)(x => extract(x).blksHit, (row, value) => merge(row, extract(row).copy(blksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, blksRead, blksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioSysSequencesViewRow, merge: (NewRow, PgStatioSysSequencesViewRow) => NewRow): PgStatioSysSequencesViewStructure[NewRow] = + new PgStatioSysSequencesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewFields.scala new file mode 100644 index 0000000000..79a791faab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioSysTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val heapBlksRead: OptField[/* nullability unknown */ Long, Row] + val heapBlksHit: OptField[/* nullability unknown */ Long, Row] + val idxBlksRead: OptField[/* nullability unknown */ Long, Row] + val idxBlksHit: OptField[/* nullability unknown */ Long, Row] + val toastBlksRead: OptField[/* nullability unknown */ Long, Row] + val toastBlksHit: OptField[/* nullability unknown */ Long, Row] + val tidxBlksRead: OptField[/* nullability unknown */ Long, Row] + val tidxBlksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioSysTablesViewFields extends PgStatioSysTablesViewStructure[PgStatioSysTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepo.scala new file mode 100644 index 0000000000..e078ccb24b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioSysTablesViewRepo { + def select: SelectBuilder[PgStatioSysTablesViewFields, PgStatioSysTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioSysTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepoImpl.scala new file mode 100644 index 0000000000..b5de978f68 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioSysTablesViewRepoImpl extends PgStatioSysTablesViewRepo { + override def select: SelectBuilder[PgStatioSysTablesViewFields, PgStatioSysTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_sys_tables", PgStatioSysTablesViewFields, PgStatioSysTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioSysTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "heap_blks_read", "heap_blks_hit", "idx_blks_read", "idx_blks_hit", "toast_blks_read", "toast_blks_hit", "tidx_blks_read", "tidx_blks_hit" from pg_catalog.pg_statio_sys_tables""".query(PgStatioSysTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRow.scala new file mode 100644 index 0000000000..f51dce4a7c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewRow.scala @@ -0,0 +1,115 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioSysTablesViewRow( + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.heapBlksRead]] */ + heapBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.heapBlksHit]] */ + heapBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.idxBlksRead]] */ + idxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.idxBlksHit]] */ + idxBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.toastBlksRead]] */ + toastBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.toastBlksHit]] */ + toastBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.tidxBlksRead]] */ + tidxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.tidxBlksHit]] */ + tidxBlksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioSysTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioSysTablesViewRow] = new JdbcDecoder[PgStatioSysTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioSysTablesViewRow) = + columIndex + 10 -> + PgStatioSysTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + heapBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + heapBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + toastBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + toastBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + tidxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + tidxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioSysTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val heapBlksRead = jsonObj.get("heap_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksHit = jsonObj.get("heap_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksRead = jsonObj.get("toast_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksHit = jsonObj.get("toast_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksRead = jsonObj.get("tidx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksHit = jsonObj.get("tidx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && heapBlksRead.isRight && heapBlksHit.isRight && idxBlksRead.isRight && idxBlksHit.isRight && toastBlksRead.isRight && toastBlksHit.isRight && tidxBlksRead.isRight && tidxBlksHit.isRight) + Right(PgStatioSysTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, heapBlksRead = heapBlksRead.toOption.get, heapBlksHit = heapBlksHit.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get, toastBlksRead = toastBlksRead.toOption.get, toastBlksHit = toastBlksHit.toOption.get, tidxBlksRead = tidxBlksRead.toOption.get, tidxBlksHit = tidxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioSysTablesViewRow] = new JsonEncoder[PgStatioSysTablesViewRow] { + override def unsafeEncode(a: PgStatioSysTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""heap_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksRead, indent, out) + out.write(",") + out.write(""""heap_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksHit, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write(",") + out.write(""""toast_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksRead, indent, out) + out.write(",") + out.write(""""toast_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksHit, indent, out) + out.write(",") + out.write(""""tidx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksRead, indent, out) + out.write(",") + out.write(""""tidx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewStructure.scala new file mode 100644 index 0000000000..f30c5291dd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_sys_tables/PgStatioSysTablesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_sys_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioSysTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioSysTablesViewRow, val merge: (Row, PgStatioSysTablesViewRow) => Row) + extends Relation[PgStatioSysTablesViewFields, PgStatioSysTablesViewRow, Row] + with PgStatioSysTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val heapBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "heap_blks_read", None, None)(x => extract(x).heapBlksRead, (row, value) => merge(row, extract(row).copy(heapBlksRead = value))) + override val heapBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "heap_blks_hit", None, None)(x => extract(x).heapBlksHit, (row, value) => merge(row, extract(row).copy(heapBlksHit = value))) + override val idxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + override val toastBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "toast_blks_read", None, None)(x => extract(x).toastBlksRead, (row, value) => merge(row, extract(row).copy(toastBlksRead = value))) + override val toastBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "toast_blks_hit", None, None)(x => extract(x).toastBlksHit, (row, value) => merge(row, extract(row).copy(toastBlksHit = value))) + override val tidxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "tidx_blks_read", None, None)(x => extract(x).tidxBlksRead, (row, value) => merge(row, extract(row).copy(tidxBlksRead = value))) + override val tidxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "tidx_blks_hit", None, None)(x => extract(x).tidxBlksHit, (row, value) => merge(row, extract(row).copy(tidxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioSysTablesViewRow, merge: (NewRow, PgStatioSysTablesViewRow) => NewRow): PgStatioSysTablesViewStructure[NewRow] = + new PgStatioSysTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewFields.scala new file mode 100644 index 0000000000..9f199d9eb6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioUserIndexesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val indexrelid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val indexrelname: OptField[String, Row] + val idxBlksRead: OptField[/* nullability unknown */ Long, Row] + val idxBlksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioUserIndexesViewFields extends PgStatioUserIndexesViewStructure[PgStatioUserIndexesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepo.scala new file mode 100644 index 0000000000..e21c3a25ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_indexes + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioUserIndexesViewRepo { + def select: SelectBuilder[PgStatioUserIndexesViewFields, PgStatioUserIndexesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioUserIndexesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepoImpl.scala new file mode 100644 index 0000000000..ffa8d2e8bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_indexes + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioUserIndexesViewRepoImpl extends PgStatioUserIndexesViewRepo { + override def select: SelectBuilder[PgStatioUserIndexesViewFields, PgStatioUserIndexesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_user_indexes", PgStatioUserIndexesViewFields, PgStatioUserIndexesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioUserIndexesViewRow] = { + sql"""select "relid", "indexrelid", "schemaname", "relname", "indexrelname", "idx_blks_read", "idx_blks_hit" from pg_catalog.pg_statio_user_indexes""".query(PgStatioUserIndexesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRow.scala new file mode 100644 index 0000000000..0dcafa1be2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewRow.scala @@ -0,0 +1,87 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioUserIndexesViewRow( + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.indexrelid]] */ + indexrelid: Option[PgClassId], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.indexrelname]] */ + indexrelname: Option[String], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.idxBlksRead]] */ + idxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_indexes.PgStatioAllIndexesViewRow.idxBlksHit]] */ + idxBlksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioUserIndexesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioUserIndexesViewRow] = new JdbcDecoder[PgStatioUserIndexesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioUserIndexesViewRow) = + columIndex + 6 -> + PgStatioUserIndexesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + indexrelid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + indexrelname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioUserIndexesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val indexrelid = jsonObj.get("indexrelid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val indexrelname = jsonObj.get("indexrelname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && indexrelid.isRight && schemaname.isRight && relname.isRight && indexrelname.isRight && idxBlksRead.isRight && idxBlksHit.isRight) + Right(PgStatioUserIndexesViewRow(relid = relid.toOption.get, indexrelid = indexrelid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, indexrelname = indexrelname.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioUserIndexesViewRow] = new JsonEncoder[PgStatioUserIndexesViewRow] { + override def unsafeEncode(a: PgStatioUserIndexesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""indexrelid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.indexrelid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""indexrelname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.indexrelname, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewStructure.scala new file mode 100644 index 0000000000..27d388d71b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_indexes/PgStatioUserIndexesViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_indexes + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioUserIndexesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioUserIndexesViewRow, val merge: (Row, PgStatioUserIndexesViewRow) => Row) + extends Relation[PgStatioUserIndexesViewFields, PgStatioUserIndexesViewRow, Row] + with PgStatioUserIndexesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val indexrelid = new OptField[PgClassId, Row](prefix, "indexrelid", None, None)(x => extract(x).indexrelid, (row, value) => merge(row, extract(row).copy(indexrelid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val indexrelname = new OptField[String, Row](prefix, "indexrelname", None, None)(x => extract(x).indexrelname, (row, value) => merge(row, extract(row).copy(indexrelname = value))) + override val idxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, indexrelid, schemaname, relname, indexrelname, idxBlksRead, idxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioUserIndexesViewRow, merge: (NewRow, PgStatioUserIndexesViewRow) => NewRow): PgStatioUserIndexesViewStructure[NewRow] = + new PgStatioUserIndexesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewFields.scala new file mode 100644 index 0000000000..c51973d4e8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioUserSequencesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val blksRead: OptField[/* nullability unknown */ Long, Row] + val blksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioUserSequencesViewFields extends PgStatioUserSequencesViewStructure[PgStatioUserSequencesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepo.scala new file mode 100644 index 0000000000..d3f4cf9973 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_sequences + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioUserSequencesViewRepo { + def select: SelectBuilder[PgStatioUserSequencesViewFields, PgStatioUserSequencesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioUserSequencesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepoImpl.scala new file mode 100644 index 0000000000..0bed612e99 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_sequences + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioUserSequencesViewRepoImpl extends PgStatioUserSequencesViewRepo { + override def select: SelectBuilder[PgStatioUserSequencesViewFields, PgStatioUserSequencesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_user_sequences", PgStatioUserSequencesViewFields, PgStatioUserSequencesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioUserSequencesViewRow] = { + sql"""select "relid", "schemaname", "relname", "blks_read", "blks_hit" from pg_catalog.pg_statio_user_sequences""".query(PgStatioUserSequencesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRow.scala new file mode 100644 index 0000000000..e388f93802 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioUserSequencesViewRow( + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.blksRead]] */ + blksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_sequences.PgStatioAllSequencesViewRow.blksHit]] */ + blksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioUserSequencesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioUserSequencesViewRow] = new JdbcDecoder[PgStatioUserSequencesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioUserSequencesViewRow) = + columIndex + 4 -> + PgStatioUserSequencesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + blksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + blksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioUserSequencesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val blksRead = jsonObj.get("blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val blksHit = jsonObj.get("blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && blksRead.isRight && blksHit.isRight) + Right(PgStatioUserSequencesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, blksRead = blksRead.toOption.get, blksHit = blksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, blksRead, blksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioUserSequencesViewRow] = new JsonEncoder[PgStatioUserSequencesViewRow] { + override def unsafeEncode(a: PgStatioUserSequencesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksRead, indent, out) + out.write(",") + out.write(""""blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.blksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewStructure.scala new file mode 100644 index 0000000000..72cfefa21e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_sequences/PgStatioUserSequencesViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_sequences + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioUserSequencesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioUserSequencesViewRow, val merge: (Row, PgStatioUserSequencesViewRow) => Row) + extends Relation[PgStatioUserSequencesViewFields, PgStatioUserSequencesViewRow, Row] + with PgStatioUserSequencesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val blksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "blks_read", None, None)(x => extract(x).blksRead, (row, value) => merge(row, extract(row).copy(blksRead = value))) + override val blksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "blks_hit", None, None)(x => extract(x).blksHit, (row, value) => merge(row, extract(row).copy(blksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, blksRead, blksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioUserSequencesViewRow, merge: (NewRow, PgStatioUserSequencesViewRow) => NewRow): PgStatioUserSequencesViewStructure[NewRow] = + new PgStatioUserSequencesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewFields.scala new file mode 100644 index 0000000000..1ac7ebb165 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.OptField + +trait PgStatioUserTablesViewFields[Row] { + val relid: OptField[PgClassId, Row] + val schemaname: OptField[String, Row] + val relname: OptField[String, Row] + val heapBlksRead: OptField[/* nullability unknown */ Long, Row] + val heapBlksHit: OptField[/* nullability unknown */ Long, Row] + val idxBlksRead: OptField[/* nullability unknown */ Long, Row] + val idxBlksHit: OptField[/* nullability unknown */ Long, Row] + val toastBlksRead: OptField[/* nullability unknown */ Long, Row] + val toastBlksHit: OptField[/* nullability unknown */ Long, Row] + val tidxBlksRead: OptField[/* nullability unknown */ Long, Row] + val tidxBlksHit: OptField[/* nullability unknown */ Long, Row] +} +object PgStatioUserTablesViewFields extends PgStatioUserTablesViewStructure[PgStatioUserTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepo.scala new file mode 100644 index 0000000000..44e355aa9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatioUserTablesViewRepo { + def select: SelectBuilder[PgStatioUserTablesViewFields, PgStatioUserTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatioUserTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepoImpl.scala new file mode 100644 index 0000000000..a289132bfd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatioUserTablesViewRepoImpl extends PgStatioUserTablesViewRepo { + override def select: SelectBuilder[PgStatioUserTablesViewFields, PgStatioUserTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_statio_user_tables", PgStatioUserTablesViewFields, PgStatioUserTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatioUserTablesViewRow] = { + sql"""select "relid", "schemaname", "relname", "heap_blks_read", "heap_blks_hit", "idx_blks_read", "idx_blks_hit", "toast_blks_read", "toast_blks_hit", "tidx_blks_read", "tidx_blks_hit" from pg_catalog.pg_statio_user_tables""".query(PgStatioUserTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRow.scala new file mode 100644 index 0000000000..b3c7ac813d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewRow.scala @@ -0,0 +1,115 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatioUserTablesViewRow( + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.relid]] */ + relid: Option[PgClassId], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.schemaname]] */ + schemaname: Option[String], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.relname]] */ + relname: Option[String], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.heapBlksRead]] */ + heapBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.heapBlksHit]] */ + heapBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.idxBlksRead]] */ + idxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.idxBlksHit]] */ + idxBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.toastBlksRead]] */ + toastBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.toastBlksHit]] */ + toastBlksHit: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.tidxBlksRead]] */ + tidxBlksRead: Option[/* nullability unknown */ Long], + /** Points to [[pg_statio_all_tables.PgStatioAllTablesViewRow.tidxBlksHit]] */ + tidxBlksHit: Option[/* nullability unknown */ Long] +) + +object PgStatioUserTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatioUserTablesViewRow] = new JdbcDecoder[PgStatioUserTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatioUserTablesViewRow) = + columIndex + 10 -> + PgStatioUserTablesViewRow( + relid = JdbcDecoder.optionDecoder(PgClassId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + relname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + heapBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2, + heapBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 4, rs)._2, + idxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 5, rs)._2, + idxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 6, rs)._2, + toastBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 7, rs)._2, + toastBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 8, rs)._2, + tidxBlksRead = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 9, rs)._2, + tidxBlksHit = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatioUserTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val relid = jsonObj.get("relid").fold[Either[String, Option[PgClassId]]](Right(None))(_.as(JsonDecoder.option(PgClassId.jsonDecoder))) + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val relname = jsonObj.get("relname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val heapBlksRead = jsonObj.get("heap_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val heapBlksHit = jsonObj.get("heap_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksRead = jsonObj.get("idx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val idxBlksHit = jsonObj.get("idx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksRead = jsonObj.get("toast_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val toastBlksHit = jsonObj.get("toast_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksRead = jsonObj.get("tidx_blks_read").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val tidxBlksHit = jsonObj.get("tidx_blks_hit").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (relid.isRight && schemaname.isRight && relname.isRight && heapBlksRead.isRight && heapBlksHit.isRight && idxBlksRead.isRight && idxBlksHit.isRight && toastBlksRead.isRight && toastBlksHit.isRight && tidxBlksRead.isRight && tidxBlksHit.isRight) + Right(PgStatioUserTablesViewRow(relid = relid.toOption.get, schemaname = schemaname.toOption.get, relname = relname.toOption.get, heapBlksRead = heapBlksRead.toOption.get, heapBlksHit = heapBlksHit.toOption.get, idxBlksRead = idxBlksRead.toOption.get, idxBlksHit = idxBlksHit.toOption.get, toastBlksRead = toastBlksRead.toOption.get, toastBlksHit = toastBlksHit.toOption.get, tidxBlksRead = tidxBlksRead.toOption.get, tidxBlksHit = tidxBlksHit.toOption.get)) + else Left(List[Either[String, Any]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatioUserTablesViewRow] = new JsonEncoder[PgStatioUserTablesViewRow] { + override def unsafeEncode(a: PgStatioUserTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""relid":""") + JsonEncoder.option(PgClassId.jsonEncoder).unsafeEncode(a.relid, indent, out) + out.write(",") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""relname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.relname, indent, out) + out.write(",") + out.write(""""heap_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksRead, indent, out) + out.write(",") + out.write(""""heap_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.heapBlksHit, indent, out) + out.write(",") + out.write(""""idx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksRead, indent, out) + out.write(",") + out.write(""""idx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.idxBlksHit, indent, out) + out.write(",") + out.write(""""toast_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksRead, indent, out) + out.write(",") + out.write(""""toast_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.toastBlksHit, indent, out) + out.write(",") + out.write(""""tidx_blks_read":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksRead, indent, out) + out.write(",") + out.write(""""tidx_blks_hit":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.tidxBlksHit, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewStructure.scala new file mode 100644 index 0000000000..5e0b8f9a90 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statio_user_tables/PgStatioUserTablesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statio_user_tables + +import adventureworks.pg_catalog.pg_class.PgClassId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatioUserTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatioUserTablesViewRow, val merge: (Row, PgStatioUserTablesViewRow) => Row) + extends Relation[PgStatioUserTablesViewFields, PgStatioUserTablesViewRow, Row] + with PgStatioUserTablesViewFields[Row] { outer => + + override val relid = new OptField[PgClassId, Row](prefix, "relid", None, None)(x => extract(x).relid, (row, value) => merge(row, extract(row).copy(relid = value))) + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val relname = new OptField[String, Row](prefix, "relname", None, None)(x => extract(x).relname, (row, value) => merge(row, extract(row).copy(relname = value))) + override val heapBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "heap_blks_read", None, None)(x => extract(x).heapBlksRead, (row, value) => merge(row, extract(row).copy(heapBlksRead = value))) + override val heapBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "heap_blks_hit", None, None)(x => extract(x).heapBlksHit, (row, value) => merge(row, extract(row).copy(heapBlksHit = value))) + override val idxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_read", None, None)(x => extract(x).idxBlksRead, (row, value) => merge(row, extract(row).copy(idxBlksRead = value))) + override val idxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "idx_blks_hit", None, None)(x => extract(x).idxBlksHit, (row, value) => merge(row, extract(row).copy(idxBlksHit = value))) + override val toastBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "toast_blks_read", None, None)(x => extract(x).toastBlksRead, (row, value) => merge(row, extract(row).copy(toastBlksRead = value))) + override val toastBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "toast_blks_hit", None, None)(x => extract(x).toastBlksHit, (row, value) => merge(row, extract(row).copy(toastBlksHit = value))) + override val tidxBlksRead = new OptField[/* nullability unknown */ Long, Row](prefix, "tidx_blks_read", None, None)(x => extract(x).tidxBlksRead, (row, value) => merge(row, extract(row).copy(tidxBlksRead = value))) + override val tidxBlksHit = new OptField[/* nullability unknown */ Long, Row](prefix, "tidx_blks_hit", None, None)(x => extract(x).tidxBlksHit, (row, value) => merge(row, extract(row).copy(tidxBlksHit = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](relid, schemaname, relname, heapBlksRead, heapBlksHit, idxBlksRead, idxBlksHit, toastBlksRead, toastBlksHit, tidxBlksRead, tidxBlksHit) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatioUserTablesViewRow, merge: (NewRow, PgStatioUserTablesViewRow) => NewRow): PgStatioUserTablesViewStructure[NewRow] = + new PgStatioUserTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticFields.scala new file mode 100644 index 0000000000..75548c3f79 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticFields.scala @@ -0,0 +1,50 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgStatisticFields[Row] { + val starelid: IdField[/* oid */ Long, Row] + val staattnum: IdField[TypoShort, Row] + val stainherit: IdField[Boolean, Row] + val stanullfrac: Field[Float, Row] + val stawidth: Field[Int, Row] + val stadistinct: Field[Float, Row] + val stakind1: Field[TypoShort, Row] + val stakind2: Field[TypoShort, Row] + val stakind3: Field[TypoShort, Row] + val stakind4: Field[TypoShort, Row] + val stakind5: Field[TypoShort, Row] + val staop1: Field[/* oid */ Long, Row] + val staop2: Field[/* oid */ Long, Row] + val staop3: Field[/* oid */ Long, Row] + val staop4: Field[/* oid */ Long, Row] + val staop5: Field[/* oid */ Long, Row] + val stacoll1: Field[/* oid */ Long, Row] + val stacoll2: Field[/* oid */ Long, Row] + val stacoll3: Field[/* oid */ Long, Row] + val stacoll4: Field[/* oid */ Long, Row] + val stacoll5: Field[/* oid */ Long, Row] + val stanumbers1: OptField[Array[Float], Row] + val stanumbers2: OptField[Array[Float], Row] + val stanumbers3: OptField[Array[Float], Row] + val stanumbers4: OptField[Array[Float], Row] + val stanumbers5: OptField[Array[Float], Row] + val stavalues1: OptField[TypoAnyArray, Row] + val stavalues2: OptField[TypoAnyArray, Row] + val stavalues3: OptField[TypoAnyArray, Row] + val stavalues4: OptField[TypoAnyArray, Row] + val stavalues5: OptField[TypoAnyArray, Row] +} +object PgStatisticFields extends PgStatisticStructure[PgStatisticRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticId.scala new file mode 100644 index 0000000000..1a3c545595 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticId.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import adventureworks.customtypes.TypoShort +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_statistic` */ +case class PgStatisticId(starelid: /* oid */ Long, staattnum: TypoShort, stainherit: Boolean) +object PgStatisticId { + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val starelid = jsonObj.get("starelid").toRight("Missing field 'starelid'").flatMap(_.as(JsonDecoder.long)) + val staattnum = jsonObj.get("staattnum").toRight("Missing field 'staattnum'").flatMap(_.as(TypoShort.jsonDecoder)) + val stainherit = jsonObj.get("stainherit").toRight("Missing field 'stainherit'").flatMap(_.as(JsonDecoder.boolean)) + if (starelid.isRight && staattnum.isRight && stainherit.isRight) + Right(PgStatisticId(starelid = starelid.toOption.get, staattnum = staattnum.toOption.get, stainherit = stainherit.toOption.get)) + else Left(List[Either[String, Any]](starelid, staattnum, stainherit).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticId] = new JsonEncoder[PgStatisticId] { + override def unsafeEncode(a: PgStatisticId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""starelid":""") + JsonEncoder.long.unsafeEncode(a.starelid, indent, out) + out.write(",") + out.write(""""staattnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.staattnum, indent, out) + out.write(",") + out.write(""""stainherit":""") + JsonEncoder.boolean.unsafeEncode(a.stainherit, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoShort]): Ordering[PgStatisticId] = Ordering.by(x => (x.starelid, x.staattnum, x.stainherit)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepo.scala new file mode 100644 index 0000000000..e188228f31 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatisticRepo { + def delete(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgStatisticFields, PgStatisticRow] + def insert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, PgStatisticRow] + def select: SelectBuilder[PgStatisticFields, PgStatisticRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatisticRow] + def selectById(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Option[PgStatisticRow]] + def update(row: PgStatisticRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgStatisticFields, PgStatisticRow] + def upsert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoImpl.scala new file mode 100644 index 0000000000..e96939991b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoImpl.scala @@ -0,0 +1,149 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatisticRepoImpl extends PgStatisticRepo { + override def delete(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_statistic where "starelid" = ${Segment.paramSegment(compositeId.starelid)(Setter.longSetter)} AND "staattnum" = ${Segment.paramSegment(compositeId.staattnum)(TypoShort.setter)} AND "stainherit" = ${Segment.paramSegment(compositeId.stainherit)(Setter.booleanSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgStatisticFields, PgStatisticRow] = { + DeleteBuilder("pg_catalog.pg_statistic", PgStatisticFields) + } + override def insert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, PgStatisticRow] = { + sql"""insert into pg_catalog.pg_statistic("starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5") + values (${Segment.paramSegment(unsaved.starelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.staattnum)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.stainherit)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.stanullfrac)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.stawidth)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.stadistinct)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.stakind1)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.stakind2)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.stakind3)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.stakind4)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.stakind5)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.staop1)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.staop2)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.staop3)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.staop4)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.staop5)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stacoll1)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stacoll2)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stacoll3)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stacoll4)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stacoll5)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stanumbers1)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.stanumbers2)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.stanumbers3)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.stanumbers4)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.stanumbers5)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.stavalues1)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, ${Segment.paramSegment(unsaved.stavalues2)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, ${Segment.paramSegment(unsaved.stavalues3)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, ${Segment.paramSegment(unsaved.stavalues4)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, ${Segment.paramSegment(unsaved.stavalues5)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray) + returning "starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5" + """.insertReturning(PgStatisticRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgStatisticFields, PgStatisticRow] = { + SelectBuilderSql("pg_catalog.pg_statistic", PgStatisticFields, PgStatisticRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticRow] = { + sql"""select "starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5" from pg_catalog.pg_statistic""".query(PgStatisticRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Option[PgStatisticRow]] = { + sql"""select "starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5" from pg_catalog.pg_statistic where "starelid" = ${Segment.paramSegment(compositeId.starelid)(Setter.longSetter)} AND "staattnum" = ${Segment.paramSegment(compositeId.staattnum)(TypoShort.setter)} AND "stainherit" = ${Segment.paramSegment(compositeId.stainherit)(Setter.booleanSetter)}""".query(PgStatisticRow.jdbcDecoder).selectOne + } + override def update(row: PgStatisticRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_statistic + set "stanullfrac" = ${Segment.paramSegment(row.stanullfrac)(Setter.floatSetter)}::float4, + "stawidth" = ${Segment.paramSegment(row.stawidth)(Setter.intSetter)}::int4, + "stadistinct" = ${Segment.paramSegment(row.stadistinct)(Setter.floatSetter)}::float4, + "stakind1" = ${Segment.paramSegment(row.stakind1)(TypoShort.setter)}::int2, + "stakind2" = ${Segment.paramSegment(row.stakind2)(TypoShort.setter)}::int2, + "stakind3" = ${Segment.paramSegment(row.stakind3)(TypoShort.setter)}::int2, + "stakind4" = ${Segment.paramSegment(row.stakind4)(TypoShort.setter)}::int2, + "stakind5" = ${Segment.paramSegment(row.stakind5)(TypoShort.setter)}::int2, + "staop1" = ${Segment.paramSegment(row.staop1)(Setter.longSetter)}::oid, + "staop2" = ${Segment.paramSegment(row.staop2)(Setter.longSetter)}::oid, + "staop3" = ${Segment.paramSegment(row.staop3)(Setter.longSetter)}::oid, + "staop4" = ${Segment.paramSegment(row.staop4)(Setter.longSetter)}::oid, + "staop5" = ${Segment.paramSegment(row.staop5)(Setter.longSetter)}::oid, + "stacoll1" = ${Segment.paramSegment(row.stacoll1)(Setter.longSetter)}::oid, + "stacoll2" = ${Segment.paramSegment(row.stacoll2)(Setter.longSetter)}::oid, + "stacoll3" = ${Segment.paramSegment(row.stacoll3)(Setter.longSetter)}::oid, + "stacoll4" = ${Segment.paramSegment(row.stacoll4)(Setter.longSetter)}::oid, + "stacoll5" = ${Segment.paramSegment(row.stacoll5)(Setter.longSetter)}::oid, + "stanumbers1" = ${Segment.paramSegment(row.stanumbers1)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + "stanumbers2" = ${Segment.paramSegment(row.stanumbers2)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + "stanumbers3" = ${Segment.paramSegment(row.stanumbers3)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + "stanumbers4" = ${Segment.paramSegment(row.stanumbers4)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + "stanumbers5" = ${Segment.paramSegment(row.stanumbers5)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + "stavalues1" = ${Segment.paramSegment(row.stavalues1)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + "stavalues2" = ${Segment.paramSegment(row.stavalues2)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + "stavalues3" = ${Segment.paramSegment(row.stavalues3)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + "stavalues4" = ${Segment.paramSegment(row.stavalues4)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + "stavalues5" = ${Segment.paramSegment(row.stavalues5)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray + where "starelid" = ${Segment.paramSegment(compositeId.starelid)(Setter.longSetter)} AND "staattnum" = ${Segment.paramSegment(compositeId.staattnum)(TypoShort.setter)} AND "stainherit" = ${Segment.paramSegment(compositeId.stainherit)(Setter.booleanSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgStatisticFields, PgStatisticRow] = { + UpdateBuilder("pg_catalog.pg_statistic", PgStatisticFields, PgStatisticRow.jdbcDecoder) + } + override def upsert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticRow]] = { + sql"""insert into pg_catalog.pg_statistic("starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5") + values ( + ${Segment.paramSegment(unsaved.starelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.staattnum)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.stainherit)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.stanullfrac)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.stawidth)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.stadistinct)(Setter.floatSetter)}::float4, + ${Segment.paramSegment(unsaved.stakind1)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.stakind2)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.stakind3)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.stakind4)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.stakind5)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.staop1)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.staop2)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.staop3)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.staop4)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.staop5)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stacoll1)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stacoll2)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stacoll3)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stacoll4)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stacoll5)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stanumbers1)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + ${Segment.paramSegment(unsaved.stanumbers2)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + ${Segment.paramSegment(unsaved.stanumbers3)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + ${Segment.paramSegment(unsaved.stanumbers4)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + ${Segment.paramSegment(unsaved.stanumbers5)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, + ${Segment.paramSegment(unsaved.stavalues1)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + ${Segment.paramSegment(unsaved.stavalues2)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + ${Segment.paramSegment(unsaved.stavalues3)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + ${Segment.paramSegment(unsaved.stavalues4)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray, + ${Segment.paramSegment(unsaved.stavalues5)(Setter.optionParamSetter(TypoAnyArray.setter))}::anyarray + ) + on conflict ("starelid", "staattnum", "stainherit") + do update set + "stanullfrac" = EXCLUDED."stanullfrac", + "stawidth" = EXCLUDED."stawidth", + "stadistinct" = EXCLUDED."stadistinct", + "stakind1" = EXCLUDED."stakind1", + "stakind2" = EXCLUDED."stakind2", + "stakind3" = EXCLUDED."stakind3", + "stakind4" = EXCLUDED."stakind4", + "stakind5" = EXCLUDED."stakind5", + "staop1" = EXCLUDED."staop1", + "staop2" = EXCLUDED."staop2", + "staop3" = EXCLUDED."staop3", + "staop4" = EXCLUDED."staop4", + "staop5" = EXCLUDED."staop5", + "stacoll1" = EXCLUDED."stacoll1", + "stacoll2" = EXCLUDED."stacoll2", + "stacoll3" = EXCLUDED."stacoll3", + "stacoll4" = EXCLUDED."stacoll4", + "stacoll5" = EXCLUDED."stacoll5", + "stanumbers1" = EXCLUDED."stanumbers1", + "stanumbers2" = EXCLUDED."stanumbers2", + "stanumbers3" = EXCLUDED."stanumbers3", + "stanumbers4" = EXCLUDED."stanumbers4", + "stanumbers5" = EXCLUDED."stanumbers5", + "stavalues1" = EXCLUDED."stavalues1", + "stavalues2" = EXCLUDED."stavalues2", + "stavalues3" = EXCLUDED."stavalues3", + "stavalues4" = EXCLUDED."stavalues4", + "stavalues5" = EXCLUDED."stavalues5" + returning "starelid", "staattnum", "stainherit", "stanullfrac", "stawidth", "stadistinct", "stakind1", "stakind2", "stakind3", "stakind4", "stakind5", "staop1", "staop2", "staop3", "staop4", "staop5", "stacoll1", "stacoll2", "stacoll3", "stacoll4", "stacoll5", "stanumbers1", "stanumbers2", "stanumbers3", "stanumbers4", "stanumbers5", "stavalues1", "stavalues2", "stavalues3", "stavalues4", "stavalues5"""".insertReturning(PgStatisticRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoMock.scala new file mode 100644 index 0000000000..33f797d5e5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgStatisticRepoMock(map: scala.collection.mutable.Map[PgStatisticId, PgStatisticRow] = scala.collection.mutable.Map.empty) extends PgStatisticRepo { + override def delete(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgStatisticFields, PgStatisticRow] = { + DeleteBuilderMock(DeleteParams.empty, PgStatisticFields, map) + } + override def insert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, PgStatisticRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgStatisticFields, PgStatisticRow] = { + SelectBuilderMock(PgStatisticFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgStatisticId): ZIO[ZConnection, Throwable, Option[PgStatisticRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgStatisticRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgStatisticFields, PgStatisticRow] = { + UpdateBuilderMock(UpdateParams.empty, PgStatisticFields, map) + } + override def upsert(unsaved: PgStatisticRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRow.scala new file mode 100644 index 0000000000..86a25a2233 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticRow.scala @@ -0,0 +1,227 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatisticRow( + starelid: /* oid */ Long, + staattnum: TypoShort, + stainherit: Boolean, + stanullfrac: Float, + stawidth: Int, + stadistinct: Float, + stakind1: TypoShort, + stakind2: TypoShort, + stakind3: TypoShort, + stakind4: TypoShort, + stakind5: TypoShort, + staop1: /* oid */ Long, + staop2: /* oid */ Long, + staop3: /* oid */ Long, + staop4: /* oid */ Long, + staop5: /* oid */ Long, + stacoll1: /* oid */ Long, + stacoll2: /* oid */ Long, + stacoll3: /* oid */ Long, + stacoll4: /* oid */ Long, + stacoll5: /* oid */ Long, + stanumbers1: Option[Array[Float]], + stanumbers2: Option[Array[Float]], + stanumbers3: Option[Array[Float]], + stanumbers4: Option[Array[Float]], + stanumbers5: Option[Array[Float]], + stavalues1: Option[TypoAnyArray], + stavalues2: Option[TypoAnyArray], + stavalues3: Option[TypoAnyArray], + stavalues4: Option[TypoAnyArray], + stavalues5: Option[TypoAnyArray] +){ + val compositeId: PgStatisticId = PgStatisticId(starelid, staattnum, stainherit) + } + +object PgStatisticRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatisticRow] = new JdbcDecoder[PgStatisticRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatisticRow) = + columIndex + 30 -> + PgStatisticRow( + starelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + staattnum = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + stainherit = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 2, rs)._2, + stanullfrac = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 3, rs)._2, + stawidth = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 4, rs)._2, + stadistinct = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 5, rs)._2, + stakind1 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + stakind2 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + stakind3 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + stakind4 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + stakind5 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + staop1 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 11, rs)._2, + staop2 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 12, rs)._2, + staop3 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 13, rs)._2, + staop4 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 14, rs)._2, + staop5 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 15, rs)._2, + stacoll1 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 16, rs)._2, + stacoll2 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 17, rs)._2, + stacoll3 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 18, rs)._2, + stacoll4 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 19, rs)._2, + stacoll5 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 20, rs)._2, + stanumbers1 = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 21, rs)._2, + stanumbers2 = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 22, rs)._2, + stanumbers3 = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 23, rs)._2, + stanumbers4 = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 24, rs)._2, + stanumbers5 = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 25, rs)._2, + stavalues1 = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 26, rs)._2, + stavalues2 = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 27, rs)._2, + stavalues3 = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 28, rs)._2, + stavalues4 = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 29, rs)._2, + stavalues5 = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 30, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val starelid = jsonObj.get("starelid").toRight("Missing field 'starelid'").flatMap(_.as(JsonDecoder.long)) + val staattnum = jsonObj.get("staattnum").toRight("Missing field 'staattnum'").flatMap(_.as(TypoShort.jsonDecoder)) + val stainherit = jsonObj.get("stainherit").toRight("Missing field 'stainherit'").flatMap(_.as(JsonDecoder.boolean)) + val stanullfrac = jsonObj.get("stanullfrac").toRight("Missing field 'stanullfrac'").flatMap(_.as(JsonDecoder.float)) + val stawidth = jsonObj.get("stawidth").toRight("Missing field 'stawidth'").flatMap(_.as(JsonDecoder.int)) + val stadistinct = jsonObj.get("stadistinct").toRight("Missing field 'stadistinct'").flatMap(_.as(JsonDecoder.float)) + val stakind1 = jsonObj.get("stakind1").toRight("Missing field 'stakind1'").flatMap(_.as(TypoShort.jsonDecoder)) + val stakind2 = jsonObj.get("stakind2").toRight("Missing field 'stakind2'").flatMap(_.as(TypoShort.jsonDecoder)) + val stakind3 = jsonObj.get("stakind3").toRight("Missing field 'stakind3'").flatMap(_.as(TypoShort.jsonDecoder)) + val stakind4 = jsonObj.get("stakind4").toRight("Missing field 'stakind4'").flatMap(_.as(TypoShort.jsonDecoder)) + val stakind5 = jsonObj.get("stakind5").toRight("Missing field 'stakind5'").flatMap(_.as(TypoShort.jsonDecoder)) + val staop1 = jsonObj.get("staop1").toRight("Missing field 'staop1'").flatMap(_.as(JsonDecoder.long)) + val staop2 = jsonObj.get("staop2").toRight("Missing field 'staop2'").flatMap(_.as(JsonDecoder.long)) + val staop3 = jsonObj.get("staop3").toRight("Missing field 'staop3'").flatMap(_.as(JsonDecoder.long)) + val staop4 = jsonObj.get("staop4").toRight("Missing field 'staop4'").flatMap(_.as(JsonDecoder.long)) + val staop5 = jsonObj.get("staop5").toRight("Missing field 'staop5'").flatMap(_.as(JsonDecoder.long)) + val stacoll1 = jsonObj.get("stacoll1").toRight("Missing field 'stacoll1'").flatMap(_.as(JsonDecoder.long)) + val stacoll2 = jsonObj.get("stacoll2").toRight("Missing field 'stacoll2'").flatMap(_.as(JsonDecoder.long)) + val stacoll3 = jsonObj.get("stacoll3").toRight("Missing field 'stacoll3'").flatMap(_.as(JsonDecoder.long)) + val stacoll4 = jsonObj.get("stacoll4").toRight("Missing field 'stacoll4'").flatMap(_.as(JsonDecoder.long)) + val stacoll5 = jsonObj.get("stacoll5").toRight("Missing field 'stacoll5'").flatMap(_.as(JsonDecoder.long)) + val stanumbers1 = jsonObj.get("stanumbers1").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val stanumbers2 = jsonObj.get("stanumbers2").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val stanumbers3 = jsonObj.get("stanumbers3").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val stanumbers4 = jsonObj.get("stanumbers4").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val stanumbers5 = jsonObj.get("stanumbers5").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val stavalues1 = jsonObj.get("stavalues1").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val stavalues2 = jsonObj.get("stavalues2").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val stavalues3 = jsonObj.get("stavalues3").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val stavalues4 = jsonObj.get("stavalues4").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val stavalues5 = jsonObj.get("stavalues5").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + if (starelid.isRight && staattnum.isRight && stainherit.isRight && stanullfrac.isRight && stawidth.isRight && stadistinct.isRight && stakind1.isRight && stakind2.isRight && stakind3.isRight && stakind4.isRight && stakind5.isRight && staop1.isRight && staop2.isRight && staop3.isRight && staop4.isRight && staop5.isRight && stacoll1.isRight && stacoll2.isRight && stacoll3.isRight && stacoll4.isRight && stacoll5.isRight && stanumbers1.isRight && stanumbers2.isRight && stanumbers3.isRight && stanumbers4.isRight && stanumbers5.isRight && stavalues1.isRight && stavalues2.isRight && stavalues3.isRight && stavalues4.isRight && stavalues5.isRight) + Right(PgStatisticRow(starelid = starelid.toOption.get, staattnum = staattnum.toOption.get, stainherit = stainherit.toOption.get, stanullfrac = stanullfrac.toOption.get, stawidth = stawidth.toOption.get, stadistinct = stadistinct.toOption.get, stakind1 = stakind1.toOption.get, stakind2 = stakind2.toOption.get, stakind3 = stakind3.toOption.get, stakind4 = stakind4.toOption.get, stakind5 = stakind5.toOption.get, staop1 = staop1.toOption.get, staop2 = staop2.toOption.get, staop3 = staop3.toOption.get, staop4 = staop4.toOption.get, staop5 = staop5.toOption.get, stacoll1 = stacoll1.toOption.get, stacoll2 = stacoll2.toOption.get, stacoll3 = stacoll3.toOption.get, stacoll4 = stacoll4.toOption.get, stacoll5 = stacoll5.toOption.get, stanumbers1 = stanumbers1.toOption.get, stanumbers2 = stanumbers2.toOption.get, stanumbers3 = stanumbers3.toOption.get, stanumbers4 = stanumbers4.toOption.get, stanumbers5 = stanumbers5.toOption.get, stavalues1 = stavalues1.toOption.get, stavalues2 = stavalues2.toOption.get, stavalues3 = stavalues3.toOption.get, stavalues4 = stavalues4.toOption.get, stavalues5 = stavalues5.toOption.get)) + else Left(List[Either[String, Any]](starelid, staattnum, stainherit, stanullfrac, stawidth, stadistinct, stakind1, stakind2, stakind3, stakind4, stakind5, staop1, staop2, staop3, staop4, staop5, stacoll1, stacoll2, stacoll3, stacoll4, stacoll5, stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5, stavalues1, stavalues2, stavalues3, stavalues4, stavalues5).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticRow] = new JsonEncoder[PgStatisticRow] { + override def unsafeEncode(a: PgStatisticRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""starelid":""") + JsonEncoder.long.unsafeEncode(a.starelid, indent, out) + out.write(",") + out.write(""""staattnum":""") + TypoShort.jsonEncoder.unsafeEncode(a.staattnum, indent, out) + out.write(",") + out.write(""""stainherit":""") + JsonEncoder.boolean.unsafeEncode(a.stainherit, indent, out) + out.write(",") + out.write(""""stanullfrac":""") + JsonEncoder.float.unsafeEncode(a.stanullfrac, indent, out) + out.write(",") + out.write(""""stawidth":""") + JsonEncoder.int.unsafeEncode(a.stawidth, indent, out) + out.write(",") + out.write(""""stadistinct":""") + JsonEncoder.float.unsafeEncode(a.stadistinct, indent, out) + out.write(",") + out.write(""""stakind1":""") + TypoShort.jsonEncoder.unsafeEncode(a.stakind1, indent, out) + out.write(",") + out.write(""""stakind2":""") + TypoShort.jsonEncoder.unsafeEncode(a.stakind2, indent, out) + out.write(",") + out.write(""""stakind3":""") + TypoShort.jsonEncoder.unsafeEncode(a.stakind3, indent, out) + out.write(",") + out.write(""""stakind4":""") + TypoShort.jsonEncoder.unsafeEncode(a.stakind4, indent, out) + out.write(",") + out.write(""""stakind5":""") + TypoShort.jsonEncoder.unsafeEncode(a.stakind5, indent, out) + out.write(",") + out.write(""""staop1":""") + JsonEncoder.long.unsafeEncode(a.staop1, indent, out) + out.write(",") + out.write(""""staop2":""") + JsonEncoder.long.unsafeEncode(a.staop2, indent, out) + out.write(",") + out.write(""""staop3":""") + JsonEncoder.long.unsafeEncode(a.staop3, indent, out) + out.write(",") + out.write(""""staop4":""") + JsonEncoder.long.unsafeEncode(a.staop4, indent, out) + out.write(",") + out.write(""""staop5":""") + JsonEncoder.long.unsafeEncode(a.staop5, indent, out) + out.write(",") + out.write(""""stacoll1":""") + JsonEncoder.long.unsafeEncode(a.stacoll1, indent, out) + out.write(",") + out.write(""""stacoll2":""") + JsonEncoder.long.unsafeEncode(a.stacoll2, indent, out) + out.write(",") + out.write(""""stacoll3":""") + JsonEncoder.long.unsafeEncode(a.stacoll3, indent, out) + out.write(",") + out.write(""""stacoll4":""") + JsonEncoder.long.unsafeEncode(a.stacoll4, indent, out) + out.write(",") + out.write(""""stacoll5":""") + JsonEncoder.long.unsafeEncode(a.stacoll5, indent, out) + out.write(",") + out.write(""""stanumbers1":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.stanumbers1, indent, out) + out.write(",") + out.write(""""stanumbers2":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.stanumbers2, indent, out) + out.write(",") + out.write(""""stanumbers3":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.stanumbers3, indent, out) + out.write(",") + out.write(""""stanumbers4":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.stanumbers4, indent, out) + out.write(",") + out.write(""""stanumbers5":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.stanumbers5, indent, out) + out.write(",") + out.write(""""stavalues1":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.stavalues1, indent, out) + out.write(",") + out.write(""""stavalues2":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.stavalues2, indent, out) + out.write(",") + out.write(""""stavalues3":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.stavalues3, indent, out) + out.write(",") + out.write(""""stavalues4":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.stavalues4, indent, out) + out.write(",") + out.write(""""stavalues5":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.stavalues5, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticStructure.scala new file mode 100644 index 0000000000..825952408b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic/PgStatisticStructure.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic + +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatisticStructure[Row](val prefix: Option[String], val extract: Row => PgStatisticRow, val merge: (Row, PgStatisticRow) => Row) + extends Relation[PgStatisticFields, PgStatisticRow, Row] + with PgStatisticFields[Row] { outer => + + override val starelid = new IdField[/* oid */ Long, Row](prefix, "starelid", None, Some("oid"))(x => extract(x).starelid, (row, value) => merge(row, extract(row).copy(starelid = value))) + override val staattnum = new IdField[TypoShort, Row](prefix, "staattnum", None, Some("int2"))(x => extract(x).staattnum, (row, value) => merge(row, extract(row).copy(staattnum = value))) + override val stainherit = new IdField[Boolean, Row](prefix, "stainherit", None, None)(x => extract(x).stainherit, (row, value) => merge(row, extract(row).copy(stainherit = value))) + override val stanullfrac = new Field[Float, Row](prefix, "stanullfrac", None, Some("float4"))(x => extract(x).stanullfrac, (row, value) => merge(row, extract(row).copy(stanullfrac = value))) + override val stawidth = new Field[Int, Row](prefix, "stawidth", None, Some("int4"))(x => extract(x).stawidth, (row, value) => merge(row, extract(row).copy(stawidth = value))) + override val stadistinct = new Field[Float, Row](prefix, "stadistinct", None, Some("float4"))(x => extract(x).stadistinct, (row, value) => merge(row, extract(row).copy(stadistinct = value))) + override val stakind1 = new Field[TypoShort, Row](prefix, "stakind1", None, Some("int2"))(x => extract(x).stakind1, (row, value) => merge(row, extract(row).copy(stakind1 = value))) + override val stakind2 = new Field[TypoShort, Row](prefix, "stakind2", None, Some("int2"))(x => extract(x).stakind2, (row, value) => merge(row, extract(row).copy(stakind2 = value))) + override val stakind3 = new Field[TypoShort, Row](prefix, "stakind3", None, Some("int2"))(x => extract(x).stakind3, (row, value) => merge(row, extract(row).copy(stakind3 = value))) + override val stakind4 = new Field[TypoShort, Row](prefix, "stakind4", None, Some("int2"))(x => extract(x).stakind4, (row, value) => merge(row, extract(row).copy(stakind4 = value))) + override val stakind5 = new Field[TypoShort, Row](prefix, "stakind5", None, Some("int2"))(x => extract(x).stakind5, (row, value) => merge(row, extract(row).copy(stakind5 = value))) + override val staop1 = new Field[/* oid */ Long, Row](prefix, "staop1", None, Some("oid"))(x => extract(x).staop1, (row, value) => merge(row, extract(row).copy(staop1 = value))) + override val staop2 = new Field[/* oid */ Long, Row](prefix, "staop2", None, Some("oid"))(x => extract(x).staop2, (row, value) => merge(row, extract(row).copy(staop2 = value))) + override val staop3 = new Field[/* oid */ Long, Row](prefix, "staop3", None, Some("oid"))(x => extract(x).staop3, (row, value) => merge(row, extract(row).copy(staop3 = value))) + override val staop4 = new Field[/* oid */ Long, Row](prefix, "staop4", None, Some("oid"))(x => extract(x).staop4, (row, value) => merge(row, extract(row).copy(staop4 = value))) + override val staop5 = new Field[/* oid */ Long, Row](prefix, "staop5", None, Some("oid"))(x => extract(x).staop5, (row, value) => merge(row, extract(row).copy(staop5 = value))) + override val stacoll1 = new Field[/* oid */ Long, Row](prefix, "stacoll1", None, Some("oid"))(x => extract(x).stacoll1, (row, value) => merge(row, extract(row).copy(stacoll1 = value))) + override val stacoll2 = new Field[/* oid */ Long, Row](prefix, "stacoll2", None, Some("oid"))(x => extract(x).stacoll2, (row, value) => merge(row, extract(row).copy(stacoll2 = value))) + override val stacoll3 = new Field[/* oid */ Long, Row](prefix, "stacoll3", None, Some("oid"))(x => extract(x).stacoll3, (row, value) => merge(row, extract(row).copy(stacoll3 = value))) + override val stacoll4 = new Field[/* oid */ Long, Row](prefix, "stacoll4", None, Some("oid"))(x => extract(x).stacoll4, (row, value) => merge(row, extract(row).copy(stacoll4 = value))) + override val stacoll5 = new Field[/* oid */ Long, Row](prefix, "stacoll5", None, Some("oid"))(x => extract(x).stacoll5, (row, value) => merge(row, extract(row).copy(stacoll5 = value))) + override val stanumbers1 = new OptField[Array[Float], Row](prefix, "stanumbers1", None, Some("_float4"))(x => extract(x).stanumbers1, (row, value) => merge(row, extract(row).copy(stanumbers1 = value))) + override val stanumbers2 = new OptField[Array[Float], Row](prefix, "stanumbers2", None, Some("_float4"))(x => extract(x).stanumbers2, (row, value) => merge(row, extract(row).copy(stanumbers2 = value))) + override val stanumbers3 = new OptField[Array[Float], Row](prefix, "stanumbers3", None, Some("_float4"))(x => extract(x).stanumbers3, (row, value) => merge(row, extract(row).copy(stanumbers3 = value))) + override val stanumbers4 = new OptField[Array[Float], Row](prefix, "stanumbers4", None, Some("_float4"))(x => extract(x).stanumbers4, (row, value) => merge(row, extract(row).copy(stanumbers4 = value))) + override val stanumbers5 = new OptField[Array[Float], Row](prefix, "stanumbers5", None, Some("_float4"))(x => extract(x).stanumbers5, (row, value) => merge(row, extract(row).copy(stanumbers5 = value))) + override val stavalues1 = new OptField[TypoAnyArray, Row](prefix, "stavalues1", None, Some("anyarray"))(x => extract(x).stavalues1, (row, value) => merge(row, extract(row).copy(stavalues1 = value))) + override val stavalues2 = new OptField[TypoAnyArray, Row](prefix, "stavalues2", None, Some("anyarray"))(x => extract(x).stavalues2, (row, value) => merge(row, extract(row).copy(stavalues2 = value))) + override val stavalues3 = new OptField[TypoAnyArray, Row](prefix, "stavalues3", None, Some("anyarray"))(x => extract(x).stavalues3, (row, value) => merge(row, extract(row).copy(stavalues3 = value))) + override val stavalues4 = new OptField[TypoAnyArray, Row](prefix, "stavalues4", None, Some("anyarray"))(x => extract(x).stavalues4, (row, value) => merge(row, extract(row).copy(stavalues4 = value))) + override val stavalues5 = new OptField[TypoAnyArray, Row](prefix, "stavalues5", None, Some("anyarray"))(x => extract(x).stavalues5, (row, value) => merge(row, extract(row).copy(stavalues5 = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](starelid, staattnum, stainherit, stanullfrac, stawidth, stadistinct, stakind1, stakind2, stakind3, stakind4, stakind5, staop1, staop2, staop3, staop4, staop5, stacoll1, stacoll2, stacoll3, stacoll4, stacoll5, stanumbers1, stanumbers2, stanumbers3, stanumbers4, stanumbers5, stavalues1, stavalues2, stavalues3, stavalues4, stavalues5) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatisticRow, merge: (NewRow, PgStatisticRow) => NewRow): PgStatisticStructure[NewRow] = + new PgStatisticStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtFields.scala new file mode 100644 index 0000000000..e8b9d6b96f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgStatisticExtFields[Row] { + val oid: IdField[PgStatisticExtId, Row] + val stxrelid: Field[/* oid */ Long, Row] + val stxname: Field[String, Row] + val stxnamespace: Field[/* oid */ Long, Row] + val stxowner: Field[/* oid */ Long, Row] + val stxstattarget: Field[Int, Row] + val stxkeys: Field[TypoInt2Vector, Row] + val stxkind: Field[Array[String], Row] + val stxexprs: OptField[TypoPgNodeTree, Row] +} +object PgStatisticExtFields extends PgStatisticExtStructure[PgStatisticExtRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtId.scala new file mode 100644 index 0000000000..5874216479 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +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 `pg_catalog.pg_statistic_ext` */ +case class PgStatisticExtId(value: /* oid */ Long) extends AnyVal +object PgStatisticExtId { + implicit lazy val arraySetter: Setter[Array[PgStatisticExtId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgStatisticExtId, /* oid */ Long] = Bijection[PgStatisticExtId, /* oid */ Long](_.value)(PgStatisticExtId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatisticExtId] = JdbcDecoder.longDecoder.map(PgStatisticExtId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgStatisticExtId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticExtId] = JsonDecoder.long.map(PgStatisticExtId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticExtId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgStatisticExtId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgStatisticExtId] = ParameterMetaData.instance[PgStatisticExtId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgStatisticExtId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepo.scala new file mode 100644 index 0000000000..738e1d4eda --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatisticExtRepo { + def delete(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgStatisticExtFields, PgStatisticExtRow] + def insert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, PgStatisticExtRow] + def select: SelectBuilder[PgStatisticExtFields, PgStatisticExtRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtRow] + def selectById(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] + def selectByIds(oids: Array[PgStatisticExtId]): ZStream[ZConnection, Throwable, PgStatisticExtRow] + def selectByUnique(stxname: String, stxnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] + def update(row: PgStatisticExtRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgStatisticExtFields, PgStatisticExtRow] + def upsert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoImpl.scala new file mode 100644 index 0000000000..34b1e534f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoImpl.scala @@ -0,0 +1,96 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatisticExtRepoImpl extends PgStatisticExtRepo { + override def delete(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_statistic_ext where "oid" = ${Segment.paramSegment(oid)(PgStatisticExtId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + DeleteBuilder("pg_catalog.pg_statistic_ext", PgStatisticExtFields) + } + override def insert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, PgStatisticExtRow] = { + sql"""insert into pg_catalog.pg_statistic_ext("oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs") + values (${Segment.paramSegment(unsaved.oid)(PgStatisticExtId.setter)}::oid, ${Segment.paramSegment(unsaved.stxrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stxname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.stxnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stxowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.stxstattarget)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.stxkeys)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.stxkind)(adventureworks.StringArraySetter)}::_char, ${Segment.paramSegment(unsaved.stxexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree) + returning "oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs" + """.insertReturning(PgStatisticExtRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + SelectBuilderSql("pg_catalog.pg_statistic_ext", PgStatisticExtFields, PgStatisticExtRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtRow] = { + sql"""select "oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs" from pg_catalog.pg_statistic_ext""".query(PgStatisticExtRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] = { + sql"""select "oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs" from pg_catalog.pg_statistic_ext where "oid" = ${Segment.paramSegment(oid)(PgStatisticExtId.setter)}""".query(PgStatisticExtRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgStatisticExtId]): ZStream[ZConnection, Throwable, PgStatisticExtRow] = { + sql"""select "oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs" from pg_catalog.pg_statistic_ext where "oid" = ANY(${Segment.paramSegment(oids)(PgStatisticExtId.arraySetter)})""".query(PgStatisticExtRow.jdbcDecoder).selectStream + } + override def selectByUnique(stxname: String, stxnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] = { + sql"""select "stxname", "stxnamespace" + from pg_catalog.pg_statistic_ext + where "stxname" = ${Segment.paramSegment(stxname)(Setter.stringSetter)} AND "stxnamespace" = ${Segment.paramSegment(stxnamespace)(Setter.longSetter)} + """.query(PgStatisticExtRow.jdbcDecoder).selectOne + } + override def update(row: PgStatisticExtRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_statistic_ext + set "stxrelid" = ${Segment.paramSegment(row.stxrelid)(Setter.longSetter)}::oid, + "stxname" = ${Segment.paramSegment(row.stxname)(Setter.stringSetter)}::name, + "stxnamespace" = ${Segment.paramSegment(row.stxnamespace)(Setter.longSetter)}::oid, + "stxowner" = ${Segment.paramSegment(row.stxowner)(Setter.longSetter)}::oid, + "stxstattarget" = ${Segment.paramSegment(row.stxstattarget)(Setter.intSetter)}::int4, + "stxkeys" = ${Segment.paramSegment(row.stxkeys)(TypoInt2Vector.setter)}::int2vector, + "stxkind" = ${Segment.paramSegment(row.stxkind)(adventureworks.StringArraySetter)}::_char, + "stxexprs" = ${Segment.paramSegment(row.stxexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + where "oid" = ${Segment.paramSegment(oid)(PgStatisticExtId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + UpdateBuilder("pg_catalog.pg_statistic_ext", PgStatisticExtFields, PgStatisticExtRow.jdbcDecoder) + } + override def upsert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtRow]] = { + sql"""insert into pg_catalog.pg_statistic_ext("oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs") + values ( + ${Segment.paramSegment(unsaved.oid)(PgStatisticExtId.setter)}::oid, + ${Segment.paramSegment(unsaved.stxrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stxname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.stxnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stxowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.stxstattarget)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.stxkeys)(TypoInt2Vector.setter)}::int2vector, + ${Segment.paramSegment(unsaved.stxkind)(adventureworks.StringArraySetter)}::_char, + ${Segment.paramSegment(unsaved.stxexprs)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree + ) + on conflict ("oid") + do update set + "stxrelid" = EXCLUDED."stxrelid", + "stxname" = EXCLUDED."stxname", + "stxnamespace" = EXCLUDED."stxnamespace", + "stxowner" = EXCLUDED."stxowner", + "stxstattarget" = EXCLUDED."stxstattarget", + "stxkeys" = EXCLUDED."stxkeys", + "stxkind" = EXCLUDED."stxkind", + "stxexprs" = EXCLUDED."stxexprs" + returning "oid", "stxrelid", "stxname", "stxnamespace", "stxowner", "stxstattarget", "stxkeys", "stxkind", "stxexprs"""".insertReturning(PgStatisticExtRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoMock.scala new file mode 100644 index 0000000000..2d226a94f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgStatisticExtRepoMock(map: scala.collection.mutable.Map[PgStatisticExtId, PgStatisticExtRow] = scala.collection.mutable.Map.empty) extends PgStatisticExtRepo { + override def delete(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + DeleteBuilderMock(DeleteParams.empty, PgStatisticExtFields, map) + } + override def insert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, PgStatisticExtRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + SelectBuilderMock(PgStatisticExtFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgStatisticExtId): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgStatisticExtId]): ZStream[ZConnection, Throwable, PgStatisticExtRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(stxname: String, stxnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgStatisticExtRow]] = { + ZIO.succeed(map.values.find(v => stxname == v.stxname && stxnamespace == v.stxnamespace)) + } + override def update(row: PgStatisticExtRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgStatisticExtFields, PgStatisticExtRow] = { + UpdateBuilderMock(UpdateParams.empty, PgStatisticExtFields, map) + } + override def upsert(unsaved: PgStatisticExtRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRow.scala new file mode 100644 index 0000000000..3f17956cbe --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtRow.scala @@ -0,0 +1,93 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatisticExtRow( + oid: PgStatisticExtId, + stxrelid: /* oid */ Long, + stxname: String, + stxnamespace: /* oid */ Long, + stxowner: /* oid */ Long, + stxstattarget: Int, + stxkeys: TypoInt2Vector, + stxkind: Array[String], + stxexprs: Option[TypoPgNodeTree] +) + +object PgStatisticExtRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatisticExtRow] = new JdbcDecoder[PgStatisticExtRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatisticExtRow) = + columIndex + 8 -> + PgStatisticExtRow( + oid = PgStatisticExtId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stxrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + stxname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + stxnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + stxowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + stxstattarget = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 5, rs)._2, + stxkeys = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + stxkind = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 7, rs)._2, + stxexprs = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticExtRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgStatisticExtId.jsonDecoder)) + val stxrelid = jsonObj.get("stxrelid").toRight("Missing field 'stxrelid'").flatMap(_.as(JsonDecoder.long)) + val stxname = jsonObj.get("stxname").toRight("Missing field 'stxname'").flatMap(_.as(JsonDecoder.string)) + val stxnamespace = jsonObj.get("stxnamespace").toRight("Missing field 'stxnamespace'").flatMap(_.as(JsonDecoder.long)) + val stxowner = jsonObj.get("stxowner").toRight("Missing field 'stxowner'").flatMap(_.as(JsonDecoder.long)) + val stxstattarget = jsonObj.get("stxstattarget").toRight("Missing field 'stxstattarget'").flatMap(_.as(JsonDecoder.int)) + val stxkeys = jsonObj.get("stxkeys").toRight("Missing field 'stxkeys'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val stxkind = jsonObj.get("stxkind").toRight("Missing field 'stxkind'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val stxexprs = jsonObj.get("stxexprs").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + if (oid.isRight && stxrelid.isRight && stxname.isRight && stxnamespace.isRight && stxowner.isRight && stxstattarget.isRight && stxkeys.isRight && stxkind.isRight && stxexprs.isRight) + Right(PgStatisticExtRow(oid = oid.toOption.get, stxrelid = stxrelid.toOption.get, stxname = stxname.toOption.get, stxnamespace = stxnamespace.toOption.get, stxowner = stxowner.toOption.get, stxstattarget = stxstattarget.toOption.get, stxkeys = stxkeys.toOption.get, stxkind = stxkind.toOption.get, stxexprs = stxexprs.toOption.get)) + else Left(List[Either[String, Any]](oid, stxrelid, stxname, stxnamespace, stxowner, stxstattarget, stxkeys, stxkind, stxexprs).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticExtRow] = new JsonEncoder[PgStatisticExtRow] { + override def unsafeEncode(a: PgStatisticExtRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgStatisticExtId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""stxrelid":""") + JsonEncoder.long.unsafeEncode(a.stxrelid, indent, out) + out.write(",") + out.write(""""stxname":""") + JsonEncoder.string.unsafeEncode(a.stxname, indent, out) + out.write(",") + out.write(""""stxnamespace":""") + JsonEncoder.long.unsafeEncode(a.stxnamespace, indent, out) + out.write(",") + out.write(""""stxowner":""") + JsonEncoder.long.unsafeEncode(a.stxowner, indent, out) + out.write(",") + out.write(""""stxstattarget":""") + JsonEncoder.int.unsafeEncode(a.stxstattarget, indent, out) + out.write(",") + out.write(""""stxkeys":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.stxkeys, indent, out) + out.write(",") + out.write(""""stxkind":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.stxkind, indent, out) + out.write(",") + out.write(""""stxexprs":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.stxexprs, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtStructure.scala new file mode 100644 index 0000000000..986df7f628 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext/PgStatisticExtStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext + +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatisticExtStructure[Row](val prefix: Option[String], val extract: Row => PgStatisticExtRow, val merge: (Row, PgStatisticExtRow) => Row) + extends Relation[PgStatisticExtFields, PgStatisticExtRow, Row] + with PgStatisticExtFields[Row] { outer => + + override val oid = new IdField[PgStatisticExtId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val stxrelid = new Field[/* oid */ Long, Row](prefix, "stxrelid", None, Some("oid"))(x => extract(x).stxrelid, (row, value) => merge(row, extract(row).copy(stxrelid = value))) + override val stxname = new Field[String, Row](prefix, "stxname", None, Some("name"))(x => extract(x).stxname, (row, value) => merge(row, extract(row).copy(stxname = value))) + override val stxnamespace = new Field[/* oid */ Long, Row](prefix, "stxnamespace", None, Some("oid"))(x => extract(x).stxnamespace, (row, value) => merge(row, extract(row).copy(stxnamespace = value))) + override val stxowner = new Field[/* oid */ Long, Row](prefix, "stxowner", None, Some("oid"))(x => extract(x).stxowner, (row, value) => merge(row, extract(row).copy(stxowner = value))) + override val stxstattarget = new Field[Int, Row](prefix, "stxstattarget", None, Some("int4"))(x => extract(x).stxstattarget, (row, value) => merge(row, extract(row).copy(stxstattarget = value))) + override val stxkeys = new Field[TypoInt2Vector, Row](prefix, "stxkeys", None, Some("int2vector"))(x => extract(x).stxkeys, (row, value) => merge(row, extract(row).copy(stxkeys = value))) + override val stxkind = new Field[Array[String], Row](prefix, "stxkind", None, Some("_char"))(x => extract(x).stxkind, (row, value) => merge(row, extract(row).copy(stxkind = value))) + override val stxexprs = new OptField[TypoPgNodeTree, Row](prefix, "stxexprs", None, Some("pg_node_tree"))(x => extract(x).stxexprs, (row, value) => merge(row, extract(row).copy(stxexprs = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, stxrelid, stxname, stxnamespace, stxowner, stxstattarget, stxkeys, stxkind, stxexprs) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatisticExtRow, merge: (NewRow, PgStatisticExtRow) => NewRow): PgStatisticExtStructure[NewRow] = + new PgStatisticExtStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataFields.scala new file mode 100644 index 0000000000..ce6b41b5e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgMcvList +import adventureworks.customtypes.TypoUnknownPgNdistinct +import adventureworks.customtypes.TypoUnknownPgStatistic +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgStatisticExtDataFields[Row] { + val stxoid: IdField[PgStatisticExtDataId, Row] + val stxdndistinct: OptField[TypoUnknownPgNdistinct, Row] + val stxddependencies: OptField[TypoUnknownPgDependencies, Row] + val stxdmcv: OptField[TypoUnknownPgMcvList, Row] + val stxdexpr: OptField[Array[TypoUnknownPgStatistic], Row] +} +object PgStatisticExtDataFields extends PgStatisticExtDataStructure[PgStatisticExtDataRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataId.scala new file mode 100644 index 0000000000..72d3cd8140 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +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 `pg_catalog.pg_statistic_ext_data` */ +case class PgStatisticExtDataId(value: /* oid */ Long) extends AnyVal +object PgStatisticExtDataId { + implicit lazy val arraySetter: Setter[Array[PgStatisticExtDataId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgStatisticExtDataId, /* oid */ Long] = Bijection[PgStatisticExtDataId, /* oid */ Long](_.value)(PgStatisticExtDataId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatisticExtDataId] = JdbcDecoder.longDecoder.map(PgStatisticExtDataId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgStatisticExtDataId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticExtDataId] = JsonDecoder.long.map(PgStatisticExtDataId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticExtDataId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgStatisticExtDataId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgStatisticExtDataId] = ParameterMetaData.instance[PgStatisticExtDataId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgStatisticExtDataId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepo.scala new file mode 100644 index 0000000000..64edd5b3e4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatisticExtDataRepo { + def delete(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] + def insert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, PgStatisticExtDataRow] + def select: SelectBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtDataRow] + def selectById(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Option[PgStatisticExtDataRow]] + def selectByIds(stxoids: Array[PgStatisticExtDataId]): ZStream[ZConnection, Throwable, PgStatisticExtDataRow] + def update(row: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] + def upsert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtDataRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoImpl.scala new file mode 100644 index 0000000000..7e37c9b449 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoImpl.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgMcvList +import adventureworks.customtypes.TypoUnknownPgNdistinct +import adventureworks.customtypes.TypoUnknownPgStatistic +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatisticExtDataRepoImpl extends PgStatisticExtDataRepo { + override def delete(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_statistic_ext_data where "stxoid" = ${Segment.paramSegment(stxoid)(PgStatisticExtDataId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + DeleteBuilder("pg_catalog.pg_statistic_ext_data", PgStatisticExtDataFields) + } + override def insert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, PgStatisticExtDataRow] = { + sql"""insert into pg_catalog.pg_statistic_ext_data("stxoid", "stxdndistinct", "stxddependencies", "stxdmcv", "stxdexpr") + values (${Segment.paramSegment(unsaved.stxoid)(PgStatisticExtDataId.setter)}::oid, ${Segment.paramSegment(unsaved.stxdndistinct)(Setter.optionParamSetter(TypoUnknownPgNdistinct.setter))}::pg_ndistinct, ${Segment.paramSegment(unsaved.stxddependencies)(Setter.optionParamSetter(TypoUnknownPgDependencies.setter))}::pg_dependencies, ${Segment.paramSegment(unsaved.stxdmcv)(Setter.optionParamSetter(TypoUnknownPgMcvList.setter))}::pg_mcv_list, ${Segment.paramSegment(unsaved.stxdexpr)(Setter.optionParamSetter(TypoUnknownPgStatistic.arraySetter))}::_pg_statistic) + returning "stxoid", "stxdndistinct"::text, "stxddependencies"::text, "stxdmcv"::text, "stxdexpr"::text[] + """.insertReturning(PgStatisticExtDataRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + SelectBuilderSql("pg_catalog.pg_statistic_ext_data", PgStatisticExtDataFields, PgStatisticExtDataRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtDataRow] = { + sql"""select "stxoid", "stxdndistinct"::text, "stxddependencies"::text, "stxdmcv"::text, "stxdexpr"::text[] from pg_catalog.pg_statistic_ext_data""".query(PgStatisticExtDataRow.jdbcDecoder).selectStream + } + override def selectById(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Option[PgStatisticExtDataRow]] = { + sql"""select "stxoid", "stxdndistinct"::text, "stxddependencies"::text, "stxdmcv"::text, "stxdexpr"::text[] from pg_catalog.pg_statistic_ext_data where "stxoid" = ${Segment.paramSegment(stxoid)(PgStatisticExtDataId.setter)}""".query(PgStatisticExtDataRow.jdbcDecoder).selectOne + } + override def selectByIds(stxoids: Array[PgStatisticExtDataId]): ZStream[ZConnection, Throwable, PgStatisticExtDataRow] = { + sql"""select "stxoid", "stxdndistinct"::text, "stxddependencies"::text, "stxdmcv"::text, "stxdexpr"::text[] from pg_catalog.pg_statistic_ext_data where "stxoid" = ANY(${Segment.paramSegment(stxoids)(PgStatisticExtDataId.arraySetter)})""".query(PgStatisticExtDataRow.jdbcDecoder).selectStream + } + override def update(row: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, Boolean] = { + val stxoid = row.stxoid + sql"""update pg_catalog.pg_statistic_ext_data + set "stxdndistinct" = ${Segment.paramSegment(row.stxdndistinct)(Setter.optionParamSetter(TypoUnknownPgNdistinct.setter))}::pg_ndistinct, + "stxddependencies" = ${Segment.paramSegment(row.stxddependencies)(Setter.optionParamSetter(TypoUnknownPgDependencies.setter))}::pg_dependencies, + "stxdmcv" = ${Segment.paramSegment(row.stxdmcv)(Setter.optionParamSetter(TypoUnknownPgMcvList.setter))}::pg_mcv_list, + "stxdexpr" = ${Segment.paramSegment(row.stxdexpr)(Setter.optionParamSetter(TypoUnknownPgStatistic.arraySetter))}::_pg_statistic + where "stxoid" = ${Segment.paramSegment(stxoid)(PgStatisticExtDataId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + UpdateBuilder("pg_catalog.pg_statistic_ext_data", PgStatisticExtDataFields, PgStatisticExtDataRow.jdbcDecoder) + } + override def upsert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtDataRow]] = { + sql"""insert into pg_catalog.pg_statistic_ext_data("stxoid", "stxdndistinct", "stxddependencies", "stxdmcv", "stxdexpr") + values ( + ${Segment.paramSegment(unsaved.stxoid)(PgStatisticExtDataId.setter)}::oid, + ${Segment.paramSegment(unsaved.stxdndistinct)(Setter.optionParamSetter(TypoUnknownPgNdistinct.setter))}::pg_ndistinct, + ${Segment.paramSegment(unsaved.stxddependencies)(Setter.optionParamSetter(TypoUnknownPgDependencies.setter))}::pg_dependencies, + ${Segment.paramSegment(unsaved.stxdmcv)(Setter.optionParamSetter(TypoUnknownPgMcvList.setter))}::pg_mcv_list, + ${Segment.paramSegment(unsaved.stxdexpr)(Setter.optionParamSetter(TypoUnknownPgStatistic.arraySetter))}::_pg_statistic + ) + on conflict ("stxoid") + do update set + "stxdndistinct" = EXCLUDED."stxdndistinct", + "stxddependencies" = EXCLUDED."stxddependencies", + "stxdmcv" = EXCLUDED."stxdmcv", + "stxdexpr" = EXCLUDED."stxdexpr" + returning "stxoid", "stxdndistinct"::text, "stxddependencies"::text, "stxdmcv"::text, "stxdexpr"::text[]""".insertReturning(PgStatisticExtDataRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoMock.scala new file mode 100644 index 0000000000..91d82ee64a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRepoMock.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgStatisticExtDataRepoMock(map: scala.collection.mutable.Map[PgStatisticExtDataId, PgStatisticExtDataRow] = scala.collection.mutable.Map.empty) extends PgStatisticExtDataRepo { + override def delete(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(stxoid).isDefined) + } + override def delete: DeleteBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + DeleteBuilderMock(DeleteParams.empty, PgStatisticExtDataFields, map) + } + override def insert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, PgStatisticExtDataRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.stxoid)) + sys.error(s"id ${unsaved.stxoid} already exists") + else + map.put(unsaved.stxoid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + SelectBuilderMock(PgStatisticExtDataFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatisticExtDataRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(stxoid: PgStatisticExtDataId): ZIO[ZConnection, Throwable, Option[PgStatisticExtDataRow]] = { + ZIO.succeed(map.get(stxoid)) + } + override def selectByIds(stxoids: Array[PgStatisticExtDataId]): ZStream[ZConnection, Throwable, PgStatisticExtDataRow] = { + ZStream.fromIterable(stxoids.flatMap(map.get)) + } + override def update(row: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.stxoid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.stxoid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgStatisticExtDataFields, PgStatisticExtDataRow] = { + UpdateBuilderMock(UpdateParams.empty, PgStatisticExtDataFields, map) + } + override def upsert(unsaved: PgStatisticExtDataRow): ZIO[ZConnection, Throwable, UpdateResult[PgStatisticExtDataRow]] = { + ZIO.succeed { + map.put(unsaved.stxoid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRow.scala new file mode 100644 index 0000000000..219bf3979c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgMcvList +import adventureworks.customtypes.TypoUnknownPgNdistinct +import adventureworks.customtypes.TypoUnknownPgStatistic +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatisticExtDataRow( + stxoid: PgStatisticExtDataId, + stxdndistinct: Option[TypoUnknownPgNdistinct], + stxddependencies: Option[TypoUnknownPgDependencies], + stxdmcv: Option[TypoUnknownPgMcvList], + stxdexpr: Option[Array[TypoUnknownPgStatistic]] +) + +object PgStatisticExtDataRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatisticExtDataRow] = new JdbcDecoder[PgStatisticExtDataRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatisticExtDataRow) = + columIndex + 4 -> + PgStatisticExtDataRow( + stxoid = PgStatisticExtDataId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stxdndistinct = JdbcDecoder.optionDecoder(TypoUnknownPgNdistinct.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + stxddependencies = JdbcDecoder.optionDecoder(TypoUnknownPgDependencies.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + stxdmcv = JdbcDecoder.optionDecoder(TypoUnknownPgMcvList.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + stxdexpr = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoUnknownPgStatistic]]).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatisticExtDataRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val stxoid = jsonObj.get("stxoid").toRight("Missing field 'stxoid'").flatMap(_.as(PgStatisticExtDataId.jsonDecoder)) + val stxdndistinct = jsonObj.get("stxdndistinct").fold[Either[String, Option[TypoUnknownPgNdistinct]]](Right(None))(_.as(JsonDecoder.option(TypoUnknownPgNdistinct.jsonDecoder))) + val stxddependencies = jsonObj.get("stxddependencies").fold[Either[String, Option[TypoUnknownPgDependencies]]](Right(None))(_.as(JsonDecoder.option(TypoUnknownPgDependencies.jsonDecoder))) + val stxdmcv = jsonObj.get("stxdmcv").fold[Either[String, Option[TypoUnknownPgMcvList]]](Right(None))(_.as(JsonDecoder.option(TypoUnknownPgMcvList.jsonDecoder))) + val stxdexpr = jsonObj.get("stxdexpr").fold[Either[String, Option[Array[TypoUnknownPgStatistic]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoUnknownPgStatistic](TypoUnknownPgStatistic.jsonDecoder, implicitly)))) + if (stxoid.isRight && stxdndistinct.isRight && stxddependencies.isRight && stxdmcv.isRight && stxdexpr.isRight) + Right(PgStatisticExtDataRow(stxoid = stxoid.toOption.get, stxdndistinct = stxdndistinct.toOption.get, stxddependencies = stxddependencies.toOption.get, stxdmcv = stxdmcv.toOption.get, stxdexpr = stxdexpr.toOption.get)) + else Left(List[Either[String, Any]](stxoid, stxdndistinct, stxddependencies, stxdmcv, stxdexpr).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatisticExtDataRow] = new JsonEncoder[PgStatisticExtDataRow] { + override def unsafeEncode(a: PgStatisticExtDataRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""stxoid":""") + PgStatisticExtDataId.jsonEncoder.unsafeEncode(a.stxoid, indent, out) + out.write(",") + out.write(""""stxdndistinct":""") + JsonEncoder.option(TypoUnknownPgNdistinct.jsonEncoder).unsafeEncode(a.stxdndistinct, indent, out) + out.write(",") + out.write(""""stxddependencies":""") + JsonEncoder.option(TypoUnknownPgDependencies.jsonEncoder).unsafeEncode(a.stxddependencies, indent, out) + out.write(",") + out.write(""""stxdmcv":""") + JsonEncoder.option(TypoUnknownPgMcvList.jsonEncoder).unsafeEncode(a.stxdmcv, indent, out) + out.write(",") + out.write(""""stxdexpr":""") + JsonEncoder.option(JsonEncoder.array[TypoUnknownPgStatistic](TypoUnknownPgStatistic.jsonEncoder, implicitly)).unsafeEncode(a.stxdexpr, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataStructure.scala new file mode 100644 index 0000000000..b450dea02a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_statistic_ext_data/PgStatisticExtDataStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_statistic_ext_data + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgMcvList +import adventureworks.customtypes.TypoUnknownPgNdistinct +import adventureworks.customtypes.TypoUnknownPgStatistic +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatisticExtDataStructure[Row](val prefix: Option[String], val extract: Row => PgStatisticExtDataRow, val merge: (Row, PgStatisticExtDataRow) => Row) + extends Relation[PgStatisticExtDataFields, PgStatisticExtDataRow, Row] + with PgStatisticExtDataFields[Row] { outer => + + override val stxoid = new IdField[PgStatisticExtDataId, Row](prefix, "stxoid", None, Some("oid"))(x => extract(x).stxoid, (row, value) => merge(row, extract(row).copy(stxoid = value))) + override val stxdndistinct = new OptField[TypoUnknownPgNdistinct, Row](prefix, "stxdndistinct", Some("text"), Some("pg_ndistinct"))(x => extract(x).stxdndistinct, (row, value) => merge(row, extract(row).copy(stxdndistinct = value))) + override val stxddependencies = new OptField[TypoUnknownPgDependencies, Row](prefix, "stxddependencies", Some("text"), Some("pg_dependencies"))(x => extract(x).stxddependencies, (row, value) => merge(row, extract(row).copy(stxddependencies = value))) + override val stxdmcv = new OptField[TypoUnknownPgMcvList, Row](prefix, "stxdmcv", Some("text"), Some("pg_mcv_list"))(x => extract(x).stxdmcv, (row, value) => merge(row, extract(row).copy(stxdmcv = value))) + override val stxdexpr = new OptField[Array[TypoUnknownPgStatistic], Row](prefix, "stxdexpr", Some("text[]"), Some("_pg_statistic"))(x => extract(x).stxdexpr, (row, value) => merge(row, extract(row).copy(stxdexpr = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](stxoid, stxdndistinct, stxddependencies, stxdmcv, stxdexpr) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatisticExtDataRow, merge: (NewRow, PgStatisticExtDataRow) => NewRow): PgStatisticExtDataStructure[NewRow] = + new PgStatisticExtDataStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewFields.scala new file mode 100644 index 0000000000..a291d8fd0e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats + +import adventureworks.customtypes.TypoAnyArray +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatsViewFields[Row] { + val schemaname: OptField[String, Row] + val tablename: Field[String, Row] + val attname: Field[String, Row] + val inherited: Field[Boolean, Row] + val nullFrac: Field[Float, Row] + val avgWidth: Field[Int, Row] + val nDistinct: Field[Float, Row] + val mostCommonVals: OptField[TypoAnyArray, Row] + val mostCommonFreqs: OptField[Array[Float], Row] + val histogramBounds: OptField[TypoAnyArray, Row] + val correlation: OptField[Float, Row] + val mostCommonElems: OptField[TypoAnyArray, Row] + val mostCommonElemFreqs: OptField[Array[Float], Row] + val elemCountHistogram: OptField[Array[Float], Row] +} +object PgStatsViewFields extends PgStatsViewStructure[PgStatsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepo.scala new file mode 100644 index 0000000000..2754a3d284 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatsViewRepo { + def select: SelectBuilder[PgStatsViewFields, PgStatsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepoImpl.scala new file mode 100644 index 0000000000..9e630ba9e9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatsViewRepoImpl extends PgStatsViewRepo { + override def select: SelectBuilder[PgStatsViewFields, PgStatsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stats", PgStatsViewFields, PgStatsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatsViewRow] = { + sql"""select "schemaname", "tablename", "attname", "inherited", "null_frac", "avg_width", "n_distinct", "most_common_vals", "most_common_freqs", "histogram_bounds", "correlation", "most_common_elems", "most_common_elem_freqs", "elem_count_histogram" from pg_catalog.pg_stats""".query(PgStatsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRow.scala new file mode 100644 index 0000000000..252209adcf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewRow.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats + +import adventureworks.customtypes.TypoAnyArray +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatsViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_attribute.PgAttributeRow.attname]] */ + attname: String, + /** Points to [[pg_statistic.PgStatisticRow.stainherit]] */ + inherited: Boolean, + /** Points to [[pg_statistic.PgStatisticRow.stanullfrac]] */ + nullFrac: Float, + /** Points to [[pg_statistic.PgStatisticRow.stawidth]] */ + avgWidth: Int, + /** Points to [[pg_statistic.PgStatisticRow.stadistinct]] */ + nDistinct: Float, + mostCommonVals: /* nullability unknown */ Option[TypoAnyArray], + mostCommonFreqs: /* nullability unknown */ Option[Array[Float]], + histogramBounds: /* nullability unknown */ Option[TypoAnyArray], + correlation: /* nullability unknown */ Option[Float], + mostCommonElems: /* nullability unknown */ Option[TypoAnyArray], + mostCommonElemFreqs: /* nullability unknown */ Option[Array[Float]], + elemCountHistogram: /* nullability unknown */ Option[Array[Float]] +) + +object PgStatsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatsViewRow] = new JdbcDecoder[PgStatsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatsViewRow) = + columIndex + 13 -> + PgStatsViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + attname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + inherited = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 3, rs)._2, + nullFrac = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 4, rs)._2, + avgWidth = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 5, rs)._2, + nDistinct = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 6, rs)._2, + mostCommonVals = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + mostCommonFreqs = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 8, rs)._2, + histogramBounds = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + correlation = JdbcDecoder.optionDecoder(JdbcDecoder.floatDecoder).unsafeDecode(columIndex + 10, rs)._2, + mostCommonElems = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + mostCommonElemFreqs = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 12, rs)._2, + elemCountHistogram = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 13, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val attname = jsonObj.get("attname").toRight("Missing field 'attname'").flatMap(_.as(JsonDecoder.string)) + val inherited = jsonObj.get("inherited").toRight("Missing field 'inherited'").flatMap(_.as(JsonDecoder.boolean)) + val nullFrac = jsonObj.get("null_frac").toRight("Missing field 'null_frac'").flatMap(_.as(JsonDecoder.float)) + val avgWidth = jsonObj.get("avg_width").toRight("Missing field 'avg_width'").flatMap(_.as(JsonDecoder.int)) + val nDistinct = jsonObj.get("n_distinct").toRight("Missing field 'n_distinct'").flatMap(_.as(JsonDecoder.float)) + val mostCommonVals = jsonObj.get("most_common_vals").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val mostCommonFreqs = jsonObj.get("most_common_freqs").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val histogramBounds = jsonObj.get("histogram_bounds").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val correlation = jsonObj.get("correlation").fold[Either[String, Option[Float]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.float))) + val mostCommonElems = jsonObj.get("most_common_elems").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val mostCommonElemFreqs = jsonObj.get("most_common_elem_freqs").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val elemCountHistogram = jsonObj.get("elem_count_histogram").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + if (schemaname.isRight && tablename.isRight && attname.isRight && inherited.isRight && nullFrac.isRight && avgWidth.isRight && nDistinct.isRight && mostCommonVals.isRight && mostCommonFreqs.isRight && histogramBounds.isRight && correlation.isRight && mostCommonElems.isRight && mostCommonElemFreqs.isRight && elemCountHistogram.isRight) + Right(PgStatsViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, attname = attname.toOption.get, inherited = inherited.toOption.get, nullFrac = nullFrac.toOption.get, avgWidth = avgWidth.toOption.get, nDistinct = nDistinct.toOption.get, mostCommonVals = mostCommonVals.toOption.get, mostCommonFreqs = mostCommonFreqs.toOption.get, histogramBounds = histogramBounds.toOption.get, correlation = correlation.toOption.get, mostCommonElems = mostCommonElems.toOption.get, mostCommonElemFreqs = mostCommonElemFreqs.toOption.get, elemCountHistogram = elemCountHistogram.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, attname, inherited, nullFrac, avgWidth, nDistinct, mostCommonVals, mostCommonFreqs, histogramBounds, correlation, mostCommonElems, mostCommonElemFreqs, elemCountHistogram).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatsViewRow] = new JsonEncoder[PgStatsViewRow] { + override def unsafeEncode(a: PgStatsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""attname":""") + JsonEncoder.string.unsafeEncode(a.attname, indent, out) + out.write(",") + out.write(""""inherited":""") + JsonEncoder.boolean.unsafeEncode(a.inherited, indent, out) + out.write(",") + out.write(""""null_frac":""") + JsonEncoder.float.unsafeEncode(a.nullFrac, indent, out) + out.write(",") + out.write(""""avg_width":""") + JsonEncoder.int.unsafeEncode(a.avgWidth, indent, out) + out.write(",") + out.write(""""n_distinct":""") + JsonEncoder.float.unsafeEncode(a.nDistinct, indent, out) + out.write(",") + out.write(""""most_common_vals":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.mostCommonVals, indent, out) + out.write(",") + out.write(""""most_common_freqs":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.mostCommonFreqs, indent, out) + out.write(",") + out.write(""""histogram_bounds":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.histogramBounds, indent, out) + out.write(",") + out.write(""""correlation":""") + JsonEncoder.option(JsonEncoder.float).unsafeEncode(a.correlation, indent, out) + out.write(",") + out.write(""""most_common_elems":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.mostCommonElems, indent, out) + out.write(",") + out.write(""""most_common_elem_freqs":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.mostCommonElemFreqs, indent, out) + out.write(",") + out.write(""""elem_count_histogram":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.elemCountHistogram, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewStructure.scala new file mode 100644 index 0000000000..d8ad121525 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats/PgStatsViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats + +import adventureworks.customtypes.TypoAnyArray +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatsViewRow, val merge: (Row, PgStatsViewRow) => Row) + extends Relation[PgStatsViewFields, PgStatsViewRow, Row] + with PgStatsViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val attname = new Field[String, Row](prefix, "attname", None, None)(x => extract(x).attname, (row, value) => merge(row, extract(row).copy(attname = value))) + override val inherited = new Field[Boolean, Row](prefix, "inherited", None, None)(x => extract(x).inherited, (row, value) => merge(row, extract(row).copy(inherited = value))) + override val nullFrac = new Field[Float, Row](prefix, "null_frac", None, None)(x => extract(x).nullFrac, (row, value) => merge(row, extract(row).copy(nullFrac = value))) + override val avgWidth = new Field[Int, Row](prefix, "avg_width", None, None)(x => extract(x).avgWidth, (row, value) => merge(row, extract(row).copy(avgWidth = value))) + override val nDistinct = new Field[Float, Row](prefix, "n_distinct", None, None)(x => extract(x).nDistinct, (row, value) => merge(row, extract(row).copy(nDistinct = value))) + override val mostCommonVals = new OptField[TypoAnyArray, Row](prefix, "most_common_vals", None, None)(x => extract(x).mostCommonVals, (row, value) => merge(row, extract(row).copy(mostCommonVals = value))) + override val mostCommonFreqs = new OptField[Array[Float], Row](prefix, "most_common_freqs", None, None)(x => extract(x).mostCommonFreqs, (row, value) => merge(row, extract(row).copy(mostCommonFreqs = value))) + override val histogramBounds = new OptField[TypoAnyArray, Row](prefix, "histogram_bounds", None, None)(x => extract(x).histogramBounds, (row, value) => merge(row, extract(row).copy(histogramBounds = value))) + override val correlation = new OptField[Float, Row](prefix, "correlation", None, None)(x => extract(x).correlation, (row, value) => merge(row, extract(row).copy(correlation = value))) + override val mostCommonElems = new OptField[TypoAnyArray, Row](prefix, "most_common_elems", None, None)(x => extract(x).mostCommonElems, (row, value) => merge(row, extract(row).copy(mostCommonElems = value))) + override val mostCommonElemFreqs = new OptField[Array[Float], Row](prefix, "most_common_elem_freqs", None, None)(x => extract(x).mostCommonElemFreqs, (row, value) => merge(row, extract(row).copy(mostCommonElemFreqs = value))) + override val elemCountHistogram = new OptField[Array[Float], Row](prefix, "elem_count_histogram", None, None)(x => extract(x).elemCountHistogram, (row, value) => merge(row, extract(row).copy(elemCountHistogram = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, attname, inherited, nullFrac, avgWidth, nDistinct, mostCommonVals, mostCommonFreqs, histogramBounds, correlation, mostCommonElems, mostCommonElemFreqs, elemCountHistogram) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatsViewRow, merge: (NewRow, PgStatsViewRow) => NewRow): PgStatsViewStructure[NewRow] = + new PgStatsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewFields.scala new file mode 100644 index 0000000000..a1b0c5f0a2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgNdistinct +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatsExtViewFields[Row] { + val schemaname: Field[String, Row] + val tablename: Field[String, Row] + val statisticsSchemaname: OptField[String, Row] + val statisticsName: Field[String, Row] + val statisticsOwner: OptField[String, Row] + val attnames: OptField[Array[String], Row] + val exprs: OptField[Array[String], Row] + val kinds: Field[Array[String], Row] + val nDistinct: OptField[TypoUnknownPgNdistinct, Row] + val dependencies: OptField[TypoUnknownPgDependencies, Row] + val mostCommonVals: OptField[Array[String], Row] + val mostCommonValNulls: OptField[Array[Boolean], Row] + val mostCommonFreqs: OptField[Array[Double], Row] + val mostCommonBaseFreqs: OptField[Array[Double], Row] +} +object PgStatsExtViewFields extends PgStatsExtViewStructure[PgStatsExtViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepo.scala new file mode 100644 index 0000000000..4963f3da09 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatsExtViewRepo { + def select: SelectBuilder[PgStatsExtViewFields, PgStatsExtViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatsExtViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepoImpl.scala new file mode 100644 index 0000000000..31fd801d14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatsExtViewRepoImpl extends PgStatsExtViewRepo { + override def select: SelectBuilder[PgStatsExtViewFields, PgStatsExtViewRow] = { + SelectBuilderSql("pg_catalog.pg_stats_ext", PgStatsExtViewFields, PgStatsExtViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatsExtViewRow] = { + sql"""select "schemaname", "tablename", "statistics_schemaname", "statistics_name", "statistics_owner", "attnames", "exprs", "kinds", "n_distinct"::text, "dependencies"::text, "most_common_vals", "most_common_val_nulls", "most_common_freqs", "most_common_base_freqs" from pg_catalog.pg_stats_ext""".query(PgStatsExtViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRow.scala new file mode 100644 index 0000000000..d3809468a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewRow.scala @@ -0,0 +1,130 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgNdistinct +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatsExtViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: String, + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + statisticsSchemaname: Option[String], + /** Points to [[pg_statistic_ext.PgStatisticExtRow.stxname]] */ + statisticsName: String, + statisticsOwner: /* nullability unknown */ Option[String], + attnames: /* nullability unknown */ Option[Array[String]], + exprs: /* nullability unknown */ Option[Array[String]], + /** Points to [[pg_statistic_ext.PgStatisticExtRow.stxkind]] */ + kinds: Array[String], + /** Points to [[pg_statistic_ext_data.PgStatisticExtDataRow.stxdndistinct]] */ + nDistinct: Option[TypoUnknownPgNdistinct], + /** Points to [[pg_statistic_ext_data.PgStatisticExtDataRow.stxddependencies]] */ + dependencies: Option[TypoUnknownPgDependencies], + mostCommonVals: /* nullability unknown */ Option[Array[String]], + mostCommonValNulls: /* nullability unknown */ Option[Array[Boolean]], + mostCommonFreqs: /* nullability unknown */ Option[Array[Double]], + mostCommonBaseFreqs: /* nullability unknown */ Option[Array[Double]] +) + +object PgStatsExtViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatsExtViewRow] = new JdbcDecoder[PgStatsExtViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatsExtViewRow) = + columIndex + 13 -> + PgStatsExtViewRow( + schemaname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + statisticsSchemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + statisticsName = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + statisticsOwner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + attnames = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 5, rs)._2, + exprs = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 6, rs)._2, + kinds = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 7, rs)._2, + nDistinct = JdbcDecoder.optionDecoder(TypoUnknownPgNdistinct.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + dependencies = JdbcDecoder.optionDecoder(TypoUnknownPgDependencies.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + mostCommonVals = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 10, rs)._2, + mostCommonValNulls = JdbcDecoder.optionDecoder(adventureworks.BooleanArrayDecoder).unsafeDecode(columIndex + 11, rs)._2, + mostCommonFreqs = JdbcDecoder.optionDecoder(adventureworks.DoubleArrayDecoder).unsafeDecode(columIndex + 12, rs)._2, + mostCommonBaseFreqs = JdbcDecoder.optionDecoder(adventureworks.DoubleArrayDecoder).unsafeDecode(columIndex + 13, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatsExtViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").toRight("Missing field 'schemaname'").flatMap(_.as(JsonDecoder.string)) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val statisticsSchemaname = jsonObj.get("statistics_schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val statisticsName = jsonObj.get("statistics_name").toRight("Missing field 'statistics_name'").flatMap(_.as(JsonDecoder.string)) + val statisticsOwner = jsonObj.get("statistics_owner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val attnames = jsonObj.get("attnames").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val exprs = jsonObj.get("exprs").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val kinds = jsonObj.get("kinds").toRight("Missing field 'kinds'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val nDistinct = jsonObj.get("n_distinct").fold[Either[String, Option[TypoUnknownPgNdistinct]]](Right(None))(_.as(JsonDecoder.option(TypoUnknownPgNdistinct.jsonDecoder))) + val dependencies = jsonObj.get("dependencies").fold[Either[String, Option[TypoUnknownPgDependencies]]](Right(None))(_.as(JsonDecoder.option(TypoUnknownPgDependencies.jsonDecoder))) + val mostCommonVals = jsonObj.get("most_common_vals").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val mostCommonValNulls = jsonObj.get("most_common_val_nulls").fold[Either[String, Option[Array[Boolean]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Boolean](JsonDecoder.boolean, implicitly)))) + val mostCommonFreqs = jsonObj.get("most_common_freqs").fold[Either[String, Option[Array[Double]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Double](JsonDecoder.double, implicitly)))) + val mostCommonBaseFreqs = jsonObj.get("most_common_base_freqs").fold[Either[String, Option[Array[Double]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Double](JsonDecoder.double, implicitly)))) + if (schemaname.isRight && tablename.isRight && statisticsSchemaname.isRight && statisticsName.isRight && statisticsOwner.isRight && attnames.isRight && exprs.isRight && kinds.isRight && nDistinct.isRight && dependencies.isRight && mostCommonVals.isRight && mostCommonValNulls.isRight && mostCommonFreqs.isRight && mostCommonBaseFreqs.isRight) + Right(PgStatsExtViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, statisticsSchemaname = statisticsSchemaname.toOption.get, statisticsName = statisticsName.toOption.get, statisticsOwner = statisticsOwner.toOption.get, attnames = attnames.toOption.get, exprs = exprs.toOption.get, kinds = kinds.toOption.get, nDistinct = nDistinct.toOption.get, dependencies = dependencies.toOption.get, mostCommonVals = mostCommonVals.toOption.get, mostCommonValNulls = mostCommonValNulls.toOption.get, mostCommonFreqs = mostCommonFreqs.toOption.get, mostCommonBaseFreqs = mostCommonBaseFreqs.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, statisticsSchemaname, statisticsName, statisticsOwner, attnames, exprs, kinds, nDistinct, dependencies, mostCommonVals, mostCommonValNulls, mostCommonFreqs, mostCommonBaseFreqs).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatsExtViewRow] = new JsonEncoder[PgStatsExtViewRow] { + override def unsafeEncode(a: PgStatsExtViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.string.unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""statistics_schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statisticsSchemaname, indent, out) + out.write(",") + out.write(""""statistics_name":""") + JsonEncoder.string.unsafeEncode(a.statisticsName, indent, out) + out.write(",") + out.write(""""statistics_owner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statisticsOwner, indent, out) + out.write(",") + out.write(""""attnames":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.attnames, indent, out) + out.write(",") + out.write(""""exprs":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.exprs, indent, out) + out.write(",") + out.write(""""kinds":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.kinds, indent, out) + out.write(",") + out.write(""""n_distinct":""") + JsonEncoder.option(TypoUnknownPgNdistinct.jsonEncoder).unsafeEncode(a.nDistinct, indent, out) + out.write(",") + out.write(""""dependencies":""") + JsonEncoder.option(TypoUnknownPgDependencies.jsonEncoder).unsafeEncode(a.dependencies, indent, out) + out.write(",") + out.write(""""most_common_vals":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.mostCommonVals, indent, out) + out.write(",") + out.write(""""most_common_val_nulls":""") + JsonEncoder.option(JsonEncoder.array[Boolean](JsonEncoder.boolean, implicitly)).unsafeEncode(a.mostCommonValNulls, indent, out) + out.write(",") + out.write(""""most_common_freqs":""") + JsonEncoder.option(JsonEncoder.array[Double](JsonEncoder.double, implicitly)).unsafeEncode(a.mostCommonFreqs, indent, out) + out.write(",") + out.write(""""most_common_base_freqs":""") + JsonEncoder.option(JsonEncoder.array[Double](JsonEncoder.double, implicitly)).unsafeEncode(a.mostCommonBaseFreqs, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewStructure.scala new file mode 100644 index 0000000000..31d598d683 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext/PgStatsExtViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext + +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgNdistinct +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatsExtViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatsExtViewRow, val merge: (Row, PgStatsExtViewRow) => Row) + extends Relation[PgStatsExtViewFields, PgStatsExtViewRow, Row] + with PgStatsExtViewFields[Row] { outer => + + override val schemaname = new Field[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val statisticsSchemaname = new OptField[String, Row](prefix, "statistics_schemaname", None, None)(x => extract(x).statisticsSchemaname, (row, value) => merge(row, extract(row).copy(statisticsSchemaname = value))) + override val statisticsName = new Field[String, Row](prefix, "statistics_name", None, None)(x => extract(x).statisticsName, (row, value) => merge(row, extract(row).copy(statisticsName = value))) + override val statisticsOwner = new OptField[String, Row](prefix, "statistics_owner", None, None)(x => extract(x).statisticsOwner, (row, value) => merge(row, extract(row).copy(statisticsOwner = value))) + override val attnames = new OptField[Array[String], Row](prefix, "attnames", None, None)(x => extract(x).attnames, (row, value) => merge(row, extract(row).copy(attnames = value))) + override val exprs = new OptField[Array[String], Row](prefix, "exprs", None, None)(x => extract(x).exprs, (row, value) => merge(row, extract(row).copy(exprs = value))) + override val kinds = new Field[Array[String], Row](prefix, "kinds", None, None)(x => extract(x).kinds, (row, value) => merge(row, extract(row).copy(kinds = value))) + override val nDistinct = new OptField[TypoUnknownPgNdistinct, Row](prefix, "n_distinct", Some("text"), Some("pg_ndistinct"))(x => extract(x).nDistinct, (row, value) => merge(row, extract(row).copy(nDistinct = value))) + override val dependencies = new OptField[TypoUnknownPgDependencies, Row](prefix, "dependencies", Some("text"), Some("pg_dependencies"))(x => extract(x).dependencies, (row, value) => merge(row, extract(row).copy(dependencies = value))) + override val mostCommonVals = new OptField[Array[String], Row](prefix, "most_common_vals", None, None)(x => extract(x).mostCommonVals, (row, value) => merge(row, extract(row).copy(mostCommonVals = value))) + override val mostCommonValNulls = new OptField[Array[Boolean], Row](prefix, "most_common_val_nulls", None, None)(x => extract(x).mostCommonValNulls, (row, value) => merge(row, extract(row).copy(mostCommonValNulls = value))) + override val mostCommonFreqs = new OptField[Array[Double], Row](prefix, "most_common_freqs", None, None)(x => extract(x).mostCommonFreqs, (row, value) => merge(row, extract(row).copy(mostCommonFreqs = value))) + override val mostCommonBaseFreqs = new OptField[Array[Double], Row](prefix, "most_common_base_freqs", None, None)(x => extract(x).mostCommonBaseFreqs, (row, value) => merge(row, extract(row).copy(mostCommonBaseFreqs = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, statisticsSchemaname, statisticsName, statisticsOwner, attnames, exprs, kinds, nDistinct, dependencies, mostCommonVals, mostCommonValNulls, mostCommonFreqs, mostCommonBaseFreqs) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatsExtViewRow, merge: (NewRow, PgStatsExtViewRow) => NewRow): PgStatsExtViewStructure[NewRow] = + new PgStatsExtViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewFields.scala new file mode 100644 index 0000000000..bd85371f2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext_exprs + +import adventureworks.customtypes.TypoAnyArray +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgStatsExtExprsViewFields[Row] { + val schemaname: OptField[String, Row] + val tablename: Field[String, Row] + val statisticsSchemaname: OptField[String, Row] + val statisticsName: Field[String, Row] + val statisticsOwner: OptField[String, Row] + val expr: OptField[String, Row] + val nullFrac: OptField[Float, Row] + val avgWidth: OptField[Int, Row] + val nDistinct: OptField[Float, Row] + val mostCommonVals: OptField[TypoAnyArray, Row] + val mostCommonFreqs: OptField[Array[Float], Row] + val histogramBounds: OptField[TypoAnyArray, Row] + val correlation: OptField[Float, Row] + val mostCommonElems: OptField[TypoAnyArray, Row] + val mostCommonElemFreqs: OptField[Array[Float], Row] + val elemCountHistogram: OptField[Array[Float], Row] +} +object PgStatsExtExprsViewFields extends PgStatsExtExprsViewStructure[PgStatsExtExprsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepo.scala new file mode 100644 index 0000000000..02955940d6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext_exprs + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgStatsExtExprsViewRepo { + def select: SelectBuilder[PgStatsExtExprsViewFields, PgStatsExtExprsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgStatsExtExprsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepoImpl.scala new file mode 100644 index 0000000000..67cdd11bc4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext_exprs + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgStatsExtExprsViewRepoImpl extends PgStatsExtExprsViewRepo { + override def select: SelectBuilder[PgStatsExtExprsViewFields, PgStatsExtExprsViewRow] = { + SelectBuilderSql("pg_catalog.pg_stats_ext_exprs", PgStatsExtExprsViewFields, PgStatsExtExprsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgStatsExtExprsViewRow] = { + sql"""select "schemaname", "tablename", "statistics_schemaname", "statistics_name", "statistics_owner", "expr", "null_frac", "avg_width", "n_distinct", "most_common_vals", "most_common_freqs", "histogram_bounds", "correlation", "most_common_elems", "most_common_elem_freqs", "elem_count_histogram" from pg_catalog.pg_stats_ext_exprs""".query(PgStatsExtExprsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRow.scala new file mode 100644 index 0000000000..40cc4dc1fe --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewRow.scala @@ -0,0 +1,138 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext_exprs + +import adventureworks.customtypes.TypoAnyArray +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgStatsExtExprsViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + statisticsSchemaname: Option[String], + /** Points to [[pg_statistic_ext.PgStatisticExtRow.stxname]] */ + statisticsName: String, + statisticsOwner: /* nullability unknown */ Option[String], + expr: /* nullability unknown */ Option[String], + nullFrac: /* nullability unknown */ Option[Float], + avgWidth: /* nullability unknown */ Option[Int], + nDistinct: /* nullability unknown */ Option[Float], + mostCommonVals: /* nullability unknown */ Option[TypoAnyArray], + mostCommonFreqs: /* nullability unknown */ Option[Array[Float]], + histogramBounds: /* nullability unknown */ Option[TypoAnyArray], + correlation: /* nullability unknown */ Option[Float], + mostCommonElems: /* nullability unknown */ Option[TypoAnyArray], + mostCommonElemFreqs: /* nullability unknown */ Option[Array[Float]], + elemCountHistogram: /* nullability unknown */ Option[Array[Float]] +) + +object PgStatsExtExprsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgStatsExtExprsViewRow] = new JdbcDecoder[PgStatsExtExprsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgStatsExtExprsViewRow) = + columIndex + 15 -> + PgStatsExtExprsViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + statisticsSchemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + statisticsName = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + statisticsOwner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + expr = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + nullFrac = JdbcDecoder.optionDecoder(JdbcDecoder.floatDecoder).unsafeDecode(columIndex + 6, rs)._2, + avgWidth = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + nDistinct = JdbcDecoder.optionDecoder(JdbcDecoder.floatDecoder).unsafeDecode(columIndex + 8, rs)._2, + mostCommonVals = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + mostCommonFreqs = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 10, rs)._2, + histogramBounds = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + correlation = JdbcDecoder.optionDecoder(JdbcDecoder.floatDecoder).unsafeDecode(columIndex + 12, rs)._2, + mostCommonElems = JdbcDecoder.optionDecoder(TypoAnyArray.jdbcDecoder).unsafeDecode(columIndex + 13, rs)._2, + mostCommonElemFreqs = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 14, rs)._2, + elemCountHistogram = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 15, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgStatsExtExprsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val statisticsSchemaname = jsonObj.get("statistics_schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val statisticsName = jsonObj.get("statistics_name").toRight("Missing field 'statistics_name'").flatMap(_.as(JsonDecoder.string)) + val statisticsOwner = jsonObj.get("statistics_owner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val expr = jsonObj.get("expr").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val nullFrac = jsonObj.get("null_frac").fold[Either[String, Option[Float]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.float))) + val avgWidth = jsonObj.get("avg_width").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val nDistinct = jsonObj.get("n_distinct").fold[Either[String, Option[Float]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.float))) + val mostCommonVals = jsonObj.get("most_common_vals").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val mostCommonFreqs = jsonObj.get("most_common_freqs").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val histogramBounds = jsonObj.get("histogram_bounds").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val correlation = jsonObj.get("correlation").fold[Either[String, Option[Float]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.float))) + val mostCommonElems = jsonObj.get("most_common_elems").fold[Either[String, Option[TypoAnyArray]]](Right(None))(_.as(JsonDecoder.option(TypoAnyArray.jsonDecoder))) + val mostCommonElemFreqs = jsonObj.get("most_common_elem_freqs").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val elemCountHistogram = jsonObj.get("elem_count_histogram").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + if (schemaname.isRight && tablename.isRight && statisticsSchemaname.isRight && statisticsName.isRight && statisticsOwner.isRight && expr.isRight && nullFrac.isRight && avgWidth.isRight && nDistinct.isRight && mostCommonVals.isRight && mostCommonFreqs.isRight && histogramBounds.isRight && correlation.isRight && mostCommonElems.isRight && mostCommonElemFreqs.isRight && elemCountHistogram.isRight) + Right(PgStatsExtExprsViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, statisticsSchemaname = statisticsSchemaname.toOption.get, statisticsName = statisticsName.toOption.get, statisticsOwner = statisticsOwner.toOption.get, expr = expr.toOption.get, nullFrac = nullFrac.toOption.get, avgWidth = avgWidth.toOption.get, nDistinct = nDistinct.toOption.get, mostCommonVals = mostCommonVals.toOption.get, mostCommonFreqs = mostCommonFreqs.toOption.get, histogramBounds = histogramBounds.toOption.get, correlation = correlation.toOption.get, mostCommonElems = mostCommonElems.toOption.get, mostCommonElemFreqs = mostCommonElemFreqs.toOption.get, elemCountHistogram = elemCountHistogram.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, statisticsSchemaname, statisticsName, statisticsOwner, expr, nullFrac, avgWidth, nDistinct, mostCommonVals, mostCommonFreqs, histogramBounds, correlation, mostCommonElems, mostCommonElemFreqs, elemCountHistogram).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgStatsExtExprsViewRow] = new JsonEncoder[PgStatsExtExprsViewRow] { + override def unsafeEncode(a: PgStatsExtExprsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""statistics_schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statisticsSchemaname, indent, out) + out.write(",") + out.write(""""statistics_name":""") + JsonEncoder.string.unsafeEncode(a.statisticsName, indent, out) + out.write(",") + out.write(""""statistics_owner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.statisticsOwner, indent, out) + out.write(",") + out.write(""""expr":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.expr, indent, out) + out.write(",") + out.write(""""null_frac":""") + JsonEncoder.option(JsonEncoder.float).unsafeEncode(a.nullFrac, indent, out) + out.write(",") + out.write(""""avg_width":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.avgWidth, indent, out) + out.write(",") + out.write(""""n_distinct":""") + JsonEncoder.option(JsonEncoder.float).unsafeEncode(a.nDistinct, indent, out) + out.write(",") + out.write(""""most_common_vals":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.mostCommonVals, indent, out) + out.write(",") + out.write(""""most_common_freqs":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.mostCommonFreqs, indent, out) + out.write(",") + out.write(""""histogram_bounds":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.histogramBounds, indent, out) + out.write(",") + out.write(""""correlation":""") + JsonEncoder.option(JsonEncoder.float).unsafeEncode(a.correlation, indent, out) + out.write(",") + out.write(""""most_common_elems":""") + JsonEncoder.option(TypoAnyArray.jsonEncoder).unsafeEncode(a.mostCommonElems, indent, out) + out.write(",") + out.write(""""most_common_elem_freqs":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.mostCommonElemFreqs, indent, out) + out.write(",") + out.write(""""elem_count_histogram":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.elemCountHistogram, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewStructure.scala new file mode 100644 index 0000000000..4dd36758cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_stats_ext_exprs/PgStatsExtExprsViewStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_stats_ext_exprs + +import adventureworks.customtypes.TypoAnyArray +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgStatsExtExprsViewStructure[Row](val prefix: Option[String], val extract: Row => PgStatsExtExprsViewRow, val merge: (Row, PgStatsExtExprsViewRow) => Row) + extends Relation[PgStatsExtExprsViewFields, PgStatsExtExprsViewRow, Row] + with PgStatsExtExprsViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val statisticsSchemaname = new OptField[String, Row](prefix, "statistics_schemaname", None, None)(x => extract(x).statisticsSchemaname, (row, value) => merge(row, extract(row).copy(statisticsSchemaname = value))) + override val statisticsName = new Field[String, Row](prefix, "statistics_name", None, None)(x => extract(x).statisticsName, (row, value) => merge(row, extract(row).copy(statisticsName = value))) + override val statisticsOwner = new OptField[String, Row](prefix, "statistics_owner", None, None)(x => extract(x).statisticsOwner, (row, value) => merge(row, extract(row).copy(statisticsOwner = value))) + override val expr = new OptField[String, Row](prefix, "expr", None, None)(x => extract(x).expr, (row, value) => merge(row, extract(row).copy(expr = value))) + override val nullFrac = new OptField[Float, Row](prefix, "null_frac", None, None)(x => extract(x).nullFrac, (row, value) => merge(row, extract(row).copy(nullFrac = value))) + override val avgWidth = new OptField[Int, Row](prefix, "avg_width", None, None)(x => extract(x).avgWidth, (row, value) => merge(row, extract(row).copy(avgWidth = value))) + override val nDistinct = new OptField[Float, Row](prefix, "n_distinct", None, None)(x => extract(x).nDistinct, (row, value) => merge(row, extract(row).copy(nDistinct = value))) + override val mostCommonVals = new OptField[TypoAnyArray, Row](prefix, "most_common_vals", None, None)(x => extract(x).mostCommonVals, (row, value) => merge(row, extract(row).copy(mostCommonVals = value))) + override val mostCommonFreqs = new OptField[Array[Float], Row](prefix, "most_common_freqs", None, None)(x => extract(x).mostCommonFreqs, (row, value) => merge(row, extract(row).copy(mostCommonFreqs = value))) + override val histogramBounds = new OptField[TypoAnyArray, Row](prefix, "histogram_bounds", None, None)(x => extract(x).histogramBounds, (row, value) => merge(row, extract(row).copy(histogramBounds = value))) + override val correlation = new OptField[Float, Row](prefix, "correlation", None, None)(x => extract(x).correlation, (row, value) => merge(row, extract(row).copy(correlation = value))) + override val mostCommonElems = new OptField[TypoAnyArray, Row](prefix, "most_common_elems", None, None)(x => extract(x).mostCommonElems, (row, value) => merge(row, extract(row).copy(mostCommonElems = value))) + override val mostCommonElemFreqs = new OptField[Array[Float], Row](prefix, "most_common_elem_freqs", None, None)(x => extract(x).mostCommonElemFreqs, (row, value) => merge(row, extract(row).copy(mostCommonElemFreqs = value))) + override val elemCountHistogram = new OptField[Array[Float], Row](prefix, "elem_count_histogram", None, None)(x => extract(x).elemCountHistogram, (row, value) => merge(row, extract(row).copy(elemCountHistogram = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, statisticsSchemaname, statisticsName, statisticsOwner, expr, nullFrac, avgWidth, nDistinct, mostCommonVals, mostCommonFreqs, histogramBounds, correlation, mostCommonElems, mostCommonElemFreqs, elemCountHistogram) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgStatsExtExprsViewRow, merge: (NewRow, PgStatsExtExprsViewRow) => NewRow): PgStatsExtExprsViewStructure[NewRow] = + new PgStatsExtExprsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionFields.scala new file mode 100644 index 0000000000..cd63c338b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgSubscriptionFields[Row] { + val oid: IdField[PgSubscriptionId, Row] + val subdbid: Field[/* oid */ Long, Row] + val subname: Field[String, Row] + val subowner: Field[/* oid */ Long, Row] + val subenabled: Field[Boolean, Row] + val subbinary: Field[Boolean, Row] + val substream: Field[Boolean, Row] + val subconninfo: Field[String, Row] + val subslotname: OptField[String, Row] + val subsynccommit: Field[String, Row] + val subpublications: Field[Array[String], Row] +} +object PgSubscriptionFields extends PgSubscriptionStructure[PgSubscriptionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionId.scala new file mode 100644 index 0000000000..7c7871298d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +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 `pg_catalog.pg_subscription` */ +case class PgSubscriptionId(value: /* oid */ Long) extends AnyVal +object PgSubscriptionId { + implicit lazy val arraySetter: Setter[Array[PgSubscriptionId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgSubscriptionId, /* oid */ Long] = Bijection[PgSubscriptionId, /* oid */ Long](_.value)(PgSubscriptionId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgSubscriptionId] = JdbcDecoder.longDecoder.map(PgSubscriptionId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgSubscriptionId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgSubscriptionId] = JsonDecoder.long.map(PgSubscriptionId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgSubscriptionId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgSubscriptionId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgSubscriptionId] = ParameterMetaData.instance[PgSubscriptionId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgSubscriptionId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepo.scala new file mode 100644 index 0000000000..4bfe9b224c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSubscriptionRepo { + def delete(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgSubscriptionFields, PgSubscriptionRow] + def insert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, PgSubscriptionRow] + def select: SelectBuilder[PgSubscriptionFields, PgSubscriptionRow] + def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRow] + def selectById(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] + def selectByIds(oids: Array[PgSubscriptionId]): ZStream[ZConnection, Throwable, PgSubscriptionRow] + def selectByUnique(subdbid: /* oid */ Long, subname: String): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] + def update(row: PgSubscriptionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgSubscriptionFields, PgSubscriptionRow] + def upsert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoImpl.scala new file mode 100644 index 0000000000..2ed9259129 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoImpl.scala @@ -0,0 +1,100 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSubscriptionRepoImpl extends PgSubscriptionRepo { + override def delete(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_subscription where "oid" = ${Segment.paramSegment(oid)(PgSubscriptionId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + DeleteBuilder("pg_catalog.pg_subscription", PgSubscriptionFields) + } + override def insert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, PgSubscriptionRow] = { + sql"""insert into pg_catalog.pg_subscription("oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications") + values (${Segment.paramSegment(unsaved.oid)(PgSubscriptionId.setter)}::oid, ${Segment.paramSegment(unsaved.subdbid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.subname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.subowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.subenabled)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.subbinary)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.substream)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.subconninfo)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.subslotname)(Setter.optionParamSetter(Setter.stringSetter))}::name, ${Segment.paramSegment(unsaved.subsynccommit)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.subpublications)(adventureworks.StringArraySetter)}::_text) + returning "oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications" + """.insertReturning(PgSubscriptionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + SelectBuilderSql("pg_catalog.pg_subscription", PgSubscriptionFields, PgSubscriptionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRow] = { + sql"""select "oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications" from pg_catalog.pg_subscription""".query(PgSubscriptionRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] = { + sql"""select "oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications" from pg_catalog.pg_subscription where "oid" = ${Segment.paramSegment(oid)(PgSubscriptionId.setter)}""".query(PgSubscriptionRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgSubscriptionId]): ZStream[ZConnection, Throwable, PgSubscriptionRow] = { + sql"""select "oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications" from pg_catalog.pg_subscription where "oid" = ANY(${Segment.paramSegment(oids)(PgSubscriptionId.arraySetter)})""".query(PgSubscriptionRow.jdbcDecoder).selectStream + } + override def selectByUnique(subdbid: /* oid */ Long, subname: String): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] = { + sql"""select "subdbid", "subname" + from pg_catalog.pg_subscription + where "subdbid" = ${Segment.paramSegment(subdbid)(Setter.longSetter)} AND "subname" = ${Segment.paramSegment(subname)(Setter.stringSetter)} + """.query(PgSubscriptionRow.jdbcDecoder).selectOne + } + override def update(row: PgSubscriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_subscription + set "subdbid" = ${Segment.paramSegment(row.subdbid)(Setter.longSetter)}::oid, + "subname" = ${Segment.paramSegment(row.subname)(Setter.stringSetter)}::name, + "subowner" = ${Segment.paramSegment(row.subowner)(Setter.longSetter)}::oid, + "subenabled" = ${Segment.paramSegment(row.subenabled)(Setter.booleanSetter)}, + "subbinary" = ${Segment.paramSegment(row.subbinary)(Setter.booleanSetter)}, + "substream" = ${Segment.paramSegment(row.substream)(Setter.booleanSetter)}, + "subconninfo" = ${Segment.paramSegment(row.subconninfo)(Setter.stringSetter)}, + "subslotname" = ${Segment.paramSegment(row.subslotname)(Setter.optionParamSetter(Setter.stringSetter))}::name, + "subsynccommit" = ${Segment.paramSegment(row.subsynccommit)(Setter.stringSetter)}, + "subpublications" = ${Segment.paramSegment(row.subpublications)(adventureworks.StringArraySetter)}::_text + where "oid" = ${Segment.paramSegment(oid)(PgSubscriptionId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + UpdateBuilder("pg_catalog.pg_subscription", PgSubscriptionFields, PgSubscriptionRow.jdbcDecoder) + } + override def upsert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRow]] = { + sql"""insert into pg_catalog.pg_subscription("oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications") + values ( + ${Segment.paramSegment(unsaved.oid)(PgSubscriptionId.setter)}::oid, + ${Segment.paramSegment(unsaved.subdbid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.subname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.subowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.subenabled)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.subbinary)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.substream)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.subconninfo)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.subslotname)(Setter.optionParamSetter(Setter.stringSetter))}::name, + ${Segment.paramSegment(unsaved.subsynccommit)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.subpublications)(adventureworks.StringArraySetter)}::_text + ) + on conflict ("oid") + do update set + "subdbid" = EXCLUDED."subdbid", + "subname" = EXCLUDED."subname", + "subowner" = EXCLUDED."subowner", + "subenabled" = EXCLUDED."subenabled", + "subbinary" = EXCLUDED."subbinary", + "substream" = EXCLUDED."substream", + "subconninfo" = EXCLUDED."subconninfo", + "subslotname" = EXCLUDED."subslotname", + "subsynccommit" = EXCLUDED."subsynccommit", + "subpublications" = EXCLUDED."subpublications" + returning "oid", "subdbid", "subname", "subowner", "subenabled", "subbinary", "substream", "subconninfo", "subslotname", "subsynccommit", "subpublications"""".insertReturning(PgSubscriptionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoMock.scala new file mode 100644 index 0000000000..110431245e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgSubscriptionRepoMock(map: scala.collection.mutable.Map[PgSubscriptionId, PgSubscriptionRow] = scala.collection.mutable.Map.empty) extends PgSubscriptionRepo { + override def delete(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + DeleteBuilderMock(DeleteParams.empty, PgSubscriptionFields, map) + } + override def insert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, PgSubscriptionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + SelectBuilderMock(PgSubscriptionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgSubscriptionId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgSubscriptionId]): ZStream[ZConnection, Throwable, PgSubscriptionRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(subdbid: /* oid */ Long, subname: String): ZIO[ZConnection, Throwable, Option[PgSubscriptionRow]] = { + ZIO.succeed(map.values.find(v => subdbid == v.subdbid && subname == v.subname)) + } + override def update(row: PgSubscriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgSubscriptionFields, PgSubscriptionRow] = { + UpdateBuilderMock(UpdateParams.empty, PgSubscriptionFields, map) + } + override def upsert(unsaved: PgSubscriptionRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRow.scala new file mode 100644 index 0000000000..f4a55d8099 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionRow.scala @@ -0,0 +1,103 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSubscriptionRow( + oid: PgSubscriptionId, + subdbid: /* oid */ Long, + subname: String, + subowner: /* oid */ Long, + subenabled: Boolean, + subbinary: Boolean, + substream: Boolean, + subconninfo: String, + subslotname: Option[String], + subsynccommit: String, + subpublications: Array[String] +) + +object PgSubscriptionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSubscriptionRow] = new JdbcDecoder[PgSubscriptionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSubscriptionRow) = + columIndex + 10 -> + PgSubscriptionRow( + oid = PgSubscriptionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + subdbid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + subname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + subowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + subenabled = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + subbinary = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + substream = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + subconninfo = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + subslotname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + subsynccommit = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 9, rs)._2, + subpublications = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSubscriptionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgSubscriptionId.jsonDecoder)) + val subdbid = jsonObj.get("subdbid").toRight("Missing field 'subdbid'").flatMap(_.as(JsonDecoder.long)) + val subname = jsonObj.get("subname").toRight("Missing field 'subname'").flatMap(_.as(JsonDecoder.string)) + val subowner = jsonObj.get("subowner").toRight("Missing field 'subowner'").flatMap(_.as(JsonDecoder.long)) + val subenabled = jsonObj.get("subenabled").toRight("Missing field 'subenabled'").flatMap(_.as(JsonDecoder.boolean)) + val subbinary = jsonObj.get("subbinary").toRight("Missing field 'subbinary'").flatMap(_.as(JsonDecoder.boolean)) + val substream = jsonObj.get("substream").toRight("Missing field 'substream'").flatMap(_.as(JsonDecoder.boolean)) + val subconninfo = jsonObj.get("subconninfo").toRight("Missing field 'subconninfo'").flatMap(_.as(JsonDecoder.string)) + val subslotname = jsonObj.get("subslotname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val subsynccommit = jsonObj.get("subsynccommit").toRight("Missing field 'subsynccommit'").flatMap(_.as(JsonDecoder.string)) + val subpublications = jsonObj.get("subpublications").toRight("Missing field 'subpublications'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + if (oid.isRight && subdbid.isRight && subname.isRight && subowner.isRight && subenabled.isRight && subbinary.isRight && substream.isRight && subconninfo.isRight && subslotname.isRight && subsynccommit.isRight && subpublications.isRight) + Right(PgSubscriptionRow(oid = oid.toOption.get, subdbid = subdbid.toOption.get, subname = subname.toOption.get, subowner = subowner.toOption.get, subenabled = subenabled.toOption.get, subbinary = subbinary.toOption.get, substream = substream.toOption.get, subconninfo = subconninfo.toOption.get, subslotname = subslotname.toOption.get, subsynccommit = subsynccommit.toOption.get, subpublications = subpublications.toOption.get)) + else Left(List[Either[String, Any]](oid, subdbid, subname, subowner, subenabled, subbinary, substream, subconninfo, subslotname, subsynccommit, subpublications).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSubscriptionRow] = new JsonEncoder[PgSubscriptionRow] { + override def unsafeEncode(a: PgSubscriptionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgSubscriptionId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""subdbid":""") + JsonEncoder.long.unsafeEncode(a.subdbid, indent, out) + out.write(",") + out.write(""""subname":""") + JsonEncoder.string.unsafeEncode(a.subname, indent, out) + out.write(",") + out.write(""""subowner":""") + JsonEncoder.long.unsafeEncode(a.subowner, indent, out) + out.write(",") + out.write(""""subenabled":""") + JsonEncoder.boolean.unsafeEncode(a.subenabled, indent, out) + out.write(",") + out.write(""""subbinary":""") + JsonEncoder.boolean.unsafeEncode(a.subbinary, indent, out) + out.write(",") + out.write(""""substream":""") + JsonEncoder.boolean.unsafeEncode(a.substream, indent, out) + out.write(",") + out.write(""""subconninfo":""") + JsonEncoder.string.unsafeEncode(a.subconninfo, indent, out) + out.write(",") + out.write(""""subslotname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.subslotname, indent, out) + out.write(",") + out.write(""""subsynccommit":""") + JsonEncoder.string.unsafeEncode(a.subsynccommit, indent, out) + out.write(",") + out.write(""""subpublications":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.subpublications, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionStructure.scala new file mode 100644 index 0000000000..1716f0e7bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription/PgSubscriptionStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgSubscriptionStructure[Row](val prefix: Option[String], val extract: Row => PgSubscriptionRow, val merge: (Row, PgSubscriptionRow) => Row) + extends Relation[PgSubscriptionFields, PgSubscriptionRow, Row] + with PgSubscriptionFields[Row] { outer => + + override val oid = new IdField[PgSubscriptionId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val subdbid = new Field[/* oid */ Long, Row](prefix, "subdbid", None, Some("oid"))(x => extract(x).subdbid, (row, value) => merge(row, extract(row).copy(subdbid = value))) + override val subname = new Field[String, Row](prefix, "subname", None, Some("name"))(x => extract(x).subname, (row, value) => merge(row, extract(row).copy(subname = value))) + override val subowner = new Field[/* oid */ Long, Row](prefix, "subowner", None, Some("oid"))(x => extract(x).subowner, (row, value) => merge(row, extract(row).copy(subowner = value))) + override val subenabled = new Field[Boolean, Row](prefix, "subenabled", None, None)(x => extract(x).subenabled, (row, value) => merge(row, extract(row).copy(subenabled = value))) + override val subbinary = new Field[Boolean, Row](prefix, "subbinary", None, None)(x => extract(x).subbinary, (row, value) => merge(row, extract(row).copy(subbinary = value))) + override val substream = new Field[Boolean, Row](prefix, "substream", None, None)(x => extract(x).substream, (row, value) => merge(row, extract(row).copy(substream = value))) + override val subconninfo = new Field[String, Row](prefix, "subconninfo", None, None)(x => extract(x).subconninfo, (row, value) => merge(row, extract(row).copy(subconninfo = value))) + override val subslotname = new OptField[String, Row](prefix, "subslotname", None, Some("name"))(x => extract(x).subslotname, (row, value) => merge(row, extract(row).copy(subslotname = value))) + override val subsynccommit = new Field[String, Row](prefix, "subsynccommit", None, None)(x => extract(x).subsynccommit, (row, value) => merge(row, extract(row).copy(subsynccommit = value))) + override val subpublications = new Field[Array[String], Row](prefix, "subpublications", None, Some("_text"))(x => extract(x).subpublications, (row, value) => merge(row, extract(row).copy(subpublications = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, subdbid, subname, subowner, subenabled, subbinary, substream, subconninfo, subslotname, subsynccommit, subpublications) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSubscriptionRow, merge: (NewRow, PgSubscriptionRow) => NewRow): PgSubscriptionStructure[NewRow] = + new PgSubscriptionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelFields.scala new file mode 100644 index 0000000000..8271eeb6a7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgSubscriptionRelFields[Row] { + val srsubid: IdField[/* oid */ Long, Row] + val srrelid: IdField[/* oid */ Long, Row] + val srsubstate: Field[String, Row] + val srsublsn: OptField[/* pg_lsn */ Long, Row] +} +object PgSubscriptionRelFields extends PgSubscriptionRelStructure[PgSubscriptionRelRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelId.scala new file mode 100644 index 0000000000..bfafbfd23f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelId.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_subscription_rel` */ +case class PgSubscriptionRelId(srrelid: /* oid */ Long, srsubid: /* oid */ Long) +object PgSubscriptionRelId { + implicit lazy val jsonDecoder: JsonDecoder[PgSubscriptionRelId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val srrelid = jsonObj.get("srrelid").toRight("Missing field 'srrelid'").flatMap(_.as(JsonDecoder.long)) + val srsubid = jsonObj.get("srsubid").toRight("Missing field 'srsubid'").flatMap(_.as(JsonDecoder.long)) + if (srrelid.isRight && srsubid.isRight) + Right(PgSubscriptionRelId(srrelid = srrelid.toOption.get, srsubid = srsubid.toOption.get)) + else Left(List[Either[String, Any]](srrelid, srsubid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSubscriptionRelId] = new JsonEncoder[PgSubscriptionRelId] { + override def unsafeEncode(a: PgSubscriptionRelId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""srrelid":""") + JsonEncoder.long.unsafeEncode(a.srrelid, indent, out) + out.write(",") + out.write(""""srsubid":""") + JsonEncoder.long.unsafeEncode(a.srsubid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgSubscriptionRelId] = Ordering.by(x => (x.srrelid, x.srsubid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepo.scala new file mode 100644 index 0000000000..c5cb2d527a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgSubscriptionRelRepo { + def delete(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] + def insert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, PgSubscriptionRelRow] + def select: SelectBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] + def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRelRow] + def selectById(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRelRow]] + def update(row: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] + def upsert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRelRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoImpl.scala new file mode 100644 index 0000000000..3301b82436 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoImpl.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgSubscriptionRelRepoImpl extends PgSubscriptionRelRepo { + override def delete(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_subscription_rel where "srrelid" = ${Segment.paramSegment(compositeId.srrelid)(Setter.longSetter)} AND "srsubid" = ${Segment.paramSegment(compositeId.srsubid)(Setter.longSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + DeleteBuilder("pg_catalog.pg_subscription_rel", PgSubscriptionRelFields) + } + override def insert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, PgSubscriptionRelRow] = { + sql"""insert into pg_catalog.pg_subscription_rel("srsubid", "srrelid", "srsubstate", "srsublsn") + values (${Segment.paramSegment(unsaved.srsubid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.srrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.srsubstate)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.srsublsn)(Setter.optionParamSetter(Setter.longSetter))}::pg_lsn) + returning "srsubid", "srrelid", "srsubstate", "srsublsn" + """.insertReturning(PgSubscriptionRelRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + SelectBuilderSql("pg_catalog.pg_subscription_rel", PgSubscriptionRelFields, PgSubscriptionRelRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRelRow] = { + sql"""select "srsubid", "srrelid", "srsubstate", "srsublsn" from pg_catalog.pg_subscription_rel""".query(PgSubscriptionRelRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRelRow]] = { + sql"""select "srsubid", "srrelid", "srsubstate", "srsublsn" from pg_catalog.pg_subscription_rel where "srrelid" = ${Segment.paramSegment(compositeId.srrelid)(Setter.longSetter)} AND "srsubid" = ${Segment.paramSegment(compositeId.srsubid)(Setter.longSetter)}""".query(PgSubscriptionRelRow.jdbcDecoder).selectOne + } + override def update(row: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_subscription_rel + set "srsubstate" = ${Segment.paramSegment(row.srsubstate)(Setter.stringSetter)}::char, + "srsublsn" = ${Segment.paramSegment(row.srsublsn)(Setter.optionParamSetter(Setter.longSetter))}::pg_lsn + where "srrelid" = ${Segment.paramSegment(compositeId.srrelid)(Setter.longSetter)} AND "srsubid" = ${Segment.paramSegment(compositeId.srsubid)(Setter.longSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + UpdateBuilder("pg_catalog.pg_subscription_rel", PgSubscriptionRelFields, PgSubscriptionRelRow.jdbcDecoder) + } + override def upsert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRelRow]] = { + sql"""insert into pg_catalog.pg_subscription_rel("srsubid", "srrelid", "srsubstate", "srsublsn") + values ( + ${Segment.paramSegment(unsaved.srsubid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.srrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.srsubstate)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.srsublsn)(Setter.optionParamSetter(Setter.longSetter))}::pg_lsn + ) + on conflict ("srrelid", "srsubid") + do update set + "srsubstate" = EXCLUDED."srsubstate", + "srsublsn" = EXCLUDED."srsublsn" + returning "srsubid", "srrelid", "srsubstate", "srsublsn"""".insertReturning(PgSubscriptionRelRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoMock.scala new file mode 100644 index 0000000000..47041f1f35 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgSubscriptionRelRepoMock(map: scala.collection.mutable.Map[PgSubscriptionRelId, PgSubscriptionRelRow] = scala.collection.mutable.Map.empty) extends PgSubscriptionRelRepo { + override def delete(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + DeleteBuilderMock(DeleteParams.empty, PgSubscriptionRelFields, map) + } + override def insert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, PgSubscriptionRelRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + SelectBuilderMock(PgSubscriptionRelFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgSubscriptionRelRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgSubscriptionRelId): ZIO[ZConnection, Throwable, Option[PgSubscriptionRelRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgSubscriptionRelFields, PgSubscriptionRelRow] = { + UpdateBuilderMock(UpdateParams.empty, PgSubscriptionRelFields, map) + } + override def upsert(unsaved: PgSubscriptionRelRow): ZIO[ZConnection, Throwable, UpdateResult[PgSubscriptionRelRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRow.scala new file mode 100644 index 0000000000..746a34b772 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgSubscriptionRelRow( + srsubid: /* oid */ Long, + srrelid: /* oid */ Long, + srsubstate: String, + srsublsn: Option[/* pg_lsn */ Long] +){ + val compositeId: PgSubscriptionRelId = PgSubscriptionRelId(srrelid, srsubid) + } + +object PgSubscriptionRelRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgSubscriptionRelRow] = new JdbcDecoder[PgSubscriptionRelRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgSubscriptionRelRow) = + columIndex + 3 -> + PgSubscriptionRelRow( + srsubid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + srrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + srsubstate = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + srsublsn = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgSubscriptionRelRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val srsubid = jsonObj.get("srsubid").toRight("Missing field 'srsubid'").flatMap(_.as(JsonDecoder.long)) + val srrelid = jsonObj.get("srrelid").toRight("Missing field 'srrelid'").flatMap(_.as(JsonDecoder.long)) + val srsubstate = jsonObj.get("srsubstate").toRight("Missing field 'srsubstate'").flatMap(_.as(JsonDecoder.string)) + val srsublsn = jsonObj.get("srsublsn").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + if (srsubid.isRight && srrelid.isRight && srsubstate.isRight && srsublsn.isRight) + Right(PgSubscriptionRelRow(srsubid = srsubid.toOption.get, srrelid = srrelid.toOption.get, srsubstate = srsubstate.toOption.get, srsublsn = srsublsn.toOption.get)) + else Left(List[Either[String, Any]](srsubid, srrelid, srsubstate, srsublsn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgSubscriptionRelRow] = new JsonEncoder[PgSubscriptionRelRow] { + override def unsafeEncode(a: PgSubscriptionRelRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""srsubid":""") + JsonEncoder.long.unsafeEncode(a.srsubid, indent, out) + out.write(",") + out.write(""""srrelid":""") + JsonEncoder.long.unsafeEncode(a.srrelid, indent, out) + out.write(",") + out.write(""""srsubstate":""") + JsonEncoder.string.unsafeEncode(a.srsubstate, indent, out) + out.write(",") + out.write(""""srsublsn":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.srsublsn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelStructure.scala new file mode 100644 index 0000000000..48fccf2a73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_subscription_rel/PgSubscriptionRelStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_subscription_rel + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgSubscriptionRelStructure[Row](val prefix: Option[String], val extract: Row => PgSubscriptionRelRow, val merge: (Row, PgSubscriptionRelRow) => Row) + extends Relation[PgSubscriptionRelFields, PgSubscriptionRelRow, Row] + with PgSubscriptionRelFields[Row] { outer => + + override val srsubid = new IdField[/* oid */ Long, Row](prefix, "srsubid", None, Some("oid"))(x => extract(x).srsubid, (row, value) => merge(row, extract(row).copy(srsubid = value))) + override val srrelid = new IdField[/* oid */ Long, Row](prefix, "srrelid", None, Some("oid"))(x => extract(x).srrelid, (row, value) => merge(row, extract(row).copy(srrelid = value))) + override val srsubstate = new Field[String, Row](prefix, "srsubstate", None, Some("char"))(x => extract(x).srsubstate, (row, value) => merge(row, extract(row).copy(srsubstate = value))) + override val srsublsn = new OptField[/* pg_lsn */ Long, Row](prefix, "srsublsn", None, Some("pg_lsn"))(x => extract(x).srsublsn, (row, value) => merge(row, extract(row).copy(srsublsn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](srsubid, srrelid, srsubstate, srsublsn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgSubscriptionRelRow, merge: (NewRow, PgSubscriptionRelRow) => NewRow): PgSubscriptionRelStructure[NewRow] = + new PgSubscriptionRelStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewFields.scala new file mode 100644 index 0000000000..54008c3c86 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tables + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgTablesViewFields[Row] { + val schemaname: OptField[String, Row] + val tablename: Field[String, Row] + val tableowner: OptField[String, Row] + val tablespace: OptField[String, Row] + val hasindexes: Field[Boolean, Row] + val hasrules: Field[Boolean, Row] + val hastriggers: Field[Boolean, Row] + val rowsecurity: Field[Boolean, Row] +} +object PgTablesViewFields extends PgTablesViewStructure[PgTablesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepo.scala new file mode 100644 index 0000000000..40cb09b0e7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tables + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTablesViewRepo { + def select: SelectBuilder[PgTablesViewFields, PgTablesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgTablesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepoImpl.scala new file mode 100644 index 0000000000..bb4b09aaa0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tables + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTablesViewRepoImpl extends PgTablesViewRepo { + override def select: SelectBuilder[PgTablesViewFields, PgTablesViewRow] = { + SelectBuilderSql("pg_catalog.pg_tables", PgTablesViewFields, PgTablesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTablesViewRow] = { + sql"""select "schemaname", "tablename", "tableowner", "tablespace", "hasindexes", "hasrules", "hastriggers", "rowsecurity" from pg_catalog.pg_tables""".query(PgTablesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRow.scala new file mode 100644 index 0000000000..95aa62ad1c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewRow.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tables + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTablesViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + tablename: String, + tableowner: /* nullability unknown */ Option[String], + /** Points to [[pg_tablespace.PgTablespaceRow.spcname]] */ + tablespace: Option[String], + /** Points to [[pg_class.PgClassRow.relhasindex]] */ + hasindexes: Boolean, + /** Points to [[pg_class.PgClassRow.relhasrules]] */ + hasrules: Boolean, + /** Points to [[pg_class.PgClassRow.relhastriggers]] */ + hastriggers: Boolean, + /** Points to [[pg_class.PgClassRow.relrowsecurity]] */ + rowsecurity: Boolean +) + +object PgTablesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTablesViewRow] = new JdbcDecoder[PgTablesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTablesViewRow) = + columIndex + 7 -> + PgTablesViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + tablename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + tableowner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + tablespace = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + hasindexes = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 4, rs)._2, + hasrules = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + hastriggers = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 6, rs)._2, + rowsecurity = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTablesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablename = jsonObj.get("tablename").toRight("Missing field 'tablename'").flatMap(_.as(JsonDecoder.string)) + val tableowner = jsonObj.get("tableowner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tablespace = jsonObj.get("tablespace").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val hasindexes = jsonObj.get("hasindexes").toRight("Missing field 'hasindexes'").flatMap(_.as(JsonDecoder.boolean)) + val hasrules = jsonObj.get("hasrules").toRight("Missing field 'hasrules'").flatMap(_.as(JsonDecoder.boolean)) + val hastriggers = jsonObj.get("hastriggers").toRight("Missing field 'hastriggers'").flatMap(_.as(JsonDecoder.boolean)) + val rowsecurity = jsonObj.get("rowsecurity").toRight("Missing field 'rowsecurity'").flatMap(_.as(JsonDecoder.boolean)) + if (schemaname.isRight && tablename.isRight && tableowner.isRight && tablespace.isRight && hasindexes.isRight && hasrules.isRight && hastriggers.isRight && rowsecurity.isRight) + Right(PgTablesViewRow(schemaname = schemaname.toOption.get, tablename = tablename.toOption.get, tableowner = tableowner.toOption.get, tablespace = tablespace.toOption.get, hasindexes = hasindexes.toOption.get, hasrules = hasrules.toOption.get, hastriggers = hastriggers.toOption.get, rowsecurity = rowsecurity.toOption.get)) + else Left(List[Either[String, Any]](schemaname, tablename, tableowner, tablespace, hasindexes, hasrules, hastriggers, rowsecurity).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTablesViewRow] = new JsonEncoder[PgTablesViewRow] { + override def unsafeEncode(a: PgTablesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""tablename":""") + JsonEncoder.string.unsafeEncode(a.tablename, indent, out) + out.write(",") + out.write(""""tableowner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tableowner, indent, out) + out.write(",") + out.write(""""tablespace":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tablespace, indent, out) + out.write(",") + out.write(""""hasindexes":""") + JsonEncoder.boolean.unsafeEncode(a.hasindexes, indent, out) + out.write(",") + out.write(""""hasrules":""") + JsonEncoder.boolean.unsafeEncode(a.hasrules, indent, out) + out.write(",") + out.write(""""hastriggers":""") + JsonEncoder.boolean.unsafeEncode(a.hastriggers, indent, out) + out.write(",") + out.write(""""rowsecurity":""") + JsonEncoder.boolean.unsafeEncode(a.rowsecurity, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewStructure.scala new file mode 100644 index 0000000000..9aa9925efa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tables/PgTablesViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tables + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTablesViewStructure[Row](val prefix: Option[String], val extract: Row => PgTablesViewRow, val merge: (Row, PgTablesViewRow) => Row) + extends Relation[PgTablesViewFields, PgTablesViewRow, Row] + with PgTablesViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val tablename = new Field[String, Row](prefix, "tablename", None, None)(x => extract(x).tablename, (row, value) => merge(row, extract(row).copy(tablename = value))) + override val tableowner = new OptField[String, Row](prefix, "tableowner", None, None)(x => extract(x).tableowner, (row, value) => merge(row, extract(row).copy(tableowner = value))) + override val tablespace = new OptField[String, Row](prefix, "tablespace", None, None)(x => extract(x).tablespace, (row, value) => merge(row, extract(row).copy(tablespace = value))) + override val hasindexes = new Field[Boolean, Row](prefix, "hasindexes", None, None)(x => extract(x).hasindexes, (row, value) => merge(row, extract(row).copy(hasindexes = value))) + override val hasrules = new Field[Boolean, Row](prefix, "hasrules", None, None)(x => extract(x).hasrules, (row, value) => merge(row, extract(row).copy(hasrules = value))) + override val hastriggers = new Field[Boolean, Row](prefix, "hastriggers", None, None)(x => extract(x).hastriggers, (row, value) => merge(row, extract(row).copy(hastriggers = value))) + override val rowsecurity = new Field[Boolean, Row](prefix, "rowsecurity", None, None)(x => extract(x).rowsecurity, (row, value) => merge(row, extract(row).copy(rowsecurity = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, tablename, tableowner, tablespace, hasindexes, hasrules, hastriggers, rowsecurity) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTablesViewRow, merge: (NewRow, PgTablesViewRow) => NewRow): PgTablesViewStructure[NewRow] = + new PgTablesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceFields.scala new file mode 100644 index 0000000000..67d4db414e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgTablespaceFields[Row] { + val oid: IdField[PgTablespaceId, Row] + val spcname: Field[String, Row] + val spcowner: Field[/* oid */ Long, Row] + val spcacl: OptField[Array[TypoAclItem], Row] + val spcoptions: OptField[Array[String], Row] +} +object PgTablespaceFields extends PgTablespaceStructure[PgTablespaceRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceId.scala new file mode 100644 index 0000000000..51de34d043 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +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 `pg_catalog.pg_tablespace` */ +case class PgTablespaceId(value: /* oid */ Long) extends AnyVal +object PgTablespaceId { + implicit lazy val arraySetter: Setter[Array[PgTablespaceId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTablespaceId, /* oid */ Long] = Bijection[PgTablespaceId, /* oid */ Long](_.value)(PgTablespaceId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTablespaceId] = JdbcDecoder.longDecoder.map(PgTablespaceId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTablespaceId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTablespaceId] = JsonDecoder.long.map(PgTablespaceId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTablespaceId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTablespaceId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTablespaceId] = ParameterMetaData.instance[PgTablespaceId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTablespaceId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepo.scala new file mode 100644 index 0000000000..e3ae0f62e5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTablespaceRepo { + def delete(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTablespaceFields, PgTablespaceRow] + def insert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, PgTablespaceRow] + def select: SelectBuilder[PgTablespaceFields, PgTablespaceRow] + def selectAll: ZStream[ZConnection, Throwable, PgTablespaceRow] + def selectById(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] + def selectByIds(oids: Array[PgTablespaceId]): ZStream[ZConnection, Throwable, PgTablespaceRow] + def selectByUnique(spcname: String): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] + def update(row: PgTablespaceRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTablespaceFields, PgTablespaceRow] + def upsert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgTablespaceRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoImpl.scala new file mode 100644 index 0000000000..8f413a127f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoImpl.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTablespaceRepoImpl extends PgTablespaceRepo { + override def delete(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_tablespace where "oid" = ${Segment.paramSegment(oid)(PgTablespaceId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTablespaceFields, PgTablespaceRow] = { + DeleteBuilder("pg_catalog.pg_tablespace", PgTablespaceFields) + } + override def insert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, PgTablespaceRow] = { + sql"""insert into pg_catalog.pg_tablespace("oid", "spcname", "spcowner", "spcacl", "spcoptions") + values (${Segment.paramSegment(unsaved.oid)(PgTablespaceId.setter)}::oid, ${Segment.paramSegment(unsaved.spcname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.spcowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.spcacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, ${Segment.paramSegment(unsaved.spcoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "spcname", "spcowner", "spcacl", "spcoptions" + """.insertReturning(PgTablespaceRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTablespaceFields, PgTablespaceRow] = { + SelectBuilderSql("pg_catalog.pg_tablespace", PgTablespaceFields, PgTablespaceRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTablespaceRow] = { + sql"""select "oid", "spcname", "spcowner", "spcacl", "spcoptions" from pg_catalog.pg_tablespace""".query(PgTablespaceRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] = { + sql"""select "oid", "spcname", "spcowner", "spcacl", "spcoptions" from pg_catalog.pg_tablespace where "oid" = ${Segment.paramSegment(oid)(PgTablespaceId.setter)}""".query(PgTablespaceRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTablespaceId]): ZStream[ZConnection, Throwable, PgTablespaceRow] = { + sql"""select "oid", "spcname", "spcowner", "spcacl", "spcoptions" from pg_catalog.pg_tablespace where "oid" = ANY(${Segment.paramSegment(oids)(PgTablespaceId.arraySetter)})""".query(PgTablespaceRow.jdbcDecoder).selectStream + } + override def selectByUnique(spcname: String): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] = { + sql"""select "spcname" + from pg_catalog.pg_tablespace + where "spcname" = ${Segment.paramSegment(spcname)(Setter.stringSetter)} + """.query(PgTablespaceRow.jdbcDecoder).selectOne + } + override def update(row: PgTablespaceRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_tablespace + set "spcname" = ${Segment.paramSegment(row.spcname)(Setter.stringSetter)}::name, + "spcowner" = ${Segment.paramSegment(row.spcowner)(Setter.longSetter)}::oid, + "spcacl" = ${Segment.paramSegment(row.spcacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + "spcoptions" = ${Segment.paramSegment(row.spcoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgTablespaceId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTablespaceFields, PgTablespaceRow] = { + UpdateBuilder("pg_catalog.pg_tablespace", PgTablespaceFields, PgTablespaceRow.jdbcDecoder) + } + override def upsert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgTablespaceRow]] = { + sql"""insert into pg_catalog.pg_tablespace("oid", "spcname", "spcowner", "spcacl", "spcoptions") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTablespaceId.setter)}::oid, + ${Segment.paramSegment(unsaved.spcname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.spcowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.spcacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem, + ${Segment.paramSegment(unsaved.spcoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "spcname" = EXCLUDED."spcname", + "spcowner" = EXCLUDED."spcowner", + "spcacl" = EXCLUDED."spcacl", + "spcoptions" = EXCLUDED."spcoptions" + returning "oid", "spcname", "spcowner", "spcacl", "spcoptions"""".insertReturning(PgTablespaceRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoMock.scala new file mode 100644 index 0000000000..96ee54812c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTablespaceRepoMock(map: scala.collection.mutable.Map[PgTablespaceId, PgTablespaceRow] = scala.collection.mutable.Map.empty) extends PgTablespaceRepo { + override def delete(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTablespaceFields, PgTablespaceRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTablespaceFields, map) + } + override def insert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, PgTablespaceRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTablespaceFields, PgTablespaceRow] = { + SelectBuilderMock(PgTablespaceFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTablespaceRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTablespaceId): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTablespaceId]): ZStream[ZConnection, Throwable, PgTablespaceRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(spcname: String): ZIO[ZConnection, Throwable, Option[PgTablespaceRow]] = { + ZIO.succeed(map.values.find(v => spcname == v.spcname)) + } + override def update(row: PgTablespaceRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTablespaceFields, PgTablespaceRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTablespaceFields, map) + } + override def upsert(unsaved: PgTablespaceRow): ZIO[ZConnection, Throwable, UpdateResult[PgTablespaceRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRow.scala new file mode 100644 index 0000000000..261ce12713 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import adventureworks.customtypes.TypoAclItem +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTablespaceRow( + oid: PgTablespaceId, + spcname: String, + spcowner: /* oid */ Long, + spcacl: Option[Array[TypoAclItem]], + spcoptions: Option[Array[String]] +) + +object PgTablespaceRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTablespaceRow] = new JdbcDecoder[PgTablespaceRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTablespaceRow) = + columIndex + 4 -> + PgTablespaceRow( + oid = PgTablespaceId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + spcname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + spcowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + spcacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 3, rs)._2, + spcoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTablespaceRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTablespaceId.jsonDecoder)) + val spcname = jsonObj.get("spcname").toRight("Missing field 'spcname'").flatMap(_.as(JsonDecoder.string)) + val spcowner = jsonObj.get("spcowner").toRight("Missing field 'spcowner'").flatMap(_.as(JsonDecoder.long)) + val spcacl = jsonObj.get("spcacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + val spcoptions = jsonObj.get("spcoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && spcname.isRight && spcowner.isRight && spcacl.isRight && spcoptions.isRight) + Right(PgTablespaceRow(oid = oid.toOption.get, spcname = spcname.toOption.get, spcowner = spcowner.toOption.get, spcacl = spcacl.toOption.get, spcoptions = spcoptions.toOption.get)) + else Left(List[Either[String, Any]](oid, spcname, spcowner, spcacl, spcoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTablespaceRow] = new JsonEncoder[PgTablespaceRow] { + override def unsafeEncode(a: PgTablespaceRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTablespaceId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""spcname":""") + JsonEncoder.string.unsafeEncode(a.spcname, indent, out) + out.write(",") + out.write(""""spcowner":""") + JsonEncoder.long.unsafeEncode(a.spcowner, indent, out) + out.write(",") + out.write(""""spcacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.spcacl, indent, out) + out.write(",") + out.write(""""spcoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.spcoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceStructure.scala new file mode 100644 index 0000000000..fd3db03e11 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_tablespace/PgTablespaceStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_tablespace + +import adventureworks.customtypes.TypoAclItem +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTablespaceStructure[Row](val prefix: Option[String], val extract: Row => PgTablespaceRow, val merge: (Row, PgTablespaceRow) => Row) + extends Relation[PgTablespaceFields, PgTablespaceRow, Row] + with PgTablespaceFields[Row] { outer => + + override val oid = new IdField[PgTablespaceId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val spcname = new Field[String, Row](prefix, "spcname", None, Some("name"))(x => extract(x).spcname, (row, value) => merge(row, extract(row).copy(spcname = value))) + override val spcowner = new Field[/* oid */ Long, Row](prefix, "spcowner", None, Some("oid"))(x => extract(x).spcowner, (row, value) => merge(row, extract(row).copy(spcowner = value))) + override val spcacl = new OptField[Array[TypoAclItem], Row](prefix, "spcacl", None, Some("_aclitem"))(x => extract(x).spcacl, (row, value) => merge(row, extract(row).copy(spcacl = value))) + override val spcoptions = new OptField[Array[String], Row](prefix, "spcoptions", None, Some("_text"))(x => extract(x).spcoptions, (row, value) => merge(row, extract(row).copy(spcoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, spcname, spcowner, spcacl, spcoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTablespaceRow, merge: (NewRow, PgTablespaceRow) => NewRow): PgTablespaceStructure[NewRow] = + new PgTablespaceStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewFields.scala new file mode 100644 index 0000000000..1573c83756 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewFields.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_abbrevs + +import adventureworks.customtypes.TypoInterval +import typo.dsl.SqlExpr.OptField + +trait PgTimezoneAbbrevsViewFields[Row] { + val abbrev: OptField[String, Row] + val utcOffset: OptField[TypoInterval, Row] + val isDst: OptField[Boolean, Row] +} +object PgTimezoneAbbrevsViewFields extends PgTimezoneAbbrevsViewStructure[PgTimezoneAbbrevsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepo.scala new file mode 100644 index 0000000000..9c8908608c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_abbrevs + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTimezoneAbbrevsViewRepo { + def select: SelectBuilder[PgTimezoneAbbrevsViewFields, PgTimezoneAbbrevsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgTimezoneAbbrevsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepoImpl.scala new file mode 100644 index 0000000000..a8a6af6770 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_abbrevs + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTimezoneAbbrevsViewRepoImpl extends PgTimezoneAbbrevsViewRepo { + override def select: SelectBuilder[PgTimezoneAbbrevsViewFields, PgTimezoneAbbrevsViewRow] = { + SelectBuilderSql("pg_catalog.pg_timezone_abbrevs", PgTimezoneAbbrevsViewFields, PgTimezoneAbbrevsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTimezoneAbbrevsViewRow] = { + sql"""select "abbrev", "utc_offset", "is_dst" from pg_catalog.pg_timezone_abbrevs""".query(PgTimezoneAbbrevsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRow.scala new file mode 100644 index 0000000000..acf8d4087d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewRow.scala @@ -0,0 +1,56 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_abbrevs + +import adventureworks.customtypes.TypoInterval +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTimezoneAbbrevsViewRow( + abbrev: /* nullability unknown */ Option[String], + utcOffset: /* nullability unknown */ Option[TypoInterval], + isDst: /* nullability unknown */ Option[Boolean] +) + +object PgTimezoneAbbrevsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTimezoneAbbrevsViewRow] = new JdbcDecoder[PgTimezoneAbbrevsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTimezoneAbbrevsViewRow) = + columIndex + 2 -> + PgTimezoneAbbrevsViewRow( + abbrev = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + utcOffset = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + isDst = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTimezoneAbbrevsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val abbrev = jsonObj.get("abbrev").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val utcOffset = jsonObj.get("utc_offset").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val isDst = jsonObj.get("is_dst").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + if (abbrev.isRight && utcOffset.isRight && isDst.isRight) + Right(PgTimezoneAbbrevsViewRow(abbrev = abbrev.toOption.get, utcOffset = utcOffset.toOption.get, isDst = isDst.toOption.get)) + else Left(List[Either[String, Any]](abbrev, utcOffset, isDst).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTimezoneAbbrevsViewRow] = new JsonEncoder[PgTimezoneAbbrevsViewRow] { + override def unsafeEncode(a: PgTimezoneAbbrevsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""abbrev":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.abbrev, indent, out) + out.write(",") + out.write(""""utc_offset":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.utcOffset, indent, out) + out.write(",") + out.write(""""is_dst":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.isDst, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewStructure.scala new file mode 100644 index 0000000000..b54e40a864 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_abbrevs/PgTimezoneAbbrevsViewStructure.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_abbrevs + +import adventureworks.customtypes.TypoInterval +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTimezoneAbbrevsViewStructure[Row](val prefix: Option[String], val extract: Row => PgTimezoneAbbrevsViewRow, val merge: (Row, PgTimezoneAbbrevsViewRow) => Row) + extends Relation[PgTimezoneAbbrevsViewFields, PgTimezoneAbbrevsViewRow, Row] + with PgTimezoneAbbrevsViewFields[Row] { outer => + + override val abbrev = new OptField[String, Row](prefix, "abbrev", None, None)(x => extract(x).abbrev, (row, value) => merge(row, extract(row).copy(abbrev = value))) + override val utcOffset = new OptField[TypoInterval, Row](prefix, "utc_offset", None, None)(x => extract(x).utcOffset, (row, value) => merge(row, extract(row).copy(utcOffset = value))) + override val isDst = new OptField[Boolean, Row](prefix, "is_dst", None, None)(x => extract(x).isDst, (row, value) => merge(row, extract(row).copy(isDst = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](abbrev, utcOffset, isDst) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTimezoneAbbrevsViewRow, merge: (NewRow, PgTimezoneAbbrevsViewRow) => NewRow): PgTimezoneAbbrevsViewStructure[NewRow] = + new PgTimezoneAbbrevsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewFields.scala new file mode 100644 index 0000000000..bae28c1689 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_names + +import adventureworks.customtypes.TypoInterval +import typo.dsl.SqlExpr.OptField + +trait PgTimezoneNamesViewFields[Row] { + val name: OptField[String, Row] + val abbrev: OptField[String, Row] + val utcOffset: OptField[TypoInterval, Row] + val isDst: OptField[Boolean, Row] +} +object PgTimezoneNamesViewFields extends PgTimezoneNamesViewStructure[PgTimezoneNamesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepo.scala new file mode 100644 index 0000000000..e1b78265f1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_names + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTimezoneNamesViewRepo { + def select: SelectBuilder[PgTimezoneNamesViewFields, PgTimezoneNamesViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgTimezoneNamesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepoImpl.scala new file mode 100644 index 0000000000..eb28d6c5fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_names + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTimezoneNamesViewRepoImpl extends PgTimezoneNamesViewRepo { + override def select: SelectBuilder[PgTimezoneNamesViewFields, PgTimezoneNamesViewRow] = { + SelectBuilderSql("pg_catalog.pg_timezone_names", PgTimezoneNamesViewFields, PgTimezoneNamesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTimezoneNamesViewRow] = { + sql"""select "name", "abbrev", "utc_offset", "is_dst" from pg_catalog.pg_timezone_names""".query(PgTimezoneNamesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRow.scala new file mode 100644 index 0000000000..09b3998041 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewRow.scala @@ -0,0 +1,62 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_names + +import adventureworks.customtypes.TypoInterval +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTimezoneNamesViewRow( + name: /* nullability unknown */ Option[String], + abbrev: /* nullability unknown */ Option[String], + utcOffset: /* nullability unknown */ Option[TypoInterval], + isDst: /* nullability unknown */ Option[Boolean] +) + +object PgTimezoneNamesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTimezoneNamesViewRow] = new JdbcDecoder[PgTimezoneNamesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTimezoneNamesViewRow) = + columIndex + 3 -> + PgTimezoneNamesViewRow( + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + abbrev = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + utcOffset = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + isDst = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTimezoneNamesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val abbrev = jsonObj.get("abbrev").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val utcOffset = jsonObj.get("utc_offset").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val isDst = jsonObj.get("is_dst").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + if (name.isRight && abbrev.isRight && utcOffset.isRight && isDst.isRight) + Right(PgTimezoneNamesViewRow(name = name.toOption.get, abbrev = abbrev.toOption.get, utcOffset = utcOffset.toOption.get, isDst = isDst.toOption.get)) + else Left(List[Either[String, Any]](name, abbrev, utcOffset, isDst).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTimezoneNamesViewRow] = new JsonEncoder[PgTimezoneNamesViewRow] { + override def unsafeEncode(a: PgTimezoneNamesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""abbrev":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.abbrev, indent, out) + out.write(",") + out.write(""""utc_offset":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.utcOffset, indent, out) + out.write(",") + out.write(""""is_dst":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.isDst, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewStructure.scala new file mode 100644 index 0000000000..746d1fdb8e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_timezone_names/PgTimezoneNamesViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_timezone_names + +import adventureworks.customtypes.TypoInterval +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTimezoneNamesViewStructure[Row](val prefix: Option[String], val extract: Row => PgTimezoneNamesViewRow, val merge: (Row, PgTimezoneNamesViewRow) => Row) + extends Relation[PgTimezoneNamesViewFields, PgTimezoneNamesViewRow, Row] + with PgTimezoneNamesViewFields[Row] { outer => + + override val name = new OptField[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val abbrev = new OptField[String, Row](prefix, "abbrev", None, None)(x => extract(x).abbrev, (row, value) => merge(row, extract(row).copy(abbrev = value))) + override val utcOffset = new OptField[TypoInterval, Row](prefix, "utc_offset", None, None)(x => extract(x).utcOffset, (row, value) => merge(row, extract(row).copy(utcOffset = value))) + override val isDst = new OptField[Boolean, Row](prefix, "is_dst", None, None)(x => extract(x).isDst, (row, value) => merge(row, extract(row).copy(isDst = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](name, abbrev, utcOffset, isDst) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTimezoneNamesViewRow, merge: (NewRow, PgTimezoneNamesViewRow) => NewRow): PgTimezoneNamesViewStructure[NewRow] = + new PgTimezoneNamesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformFields.scala new file mode 100644 index 0000000000..1933329c07 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgTransformFields[Row] { + val oid: IdField[PgTransformId, Row] + val trftype: Field[/* oid */ Long, Row] + val trflang: Field[/* oid */ Long, Row] + val trffromsql: Field[TypoRegproc, Row] + val trftosql: Field[TypoRegproc, Row] +} +object PgTransformFields extends PgTransformStructure[PgTransformRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformId.scala new file mode 100644 index 0000000000..9b53702957 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +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 `pg_catalog.pg_transform` */ +case class PgTransformId(value: /* oid */ Long) extends AnyVal +object PgTransformId { + implicit lazy val arraySetter: Setter[Array[PgTransformId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTransformId, /* oid */ Long] = Bijection[PgTransformId, /* oid */ Long](_.value)(PgTransformId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTransformId] = JdbcDecoder.longDecoder.map(PgTransformId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTransformId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTransformId] = JsonDecoder.long.map(PgTransformId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTransformId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTransformId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTransformId] = ParameterMetaData.instance[PgTransformId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTransformId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepo.scala new file mode 100644 index 0000000000..bc7f20f548 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTransformRepo { + def delete(oid: PgTransformId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTransformFields, PgTransformRow] + def insert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, PgTransformRow] + def select: SelectBuilder[PgTransformFields, PgTransformRow] + def selectAll: ZStream[ZConnection, Throwable, PgTransformRow] + def selectById(oid: PgTransformId): ZIO[ZConnection, Throwable, Option[PgTransformRow]] + def selectByIds(oids: Array[PgTransformId]): ZStream[ZConnection, Throwable, PgTransformRow] + def selectByUnique(trftype: /* oid */ Long, trflang: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTransformRow]] + def update(row: PgTransformRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTransformFields, PgTransformRow] + def upsert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, UpdateResult[PgTransformRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoImpl.scala new file mode 100644 index 0000000000..38740a1472 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoImpl.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTransformRepoImpl extends PgTransformRepo { + override def delete(oid: PgTransformId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_transform where "oid" = ${Segment.paramSegment(oid)(PgTransformId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTransformFields, PgTransformRow] = { + DeleteBuilder("pg_catalog.pg_transform", PgTransformFields) + } + override def insert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, PgTransformRow] = { + sql"""insert into pg_catalog.pg_transform("oid", "trftype", "trflang", "trffromsql", "trftosql") + values (${Segment.paramSegment(unsaved.oid)(PgTransformId.setter)}::oid, ${Segment.paramSegment(unsaved.trftype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.trflang)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.trffromsql)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.trftosql)(TypoRegproc.setter)}::regproc) + returning "oid", "trftype", "trflang", "trffromsql", "trftosql" + """.insertReturning(PgTransformRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTransformFields, PgTransformRow] = { + SelectBuilderSql("pg_catalog.pg_transform", PgTransformFields, PgTransformRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTransformRow] = { + sql"""select "oid", "trftype", "trflang", "trffromsql", "trftosql" from pg_catalog.pg_transform""".query(PgTransformRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTransformId): ZIO[ZConnection, Throwable, Option[PgTransformRow]] = { + sql"""select "oid", "trftype", "trflang", "trffromsql", "trftosql" from pg_catalog.pg_transform where "oid" = ${Segment.paramSegment(oid)(PgTransformId.setter)}""".query(PgTransformRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTransformId]): ZStream[ZConnection, Throwable, PgTransformRow] = { + sql"""select "oid", "trftype", "trflang", "trffromsql", "trftosql" from pg_catalog.pg_transform where "oid" = ANY(${Segment.paramSegment(oids)(PgTransformId.arraySetter)})""".query(PgTransformRow.jdbcDecoder).selectStream + } + override def selectByUnique(trftype: /* oid */ Long, trflang: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTransformRow]] = { + sql"""select "trftype", "trflang" + from pg_catalog.pg_transform + where "trftype" = ${Segment.paramSegment(trftype)(Setter.longSetter)} AND "trflang" = ${Segment.paramSegment(trflang)(Setter.longSetter)} + """.query(PgTransformRow.jdbcDecoder).selectOne + } + override def update(row: PgTransformRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_transform + set "trftype" = ${Segment.paramSegment(row.trftype)(Setter.longSetter)}::oid, + "trflang" = ${Segment.paramSegment(row.trflang)(Setter.longSetter)}::oid, + "trffromsql" = ${Segment.paramSegment(row.trffromsql)(TypoRegproc.setter)}::regproc, + "trftosql" = ${Segment.paramSegment(row.trftosql)(TypoRegproc.setter)}::regproc + where "oid" = ${Segment.paramSegment(oid)(PgTransformId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTransformFields, PgTransformRow] = { + UpdateBuilder("pg_catalog.pg_transform", PgTransformFields, PgTransformRow.jdbcDecoder) + } + override def upsert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, UpdateResult[PgTransformRow]] = { + sql"""insert into pg_catalog.pg_transform("oid", "trftype", "trflang", "trffromsql", "trftosql") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTransformId.setter)}::oid, + ${Segment.paramSegment(unsaved.trftype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.trflang)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.trffromsql)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.trftosql)(TypoRegproc.setter)}::regproc + ) + on conflict ("oid") + do update set + "trftype" = EXCLUDED."trftype", + "trflang" = EXCLUDED."trflang", + "trffromsql" = EXCLUDED."trffromsql", + "trftosql" = EXCLUDED."trftosql" + returning "oid", "trftype", "trflang", "trffromsql", "trftosql"""".insertReturning(PgTransformRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoMock.scala new file mode 100644 index 0000000000..62034815fe --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTransformRepoMock(map: scala.collection.mutable.Map[PgTransformId, PgTransformRow] = scala.collection.mutable.Map.empty) extends PgTransformRepo { + override def delete(oid: PgTransformId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTransformFields, PgTransformRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTransformFields, map) + } + override def insert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, PgTransformRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTransformFields, PgTransformRow] = { + SelectBuilderMock(PgTransformFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTransformRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTransformId): ZIO[ZConnection, Throwable, Option[PgTransformRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTransformId]): ZStream[ZConnection, Throwable, PgTransformRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(trftype: /* oid */ Long, trflang: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTransformRow]] = { + ZIO.succeed(map.values.find(v => trftype == v.trftype && trflang == v.trflang)) + } + override def update(row: PgTransformRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTransformFields, PgTransformRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTransformFields, map) + } + override def upsert(unsaved: PgTransformRow): ZIO[ZConnection, Throwable, UpdateResult[PgTransformRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRow.scala new file mode 100644 index 0000000000..f8facd1c00 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTransformRow( + oid: PgTransformId, + trftype: /* oid */ Long, + trflang: /* oid */ Long, + trffromsql: TypoRegproc, + trftosql: TypoRegproc +) + +object PgTransformRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTransformRow] = new JdbcDecoder[PgTransformRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTransformRow) = + columIndex + 4 -> + PgTransformRow( + oid = PgTransformId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + trftype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + trflang = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + trffromsql = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + trftosql = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTransformRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTransformId.jsonDecoder)) + val trftype = jsonObj.get("trftype").toRight("Missing field 'trftype'").flatMap(_.as(JsonDecoder.long)) + val trflang = jsonObj.get("trflang").toRight("Missing field 'trflang'").flatMap(_.as(JsonDecoder.long)) + val trffromsql = jsonObj.get("trffromsql").toRight("Missing field 'trffromsql'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val trftosql = jsonObj.get("trftosql").toRight("Missing field 'trftosql'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (oid.isRight && trftype.isRight && trflang.isRight && trffromsql.isRight && trftosql.isRight) + Right(PgTransformRow(oid = oid.toOption.get, trftype = trftype.toOption.get, trflang = trflang.toOption.get, trffromsql = trffromsql.toOption.get, trftosql = trftosql.toOption.get)) + else Left(List[Either[String, Any]](oid, trftype, trflang, trffromsql, trftosql).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTransformRow] = new JsonEncoder[PgTransformRow] { + override def unsafeEncode(a: PgTransformRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTransformId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""trftype":""") + JsonEncoder.long.unsafeEncode(a.trftype, indent, out) + out.write(",") + out.write(""""trflang":""") + JsonEncoder.long.unsafeEncode(a.trflang, indent, out) + out.write(",") + out.write(""""trffromsql":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.trffromsql, indent, out) + out.write(",") + out.write(""""trftosql":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.trftosql, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformStructure.scala new file mode 100644 index 0000000000..a413c6909f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_transform/PgTransformStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_transform + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgTransformStructure[Row](val prefix: Option[String], val extract: Row => PgTransformRow, val merge: (Row, PgTransformRow) => Row) + extends Relation[PgTransformFields, PgTransformRow, Row] + with PgTransformFields[Row] { outer => + + override val oid = new IdField[PgTransformId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val trftype = new Field[/* oid */ Long, Row](prefix, "trftype", None, Some("oid"))(x => extract(x).trftype, (row, value) => merge(row, extract(row).copy(trftype = value))) + override val trflang = new Field[/* oid */ Long, Row](prefix, "trflang", None, Some("oid"))(x => extract(x).trflang, (row, value) => merge(row, extract(row).copy(trflang = value))) + override val trffromsql = new Field[TypoRegproc, Row](prefix, "trffromsql", None, Some("regproc"))(x => extract(x).trffromsql, (row, value) => merge(row, extract(row).copy(trffromsql = value))) + override val trftosql = new Field[TypoRegproc, Row](prefix, "trftosql", None, Some("regproc"))(x => extract(x).trftosql, (row, value) => merge(row, extract(row).copy(trftosql = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, trftype, trflang, trffromsql, trftosql) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTransformRow, merge: (NewRow, PgTransformRow) => NewRow): PgTransformStructure[NewRow] = + new PgTransformStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerFields.scala new file mode 100644 index 0000000000..1e7921f8b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerFields.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgTriggerFields[Row] { + val oid: IdField[PgTriggerId, Row] + val tgrelid: Field[/* oid */ Long, Row] + val tgparentid: Field[/* oid */ Long, Row] + val tgname: Field[String, Row] + val tgfoid: Field[/* oid */ Long, Row] + val tgtype: Field[TypoShort, Row] + val tgenabled: Field[String, Row] + val tgisinternal: Field[Boolean, Row] + val tgconstrrelid: Field[/* oid */ Long, Row] + val tgconstrindid: Field[/* oid */ Long, Row] + val tgconstraint: Field[/* oid */ Long, Row] + val tgdeferrable: Field[Boolean, Row] + val tginitdeferred: Field[Boolean, Row] + val tgnargs: Field[TypoShort, Row] + val tgattr: Field[TypoInt2Vector, Row] + val tgargs: Field[TypoBytea, Row] + val tgqual: OptField[TypoPgNodeTree, Row] + val tgoldtable: OptField[String, Row] + val tgnewtable: OptField[String, Row] +} +object PgTriggerFields extends PgTriggerStructure[PgTriggerRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerId.scala new file mode 100644 index 0000000000..8940d8931f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +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 `pg_catalog.pg_trigger` */ +case class PgTriggerId(value: /* oid */ Long) extends AnyVal +object PgTriggerId { + implicit lazy val arraySetter: Setter[Array[PgTriggerId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTriggerId, /* oid */ Long] = Bijection[PgTriggerId, /* oid */ Long](_.value)(PgTriggerId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTriggerId] = JdbcDecoder.longDecoder.map(PgTriggerId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTriggerId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTriggerId] = JsonDecoder.long.map(PgTriggerId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTriggerId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTriggerId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTriggerId] = ParameterMetaData.instance[PgTriggerId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTriggerId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepo.scala new file mode 100644 index 0000000000..ebfb3e7517 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTriggerRepo { + def delete(oid: PgTriggerId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTriggerFields, PgTriggerRow] + def insert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, PgTriggerRow] + def select: SelectBuilder[PgTriggerFields, PgTriggerRow] + def selectAll: ZStream[ZConnection, Throwable, PgTriggerRow] + def selectById(oid: PgTriggerId): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] + def selectByIds(oids: Array[PgTriggerId]): ZStream[ZConnection, Throwable, PgTriggerRow] + def selectByUnique(tgrelid: /* oid */ Long, tgname: String): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] + def update(row: PgTriggerRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTriggerFields, PgTriggerRow] + def upsert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgTriggerRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoImpl.scala new file mode 100644 index 0000000000..8c77dc73df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoImpl.scala @@ -0,0 +1,128 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTriggerRepoImpl extends PgTriggerRepo { + override def delete(oid: PgTriggerId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_trigger where "oid" = ${Segment.paramSegment(oid)(PgTriggerId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTriggerFields, PgTriggerRow] = { + DeleteBuilder("pg_catalog.pg_trigger", PgTriggerFields) + } + override def insert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, PgTriggerRow] = { + sql"""insert into pg_catalog.pg_trigger("oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable") + values (${Segment.paramSegment(unsaved.oid)(PgTriggerId.setter)}::oid, ${Segment.paramSegment(unsaved.tgrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgparentid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.tgfoid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgtype)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.tgenabled)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.tgisinternal)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.tgconstrrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgconstrindid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgconstraint)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tgdeferrable)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.tginitdeferred)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.tgnargs)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.tgattr)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.tgargs)(TypoBytea.setter)}::bytea, ${Segment.paramSegment(unsaved.tgqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.tgoldtable)(Setter.optionParamSetter(Setter.stringSetter))}::name, ${Segment.paramSegment(unsaved.tgnewtable)(Setter.optionParamSetter(Setter.stringSetter))}::name) + returning "oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable" + """.insertReturning(PgTriggerRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTriggerFields, PgTriggerRow] = { + SelectBuilderSql("pg_catalog.pg_trigger", PgTriggerFields, PgTriggerRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTriggerRow] = { + sql"""select "oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable" from pg_catalog.pg_trigger""".query(PgTriggerRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTriggerId): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] = { + sql"""select "oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable" from pg_catalog.pg_trigger where "oid" = ${Segment.paramSegment(oid)(PgTriggerId.setter)}""".query(PgTriggerRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTriggerId]): ZStream[ZConnection, Throwable, PgTriggerRow] = { + sql"""select "oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable" from pg_catalog.pg_trigger where "oid" = ANY(${Segment.paramSegment(oids)(PgTriggerId.arraySetter)})""".query(PgTriggerRow.jdbcDecoder).selectStream + } + override def selectByUnique(tgrelid: /* oid */ Long, tgname: String): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] = { + sql"""select "tgrelid", "tgname" + from pg_catalog.pg_trigger + where "tgrelid" = ${Segment.paramSegment(tgrelid)(Setter.longSetter)} AND "tgname" = ${Segment.paramSegment(tgname)(Setter.stringSetter)} + """.query(PgTriggerRow.jdbcDecoder).selectOne + } + override def update(row: PgTriggerRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_trigger + set "tgrelid" = ${Segment.paramSegment(row.tgrelid)(Setter.longSetter)}::oid, + "tgparentid" = ${Segment.paramSegment(row.tgparentid)(Setter.longSetter)}::oid, + "tgname" = ${Segment.paramSegment(row.tgname)(Setter.stringSetter)}::name, + "tgfoid" = ${Segment.paramSegment(row.tgfoid)(Setter.longSetter)}::oid, + "tgtype" = ${Segment.paramSegment(row.tgtype)(TypoShort.setter)}::int2, + "tgenabled" = ${Segment.paramSegment(row.tgenabled)(Setter.stringSetter)}::char, + "tgisinternal" = ${Segment.paramSegment(row.tgisinternal)(Setter.booleanSetter)}, + "tgconstrrelid" = ${Segment.paramSegment(row.tgconstrrelid)(Setter.longSetter)}::oid, + "tgconstrindid" = ${Segment.paramSegment(row.tgconstrindid)(Setter.longSetter)}::oid, + "tgconstraint" = ${Segment.paramSegment(row.tgconstraint)(Setter.longSetter)}::oid, + "tgdeferrable" = ${Segment.paramSegment(row.tgdeferrable)(Setter.booleanSetter)}, + "tginitdeferred" = ${Segment.paramSegment(row.tginitdeferred)(Setter.booleanSetter)}, + "tgnargs" = ${Segment.paramSegment(row.tgnargs)(TypoShort.setter)}::int2, + "tgattr" = ${Segment.paramSegment(row.tgattr)(TypoInt2Vector.setter)}::int2vector, + "tgargs" = ${Segment.paramSegment(row.tgargs)(TypoBytea.setter)}::bytea, + "tgqual" = ${Segment.paramSegment(row.tgqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "tgoldtable" = ${Segment.paramSegment(row.tgoldtable)(Setter.optionParamSetter(Setter.stringSetter))}::name, + "tgnewtable" = ${Segment.paramSegment(row.tgnewtable)(Setter.optionParamSetter(Setter.stringSetter))}::name + where "oid" = ${Segment.paramSegment(oid)(PgTriggerId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTriggerFields, PgTriggerRow] = { + UpdateBuilder("pg_catalog.pg_trigger", PgTriggerFields, PgTriggerRow.jdbcDecoder) + } + override def upsert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgTriggerRow]] = { + sql"""insert into pg_catalog.pg_trigger("oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTriggerId.setter)}::oid, + ${Segment.paramSegment(unsaved.tgrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgparentid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.tgfoid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgtype)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.tgenabled)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.tgisinternal)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.tgconstrrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgconstrindid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgconstraint)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tgdeferrable)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.tginitdeferred)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.tgnargs)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.tgattr)(TypoInt2Vector.setter)}::int2vector, + ${Segment.paramSegment(unsaved.tgargs)(TypoBytea.setter)}::bytea, + ${Segment.paramSegment(unsaved.tgqual)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.tgoldtable)(Setter.optionParamSetter(Setter.stringSetter))}::name, + ${Segment.paramSegment(unsaved.tgnewtable)(Setter.optionParamSetter(Setter.stringSetter))}::name + ) + on conflict ("oid") + do update set + "tgrelid" = EXCLUDED."tgrelid", + "tgparentid" = EXCLUDED."tgparentid", + "tgname" = EXCLUDED."tgname", + "tgfoid" = EXCLUDED."tgfoid", + "tgtype" = EXCLUDED."tgtype", + "tgenabled" = EXCLUDED."tgenabled", + "tgisinternal" = EXCLUDED."tgisinternal", + "tgconstrrelid" = EXCLUDED."tgconstrrelid", + "tgconstrindid" = EXCLUDED."tgconstrindid", + "tgconstraint" = EXCLUDED."tgconstraint", + "tgdeferrable" = EXCLUDED."tgdeferrable", + "tginitdeferred" = EXCLUDED."tginitdeferred", + "tgnargs" = EXCLUDED."tgnargs", + "tgattr" = EXCLUDED."tgattr", + "tgargs" = EXCLUDED."tgargs", + "tgqual" = EXCLUDED."tgqual", + "tgoldtable" = EXCLUDED."tgoldtable", + "tgnewtable" = EXCLUDED."tgnewtable" + returning "oid", "tgrelid", "tgparentid", "tgname", "tgfoid", "tgtype", "tgenabled", "tgisinternal", "tgconstrrelid", "tgconstrindid", "tgconstraint", "tgdeferrable", "tginitdeferred", "tgnargs", "tgattr", "tgargs", "tgqual", "tgoldtable", "tgnewtable"""".insertReturning(PgTriggerRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoMock.scala new file mode 100644 index 0000000000..273870f4c0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTriggerRepoMock(map: scala.collection.mutable.Map[PgTriggerId, PgTriggerRow] = scala.collection.mutable.Map.empty) extends PgTriggerRepo { + override def delete(oid: PgTriggerId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTriggerFields, PgTriggerRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTriggerFields, map) + } + override def insert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, PgTriggerRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTriggerFields, PgTriggerRow] = { + SelectBuilderMock(PgTriggerFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTriggerRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTriggerId): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTriggerId]): ZStream[ZConnection, Throwable, PgTriggerRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(tgrelid: /* oid */ Long, tgname: String): ZIO[ZConnection, Throwable, Option[PgTriggerRow]] = { + ZIO.succeed(map.values.find(v => tgrelid == v.tgrelid && tgname == v.tgname)) + } + override def update(row: PgTriggerRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTriggerFields, PgTriggerRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTriggerFields, map) + } + override def upsert(unsaved: PgTriggerRow): ZIO[ZConnection, Throwable, UpdateResult[PgTriggerRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRow.scala new file mode 100644 index 0000000000..4f478dd4a5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerRow.scala @@ -0,0 +1,155 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTriggerRow( + oid: PgTriggerId, + tgrelid: /* oid */ Long, + tgparentid: /* oid */ Long, + tgname: String, + tgfoid: /* oid */ Long, + tgtype: TypoShort, + tgenabled: String, + tgisinternal: Boolean, + tgconstrrelid: /* oid */ Long, + tgconstrindid: /* oid */ Long, + tgconstraint: /* oid */ Long, + tgdeferrable: Boolean, + tginitdeferred: Boolean, + tgnargs: TypoShort, + tgattr: TypoInt2Vector, + tgargs: TypoBytea, + tgqual: Option[TypoPgNodeTree], + tgoldtable: Option[String], + tgnewtable: Option[String] +) + +object PgTriggerRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTriggerRow] = new JdbcDecoder[PgTriggerRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTriggerRow) = + columIndex + 18 -> + PgTriggerRow( + oid = PgTriggerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + tgrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + tgparentid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + tgname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + tgfoid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + tgtype = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + tgenabled = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + tgisinternal = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 7, rs)._2, + tgconstrrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 8, rs)._2, + tgconstrindid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 9, rs)._2, + tgconstraint = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 10, rs)._2, + tgdeferrable = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 11, rs)._2, + tginitdeferred = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 12, rs)._2, + tgnargs = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + tgattr = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + tgargs = TypoBytea.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + tgqual = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + tgoldtable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + tgnewtable = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTriggerRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTriggerId.jsonDecoder)) + val tgrelid = jsonObj.get("tgrelid").toRight("Missing field 'tgrelid'").flatMap(_.as(JsonDecoder.long)) + val tgparentid = jsonObj.get("tgparentid").toRight("Missing field 'tgparentid'").flatMap(_.as(JsonDecoder.long)) + val tgname = jsonObj.get("tgname").toRight("Missing field 'tgname'").flatMap(_.as(JsonDecoder.string)) + val tgfoid = jsonObj.get("tgfoid").toRight("Missing field 'tgfoid'").flatMap(_.as(JsonDecoder.long)) + val tgtype = jsonObj.get("tgtype").toRight("Missing field 'tgtype'").flatMap(_.as(TypoShort.jsonDecoder)) + val tgenabled = jsonObj.get("tgenabled").toRight("Missing field 'tgenabled'").flatMap(_.as(JsonDecoder.string)) + val tgisinternal = jsonObj.get("tgisinternal").toRight("Missing field 'tgisinternal'").flatMap(_.as(JsonDecoder.boolean)) + val tgconstrrelid = jsonObj.get("tgconstrrelid").toRight("Missing field 'tgconstrrelid'").flatMap(_.as(JsonDecoder.long)) + val tgconstrindid = jsonObj.get("tgconstrindid").toRight("Missing field 'tgconstrindid'").flatMap(_.as(JsonDecoder.long)) + val tgconstraint = jsonObj.get("tgconstraint").toRight("Missing field 'tgconstraint'").flatMap(_.as(JsonDecoder.long)) + val tgdeferrable = jsonObj.get("tgdeferrable").toRight("Missing field 'tgdeferrable'").flatMap(_.as(JsonDecoder.boolean)) + val tginitdeferred = jsonObj.get("tginitdeferred").toRight("Missing field 'tginitdeferred'").flatMap(_.as(JsonDecoder.boolean)) + val tgnargs = jsonObj.get("tgnargs").toRight("Missing field 'tgnargs'").flatMap(_.as(TypoShort.jsonDecoder)) + val tgattr = jsonObj.get("tgattr").toRight("Missing field 'tgattr'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val tgargs = jsonObj.get("tgargs").toRight("Missing field 'tgargs'").flatMap(_.as(TypoBytea.jsonDecoder)) + val tgqual = jsonObj.get("tgqual").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val tgoldtable = jsonObj.get("tgoldtable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val tgnewtable = jsonObj.get("tgnewtable").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && tgrelid.isRight && tgparentid.isRight && tgname.isRight && tgfoid.isRight && tgtype.isRight && tgenabled.isRight && tgisinternal.isRight && tgconstrrelid.isRight && tgconstrindid.isRight && tgconstraint.isRight && tgdeferrable.isRight && tginitdeferred.isRight && tgnargs.isRight && tgattr.isRight && tgargs.isRight && tgqual.isRight && tgoldtable.isRight && tgnewtable.isRight) + Right(PgTriggerRow(oid = oid.toOption.get, tgrelid = tgrelid.toOption.get, tgparentid = tgparentid.toOption.get, tgname = tgname.toOption.get, tgfoid = tgfoid.toOption.get, tgtype = tgtype.toOption.get, tgenabled = tgenabled.toOption.get, tgisinternal = tgisinternal.toOption.get, tgconstrrelid = tgconstrrelid.toOption.get, tgconstrindid = tgconstrindid.toOption.get, tgconstraint = tgconstraint.toOption.get, tgdeferrable = tgdeferrable.toOption.get, tginitdeferred = tginitdeferred.toOption.get, tgnargs = tgnargs.toOption.get, tgattr = tgattr.toOption.get, tgargs = tgargs.toOption.get, tgqual = tgqual.toOption.get, tgoldtable = tgoldtable.toOption.get, tgnewtable = tgnewtable.toOption.get)) + else Left(List[Either[String, Any]](oid, tgrelid, tgparentid, tgname, tgfoid, tgtype, tgenabled, tgisinternal, tgconstrrelid, tgconstrindid, tgconstraint, tgdeferrable, tginitdeferred, tgnargs, tgattr, tgargs, tgqual, tgoldtable, tgnewtable).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTriggerRow] = new JsonEncoder[PgTriggerRow] { + override def unsafeEncode(a: PgTriggerRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTriggerId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""tgrelid":""") + JsonEncoder.long.unsafeEncode(a.tgrelid, indent, out) + out.write(",") + out.write(""""tgparentid":""") + JsonEncoder.long.unsafeEncode(a.tgparentid, indent, out) + out.write(",") + out.write(""""tgname":""") + JsonEncoder.string.unsafeEncode(a.tgname, indent, out) + out.write(",") + out.write(""""tgfoid":""") + JsonEncoder.long.unsafeEncode(a.tgfoid, indent, out) + out.write(",") + out.write(""""tgtype":""") + TypoShort.jsonEncoder.unsafeEncode(a.tgtype, indent, out) + out.write(",") + out.write(""""tgenabled":""") + JsonEncoder.string.unsafeEncode(a.tgenabled, indent, out) + out.write(",") + out.write(""""tgisinternal":""") + JsonEncoder.boolean.unsafeEncode(a.tgisinternal, indent, out) + out.write(",") + out.write(""""tgconstrrelid":""") + JsonEncoder.long.unsafeEncode(a.tgconstrrelid, indent, out) + out.write(",") + out.write(""""tgconstrindid":""") + JsonEncoder.long.unsafeEncode(a.tgconstrindid, indent, out) + out.write(",") + out.write(""""tgconstraint":""") + JsonEncoder.long.unsafeEncode(a.tgconstraint, indent, out) + out.write(",") + out.write(""""tgdeferrable":""") + JsonEncoder.boolean.unsafeEncode(a.tgdeferrable, indent, out) + out.write(",") + out.write(""""tginitdeferred":""") + JsonEncoder.boolean.unsafeEncode(a.tginitdeferred, indent, out) + out.write(",") + out.write(""""tgnargs":""") + TypoShort.jsonEncoder.unsafeEncode(a.tgnargs, indent, out) + out.write(",") + out.write(""""tgattr":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.tgattr, indent, out) + out.write(",") + out.write(""""tgargs":""") + TypoBytea.jsonEncoder.unsafeEncode(a.tgargs, indent, out) + out.write(",") + out.write(""""tgqual":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.tgqual, indent, out) + out.write(",") + out.write(""""tgoldtable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tgoldtable, indent, out) + out.write(",") + out.write(""""tgnewtable":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.tgnewtable, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerStructure.scala new file mode 100644 index 0000000000..9576d72916 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_trigger/PgTriggerStructure.scala @@ -0,0 +1,49 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_trigger + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTriggerStructure[Row](val prefix: Option[String], val extract: Row => PgTriggerRow, val merge: (Row, PgTriggerRow) => Row) + extends Relation[PgTriggerFields, PgTriggerRow, Row] + with PgTriggerFields[Row] { outer => + + override val oid = new IdField[PgTriggerId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val tgrelid = new Field[/* oid */ Long, Row](prefix, "tgrelid", None, Some("oid"))(x => extract(x).tgrelid, (row, value) => merge(row, extract(row).copy(tgrelid = value))) + override val tgparentid = new Field[/* oid */ Long, Row](prefix, "tgparentid", None, Some("oid"))(x => extract(x).tgparentid, (row, value) => merge(row, extract(row).copy(tgparentid = value))) + override val tgname = new Field[String, Row](prefix, "tgname", None, Some("name"))(x => extract(x).tgname, (row, value) => merge(row, extract(row).copy(tgname = value))) + override val tgfoid = new Field[/* oid */ Long, Row](prefix, "tgfoid", None, Some("oid"))(x => extract(x).tgfoid, (row, value) => merge(row, extract(row).copy(tgfoid = value))) + override val tgtype = new Field[TypoShort, Row](prefix, "tgtype", None, Some("int2"))(x => extract(x).tgtype, (row, value) => merge(row, extract(row).copy(tgtype = value))) + override val tgenabled = new Field[String, Row](prefix, "tgenabled", None, Some("char"))(x => extract(x).tgenabled, (row, value) => merge(row, extract(row).copy(tgenabled = value))) + override val tgisinternal = new Field[Boolean, Row](prefix, "tgisinternal", None, None)(x => extract(x).tgisinternal, (row, value) => merge(row, extract(row).copy(tgisinternal = value))) + override val tgconstrrelid = new Field[/* oid */ Long, Row](prefix, "tgconstrrelid", None, Some("oid"))(x => extract(x).tgconstrrelid, (row, value) => merge(row, extract(row).copy(tgconstrrelid = value))) + override val tgconstrindid = new Field[/* oid */ Long, Row](prefix, "tgconstrindid", None, Some("oid"))(x => extract(x).tgconstrindid, (row, value) => merge(row, extract(row).copy(tgconstrindid = value))) + override val tgconstraint = new Field[/* oid */ Long, Row](prefix, "tgconstraint", None, Some("oid"))(x => extract(x).tgconstraint, (row, value) => merge(row, extract(row).copy(tgconstraint = value))) + override val tgdeferrable = new Field[Boolean, Row](prefix, "tgdeferrable", None, None)(x => extract(x).tgdeferrable, (row, value) => merge(row, extract(row).copy(tgdeferrable = value))) + override val tginitdeferred = new Field[Boolean, Row](prefix, "tginitdeferred", None, None)(x => extract(x).tginitdeferred, (row, value) => merge(row, extract(row).copy(tginitdeferred = value))) + override val tgnargs = new Field[TypoShort, Row](prefix, "tgnargs", None, Some("int2"))(x => extract(x).tgnargs, (row, value) => merge(row, extract(row).copy(tgnargs = value))) + override val tgattr = new Field[TypoInt2Vector, Row](prefix, "tgattr", None, Some("int2vector"))(x => extract(x).tgattr, (row, value) => merge(row, extract(row).copy(tgattr = value))) + override val tgargs = new Field[TypoBytea, Row](prefix, "tgargs", None, Some("bytea"))(x => extract(x).tgargs, (row, value) => merge(row, extract(row).copy(tgargs = value))) + override val tgqual = new OptField[TypoPgNodeTree, Row](prefix, "tgqual", None, Some("pg_node_tree"))(x => extract(x).tgqual, (row, value) => merge(row, extract(row).copy(tgqual = value))) + override val tgoldtable = new OptField[String, Row](prefix, "tgoldtable", None, Some("name"))(x => extract(x).tgoldtable, (row, value) => merge(row, extract(row).copy(tgoldtable = value))) + override val tgnewtable = new OptField[String, Row](prefix, "tgnewtable", None, Some("name"))(x => extract(x).tgnewtable, (row, value) => merge(row, extract(row).copy(tgnewtable = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, tgrelid, tgparentid, tgname, tgfoid, tgtype, tgenabled, tgisinternal, tgconstrrelid, tgconstrindid, tgconstraint, tgdeferrable, tginitdeferred, tgnargs, tgattr, tgargs, tgqual, tgoldtable, tgnewtable) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTriggerRow, merge: (NewRow, PgTriggerRow) => NewRow): PgTriggerStructure[NewRow] = + new PgTriggerStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigFields.scala new file mode 100644 index 0000000000..64066f811b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgTsConfigFields[Row] { + val oid: IdField[PgTsConfigId, Row] + val cfgname: Field[String, Row] + val cfgnamespace: Field[/* oid */ Long, Row] + val cfgowner: Field[/* oid */ Long, Row] + val cfgparser: Field[/* oid */ Long, Row] +} +object PgTsConfigFields extends PgTsConfigStructure[PgTsConfigRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigId.scala new file mode 100644 index 0000000000..fe7dbf105c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +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 `pg_catalog.pg_ts_config` */ +case class PgTsConfigId(value: /* oid */ Long) extends AnyVal +object PgTsConfigId { + implicit lazy val arraySetter: Setter[Array[PgTsConfigId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTsConfigId, /* oid */ Long] = Bijection[PgTsConfigId, /* oid */ Long](_.value)(PgTsConfigId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsConfigId] = JdbcDecoder.longDecoder.map(PgTsConfigId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTsConfigId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTsConfigId] = JsonDecoder.long.map(PgTsConfigId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTsConfigId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTsConfigId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTsConfigId] = ParameterMetaData.instance[PgTsConfigId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTsConfigId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepo.scala new file mode 100644 index 0000000000..81a4e6efd6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTsConfigRepo { + def delete(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTsConfigFields, PgTsConfigRow] + def insert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, PgTsConfigRow] + def select: SelectBuilder[PgTsConfigFields, PgTsConfigRow] + def selectAll: ZStream[ZConnection, Throwable, PgTsConfigRow] + def selectById(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] + def selectByIds(oids: Array[PgTsConfigId]): ZStream[ZConnection, Throwable, PgTsConfigRow] + def selectByUnique(cfgname: String, cfgnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] + def update(row: PgTsConfigRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTsConfigFields, PgTsConfigRow] + def upsert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoImpl.scala new file mode 100644 index 0000000000..31bae47926 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoImpl.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTsConfigRepoImpl extends PgTsConfigRepo { + override def delete(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_ts_config where "oid" = ${Segment.paramSegment(oid)(PgTsConfigId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTsConfigFields, PgTsConfigRow] = { + DeleteBuilder("pg_catalog.pg_ts_config", PgTsConfigFields) + } + override def insert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, PgTsConfigRow] = { + sql"""insert into pg_catalog.pg_ts_config("oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser") + values (${Segment.paramSegment(unsaved.oid)(PgTsConfigId.setter)}::oid, ${Segment.paramSegment(unsaved.cfgname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.cfgnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.cfgowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.cfgparser)(Setter.longSetter)}::oid) + returning "oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser" + """.insertReturning(PgTsConfigRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTsConfigFields, PgTsConfigRow] = { + SelectBuilderSql("pg_catalog.pg_ts_config", PgTsConfigFields, PgTsConfigRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsConfigRow] = { + sql"""select "oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser" from pg_catalog.pg_ts_config""".query(PgTsConfigRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] = { + sql"""select "oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser" from pg_catalog.pg_ts_config where "oid" = ${Segment.paramSegment(oid)(PgTsConfigId.setter)}""".query(PgTsConfigRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTsConfigId]): ZStream[ZConnection, Throwable, PgTsConfigRow] = { + sql"""select "oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser" from pg_catalog.pg_ts_config where "oid" = ANY(${Segment.paramSegment(oids)(PgTsConfigId.arraySetter)})""".query(PgTsConfigRow.jdbcDecoder).selectStream + } + override def selectByUnique(cfgname: String, cfgnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] = { + sql"""select "cfgname", "cfgnamespace" + from pg_catalog.pg_ts_config + where "cfgname" = ${Segment.paramSegment(cfgname)(Setter.stringSetter)} AND "cfgnamespace" = ${Segment.paramSegment(cfgnamespace)(Setter.longSetter)} + """.query(PgTsConfigRow.jdbcDecoder).selectOne + } + override def update(row: PgTsConfigRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_ts_config + set "cfgname" = ${Segment.paramSegment(row.cfgname)(Setter.stringSetter)}::name, + "cfgnamespace" = ${Segment.paramSegment(row.cfgnamespace)(Setter.longSetter)}::oid, + "cfgowner" = ${Segment.paramSegment(row.cfgowner)(Setter.longSetter)}::oid, + "cfgparser" = ${Segment.paramSegment(row.cfgparser)(Setter.longSetter)}::oid + where "oid" = ${Segment.paramSegment(oid)(PgTsConfigId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTsConfigFields, PgTsConfigRow] = { + UpdateBuilder("pg_catalog.pg_ts_config", PgTsConfigFields, PgTsConfigRow.jdbcDecoder) + } + override def upsert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigRow]] = { + sql"""insert into pg_catalog.pg_ts_config("oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTsConfigId.setter)}::oid, + ${Segment.paramSegment(unsaved.cfgname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.cfgnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.cfgowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.cfgparser)(Setter.longSetter)}::oid + ) + on conflict ("oid") + do update set + "cfgname" = EXCLUDED."cfgname", + "cfgnamespace" = EXCLUDED."cfgnamespace", + "cfgowner" = EXCLUDED."cfgowner", + "cfgparser" = EXCLUDED."cfgparser" + returning "oid", "cfgname", "cfgnamespace", "cfgowner", "cfgparser"""".insertReturning(PgTsConfigRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoMock.scala new file mode 100644 index 0000000000..b3248d26f5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTsConfigRepoMock(map: scala.collection.mutable.Map[PgTsConfigId, PgTsConfigRow] = scala.collection.mutable.Map.empty) extends PgTsConfigRepo { + override def delete(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTsConfigFields, PgTsConfigRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTsConfigFields, map) + } + override def insert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, PgTsConfigRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTsConfigFields, PgTsConfigRow] = { + SelectBuilderMock(PgTsConfigFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsConfigRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTsConfigId): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTsConfigId]): ZStream[ZConnection, Throwable, PgTsConfigRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(cfgname: String, cfgnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsConfigRow]] = { + ZIO.succeed(map.values.find(v => cfgname == v.cfgname && cfgnamespace == v.cfgnamespace)) + } + override def update(row: PgTsConfigRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTsConfigFields, PgTsConfigRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTsConfigFields, map) + } + override def upsert(unsaved: PgTsConfigRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRow.scala new file mode 100644 index 0000000000..58af9b1f4f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigRow.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTsConfigRow( + oid: PgTsConfigId, + cfgname: String, + cfgnamespace: /* oid */ Long, + cfgowner: /* oid */ Long, + cfgparser: /* oid */ Long +) + +object PgTsConfigRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsConfigRow] = new JdbcDecoder[PgTsConfigRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTsConfigRow) = + columIndex + 4 -> + PgTsConfigRow( + oid = PgTsConfigId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + cfgname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + cfgnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + cfgowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + cfgparser = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTsConfigRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTsConfigId.jsonDecoder)) + val cfgname = jsonObj.get("cfgname").toRight("Missing field 'cfgname'").flatMap(_.as(JsonDecoder.string)) + val cfgnamespace = jsonObj.get("cfgnamespace").toRight("Missing field 'cfgnamespace'").flatMap(_.as(JsonDecoder.long)) + val cfgowner = jsonObj.get("cfgowner").toRight("Missing field 'cfgowner'").flatMap(_.as(JsonDecoder.long)) + val cfgparser = jsonObj.get("cfgparser").toRight("Missing field 'cfgparser'").flatMap(_.as(JsonDecoder.long)) + if (oid.isRight && cfgname.isRight && cfgnamespace.isRight && cfgowner.isRight && cfgparser.isRight) + Right(PgTsConfigRow(oid = oid.toOption.get, cfgname = cfgname.toOption.get, cfgnamespace = cfgnamespace.toOption.get, cfgowner = cfgowner.toOption.get, cfgparser = cfgparser.toOption.get)) + else Left(List[Either[String, Any]](oid, cfgname, cfgnamespace, cfgowner, cfgparser).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsConfigRow] = new JsonEncoder[PgTsConfigRow] { + override def unsafeEncode(a: PgTsConfigRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTsConfigId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""cfgname":""") + JsonEncoder.string.unsafeEncode(a.cfgname, indent, out) + out.write(",") + out.write(""""cfgnamespace":""") + JsonEncoder.long.unsafeEncode(a.cfgnamespace, indent, out) + out.write(",") + out.write(""""cfgowner":""") + JsonEncoder.long.unsafeEncode(a.cfgowner, indent, out) + out.write(",") + out.write(""""cfgparser":""") + JsonEncoder.long.unsafeEncode(a.cfgparser, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigStructure.scala new file mode 100644 index 0000000000..3f209a9746 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config/PgTsConfigStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgTsConfigStructure[Row](val prefix: Option[String], val extract: Row => PgTsConfigRow, val merge: (Row, PgTsConfigRow) => Row) + extends Relation[PgTsConfigFields, PgTsConfigRow, Row] + with PgTsConfigFields[Row] { outer => + + override val oid = new IdField[PgTsConfigId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val cfgname = new Field[String, Row](prefix, "cfgname", None, Some("name"))(x => extract(x).cfgname, (row, value) => merge(row, extract(row).copy(cfgname = value))) + override val cfgnamespace = new Field[/* oid */ Long, Row](prefix, "cfgnamespace", None, Some("oid"))(x => extract(x).cfgnamespace, (row, value) => merge(row, extract(row).copy(cfgnamespace = value))) + override val cfgowner = new Field[/* oid */ Long, Row](prefix, "cfgowner", None, Some("oid"))(x => extract(x).cfgowner, (row, value) => merge(row, extract(row).copy(cfgowner = value))) + override val cfgparser = new Field[/* oid */ Long, Row](prefix, "cfgparser", None, Some("oid"))(x => extract(x).cfgparser, (row, value) => merge(row, extract(row).copy(cfgparser = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, cfgname, cfgnamespace, cfgowner, cfgparser) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTsConfigRow, merge: (NewRow, PgTsConfigRow) => NewRow): PgTsConfigStructure[NewRow] = + new PgTsConfigStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapFields.scala new file mode 100644 index 0000000000..31f23a4142 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgTsConfigMapFields[Row] { + val mapcfg: IdField[/* oid */ Long, Row] + val maptokentype: IdField[Int, Row] + val mapseqno: IdField[Int, Row] + val mapdict: Field[/* oid */ Long, Row] +} +object PgTsConfigMapFields extends PgTsConfigMapStructure[PgTsConfigMapRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapId.scala new file mode 100644 index 0000000000..bd07c73f38 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapId.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `pg_catalog.pg_ts_config_map` */ +case class PgTsConfigMapId(mapcfg: /* oid */ Long, maptokentype: Int, mapseqno: Int) +object PgTsConfigMapId { + implicit lazy val jsonDecoder: JsonDecoder[PgTsConfigMapId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val mapcfg = jsonObj.get("mapcfg").toRight("Missing field 'mapcfg'").flatMap(_.as(JsonDecoder.long)) + val maptokentype = jsonObj.get("maptokentype").toRight("Missing field 'maptokentype'").flatMap(_.as(JsonDecoder.int)) + val mapseqno = jsonObj.get("mapseqno").toRight("Missing field 'mapseqno'").flatMap(_.as(JsonDecoder.int)) + if (mapcfg.isRight && maptokentype.isRight && mapseqno.isRight) + Right(PgTsConfigMapId(mapcfg = mapcfg.toOption.get, maptokentype = maptokentype.toOption.get, mapseqno = mapseqno.toOption.get)) + else Left(List[Either[String, Any]](mapcfg, maptokentype, mapseqno).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsConfigMapId] = new JsonEncoder[PgTsConfigMapId] { + override def unsafeEncode(a: PgTsConfigMapId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""mapcfg":""") + JsonEncoder.long.unsafeEncode(a.mapcfg, indent, out) + out.write(",") + out.write(""""maptokentype":""") + JsonEncoder.int.unsafeEncode(a.maptokentype, indent, out) + out.write(",") + out.write(""""mapseqno":""") + JsonEncoder.int.unsafeEncode(a.mapseqno, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PgTsConfigMapId] = Ordering.by(x => (x.mapcfg, x.maptokentype, x.mapseqno)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepo.scala new file mode 100644 index 0000000000..b1a8d87513 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepo.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTsConfigMapRepo { + def delete(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTsConfigMapFields, PgTsConfigMapRow] + def insert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, PgTsConfigMapRow] + def select: SelectBuilder[PgTsConfigMapFields, PgTsConfigMapRow] + def selectAll: ZStream[ZConnection, Throwable, PgTsConfigMapRow] + def selectById(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Option[PgTsConfigMapRow]] + def update(row: PgTsConfigMapRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTsConfigMapFields, PgTsConfigMapRow] + def upsert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigMapRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoImpl.scala new file mode 100644 index 0000000000..627765b16c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTsConfigMapRepoImpl extends PgTsConfigMapRepo { + override def delete(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_ts_config_map where "mapcfg" = ${Segment.paramSegment(compositeId.mapcfg)(Setter.longSetter)} AND "maptokentype" = ${Segment.paramSegment(compositeId.maptokentype)(Setter.intSetter)} AND "mapseqno" = ${Segment.paramSegment(compositeId.mapseqno)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + DeleteBuilder("pg_catalog.pg_ts_config_map", PgTsConfigMapFields) + } + override def insert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, PgTsConfigMapRow] = { + sql"""insert into pg_catalog.pg_ts_config_map("mapcfg", "maptokentype", "mapseqno", "mapdict") + values (${Segment.paramSegment(unsaved.mapcfg)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.maptokentype)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.mapseqno)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.mapdict)(Setter.longSetter)}::oid) + returning "mapcfg", "maptokentype", "mapseqno", "mapdict" + """.insertReturning(PgTsConfigMapRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + SelectBuilderSql("pg_catalog.pg_ts_config_map", PgTsConfigMapFields, PgTsConfigMapRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsConfigMapRow] = { + sql"""select "mapcfg", "maptokentype", "mapseqno", "mapdict" from pg_catalog.pg_ts_config_map""".query(PgTsConfigMapRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Option[PgTsConfigMapRow]] = { + sql"""select "mapcfg", "maptokentype", "mapseqno", "mapdict" from pg_catalog.pg_ts_config_map where "mapcfg" = ${Segment.paramSegment(compositeId.mapcfg)(Setter.longSetter)} AND "maptokentype" = ${Segment.paramSegment(compositeId.maptokentype)(Setter.intSetter)} AND "mapseqno" = ${Segment.paramSegment(compositeId.mapseqno)(Setter.intSetter)}""".query(PgTsConfigMapRow.jdbcDecoder).selectOne + } + override def update(row: PgTsConfigMapRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update pg_catalog.pg_ts_config_map + set "mapdict" = ${Segment.paramSegment(row.mapdict)(Setter.longSetter)}::oid + where "mapcfg" = ${Segment.paramSegment(compositeId.mapcfg)(Setter.longSetter)} AND "maptokentype" = ${Segment.paramSegment(compositeId.maptokentype)(Setter.intSetter)} AND "mapseqno" = ${Segment.paramSegment(compositeId.mapseqno)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + UpdateBuilder("pg_catalog.pg_ts_config_map", PgTsConfigMapFields, PgTsConfigMapRow.jdbcDecoder) + } + override def upsert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigMapRow]] = { + sql"""insert into pg_catalog.pg_ts_config_map("mapcfg", "maptokentype", "mapseqno", "mapdict") + values ( + ${Segment.paramSegment(unsaved.mapcfg)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.maptokentype)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.mapseqno)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.mapdict)(Setter.longSetter)}::oid + ) + on conflict ("mapcfg", "maptokentype", "mapseqno") + do update set + "mapdict" = EXCLUDED."mapdict" + returning "mapcfg", "maptokentype", "mapseqno", "mapdict"""".insertReturning(PgTsConfigMapRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoMock.scala new file mode 100644 index 0000000000..b16f70ec64 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRepoMock.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTsConfigMapRepoMock(map: scala.collection.mutable.Map[PgTsConfigMapId, PgTsConfigMapRow] = scala.collection.mutable.Map.empty) extends PgTsConfigMapRepo { + override def delete(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTsConfigMapFields, map) + } + override def insert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, PgTsConfigMapRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + SelectBuilderMock(PgTsConfigMapFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsConfigMapRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PgTsConfigMapId): ZIO[ZConnection, Throwable, Option[PgTsConfigMapRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PgTsConfigMapRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTsConfigMapFields, PgTsConfigMapRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTsConfigMapFields, map) + } + override def upsert(unsaved: PgTsConfigMapRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsConfigMapRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRow.scala new file mode 100644 index 0000000000..6be6df6b76 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTsConfigMapRow( + mapcfg: /* oid */ Long, + maptokentype: Int, + mapseqno: Int, + mapdict: /* oid */ Long +){ + val compositeId: PgTsConfigMapId = PgTsConfigMapId(mapcfg, maptokentype, mapseqno) + } + +object PgTsConfigMapRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsConfigMapRow] = new JdbcDecoder[PgTsConfigMapRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTsConfigMapRow) = + columIndex + 3 -> + PgTsConfigMapRow( + mapcfg = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 0, rs)._2, + maptokentype = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + mapseqno = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + mapdict = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTsConfigMapRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val mapcfg = jsonObj.get("mapcfg").toRight("Missing field 'mapcfg'").flatMap(_.as(JsonDecoder.long)) + val maptokentype = jsonObj.get("maptokentype").toRight("Missing field 'maptokentype'").flatMap(_.as(JsonDecoder.int)) + val mapseqno = jsonObj.get("mapseqno").toRight("Missing field 'mapseqno'").flatMap(_.as(JsonDecoder.int)) + val mapdict = jsonObj.get("mapdict").toRight("Missing field 'mapdict'").flatMap(_.as(JsonDecoder.long)) + if (mapcfg.isRight && maptokentype.isRight && mapseqno.isRight && mapdict.isRight) + Right(PgTsConfigMapRow(mapcfg = mapcfg.toOption.get, maptokentype = maptokentype.toOption.get, mapseqno = mapseqno.toOption.get, mapdict = mapdict.toOption.get)) + else Left(List[Either[String, Any]](mapcfg, maptokentype, mapseqno, mapdict).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsConfigMapRow] = new JsonEncoder[PgTsConfigMapRow] { + override def unsafeEncode(a: PgTsConfigMapRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""mapcfg":""") + JsonEncoder.long.unsafeEncode(a.mapcfg, indent, out) + out.write(",") + out.write(""""maptokentype":""") + JsonEncoder.int.unsafeEncode(a.maptokentype, indent, out) + out.write(",") + out.write(""""mapseqno":""") + JsonEncoder.int.unsafeEncode(a.mapseqno, indent, out) + out.write(",") + out.write(""""mapdict":""") + JsonEncoder.long.unsafeEncode(a.mapdict, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapStructure.scala new file mode 100644 index 0000000000..b0489491ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_config_map/PgTsConfigMapStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_config_map + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgTsConfigMapStructure[Row](val prefix: Option[String], val extract: Row => PgTsConfigMapRow, val merge: (Row, PgTsConfigMapRow) => Row) + extends Relation[PgTsConfigMapFields, PgTsConfigMapRow, Row] + with PgTsConfigMapFields[Row] { outer => + + override val mapcfg = new IdField[/* oid */ Long, Row](prefix, "mapcfg", None, Some("oid"))(x => extract(x).mapcfg, (row, value) => merge(row, extract(row).copy(mapcfg = value))) + override val maptokentype = new IdField[Int, Row](prefix, "maptokentype", None, Some("int4"))(x => extract(x).maptokentype, (row, value) => merge(row, extract(row).copy(maptokentype = value))) + override val mapseqno = new IdField[Int, Row](prefix, "mapseqno", None, Some("int4"))(x => extract(x).mapseqno, (row, value) => merge(row, extract(row).copy(mapseqno = value))) + override val mapdict = new Field[/* oid */ Long, Row](prefix, "mapdict", None, Some("oid"))(x => extract(x).mapdict, (row, value) => merge(row, extract(row).copy(mapdict = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](mapcfg, maptokentype, mapseqno, mapdict) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTsConfigMapRow, merge: (NewRow, PgTsConfigMapRow) => NewRow): PgTsConfigMapStructure[NewRow] = + new PgTsConfigMapStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictFields.scala new file mode 100644 index 0000000000..aff1a9253f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgTsDictFields[Row] { + val oid: IdField[PgTsDictId, Row] + val dictname: Field[String, Row] + val dictnamespace: Field[/* oid */ Long, Row] + val dictowner: Field[/* oid */ Long, Row] + val dicttemplate: Field[/* oid */ Long, Row] + val dictinitoption: OptField[String, Row] +} +object PgTsDictFields extends PgTsDictStructure[PgTsDictRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictId.scala new file mode 100644 index 0000000000..c120314675 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +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 `pg_catalog.pg_ts_dict` */ +case class PgTsDictId(value: /* oid */ Long) extends AnyVal +object PgTsDictId { + implicit lazy val arraySetter: Setter[Array[PgTsDictId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTsDictId, /* oid */ Long] = Bijection[PgTsDictId, /* oid */ Long](_.value)(PgTsDictId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsDictId] = JdbcDecoder.longDecoder.map(PgTsDictId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTsDictId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTsDictId] = JsonDecoder.long.map(PgTsDictId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTsDictId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTsDictId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTsDictId] = ParameterMetaData.instance[PgTsDictId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTsDictId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepo.scala new file mode 100644 index 0000000000..d6316b229b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTsDictRepo { + def delete(oid: PgTsDictId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTsDictFields, PgTsDictRow] + def insert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, PgTsDictRow] + def select: SelectBuilder[PgTsDictFields, PgTsDictRow] + def selectAll: ZStream[ZConnection, Throwable, PgTsDictRow] + def selectById(oid: PgTsDictId): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] + def selectByIds(oids: Array[PgTsDictId]): ZStream[ZConnection, Throwable, PgTsDictRow] + def selectByUnique(dictname: String, dictnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] + def update(row: PgTsDictRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTsDictFields, PgTsDictRow] + def upsert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsDictRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoImpl.scala new file mode 100644 index 0000000000..0d5a0d9adf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoImpl.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTsDictRepoImpl extends PgTsDictRepo { + override def delete(oid: PgTsDictId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_ts_dict where "oid" = ${Segment.paramSegment(oid)(PgTsDictId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTsDictFields, PgTsDictRow] = { + DeleteBuilder("pg_catalog.pg_ts_dict", PgTsDictFields) + } + override def insert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, PgTsDictRow] = { + sql"""insert into pg_catalog.pg_ts_dict("oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption") + values (${Segment.paramSegment(unsaved.oid)(PgTsDictId.setter)}::oid, ${Segment.paramSegment(unsaved.dictname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.dictnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.dictowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.dicttemplate)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.dictinitoption)(Setter.optionParamSetter(Setter.stringSetter))}) + returning "oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption" + """.insertReturning(PgTsDictRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTsDictFields, PgTsDictRow] = { + SelectBuilderSql("pg_catalog.pg_ts_dict", PgTsDictFields, PgTsDictRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsDictRow] = { + sql"""select "oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption" from pg_catalog.pg_ts_dict""".query(PgTsDictRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTsDictId): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] = { + sql"""select "oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption" from pg_catalog.pg_ts_dict where "oid" = ${Segment.paramSegment(oid)(PgTsDictId.setter)}""".query(PgTsDictRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTsDictId]): ZStream[ZConnection, Throwable, PgTsDictRow] = { + sql"""select "oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption" from pg_catalog.pg_ts_dict where "oid" = ANY(${Segment.paramSegment(oids)(PgTsDictId.arraySetter)})""".query(PgTsDictRow.jdbcDecoder).selectStream + } + override def selectByUnique(dictname: String, dictnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] = { + sql"""select "dictname", "dictnamespace" + from pg_catalog.pg_ts_dict + where "dictname" = ${Segment.paramSegment(dictname)(Setter.stringSetter)} AND "dictnamespace" = ${Segment.paramSegment(dictnamespace)(Setter.longSetter)} + """.query(PgTsDictRow.jdbcDecoder).selectOne + } + override def update(row: PgTsDictRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_ts_dict + set "dictname" = ${Segment.paramSegment(row.dictname)(Setter.stringSetter)}::name, + "dictnamespace" = ${Segment.paramSegment(row.dictnamespace)(Setter.longSetter)}::oid, + "dictowner" = ${Segment.paramSegment(row.dictowner)(Setter.longSetter)}::oid, + "dicttemplate" = ${Segment.paramSegment(row.dicttemplate)(Setter.longSetter)}::oid, + "dictinitoption" = ${Segment.paramSegment(row.dictinitoption)(Setter.optionParamSetter(Setter.stringSetter))} + where "oid" = ${Segment.paramSegment(oid)(PgTsDictId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTsDictFields, PgTsDictRow] = { + UpdateBuilder("pg_catalog.pg_ts_dict", PgTsDictFields, PgTsDictRow.jdbcDecoder) + } + override def upsert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsDictRow]] = { + sql"""insert into pg_catalog.pg_ts_dict("oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTsDictId.setter)}::oid, + ${Segment.paramSegment(unsaved.dictname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.dictnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.dictowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.dicttemplate)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.dictinitoption)(Setter.optionParamSetter(Setter.stringSetter))} + ) + on conflict ("oid") + do update set + "dictname" = EXCLUDED."dictname", + "dictnamespace" = EXCLUDED."dictnamespace", + "dictowner" = EXCLUDED."dictowner", + "dicttemplate" = EXCLUDED."dicttemplate", + "dictinitoption" = EXCLUDED."dictinitoption" + returning "oid", "dictname", "dictnamespace", "dictowner", "dicttemplate", "dictinitoption"""".insertReturning(PgTsDictRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoMock.scala new file mode 100644 index 0000000000..d632160c24 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTsDictRepoMock(map: scala.collection.mutable.Map[PgTsDictId, PgTsDictRow] = scala.collection.mutable.Map.empty) extends PgTsDictRepo { + override def delete(oid: PgTsDictId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTsDictFields, PgTsDictRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTsDictFields, map) + } + override def insert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, PgTsDictRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTsDictFields, PgTsDictRow] = { + SelectBuilderMock(PgTsDictFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsDictRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTsDictId): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTsDictId]): ZStream[ZConnection, Throwable, PgTsDictRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(dictname: String, dictnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsDictRow]] = { + ZIO.succeed(map.values.find(v => dictname == v.dictname && dictnamespace == v.dictnamespace)) + } + override def update(row: PgTsDictRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTsDictFields, PgTsDictRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTsDictFields, map) + } + override def upsert(unsaved: PgTsDictRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsDictRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRow.scala new file mode 100644 index 0000000000..8c4045d3f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTsDictRow( + oid: PgTsDictId, + dictname: String, + dictnamespace: /* oid */ Long, + dictowner: /* oid */ Long, + dicttemplate: /* oid */ Long, + dictinitoption: Option[String] +) + +object PgTsDictRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsDictRow] = new JdbcDecoder[PgTsDictRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTsDictRow) = + columIndex + 5 -> + PgTsDictRow( + oid = PgTsDictId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + dictname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + dictnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + dictowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + dicttemplate = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 4, rs)._2, + dictinitoption = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTsDictRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTsDictId.jsonDecoder)) + val dictname = jsonObj.get("dictname").toRight("Missing field 'dictname'").flatMap(_.as(JsonDecoder.string)) + val dictnamespace = jsonObj.get("dictnamespace").toRight("Missing field 'dictnamespace'").flatMap(_.as(JsonDecoder.long)) + val dictowner = jsonObj.get("dictowner").toRight("Missing field 'dictowner'").flatMap(_.as(JsonDecoder.long)) + val dicttemplate = jsonObj.get("dicttemplate").toRight("Missing field 'dicttemplate'").flatMap(_.as(JsonDecoder.long)) + val dictinitoption = jsonObj.get("dictinitoption").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (oid.isRight && dictname.isRight && dictnamespace.isRight && dictowner.isRight && dicttemplate.isRight && dictinitoption.isRight) + Right(PgTsDictRow(oid = oid.toOption.get, dictname = dictname.toOption.get, dictnamespace = dictnamespace.toOption.get, dictowner = dictowner.toOption.get, dicttemplate = dicttemplate.toOption.get, dictinitoption = dictinitoption.toOption.get)) + else Left(List[Either[String, Any]](oid, dictname, dictnamespace, dictowner, dicttemplate, dictinitoption).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsDictRow] = new JsonEncoder[PgTsDictRow] { + override def unsafeEncode(a: PgTsDictRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTsDictId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""dictname":""") + JsonEncoder.string.unsafeEncode(a.dictname, indent, out) + out.write(",") + out.write(""""dictnamespace":""") + JsonEncoder.long.unsafeEncode(a.dictnamespace, indent, out) + out.write(",") + out.write(""""dictowner":""") + JsonEncoder.long.unsafeEncode(a.dictowner, indent, out) + out.write(",") + out.write(""""dicttemplate":""") + JsonEncoder.long.unsafeEncode(a.dicttemplate, indent, out) + out.write(",") + out.write(""""dictinitoption":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.dictinitoption, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictStructure.scala new file mode 100644 index 0000000000..049e4bca00 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_dict/PgTsDictStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_dict + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTsDictStructure[Row](val prefix: Option[String], val extract: Row => PgTsDictRow, val merge: (Row, PgTsDictRow) => Row) + extends Relation[PgTsDictFields, PgTsDictRow, Row] + with PgTsDictFields[Row] { outer => + + override val oid = new IdField[PgTsDictId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val dictname = new Field[String, Row](prefix, "dictname", None, Some("name"))(x => extract(x).dictname, (row, value) => merge(row, extract(row).copy(dictname = value))) + override val dictnamespace = new Field[/* oid */ Long, Row](prefix, "dictnamespace", None, Some("oid"))(x => extract(x).dictnamespace, (row, value) => merge(row, extract(row).copy(dictnamespace = value))) + override val dictowner = new Field[/* oid */ Long, Row](prefix, "dictowner", None, Some("oid"))(x => extract(x).dictowner, (row, value) => merge(row, extract(row).copy(dictowner = value))) + override val dicttemplate = new Field[/* oid */ Long, Row](prefix, "dicttemplate", None, Some("oid"))(x => extract(x).dicttemplate, (row, value) => merge(row, extract(row).copy(dicttemplate = value))) + override val dictinitoption = new OptField[String, Row](prefix, "dictinitoption", None, None)(x => extract(x).dictinitoption, (row, value) => merge(row, extract(row).copy(dictinitoption = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, dictname, dictnamespace, dictowner, dicttemplate, dictinitoption) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTsDictRow, merge: (NewRow, PgTsDictRow) => NewRow): PgTsDictStructure[NewRow] = + new PgTsDictStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserFields.scala new file mode 100644 index 0000000000..94853142e2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgTsParserFields[Row] { + val oid: IdField[PgTsParserId, Row] + val prsname: Field[String, Row] + val prsnamespace: Field[/* oid */ Long, Row] + val prsstart: Field[TypoRegproc, Row] + val prstoken: Field[TypoRegproc, Row] + val prsend: Field[TypoRegproc, Row] + val prsheadline: Field[TypoRegproc, Row] + val prslextype: Field[TypoRegproc, Row] +} +object PgTsParserFields extends PgTsParserStructure[PgTsParserRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserId.scala new file mode 100644 index 0000000000..2b41c7e4f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +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 `pg_catalog.pg_ts_parser` */ +case class PgTsParserId(value: /* oid */ Long) extends AnyVal +object PgTsParserId { + implicit lazy val arraySetter: Setter[Array[PgTsParserId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTsParserId, /* oid */ Long] = Bijection[PgTsParserId, /* oid */ Long](_.value)(PgTsParserId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsParserId] = JdbcDecoder.longDecoder.map(PgTsParserId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTsParserId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTsParserId] = JsonDecoder.long.map(PgTsParserId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTsParserId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTsParserId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTsParserId] = ParameterMetaData.instance[PgTsParserId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTsParserId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepo.scala new file mode 100644 index 0000000000..d20f49671d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTsParserRepo { + def delete(oid: PgTsParserId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTsParserFields, PgTsParserRow] + def insert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, PgTsParserRow] + def select: SelectBuilder[PgTsParserFields, PgTsParserRow] + def selectAll: ZStream[ZConnection, Throwable, PgTsParserRow] + def selectById(oid: PgTsParserId): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] + def selectByIds(oids: Array[PgTsParserId]): ZStream[ZConnection, Throwable, PgTsParserRow] + def selectByUnique(prsname: String, prsnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] + def update(row: PgTsParserRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTsParserFields, PgTsParserRow] + def upsert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsParserRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoImpl.scala new file mode 100644 index 0000000000..fbf92d2d9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoImpl.scala @@ -0,0 +1,92 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTsParserRepoImpl extends PgTsParserRepo { + override def delete(oid: PgTsParserId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_ts_parser where "oid" = ${Segment.paramSegment(oid)(PgTsParserId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTsParserFields, PgTsParserRow] = { + DeleteBuilder("pg_catalog.pg_ts_parser", PgTsParserFields) + } + override def insert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, PgTsParserRow] = { + sql"""insert into pg_catalog.pg_ts_parser("oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype") + values (${Segment.paramSegment(unsaved.oid)(PgTsParserId.setter)}::oid, ${Segment.paramSegment(unsaved.prsname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.prsnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.prsstart)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.prstoken)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.prsend)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.prsheadline)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.prslextype)(TypoRegproc.setter)}::regproc) + returning "oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype" + """.insertReturning(PgTsParserRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTsParserFields, PgTsParserRow] = { + SelectBuilderSql("pg_catalog.pg_ts_parser", PgTsParserFields, PgTsParserRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsParserRow] = { + sql"""select "oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype" from pg_catalog.pg_ts_parser""".query(PgTsParserRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTsParserId): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] = { + sql"""select "oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype" from pg_catalog.pg_ts_parser where "oid" = ${Segment.paramSegment(oid)(PgTsParserId.setter)}""".query(PgTsParserRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTsParserId]): ZStream[ZConnection, Throwable, PgTsParserRow] = { + sql"""select "oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype" from pg_catalog.pg_ts_parser where "oid" = ANY(${Segment.paramSegment(oids)(PgTsParserId.arraySetter)})""".query(PgTsParserRow.jdbcDecoder).selectStream + } + override def selectByUnique(prsname: String, prsnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] = { + sql"""select "prsname", "prsnamespace" + from pg_catalog.pg_ts_parser + where "prsname" = ${Segment.paramSegment(prsname)(Setter.stringSetter)} AND "prsnamespace" = ${Segment.paramSegment(prsnamespace)(Setter.longSetter)} + """.query(PgTsParserRow.jdbcDecoder).selectOne + } + override def update(row: PgTsParserRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_ts_parser + set "prsname" = ${Segment.paramSegment(row.prsname)(Setter.stringSetter)}::name, + "prsnamespace" = ${Segment.paramSegment(row.prsnamespace)(Setter.longSetter)}::oid, + "prsstart" = ${Segment.paramSegment(row.prsstart)(TypoRegproc.setter)}::regproc, + "prstoken" = ${Segment.paramSegment(row.prstoken)(TypoRegproc.setter)}::regproc, + "prsend" = ${Segment.paramSegment(row.prsend)(TypoRegproc.setter)}::regproc, + "prsheadline" = ${Segment.paramSegment(row.prsheadline)(TypoRegproc.setter)}::regproc, + "prslextype" = ${Segment.paramSegment(row.prslextype)(TypoRegproc.setter)}::regproc + where "oid" = ${Segment.paramSegment(oid)(PgTsParserId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTsParserFields, PgTsParserRow] = { + UpdateBuilder("pg_catalog.pg_ts_parser", PgTsParserFields, PgTsParserRow.jdbcDecoder) + } + override def upsert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsParserRow]] = { + sql"""insert into pg_catalog.pg_ts_parser("oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTsParserId.setter)}::oid, + ${Segment.paramSegment(unsaved.prsname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.prsnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.prsstart)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.prstoken)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.prsend)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.prsheadline)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.prslextype)(TypoRegproc.setter)}::regproc + ) + on conflict ("oid") + do update set + "prsname" = EXCLUDED."prsname", + "prsnamespace" = EXCLUDED."prsnamespace", + "prsstart" = EXCLUDED."prsstart", + "prstoken" = EXCLUDED."prstoken", + "prsend" = EXCLUDED."prsend", + "prsheadline" = EXCLUDED."prsheadline", + "prslextype" = EXCLUDED."prslextype" + returning "oid", "prsname", "prsnamespace", "prsstart", "prstoken", "prsend", "prsheadline", "prslextype"""".insertReturning(PgTsParserRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoMock.scala new file mode 100644 index 0000000000..6048392db2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTsParserRepoMock(map: scala.collection.mutable.Map[PgTsParserId, PgTsParserRow] = scala.collection.mutable.Map.empty) extends PgTsParserRepo { + override def delete(oid: PgTsParserId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTsParserFields, PgTsParserRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTsParserFields, map) + } + override def insert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, PgTsParserRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTsParserFields, PgTsParserRow] = { + SelectBuilderMock(PgTsParserFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsParserRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTsParserId): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTsParserId]): ZStream[ZConnection, Throwable, PgTsParserRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(prsname: String, prsnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsParserRow]] = { + ZIO.succeed(map.values.find(v => prsname == v.prsname && prsnamespace == v.prsnamespace)) + } + override def update(row: PgTsParserRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTsParserFields, PgTsParserRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTsParserFields, map) + } + override def upsert(unsaved: PgTsParserRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsParserRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRow.scala new file mode 100644 index 0000000000..ed5f8d4156 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserRow.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTsParserRow( + oid: PgTsParserId, + prsname: String, + prsnamespace: /* oid */ Long, + prsstart: TypoRegproc, + prstoken: TypoRegproc, + prsend: TypoRegproc, + prsheadline: TypoRegproc, + prslextype: TypoRegproc +) + +object PgTsParserRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsParserRow] = new JdbcDecoder[PgTsParserRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTsParserRow) = + columIndex + 7 -> + PgTsParserRow( + oid = PgTsParserId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + prsname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + prsnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + prsstart = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + prstoken = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + prsend = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + prsheadline = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + prslextype = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTsParserRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTsParserId.jsonDecoder)) + val prsname = jsonObj.get("prsname").toRight("Missing field 'prsname'").flatMap(_.as(JsonDecoder.string)) + val prsnamespace = jsonObj.get("prsnamespace").toRight("Missing field 'prsnamespace'").flatMap(_.as(JsonDecoder.long)) + val prsstart = jsonObj.get("prsstart").toRight("Missing field 'prsstart'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val prstoken = jsonObj.get("prstoken").toRight("Missing field 'prstoken'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val prsend = jsonObj.get("prsend").toRight("Missing field 'prsend'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val prsheadline = jsonObj.get("prsheadline").toRight("Missing field 'prsheadline'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val prslextype = jsonObj.get("prslextype").toRight("Missing field 'prslextype'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (oid.isRight && prsname.isRight && prsnamespace.isRight && prsstart.isRight && prstoken.isRight && prsend.isRight && prsheadline.isRight && prslextype.isRight) + Right(PgTsParserRow(oid = oid.toOption.get, prsname = prsname.toOption.get, prsnamespace = prsnamespace.toOption.get, prsstart = prsstart.toOption.get, prstoken = prstoken.toOption.get, prsend = prsend.toOption.get, prsheadline = prsheadline.toOption.get, prslextype = prslextype.toOption.get)) + else Left(List[Either[String, Any]](oid, prsname, prsnamespace, prsstart, prstoken, prsend, prsheadline, prslextype).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsParserRow] = new JsonEncoder[PgTsParserRow] { + override def unsafeEncode(a: PgTsParserRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTsParserId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""prsname":""") + JsonEncoder.string.unsafeEncode(a.prsname, indent, out) + out.write(",") + out.write(""""prsnamespace":""") + JsonEncoder.long.unsafeEncode(a.prsnamespace, indent, out) + out.write(",") + out.write(""""prsstart":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prsstart, indent, out) + out.write(",") + out.write(""""prstoken":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prstoken, indent, out) + out.write(",") + out.write(""""prsend":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prsend, indent, out) + out.write(",") + out.write(""""prsheadline":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prsheadline, indent, out) + out.write(",") + out.write(""""prslextype":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.prslextype, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserStructure.scala new file mode 100644 index 0000000000..60857e7703 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_parser/PgTsParserStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_parser + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgTsParserStructure[Row](val prefix: Option[String], val extract: Row => PgTsParserRow, val merge: (Row, PgTsParserRow) => Row) + extends Relation[PgTsParserFields, PgTsParserRow, Row] + with PgTsParserFields[Row] { outer => + + override val oid = new IdField[PgTsParserId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val prsname = new Field[String, Row](prefix, "prsname", None, Some("name"))(x => extract(x).prsname, (row, value) => merge(row, extract(row).copy(prsname = value))) + override val prsnamespace = new Field[/* oid */ Long, Row](prefix, "prsnamespace", None, Some("oid"))(x => extract(x).prsnamespace, (row, value) => merge(row, extract(row).copy(prsnamespace = value))) + override val prsstart = new Field[TypoRegproc, Row](prefix, "prsstart", None, Some("regproc"))(x => extract(x).prsstart, (row, value) => merge(row, extract(row).copy(prsstart = value))) + override val prstoken = new Field[TypoRegproc, Row](prefix, "prstoken", None, Some("regproc"))(x => extract(x).prstoken, (row, value) => merge(row, extract(row).copy(prstoken = value))) + override val prsend = new Field[TypoRegproc, Row](prefix, "prsend", None, Some("regproc"))(x => extract(x).prsend, (row, value) => merge(row, extract(row).copy(prsend = value))) + override val prsheadline = new Field[TypoRegproc, Row](prefix, "prsheadline", None, Some("regproc"))(x => extract(x).prsheadline, (row, value) => merge(row, extract(row).copy(prsheadline = value))) + override val prslextype = new Field[TypoRegproc, Row](prefix, "prslextype", None, Some("regproc"))(x => extract(x).prslextype, (row, value) => merge(row, extract(row).copy(prslextype = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, prsname, prsnamespace, prsstart, prstoken, prsend, prsheadline, prslextype) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTsParserRow, merge: (NewRow, PgTsParserRow) => NewRow): PgTsParserStructure[NewRow] = + new PgTsParserStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateFields.scala new file mode 100644 index 0000000000..74e7ea606a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PgTsTemplateFields[Row] { + val oid: IdField[PgTsTemplateId, Row] + val tmplname: Field[String, Row] + val tmplnamespace: Field[/* oid */ Long, Row] + val tmplinit: Field[TypoRegproc, Row] + val tmpllexize: Field[TypoRegproc, Row] +} +object PgTsTemplateFields extends PgTsTemplateStructure[PgTsTemplateRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateId.scala new file mode 100644 index 0000000000..e9eb4d4535 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +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 `pg_catalog.pg_ts_template` */ +case class PgTsTemplateId(value: /* oid */ Long) extends AnyVal +object PgTsTemplateId { + implicit lazy val arraySetter: Setter[Array[PgTsTemplateId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTsTemplateId, /* oid */ Long] = Bijection[PgTsTemplateId, /* oid */ Long](_.value)(PgTsTemplateId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsTemplateId] = JdbcDecoder.longDecoder.map(PgTsTemplateId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTsTemplateId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTsTemplateId] = JsonDecoder.long.map(PgTsTemplateId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTsTemplateId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTsTemplateId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTsTemplateId] = ParameterMetaData.instance[PgTsTemplateId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTsTemplateId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepo.scala new file mode 100644 index 0000000000..4877ebb49e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTsTemplateRepo { + def delete(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTsTemplateFields, PgTsTemplateRow] + def insert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, PgTsTemplateRow] + def select: SelectBuilder[PgTsTemplateFields, PgTsTemplateRow] + def selectAll: ZStream[ZConnection, Throwable, PgTsTemplateRow] + def selectById(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] + def selectByIds(oids: Array[PgTsTemplateId]): ZStream[ZConnection, Throwable, PgTsTemplateRow] + def selectByUnique(tmplname: String, tmplnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] + def update(row: PgTsTemplateRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTsTemplateFields, PgTsTemplateRow] + def upsert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsTemplateRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoImpl.scala new file mode 100644 index 0000000000..e3c4ae6cf5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoImpl.scala @@ -0,0 +1,83 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTsTemplateRepoImpl extends PgTsTemplateRepo { + override def delete(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_ts_template where "oid" = ${Segment.paramSegment(oid)(PgTsTemplateId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + DeleteBuilder("pg_catalog.pg_ts_template", PgTsTemplateFields) + } + override def insert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, PgTsTemplateRow] = { + sql"""insert into pg_catalog.pg_ts_template("oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize") + values (${Segment.paramSegment(unsaved.oid)(PgTsTemplateId.setter)}::oid, ${Segment.paramSegment(unsaved.tmplname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.tmplnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.tmplinit)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.tmpllexize)(TypoRegproc.setter)}::regproc) + returning "oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize" + """.insertReturning(PgTsTemplateRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + SelectBuilderSql("pg_catalog.pg_ts_template", PgTsTemplateFields, PgTsTemplateRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsTemplateRow] = { + sql"""select "oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize" from pg_catalog.pg_ts_template""".query(PgTsTemplateRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] = { + sql"""select "oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize" from pg_catalog.pg_ts_template where "oid" = ${Segment.paramSegment(oid)(PgTsTemplateId.setter)}""".query(PgTsTemplateRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTsTemplateId]): ZStream[ZConnection, Throwable, PgTsTemplateRow] = { + sql"""select "oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize" from pg_catalog.pg_ts_template where "oid" = ANY(${Segment.paramSegment(oids)(PgTsTemplateId.arraySetter)})""".query(PgTsTemplateRow.jdbcDecoder).selectStream + } + override def selectByUnique(tmplname: String, tmplnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] = { + sql"""select "tmplname", "tmplnamespace" + from pg_catalog.pg_ts_template + where "tmplname" = ${Segment.paramSegment(tmplname)(Setter.stringSetter)} AND "tmplnamespace" = ${Segment.paramSegment(tmplnamespace)(Setter.longSetter)} + """.query(PgTsTemplateRow.jdbcDecoder).selectOne + } + override def update(row: PgTsTemplateRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_ts_template + set "tmplname" = ${Segment.paramSegment(row.tmplname)(Setter.stringSetter)}::name, + "tmplnamespace" = ${Segment.paramSegment(row.tmplnamespace)(Setter.longSetter)}::oid, + "tmplinit" = ${Segment.paramSegment(row.tmplinit)(TypoRegproc.setter)}::regproc, + "tmpllexize" = ${Segment.paramSegment(row.tmpllexize)(TypoRegproc.setter)}::regproc + where "oid" = ${Segment.paramSegment(oid)(PgTsTemplateId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + UpdateBuilder("pg_catalog.pg_ts_template", PgTsTemplateFields, PgTsTemplateRow.jdbcDecoder) + } + override def upsert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsTemplateRow]] = { + sql"""insert into pg_catalog.pg_ts_template("oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTsTemplateId.setter)}::oid, + ${Segment.paramSegment(unsaved.tmplname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.tmplnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.tmplinit)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.tmpllexize)(TypoRegproc.setter)}::regproc + ) + on conflict ("oid") + do update set + "tmplname" = EXCLUDED."tmplname", + "tmplnamespace" = EXCLUDED."tmplnamespace", + "tmplinit" = EXCLUDED."tmplinit", + "tmpllexize" = EXCLUDED."tmpllexize" + returning "oid", "tmplname", "tmplnamespace", "tmplinit", "tmpllexize"""".insertReturning(PgTsTemplateRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoMock.scala new file mode 100644 index 0000000000..25c38e0ad2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTsTemplateRepoMock(map: scala.collection.mutable.Map[PgTsTemplateId, PgTsTemplateRow] = scala.collection.mutable.Map.empty) extends PgTsTemplateRepo { + override def delete(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTsTemplateFields, map) + } + override def insert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, PgTsTemplateRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + SelectBuilderMock(PgTsTemplateFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTsTemplateRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTsTemplateId): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTsTemplateId]): ZStream[ZConnection, Throwable, PgTsTemplateRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(tmplname: String, tmplnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTsTemplateRow]] = { + ZIO.succeed(map.values.find(v => tmplname == v.tmplname && tmplnamespace == v.tmplnamespace)) + } + override def update(row: PgTsTemplateRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTsTemplateFields, PgTsTemplateRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTsTemplateFields, map) + } + override def upsert(unsaved: PgTsTemplateRow): ZIO[ZConnection, Throwable, UpdateResult[PgTsTemplateRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRow.scala new file mode 100644 index 0000000000..f6341ec75a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import adventureworks.customtypes.TypoRegproc +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTsTemplateRow( + oid: PgTsTemplateId, + tmplname: String, + tmplnamespace: /* oid */ Long, + tmplinit: TypoRegproc, + tmpllexize: TypoRegproc +) + +object PgTsTemplateRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTsTemplateRow] = new JdbcDecoder[PgTsTemplateRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTsTemplateRow) = + columIndex + 4 -> + PgTsTemplateRow( + oid = PgTsTemplateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + tmplname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + tmplnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + tmplinit = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + tmpllexize = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTsTemplateRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTsTemplateId.jsonDecoder)) + val tmplname = jsonObj.get("tmplname").toRight("Missing field 'tmplname'").flatMap(_.as(JsonDecoder.string)) + val tmplnamespace = jsonObj.get("tmplnamespace").toRight("Missing field 'tmplnamespace'").flatMap(_.as(JsonDecoder.long)) + val tmplinit = jsonObj.get("tmplinit").toRight("Missing field 'tmplinit'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val tmpllexize = jsonObj.get("tmpllexize").toRight("Missing field 'tmpllexize'").flatMap(_.as(TypoRegproc.jsonDecoder)) + if (oid.isRight && tmplname.isRight && tmplnamespace.isRight && tmplinit.isRight && tmpllexize.isRight) + Right(PgTsTemplateRow(oid = oid.toOption.get, tmplname = tmplname.toOption.get, tmplnamespace = tmplnamespace.toOption.get, tmplinit = tmplinit.toOption.get, tmpllexize = tmpllexize.toOption.get)) + else Left(List[Either[String, Any]](oid, tmplname, tmplnamespace, tmplinit, tmpllexize).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTsTemplateRow] = new JsonEncoder[PgTsTemplateRow] { + override def unsafeEncode(a: PgTsTemplateRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTsTemplateId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""tmplname":""") + JsonEncoder.string.unsafeEncode(a.tmplname, indent, out) + out.write(",") + out.write(""""tmplnamespace":""") + JsonEncoder.long.unsafeEncode(a.tmplnamespace, indent, out) + out.write(",") + out.write(""""tmplinit":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.tmplinit, indent, out) + out.write(",") + out.write(""""tmpllexize":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.tmpllexize, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateStructure.scala new file mode 100644 index 0000000000..23a4bbb848 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_ts_template/PgTsTemplateStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_ts_template + +import adventureworks.customtypes.TypoRegproc +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PgTsTemplateStructure[Row](val prefix: Option[String], val extract: Row => PgTsTemplateRow, val merge: (Row, PgTsTemplateRow) => Row) + extends Relation[PgTsTemplateFields, PgTsTemplateRow, Row] + with PgTsTemplateFields[Row] { outer => + + override val oid = new IdField[PgTsTemplateId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val tmplname = new Field[String, Row](prefix, "tmplname", None, Some("name"))(x => extract(x).tmplname, (row, value) => merge(row, extract(row).copy(tmplname = value))) + override val tmplnamespace = new Field[/* oid */ Long, Row](prefix, "tmplnamespace", None, Some("oid"))(x => extract(x).tmplnamespace, (row, value) => merge(row, extract(row).copy(tmplnamespace = value))) + override val tmplinit = new Field[TypoRegproc, Row](prefix, "tmplinit", None, Some("regproc"))(x => extract(x).tmplinit, (row, value) => merge(row, extract(row).copy(tmplinit = value))) + override val tmpllexize = new Field[TypoRegproc, Row](prefix, "tmpllexize", None, Some("regproc"))(x => extract(x).tmpllexize, (row, value) => merge(row, extract(row).copy(tmpllexize = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, tmplname, tmplnamespace, tmplinit, tmpllexize) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTsTemplateRow, merge: (NewRow, PgTsTemplateRow) => NewRow): PgTsTemplateStructure[NewRow] = + new PgTsTemplateStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeFields.scala new file mode 100644 index 0000000000..25c9ad322c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeFields.scala @@ -0,0 +1,53 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgTypeFields[Row] { + val oid: IdField[PgTypeId, Row] + val typname: Field[String, Row] + val typnamespace: Field[/* oid */ Long, Row] + val typowner: Field[/* oid */ Long, Row] + val typlen: Field[TypoShort, Row] + val typbyval: Field[Boolean, Row] + val typtype: Field[String, Row] + val typcategory: Field[String, Row] + val typispreferred: Field[Boolean, Row] + val typisdefined: Field[Boolean, Row] + val typdelim: Field[String, Row] + val typrelid: Field[/* oid */ Long, Row] + val typsubscript: Field[TypoRegproc, Row] + val typelem: Field[/* oid */ Long, Row] + val typarray: Field[/* oid */ Long, Row] + val typinput: Field[TypoRegproc, Row] + val typoutput: Field[TypoRegproc, Row] + val typreceive: Field[TypoRegproc, Row] + val typsend: Field[TypoRegproc, Row] + val typmodin: Field[TypoRegproc, Row] + val typmodout: Field[TypoRegproc, Row] + val typanalyze: Field[TypoRegproc, Row] + val typalign: Field[String, Row] + val typstorage: Field[String, Row] + val typnotnull: Field[Boolean, Row] + val typbasetype: Field[/* oid */ Long, Row] + val typtypmod: Field[Int, Row] + val typndims: Field[Int, Row] + val typcollation: Field[/* oid */ Long, Row] + val typdefaultbin: OptField[TypoPgNodeTree, Row] + val typdefault: OptField[String, Row] + val typacl: OptField[Array[TypoAclItem], Row] +} +object PgTypeFields extends PgTypeStructure[PgTypeRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeId.scala new file mode 100644 index 0000000000..289e2a7222 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +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 `pg_catalog.pg_type` */ +case class PgTypeId(value: /* oid */ Long) extends AnyVal +object PgTypeId { + implicit lazy val arraySetter: Setter[Array[PgTypeId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgTypeId, /* oid */ Long] = Bijection[PgTypeId, /* oid */ Long](_.value)(PgTypeId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgTypeId] = JdbcDecoder.longDecoder.map(PgTypeId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgTypeId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgTypeId] = JsonDecoder.long.map(PgTypeId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgTypeId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgTypeId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgTypeId] = ParameterMetaData.instance[PgTypeId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgTypeId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepo.scala new file mode 100644 index 0000000000..2d5ac8bc2b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgTypeRepo { + def delete(oid: PgTypeId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgTypeFields, PgTypeRow] + def insert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, PgTypeRow] + def select: SelectBuilder[PgTypeFields, PgTypeRow] + def selectAll: ZStream[ZConnection, Throwable, PgTypeRow] + def selectById(oid: PgTypeId): ZIO[ZConnection, Throwable, Option[PgTypeRow]] + def selectByIds(oids: Array[PgTypeId]): ZStream[ZConnection, Throwable, PgTypeRow] + def selectByUnique(typname: String, typnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTypeRow]] + def update(row: PgTypeRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgTypeFields, PgTypeRow] + def upsert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, UpdateResult[PgTypeRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoImpl.scala new file mode 100644 index 0000000000..9542ca4a95 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoImpl.scala @@ -0,0 +1,167 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgTypeRepoImpl extends PgTypeRepo { + override def delete(oid: PgTypeId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_type where "oid" = ${Segment.paramSegment(oid)(PgTypeId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgTypeFields, PgTypeRow] = { + DeleteBuilder("pg_catalog.pg_type", PgTypeFields) + } + override def insert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, PgTypeRow] = { + sql"""insert into pg_catalog.pg_type("oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl") + values (${Segment.paramSegment(unsaved.oid)(PgTypeId.setter)}::oid, ${Segment.paramSegment(unsaved.typname)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.typnamespace)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typowner)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typlen)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.typbyval)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.typtype)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.typcategory)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.typispreferred)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.typisdefined)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.typdelim)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.typrelid)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typsubscript)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typelem)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typarray)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typinput)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typoutput)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typreceive)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typsend)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typmodin)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typmodout)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typanalyze)(TypoRegproc.setter)}::regproc, ${Segment.paramSegment(unsaved.typalign)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.typstorage)(Setter.stringSetter)}::char, ${Segment.paramSegment(unsaved.typnotnull)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.typbasetype)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typtypmod)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.typndims)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.typcollation)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.typdefaultbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, ${Segment.paramSegment(unsaved.typdefault)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.typacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem) + returning "oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl" + """.insertReturning(PgTypeRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgTypeFields, PgTypeRow] = { + SelectBuilderSql("pg_catalog.pg_type", PgTypeFields, PgTypeRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTypeRow] = { + sql"""select "oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl" from pg_catalog.pg_type""".query(PgTypeRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgTypeId): ZIO[ZConnection, Throwable, Option[PgTypeRow]] = { + sql"""select "oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl" from pg_catalog.pg_type where "oid" = ${Segment.paramSegment(oid)(PgTypeId.setter)}""".query(PgTypeRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgTypeId]): ZStream[ZConnection, Throwable, PgTypeRow] = { + sql"""select "oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl" from pg_catalog.pg_type where "oid" = ANY(${Segment.paramSegment(oids)(PgTypeId.arraySetter)})""".query(PgTypeRow.jdbcDecoder).selectStream + } + override def selectByUnique(typname: String, typnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTypeRow]] = { + sql"""select "typname", "typnamespace" + from pg_catalog.pg_type + where "typname" = ${Segment.paramSegment(typname)(Setter.stringSetter)} AND "typnamespace" = ${Segment.paramSegment(typnamespace)(Setter.longSetter)} + """.query(PgTypeRow.jdbcDecoder).selectOne + } + override def update(row: PgTypeRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_type + set "typname" = ${Segment.paramSegment(row.typname)(Setter.stringSetter)}::name, + "typnamespace" = ${Segment.paramSegment(row.typnamespace)(Setter.longSetter)}::oid, + "typowner" = ${Segment.paramSegment(row.typowner)(Setter.longSetter)}::oid, + "typlen" = ${Segment.paramSegment(row.typlen)(TypoShort.setter)}::int2, + "typbyval" = ${Segment.paramSegment(row.typbyval)(Setter.booleanSetter)}, + "typtype" = ${Segment.paramSegment(row.typtype)(Setter.stringSetter)}::char, + "typcategory" = ${Segment.paramSegment(row.typcategory)(Setter.stringSetter)}::char, + "typispreferred" = ${Segment.paramSegment(row.typispreferred)(Setter.booleanSetter)}, + "typisdefined" = ${Segment.paramSegment(row.typisdefined)(Setter.booleanSetter)}, + "typdelim" = ${Segment.paramSegment(row.typdelim)(Setter.stringSetter)}::char, + "typrelid" = ${Segment.paramSegment(row.typrelid)(Setter.longSetter)}::oid, + "typsubscript" = ${Segment.paramSegment(row.typsubscript)(TypoRegproc.setter)}::regproc, + "typelem" = ${Segment.paramSegment(row.typelem)(Setter.longSetter)}::oid, + "typarray" = ${Segment.paramSegment(row.typarray)(Setter.longSetter)}::oid, + "typinput" = ${Segment.paramSegment(row.typinput)(TypoRegproc.setter)}::regproc, + "typoutput" = ${Segment.paramSegment(row.typoutput)(TypoRegproc.setter)}::regproc, + "typreceive" = ${Segment.paramSegment(row.typreceive)(TypoRegproc.setter)}::regproc, + "typsend" = ${Segment.paramSegment(row.typsend)(TypoRegproc.setter)}::regproc, + "typmodin" = ${Segment.paramSegment(row.typmodin)(TypoRegproc.setter)}::regproc, + "typmodout" = ${Segment.paramSegment(row.typmodout)(TypoRegproc.setter)}::regproc, + "typanalyze" = ${Segment.paramSegment(row.typanalyze)(TypoRegproc.setter)}::regproc, + "typalign" = ${Segment.paramSegment(row.typalign)(Setter.stringSetter)}::char, + "typstorage" = ${Segment.paramSegment(row.typstorage)(Setter.stringSetter)}::char, + "typnotnull" = ${Segment.paramSegment(row.typnotnull)(Setter.booleanSetter)}, + "typbasetype" = ${Segment.paramSegment(row.typbasetype)(Setter.longSetter)}::oid, + "typtypmod" = ${Segment.paramSegment(row.typtypmod)(Setter.intSetter)}::int4, + "typndims" = ${Segment.paramSegment(row.typndims)(Setter.intSetter)}::int4, + "typcollation" = ${Segment.paramSegment(row.typcollation)(Setter.longSetter)}::oid, + "typdefaultbin" = ${Segment.paramSegment(row.typdefaultbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + "typdefault" = ${Segment.paramSegment(row.typdefault)(Setter.optionParamSetter(Setter.stringSetter))}, + "typacl" = ${Segment.paramSegment(row.typacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + where "oid" = ${Segment.paramSegment(oid)(PgTypeId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgTypeFields, PgTypeRow] = { + UpdateBuilder("pg_catalog.pg_type", PgTypeFields, PgTypeRow.jdbcDecoder) + } + override def upsert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, UpdateResult[PgTypeRow]] = { + sql"""insert into pg_catalog.pg_type("oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl") + values ( + ${Segment.paramSegment(unsaved.oid)(PgTypeId.setter)}::oid, + ${Segment.paramSegment(unsaved.typname)(Setter.stringSetter)}::name, + ${Segment.paramSegment(unsaved.typnamespace)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typowner)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typlen)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.typbyval)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.typtype)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.typcategory)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.typispreferred)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.typisdefined)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.typdelim)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.typrelid)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typsubscript)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typelem)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typarray)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typinput)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typoutput)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typreceive)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typsend)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typmodin)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typmodout)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typanalyze)(TypoRegproc.setter)}::regproc, + ${Segment.paramSegment(unsaved.typalign)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.typstorage)(Setter.stringSetter)}::char, + ${Segment.paramSegment(unsaved.typnotnull)(Setter.booleanSetter)}, + ${Segment.paramSegment(unsaved.typbasetype)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typtypmod)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.typndims)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.typcollation)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.typdefaultbin)(Setter.optionParamSetter(TypoPgNodeTree.setter))}::pg_node_tree, + ${Segment.paramSegment(unsaved.typdefault)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.typacl)(Setter.optionParamSetter(TypoAclItem.arraySetter))}::_aclitem + ) + on conflict ("oid") + do update set + "typname" = EXCLUDED."typname", + "typnamespace" = EXCLUDED."typnamespace", + "typowner" = EXCLUDED."typowner", + "typlen" = EXCLUDED."typlen", + "typbyval" = EXCLUDED."typbyval", + "typtype" = EXCLUDED."typtype", + "typcategory" = EXCLUDED."typcategory", + "typispreferred" = EXCLUDED."typispreferred", + "typisdefined" = EXCLUDED."typisdefined", + "typdelim" = EXCLUDED."typdelim", + "typrelid" = EXCLUDED."typrelid", + "typsubscript" = EXCLUDED."typsubscript", + "typelem" = EXCLUDED."typelem", + "typarray" = EXCLUDED."typarray", + "typinput" = EXCLUDED."typinput", + "typoutput" = EXCLUDED."typoutput", + "typreceive" = EXCLUDED."typreceive", + "typsend" = EXCLUDED."typsend", + "typmodin" = EXCLUDED."typmodin", + "typmodout" = EXCLUDED."typmodout", + "typanalyze" = EXCLUDED."typanalyze", + "typalign" = EXCLUDED."typalign", + "typstorage" = EXCLUDED."typstorage", + "typnotnull" = EXCLUDED."typnotnull", + "typbasetype" = EXCLUDED."typbasetype", + "typtypmod" = EXCLUDED."typtypmod", + "typndims" = EXCLUDED."typndims", + "typcollation" = EXCLUDED."typcollation", + "typdefaultbin" = EXCLUDED."typdefaultbin", + "typdefault" = EXCLUDED."typdefault", + "typacl" = EXCLUDED."typacl" + returning "oid", "typname", "typnamespace", "typowner", "typlen", "typbyval", "typtype", "typcategory", "typispreferred", "typisdefined", "typdelim", "typrelid", "typsubscript", "typelem", "typarray", "typinput", "typoutput", "typreceive", "typsend", "typmodin", "typmodout", "typanalyze", "typalign", "typstorage", "typnotnull", "typbasetype", "typtypmod", "typndims", "typcollation", "typdefaultbin", "typdefault", "typacl"""".insertReturning(PgTypeRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoMock.scala new file mode 100644 index 0000000000..7e5eae8cc9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgTypeRepoMock(map: scala.collection.mutable.Map[PgTypeId, PgTypeRow] = scala.collection.mutable.Map.empty) extends PgTypeRepo { + override def delete(oid: PgTypeId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgTypeFields, PgTypeRow] = { + DeleteBuilderMock(DeleteParams.empty, PgTypeFields, map) + } + override def insert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, PgTypeRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgTypeFields, PgTypeRow] = { + SelectBuilderMock(PgTypeFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgTypeRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgTypeId): ZIO[ZConnection, Throwable, Option[PgTypeRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgTypeId]): ZStream[ZConnection, Throwable, PgTypeRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(typname: String, typnamespace: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgTypeRow]] = { + ZIO.succeed(map.values.find(v => typname == v.typname && typnamespace == v.typnamespace)) + } + override def update(row: PgTypeRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgTypeFields, PgTypeRow] = { + UpdateBuilderMock(UpdateParams.empty, PgTypeFields, map) + } + override def upsert(unsaved: PgTypeRow): ZIO[ZConnection, Throwable, UpdateResult[PgTypeRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRow.scala new file mode 100644 index 0000000000..63f5e5f84b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeRow.scala @@ -0,0 +1,233 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgTypeRow( + oid: PgTypeId, + typname: String, + typnamespace: /* oid */ Long, + typowner: /* oid */ Long, + typlen: TypoShort, + typbyval: Boolean, + typtype: String, + typcategory: String, + typispreferred: Boolean, + typisdefined: Boolean, + typdelim: String, + typrelid: /* oid */ Long, + typsubscript: TypoRegproc, + typelem: /* oid */ Long, + typarray: /* oid */ Long, + typinput: TypoRegproc, + typoutput: TypoRegproc, + typreceive: TypoRegproc, + typsend: TypoRegproc, + typmodin: TypoRegproc, + typmodout: TypoRegproc, + typanalyze: TypoRegproc, + typalign: String, + typstorage: String, + typnotnull: Boolean, + typbasetype: /* oid */ Long, + typtypmod: Int, + typndims: Int, + typcollation: /* oid */ Long, + typdefaultbin: Option[TypoPgNodeTree], + typdefault: Option[String], + typacl: Option[Array[TypoAclItem]] +) + +object PgTypeRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgTypeRow] = new JdbcDecoder[PgTypeRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgTypeRow) = + columIndex + 31 -> + PgTypeRow( + oid = PgTypeId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + typname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + typnamespace = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + typowner = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + typlen = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + typbyval = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 5, rs)._2, + typtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + typcategory = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + typispreferred = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 8, rs)._2, + typisdefined = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 9, rs)._2, + typdelim = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 10, rs)._2, + typrelid = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 11, rs)._2, + typsubscript = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + typelem = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 13, rs)._2, + typarray = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 14, rs)._2, + typinput = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + typoutput = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + typreceive = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 17, rs)._2, + typsend = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 18, rs)._2, + typmodin = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 19, rs)._2, + typmodout = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 20, rs)._2, + typanalyze = TypoRegproc.jdbcDecoder.unsafeDecode(columIndex + 21, rs)._2, + typalign = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 22, rs)._2, + typstorage = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 23, rs)._2, + typnotnull = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 24, rs)._2, + typbasetype = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 25, rs)._2, + typtypmod = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 26, rs)._2, + typndims = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 27, rs)._2, + typcollation = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 28, rs)._2, + typdefaultbin = JdbcDecoder.optionDecoder(TypoPgNodeTree.jdbcDecoder).unsafeDecode(columIndex + 29, rs)._2, + typdefault = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 30, rs)._2, + typacl = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoAclItem]]).unsafeDecode(columIndex + 31, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgTypeRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgTypeId.jsonDecoder)) + val typname = jsonObj.get("typname").toRight("Missing field 'typname'").flatMap(_.as(JsonDecoder.string)) + val typnamespace = jsonObj.get("typnamespace").toRight("Missing field 'typnamespace'").flatMap(_.as(JsonDecoder.long)) + val typowner = jsonObj.get("typowner").toRight("Missing field 'typowner'").flatMap(_.as(JsonDecoder.long)) + val typlen = jsonObj.get("typlen").toRight("Missing field 'typlen'").flatMap(_.as(TypoShort.jsonDecoder)) + val typbyval = jsonObj.get("typbyval").toRight("Missing field 'typbyval'").flatMap(_.as(JsonDecoder.boolean)) + val typtype = jsonObj.get("typtype").toRight("Missing field 'typtype'").flatMap(_.as(JsonDecoder.string)) + val typcategory = jsonObj.get("typcategory").toRight("Missing field 'typcategory'").flatMap(_.as(JsonDecoder.string)) + val typispreferred = jsonObj.get("typispreferred").toRight("Missing field 'typispreferred'").flatMap(_.as(JsonDecoder.boolean)) + val typisdefined = jsonObj.get("typisdefined").toRight("Missing field 'typisdefined'").flatMap(_.as(JsonDecoder.boolean)) + val typdelim = jsonObj.get("typdelim").toRight("Missing field 'typdelim'").flatMap(_.as(JsonDecoder.string)) + val typrelid = jsonObj.get("typrelid").toRight("Missing field 'typrelid'").flatMap(_.as(JsonDecoder.long)) + val typsubscript = jsonObj.get("typsubscript").toRight("Missing field 'typsubscript'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typelem = jsonObj.get("typelem").toRight("Missing field 'typelem'").flatMap(_.as(JsonDecoder.long)) + val typarray = jsonObj.get("typarray").toRight("Missing field 'typarray'").flatMap(_.as(JsonDecoder.long)) + val typinput = jsonObj.get("typinput").toRight("Missing field 'typinput'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typoutput = jsonObj.get("typoutput").toRight("Missing field 'typoutput'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typreceive = jsonObj.get("typreceive").toRight("Missing field 'typreceive'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typsend = jsonObj.get("typsend").toRight("Missing field 'typsend'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typmodin = jsonObj.get("typmodin").toRight("Missing field 'typmodin'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typmodout = jsonObj.get("typmodout").toRight("Missing field 'typmodout'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typanalyze = jsonObj.get("typanalyze").toRight("Missing field 'typanalyze'").flatMap(_.as(TypoRegproc.jsonDecoder)) + val typalign = jsonObj.get("typalign").toRight("Missing field 'typalign'").flatMap(_.as(JsonDecoder.string)) + val typstorage = jsonObj.get("typstorage").toRight("Missing field 'typstorage'").flatMap(_.as(JsonDecoder.string)) + val typnotnull = jsonObj.get("typnotnull").toRight("Missing field 'typnotnull'").flatMap(_.as(JsonDecoder.boolean)) + val typbasetype = jsonObj.get("typbasetype").toRight("Missing field 'typbasetype'").flatMap(_.as(JsonDecoder.long)) + val typtypmod = jsonObj.get("typtypmod").toRight("Missing field 'typtypmod'").flatMap(_.as(JsonDecoder.int)) + val typndims = jsonObj.get("typndims").toRight("Missing field 'typndims'").flatMap(_.as(JsonDecoder.int)) + val typcollation = jsonObj.get("typcollation").toRight("Missing field 'typcollation'").flatMap(_.as(JsonDecoder.long)) + val typdefaultbin = jsonObj.get("typdefaultbin").fold[Either[String, Option[TypoPgNodeTree]]](Right(None))(_.as(JsonDecoder.option(TypoPgNodeTree.jsonDecoder))) + val typdefault = jsonObj.get("typdefault").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val typacl = jsonObj.get("typacl").fold[Either[String, Option[Array[TypoAclItem]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoAclItem](TypoAclItem.jsonDecoder, implicitly)))) + if (oid.isRight && typname.isRight && typnamespace.isRight && typowner.isRight && typlen.isRight && typbyval.isRight && typtype.isRight && typcategory.isRight && typispreferred.isRight && typisdefined.isRight && typdelim.isRight && typrelid.isRight && typsubscript.isRight && typelem.isRight && typarray.isRight && typinput.isRight && typoutput.isRight && typreceive.isRight && typsend.isRight && typmodin.isRight && typmodout.isRight && typanalyze.isRight && typalign.isRight && typstorage.isRight && typnotnull.isRight && typbasetype.isRight && typtypmod.isRight && typndims.isRight && typcollation.isRight && typdefaultbin.isRight && typdefault.isRight && typacl.isRight) + Right(PgTypeRow(oid = oid.toOption.get, typname = typname.toOption.get, typnamespace = typnamespace.toOption.get, typowner = typowner.toOption.get, typlen = typlen.toOption.get, typbyval = typbyval.toOption.get, typtype = typtype.toOption.get, typcategory = typcategory.toOption.get, typispreferred = typispreferred.toOption.get, typisdefined = typisdefined.toOption.get, typdelim = typdelim.toOption.get, typrelid = typrelid.toOption.get, typsubscript = typsubscript.toOption.get, typelem = typelem.toOption.get, typarray = typarray.toOption.get, typinput = typinput.toOption.get, typoutput = typoutput.toOption.get, typreceive = typreceive.toOption.get, typsend = typsend.toOption.get, typmodin = typmodin.toOption.get, typmodout = typmodout.toOption.get, typanalyze = typanalyze.toOption.get, typalign = typalign.toOption.get, typstorage = typstorage.toOption.get, typnotnull = typnotnull.toOption.get, typbasetype = typbasetype.toOption.get, typtypmod = typtypmod.toOption.get, typndims = typndims.toOption.get, typcollation = typcollation.toOption.get, typdefaultbin = typdefaultbin.toOption.get, typdefault = typdefault.toOption.get, typacl = typacl.toOption.get)) + else Left(List[Either[String, Any]](oid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typsubscript, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgTypeRow] = new JsonEncoder[PgTypeRow] { + override def unsafeEncode(a: PgTypeRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgTypeId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""typname":""") + JsonEncoder.string.unsafeEncode(a.typname, indent, out) + out.write(",") + out.write(""""typnamespace":""") + JsonEncoder.long.unsafeEncode(a.typnamespace, indent, out) + out.write(",") + out.write(""""typowner":""") + JsonEncoder.long.unsafeEncode(a.typowner, indent, out) + out.write(",") + out.write(""""typlen":""") + TypoShort.jsonEncoder.unsafeEncode(a.typlen, indent, out) + out.write(",") + out.write(""""typbyval":""") + JsonEncoder.boolean.unsafeEncode(a.typbyval, indent, out) + out.write(",") + out.write(""""typtype":""") + JsonEncoder.string.unsafeEncode(a.typtype, indent, out) + out.write(",") + out.write(""""typcategory":""") + JsonEncoder.string.unsafeEncode(a.typcategory, indent, out) + out.write(",") + out.write(""""typispreferred":""") + JsonEncoder.boolean.unsafeEncode(a.typispreferred, indent, out) + out.write(",") + out.write(""""typisdefined":""") + JsonEncoder.boolean.unsafeEncode(a.typisdefined, indent, out) + out.write(",") + out.write(""""typdelim":""") + JsonEncoder.string.unsafeEncode(a.typdelim, indent, out) + out.write(",") + out.write(""""typrelid":""") + JsonEncoder.long.unsafeEncode(a.typrelid, indent, out) + out.write(",") + out.write(""""typsubscript":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typsubscript, indent, out) + out.write(",") + out.write(""""typelem":""") + JsonEncoder.long.unsafeEncode(a.typelem, indent, out) + out.write(",") + out.write(""""typarray":""") + JsonEncoder.long.unsafeEncode(a.typarray, indent, out) + out.write(",") + out.write(""""typinput":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typinput, indent, out) + out.write(",") + out.write(""""typoutput":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typoutput, indent, out) + out.write(",") + out.write(""""typreceive":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typreceive, indent, out) + out.write(",") + out.write(""""typsend":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typsend, indent, out) + out.write(",") + out.write(""""typmodin":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typmodin, indent, out) + out.write(",") + out.write(""""typmodout":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typmodout, indent, out) + out.write(",") + out.write(""""typanalyze":""") + TypoRegproc.jsonEncoder.unsafeEncode(a.typanalyze, indent, out) + out.write(",") + out.write(""""typalign":""") + JsonEncoder.string.unsafeEncode(a.typalign, indent, out) + out.write(",") + out.write(""""typstorage":""") + JsonEncoder.string.unsafeEncode(a.typstorage, indent, out) + out.write(",") + out.write(""""typnotnull":""") + JsonEncoder.boolean.unsafeEncode(a.typnotnull, indent, out) + out.write(",") + out.write(""""typbasetype":""") + JsonEncoder.long.unsafeEncode(a.typbasetype, indent, out) + out.write(",") + out.write(""""typtypmod":""") + JsonEncoder.int.unsafeEncode(a.typtypmod, indent, out) + out.write(",") + out.write(""""typndims":""") + JsonEncoder.int.unsafeEncode(a.typndims, indent, out) + out.write(",") + out.write(""""typcollation":""") + JsonEncoder.long.unsafeEncode(a.typcollation, indent, out) + out.write(",") + out.write(""""typdefaultbin":""") + JsonEncoder.option(TypoPgNodeTree.jsonEncoder).unsafeEncode(a.typdefaultbin, indent, out) + out.write(",") + out.write(""""typdefault":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.typdefault, indent, out) + out.write(",") + out.write(""""typacl":""") + JsonEncoder.option(JsonEncoder.array[TypoAclItem](TypoAclItem.jsonEncoder, implicitly)).unsafeEncode(a.typacl, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeStructure.scala new file mode 100644 index 0000000000..68b4526909 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_type/PgTypeStructure.scala @@ -0,0 +1,62 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_type + +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgTypeStructure[Row](val prefix: Option[String], val extract: Row => PgTypeRow, val merge: (Row, PgTypeRow) => Row) + extends Relation[PgTypeFields, PgTypeRow, Row] + with PgTypeFields[Row] { outer => + + override val oid = new IdField[PgTypeId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val typname = new Field[String, Row](prefix, "typname", None, Some("name"))(x => extract(x).typname, (row, value) => merge(row, extract(row).copy(typname = value))) + override val typnamespace = new Field[/* oid */ Long, Row](prefix, "typnamespace", None, Some("oid"))(x => extract(x).typnamespace, (row, value) => merge(row, extract(row).copy(typnamespace = value))) + override val typowner = new Field[/* oid */ Long, Row](prefix, "typowner", None, Some("oid"))(x => extract(x).typowner, (row, value) => merge(row, extract(row).copy(typowner = value))) + override val typlen = new Field[TypoShort, Row](prefix, "typlen", None, Some("int2"))(x => extract(x).typlen, (row, value) => merge(row, extract(row).copy(typlen = value))) + override val typbyval = new Field[Boolean, Row](prefix, "typbyval", None, None)(x => extract(x).typbyval, (row, value) => merge(row, extract(row).copy(typbyval = value))) + override val typtype = new Field[String, Row](prefix, "typtype", None, Some("char"))(x => extract(x).typtype, (row, value) => merge(row, extract(row).copy(typtype = value))) + override val typcategory = new Field[String, Row](prefix, "typcategory", None, Some("char"))(x => extract(x).typcategory, (row, value) => merge(row, extract(row).copy(typcategory = value))) + override val typispreferred = new Field[Boolean, Row](prefix, "typispreferred", None, None)(x => extract(x).typispreferred, (row, value) => merge(row, extract(row).copy(typispreferred = value))) + override val typisdefined = new Field[Boolean, Row](prefix, "typisdefined", None, None)(x => extract(x).typisdefined, (row, value) => merge(row, extract(row).copy(typisdefined = value))) + override val typdelim = new Field[String, Row](prefix, "typdelim", None, Some("char"))(x => extract(x).typdelim, (row, value) => merge(row, extract(row).copy(typdelim = value))) + override val typrelid = new Field[/* oid */ Long, Row](prefix, "typrelid", None, Some("oid"))(x => extract(x).typrelid, (row, value) => merge(row, extract(row).copy(typrelid = value))) + override val typsubscript = new Field[TypoRegproc, Row](prefix, "typsubscript", None, Some("regproc"))(x => extract(x).typsubscript, (row, value) => merge(row, extract(row).copy(typsubscript = value))) + override val typelem = new Field[/* oid */ Long, Row](prefix, "typelem", None, Some("oid"))(x => extract(x).typelem, (row, value) => merge(row, extract(row).copy(typelem = value))) + override val typarray = new Field[/* oid */ Long, Row](prefix, "typarray", None, Some("oid"))(x => extract(x).typarray, (row, value) => merge(row, extract(row).copy(typarray = value))) + override val typinput = new Field[TypoRegproc, Row](prefix, "typinput", None, Some("regproc"))(x => extract(x).typinput, (row, value) => merge(row, extract(row).copy(typinput = value))) + override val typoutput = new Field[TypoRegproc, Row](prefix, "typoutput", None, Some("regproc"))(x => extract(x).typoutput, (row, value) => merge(row, extract(row).copy(typoutput = value))) + override val typreceive = new Field[TypoRegproc, Row](prefix, "typreceive", None, Some("regproc"))(x => extract(x).typreceive, (row, value) => merge(row, extract(row).copy(typreceive = value))) + override val typsend = new Field[TypoRegproc, Row](prefix, "typsend", None, Some("regproc"))(x => extract(x).typsend, (row, value) => merge(row, extract(row).copy(typsend = value))) + override val typmodin = new Field[TypoRegproc, Row](prefix, "typmodin", None, Some("regproc"))(x => extract(x).typmodin, (row, value) => merge(row, extract(row).copy(typmodin = value))) + override val typmodout = new Field[TypoRegproc, Row](prefix, "typmodout", None, Some("regproc"))(x => extract(x).typmodout, (row, value) => merge(row, extract(row).copy(typmodout = value))) + override val typanalyze = new Field[TypoRegproc, Row](prefix, "typanalyze", None, Some("regproc"))(x => extract(x).typanalyze, (row, value) => merge(row, extract(row).copy(typanalyze = value))) + override val typalign = new Field[String, Row](prefix, "typalign", None, Some("char"))(x => extract(x).typalign, (row, value) => merge(row, extract(row).copy(typalign = value))) + override val typstorage = new Field[String, Row](prefix, "typstorage", None, Some("char"))(x => extract(x).typstorage, (row, value) => merge(row, extract(row).copy(typstorage = value))) + override val typnotnull = new Field[Boolean, Row](prefix, "typnotnull", None, None)(x => extract(x).typnotnull, (row, value) => merge(row, extract(row).copy(typnotnull = value))) + override val typbasetype = new Field[/* oid */ Long, Row](prefix, "typbasetype", None, Some("oid"))(x => extract(x).typbasetype, (row, value) => merge(row, extract(row).copy(typbasetype = value))) + override val typtypmod = new Field[Int, Row](prefix, "typtypmod", None, Some("int4"))(x => extract(x).typtypmod, (row, value) => merge(row, extract(row).copy(typtypmod = value))) + override val typndims = new Field[Int, Row](prefix, "typndims", None, Some("int4"))(x => extract(x).typndims, (row, value) => merge(row, extract(row).copy(typndims = value))) + override val typcollation = new Field[/* oid */ Long, Row](prefix, "typcollation", None, Some("oid"))(x => extract(x).typcollation, (row, value) => merge(row, extract(row).copy(typcollation = value))) + override val typdefaultbin = new OptField[TypoPgNodeTree, Row](prefix, "typdefaultbin", None, Some("pg_node_tree"))(x => extract(x).typdefaultbin, (row, value) => merge(row, extract(row).copy(typdefaultbin = value))) + override val typdefault = new OptField[String, Row](prefix, "typdefault", None, None)(x => extract(x).typdefault, (row, value) => merge(row, extract(row).copy(typdefault = value))) + override val typacl = new OptField[Array[TypoAclItem], Row](prefix, "typacl", None, Some("_aclitem"))(x => extract(x).typacl, (row, value) => merge(row, extract(row).copy(typacl = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, typname, typnamespace, typowner, typlen, typbyval, typtype, typcategory, typispreferred, typisdefined, typdelim, typrelid, typsubscript, typelem, typarray, typinput, typoutput, typreceive, typsend, typmodin, typmodout, typanalyze, typalign, typstorage, typnotnull, typbasetype, typtypmod, typndims, typcollation, typdefaultbin, typdefault, typacl) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgTypeRow, merge: (NewRow, PgTypeRow) => NewRow): PgTypeStructure[NewRow] = + new PgTypeStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewFields.scala new file mode 100644 index 0000000000..09ea6a75ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.OptField + +trait PgUserViewFields[Row] { + val usename: OptField[String, Row] + val usesysid: OptField[PgAuthidId, Row] + val usecreatedb: OptField[Boolean, Row] + val usesuper: OptField[Boolean, Row] + val userepl: OptField[Boolean, Row] + val usebypassrls: OptField[Boolean, Row] + val passwd: OptField[String, Row] + val valuntil: OptField[TypoInstant, Row] + val useconfig: OptField[Array[String], Row] +} +object PgUserViewFields extends PgUserViewStructure[PgUserViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepo.scala new file mode 100644 index 0000000000..9b60f995f9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgUserViewRepo { + def select: SelectBuilder[PgUserViewFields, PgUserViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgUserViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepoImpl.scala new file mode 100644 index 0000000000..8ca855da48 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgUserViewRepoImpl extends PgUserViewRepo { + override def select: SelectBuilder[PgUserViewFields, PgUserViewRow] = { + SelectBuilderSql("pg_catalog.pg_user", PgUserViewFields, PgUserViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgUserViewRow] = { + sql"""select "usename", "usesysid", "usecreatedb", "usesuper", "userepl", "usebypassrls", "passwd", "valuntil"::text, "useconfig" from pg_catalog.pg_user""".query(PgUserViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRow.scala new file mode 100644 index 0000000000..d0f2790cfd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewRow.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgUserViewRow( + /** Points to [[pg_shadow.PgShadowViewRow.usename]] */ + usename: Option[String], + /** Points to [[pg_shadow.PgShadowViewRow.usesysid]] */ + usesysid: Option[PgAuthidId], + /** Points to [[pg_shadow.PgShadowViewRow.usecreatedb]] */ + usecreatedb: Option[Boolean], + /** Points to [[pg_shadow.PgShadowViewRow.usesuper]] */ + usesuper: Option[Boolean], + /** Points to [[pg_shadow.PgShadowViewRow.userepl]] */ + userepl: Option[Boolean], + /** Points to [[pg_shadow.PgShadowViewRow.usebypassrls]] */ + usebypassrls: Option[Boolean], + passwd: /* nullability unknown */ Option[String], + /** Points to [[pg_shadow.PgShadowViewRow.valuntil]] */ + valuntil: Option[TypoInstant], + /** Points to [[pg_shadow.PgShadowViewRow.useconfig]] */ + useconfig: Option[Array[String]] +) + +object PgUserViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgUserViewRow] = new JdbcDecoder[PgUserViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgUserViewRow) = + columIndex + 8 -> + PgUserViewRow( + usename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + usesysid = JdbcDecoder.optionDecoder(PgAuthidId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + usecreatedb = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 2, rs)._2, + usesuper = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 3, rs)._2, + userepl = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 4, rs)._2, + usebypassrls = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 5, rs)._2, + passwd = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + valuntil = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + useconfig = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgUserViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val usename = jsonObj.get("usename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val usesysid = jsonObj.get("usesysid").fold[Either[String, Option[PgAuthidId]]](Right(None))(_.as(JsonDecoder.option(PgAuthidId.jsonDecoder))) + val usecreatedb = jsonObj.get("usecreatedb").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val usesuper = jsonObj.get("usesuper").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val userepl = jsonObj.get("userepl").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val usebypassrls = jsonObj.get("usebypassrls").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val passwd = jsonObj.get("passwd").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val valuntil = jsonObj.get("valuntil").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val useconfig = jsonObj.get("useconfig").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (usename.isRight && usesysid.isRight && usecreatedb.isRight && usesuper.isRight && userepl.isRight && usebypassrls.isRight && passwd.isRight && valuntil.isRight && useconfig.isRight) + Right(PgUserViewRow(usename = usename.toOption.get, usesysid = usesysid.toOption.get, usecreatedb = usecreatedb.toOption.get, usesuper = usesuper.toOption.get, userepl = userepl.toOption.get, usebypassrls = usebypassrls.toOption.get, passwd = passwd.toOption.get, valuntil = valuntil.toOption.get, useconfig = useconfig.toOption.get)) + else Left(List[Either[String, Any]](usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgUserViewRow] = new JsonEncoder[PgUserViewRow] { + override def unsafeEncode(a: PgUserViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""usename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.usename, indent, out) + out.write(",") + out.write(""""usesysid":""") + JsonEncoder.option(PgAuthidId.jsonEncoder).unsafeEncode(a.usesysid, indent, out) + out.write(",") + out.write(""""usecreatedb":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.usecreatedb, indent, out) + out.write(",") + out.write(""""usesuper":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.usesuper, indent, out) + out.write(",") + out.write(""""userepl":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.userepl, indent, out) + out.write(",") + out.write(""""usebypassrls":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.usebypassrls, indent, out) + out.write(",") + out.write(""""passwd":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.passwd, indent, out) + out.write(",") + out.write(""""valuntil":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.valuntil, indent, out) + out.write(",") + out.write(""""useconfig":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.useconfig, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewStructure.scala new file mode 100644 index 0000000000..d6d86d0e98 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user/PgUserViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user + +import adventureworks.customtypes.TypoInstant +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgUserViewStructure[Row](val prefix: Option[String], val extract: Row => PgUserViewRow, val merge: (Row, PgUserViewRow) => Row) + extends Relation[PgUserViewFields, PgUserViewRow, Row] + with PgUserViewFields[Row] { outer => + + override val usename = new OptField[String, Row](prefix, "usename", None, None)(x => extract(x).usename, (row, value) => merge(row, extract(row).copy(usename = value))) + override val usesysid = new OptField[PgAuthidId, Row](prefix, "usesysid", None, None)(x => extract(x).usesysid, (row, value) => merge(row, extract(row).copy(usesysid = value))) + override val usecreatedb = new OptField[Boolean, Row](prefix, "usecreatedb", None, None)(x => extract(x).usecreatedb, (row, value) => merge(row, extract(row).copy(usecreatedb = value))) + override val usesuper = new OptField[Boolean, Row](prefix, "usesuper", None, None)(x => extract(x).usesuper, (row, value) => merge(row, extract(row).copy(usesuper = value))) + override val userepl = new OptField[Boolean, Row](prefix, "userepl", None, None)(x => extract(x).userepl, (row, value) => merge(row, extract(row).copy(userepl = value))) + override val usebypassrls = new OptField[Boolean, Row](prefix, "usebypassrls", None, None)(x => extract(x).usebypassrls, (row, value) => merge(row, extract(row).copy(usebypassrls = value))) + override val passwd = new OptField[String, Row](prefix, "passwd", None, None)(x => extract(x).passwd, (row, value) => merge(row, extract(row).copy(passwd = value))) + override val valuntil = new OptField[TypoInstant, Row](prefix, "valuntil", Some("text"), None)(x => extract(x).valuntil, (row, value) => merge(row, extract(row).copy(valuntil = value))) + override val useconfig = new OptField[Array[String], Row](prefix, "useconfig", None, None)(x => extract(x).useconfig, (row, value) => merge(row, extract(row).copy(useconfig = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](usename, usesysid, usecreatedb, usesuper, userepl, usebypassrls, passwd, valuntil, useconfig) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgUserViewRow, merge: (NewRow, PgUserViewRow) => NewRow): PgUserViewStructure[NewRow] = + new PgUserViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingFields.scala new file mode 100644 index 0000000000..cc198f0086 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PgUserMappingFields[Row] { + val oid: IdField[PgUserMappingId, Row] + val umuser: Field[/* oid */ Long, Row] + val umserver: Field[/* oid */ Long, Row] + val umoptions: OptField[Array[String], Row] +} +object PgUserMappingFields extends PgUserMappingStructure[PgUserMappingRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingId.scala new file mode 100644 index 0000000000..cc76e6941d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +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 `pg_catalog.pg_user_mapping` */ +case class PgUserMappingId(value: /* oid */ Long) extends AnyVal +object PgUserMappingId { + implicit lazy val arraySetter: Setter[Array[PgUserMappingId]] = adventureworks.LongArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PgUserMappingId, /* oid */ Long] = Bijection[PgUserMappingId, /* oid */ Long](_.value)(PgUserMappingId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PgUserMappingId] = JdbcDecoder.longDecoder.map(PgUserMappingId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PgUserMappingId] = JdbcEncoder.longEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PgUserMappingId] = JsonDecoder.long.map(PgUserMappingId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PgUserMappingId] = JsonEncoder.long.contramap(_.value) + implicit lazy val ordering: Ordering[PgUserMappingId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PgUserMappingId] = ParameterMetaData.instance[PgUserMappingId](ParameterMetaData.LongParameterMetaData.sqlType, ParameterMetaData.LongParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PgUserMappingId] = Setter.longSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepo.scala new file mode 100644 index 0000000000..78a4e0ffaa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgUserMappingRepo { + def delete(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PgUserMappingFields, PgUserMappingRow] + def insert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, PgUserMappingRow] + def select: SelectBuilder[PgUserMappingFields, PgUserMappingRow] + def selectAll: ZStream[ZConnection, Throwable, PgUserMappingRow] + def selectById(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] + def selectByIds(oids: Array[PgUserMappingId]): ZStream[ZConnection, Throwable, PgUserMappingRow] + def selectByUnique(umuser: /* oid */ Long, umserver: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] + def update(row: PgUserMappingRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PgUserMappingFields, PgUserMappingRow] + def upsert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, UpdateResult[PgUserMappingRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoImpl.scala new file mode 100644 index 0000000000..9e358cbfe2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoImpl.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgUserMappingRepoImpl extends PgUserMappingRepo { + override def delete(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from pg_catalog.pg_user_mapping where "oid" = ${Segment.paramSegment(oid)(PgUserMappingId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PgUserMappingFields, PgUserMappingRow] = { + DeleteBuilder("pg_catalog.pg_user_mapping", PgUserMappingFields) + } + override def insert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, PgUserMappingRow] = { + sql"""insert into pg_catalog.pg_user_mapping("oid", "umuser", "umserver", "umoptions") + values (${Segment.paramSegment(unsaved.oid)(PgUserMappingId.setter)}::oid, ${Segment.paramSegment(unsaved.umuser)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.umserver)(Setter.longSetter)}::oid, ${Segment.paramSegment(unsaved.umoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text) + returning "oid", "umuser", "umserver", "umoptions" + """.insertReturning(PgUserMappingRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgUserMappingFields, PgUserMappingRow] = { + SelectBuilderSql("pg_catalog.pg_user_mapping", PgUserMappingFields, PgUserMappingRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgUserMappingRow] = { + sql"""select "oid", "umuser", "umserver", "umoptions" from pg_catalog.pg_user_mapping""".query(PgUserMappingRow.jdbcDecoder).selectStream + } + override def selectById(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] = { + sql"""select "oid", "umuser", "umserver", "umoptions" from pg_catalog.pg_user_mapping where "oid" = ${Segment.paramSegment(oid)(PgUserMappingId.setter)}""".query(PgUserMappingRow.jdbcDecoder).selectOne + } + override def selectByIds(oids: Array[PgUserMappingId]): ZStream[ZConnection, Throwable, PgUserMappingRow] = { + sql"""select "oid", "umuser", "umserver", "umoptions" from pg_catalog.pg_user_mapping where "oid" = ANY(${Segment.paramSegment(oids)(PgUserMappingId.arraySetter)})""".query(PgUserMappingRow.jdbcDecoder).selectStream + } + override def selectByUnique(umuser: /* oid */ Long, umserver: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] = { + sql"""select "umuser", "umserver" + from pg_catalog.pg_user_mapping + where "umuser" = ${Segment.paramSegment(umuser)(Setter.longSetter)} AND "umserver" = ${Segment.paramSegment(umserver)(Setter.longSetter)} + """.query(PgUserMappingRow.jdbcDecoder).selectOne + } + override def update(row: PgUserMappingRow): ZIO[ZConnection, Throwable, Boolean] = { + val oid = row.oid + sql"""update pg_catalog.pg_user_mapping + set "umuser" = ${Segment.paramSegment(row.umuser)(Setter.longSetter)}::oid, + "umserver" = ${Segment.paramSegment(row.umserver)(Setter.longSetter)}::oid, + "umoptions" = ${Segment.paramSegment(row.umoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + where "oid" = ${Segment.paramSegment(oid)(PgUserMappingId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PgUserMappingFields, PgUserMappingRow] = { + UpdateBuilder("pg_catalog.pg_user_mapping", PgUserMappingFields, PgUserMappingRow.jdbcDecoder) + } + override def upsert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, UpdateResult[PgUserMappingRow]] = { + sql"""insert into pg_catalog.pg_user_mapping("oid", "umuser", "umserver", "umoptions") + values ( + ${Segment.paramSegment(unsaved.oid)(PgUserMappingId.setter)}::oid, + ${Segment.paramSegment(unsaved.umuser)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.umserver)(Setter.longSetter)}::oid, + ${Segment.paramSegment(unsaved.umoptions)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text + ) + on conflict ("oid") + do update set + "umuser" = EXCLUDED."umuser", + "umserver" = EXCLUDED."umserver", + "umoptions" = EXCLUDED."umoptions" + returning "oid", "umuser", "umserver", "umoptions"""".insertReturning(PgUserMappingRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoMock.scala new file mode 100644 index 0000000000..b88564b536 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRepoMock.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PgUserMappingRepoMock(map: scala.collection.mutable.Map[PgUserMappingId, PgUserMappingRow] = scala.collection.mutable.Map.empty) extends PgUserMappingRepo { + override def delete(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(oid).isDefined) + } + override def delete: DeleteBuilder[PgUserMappingFields, PgUserMappingRow] = { + DeleteBuilderMock(DeleteParams.empty, PgUserMappingFields, map) + } + override def insert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, PgUserMappingRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.oid)) + sys.error(s"id ${unsaved.oid} already exists") + else + map.put(unsaved.oid, unsaved) + + unsaved + } + } + override def select: SelectBuilder[PgUserMappingFields, PgUserMappingRow] = { + SelectBuilderMock(PgUserMappingFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PgUserMappingRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(oid: PgUserMappingId): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] = { + ZIO.succeed(map.get(oid)) + } + override def selectByIds(oids: Array[PgUserMappingId]): ZStream[ZConnection, Throwable, PgUserMappingRow] = { + ZStream.fromIterable(oids.flatMap(map.get)) + } + override def selectByUnique(umuser: /* oid */ Long, umserver: /* oid */ Long): ZIO[ZConnection, Throwable, Option[PgUserMappingRow]] = { + ZIO.succeed(map.values.find(v => umuser == v.umuser && umserver == v.umserver)) + } + override def update(row: PgUserMappingRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.oid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.oid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PgUserMappingFields, PgUserMappingRow] = { + UpdateBuilderMock(UpdateParams.empty, PgUserMappingFields, map) + } + override def upsert(unsaved: PgUserMappingRow): ZIO[ZConnection, Throwable, UpdateResult[PgUserMappingRow]] = { + ZIO.succeed { + map.put(unsaved.oid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRow.scala new file mode 100644 index 0000000000..b109914898 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgUserMappingRow( + oid: PgUserMappingId, + umuser: /* oid */ Long, + umserver: /* oid */ Long, + umoptions: Option[Array[String]] +) + +object PgUserMappingRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgUserMappingRow] = new JdbcDecoder[PgUserMappingRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgUserMappingRow) = + columIndex + 3 -> + PgUserMappingRow( + oid = PgUserMappingId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + umuser = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 1, rs)._2, + umserver = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 2, rs)._2, + umoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgUserMappingRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val oid = jsonObj.get("oid").toRight("Missing field 'oid'").flatMap(_.as(PgUserMappingId.jsonDecoder)) + val umuser = jsonObj.get("umuser").toRight("Missing field 'umuser'").flatMap(_.as(JsonDecoder.long)) + val umserver = jsonObj.get("umserver").toRight("Missing field 'umserver'").flatMap(_.as(JsonDecoder.long)) + val umoptions = jsonObj.get("umoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (oid.isRight && umuser.isRight && umserver.isRight && umoptions.isRight) + Right(PgUserMappingRow(oid = oid.toOption.get, umuser = umuser.toOption.get, umserver = umserver.toOption.get, umoptions = umoptions.toOption.get)) + else Left(List[Either[String, Any]](oid, umuser, umserver, umoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgUserMappingRow] = new JsonEncoder[PgUserMappingRow] { + override def unsafeEncode(a: PgUserMappingRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""oid":""") + PgUserMappingId.jsonEncoder.unsafeEncode(a.oid, indent, out) + out.write(",") + out.write(""""umuser":""") + JsonEncoder.long.unsafeEncode(a.umuser, indent, out) + out.write(",") + out.write(""""umserver":""") + JsonEncoder.long.unsafeEncode(a.umserver, indent, out) + out.write(",") + out.write(""""umoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.umoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingStructure.scala new file mode 100644 index 0000000000..0f8a61be8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mapping/PgUserMappingStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mapping + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgUserMappingStructure[Row](val prefix: Option[String], val extract: Row => PgUserMappingRow, val merge: (Row, PgUserMappingRow) => Row) + extends Relation[PgUserMappingFields, PgUserMappingRow, Row] + with PgUserMappingFields[Row] { outer => + + override val oid = new IdField[PgUserMappingId, Row](prefix, "oid", None, Some("oid"))(x => extract(x).oid, (row, value) => merge(row, extract(row).copy(oid = value))) + override val umuser = new Field[/* oid */ Long, Row](prefix, "umuser", None, Some("oid"))(x => extract(x).umuser, (row, value) => merge(row, extract(row).copy(umuser = value))) + override val umserver = new Field[/* oid */ Long, Row](prefix, "umserver", None, Some("oid"))(x => extract(x).umserver, (row, value) => merge(row, extract(row).copy(umserver = value))) + override val umoptions = new OptField[Array[String], Row](prefix, "umoptions", None, Some("_text"))(x => extract(x).umoptions, (row, value) => merge(row, extract(row).copy(umoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](oid, umuser, umserver, umoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgUserMappingRow, merge: (NewRow, PgUserMappingRow) => NewRow): PgUserMappingStructure[NewRow] = + new PgUserMappingStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewFields.scala new file mode 100644 index 0000000000..6b1d5f6b2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mappings + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgUserMappingsViewFields[Row] { + val umid: Field[PgUserMappingId, Row] + val srvid: Field[PgForeignServerId, Row] + val srvname: Field[String, Row] + val umuser: Field[/* oid */ Long, Row] + val usename: OptField[String, Row] + val umoptions: OptField[Array[String], Row] +} +object PgUserMappingsViewFields extends PgUserMappingsViewStructure[PgUserMappingsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepo.scala new file mode 100644 index 0000000000..fd60fa5c49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mappings + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgUserMappingsViewRepo { + def select: SelectBuilder[PgUserMappingsViewFields, PgUserMappingsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgUserMappingsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepoImpl.scala new file mode 100644 index 0000000000..ed35e94388 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mappings + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgUserMappingsViewRepoImpl extends PgUserMappingsViewRepo { + override def select: SelectBuilder[PgUserMappingsViewFields, PgUserMappingsViewRow] = { + SelectBuilderSql("pg_catalog.pg_user_mappings", PgUserMappingsViewFields, PgUserMappingsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgUserMappingsViewRow] = { + sql"""select "umid", "srvid", "srvname", "umuser", "usename", "umoptions" from pg_catalog.pg_user_mappings""".query(PgUserMappingsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRow.scala new file mode 100644 index 0000000000..38d11845f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mappings + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgUserMappingsViewRow( + /** Points to [[pg_user_mapping.PgUserMappingRow.oid]] */ + umid: PgUserMappingId, + /** Points to [[pg_foreign_server.PgForeignServerRow.oid]] */ + srvid: PgForeignServerId, + /** Points to [[pg_foreign_server.PgForeignServerRow.srvname]] */ + srvname: String, + /** Points to [[pg_user_mapping.PgUserMappingRow.umuser]] */ + umuser: /* oid */ Long, + usename: /* nullability unknown */ Option[String], + umoptions: /* nullability unknown */ Option[Array[String]] +) + +object PgUserMappingsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgUserMappingsViewRow] = new JdbcDecoder[PgUserMappingsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgUserMappingsViewRow) = + columIndex + 5 -> + PgUserMappingsViewRow( + umid = PgUserMappingId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + srvid = PgForeignServerId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + srvname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + umuser = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 3, rs)._2, + usename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + umoptions = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgUserMappingsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val umid = jsonObj.get("umid").toRight("Missing field 'umid'").flatMap(_.as(PgUserMappingId.jsonDecoder)) + val srvid = jsonObj.get("srvid").toRight("Missing field 'srvid'").flatMap(_.as(PgForeignServerId.jsonDecoder)) + val srvname = jsonObj.get("srvname").toRight("Missing field 'srvname'").flatMap(_.as(JsonDecoder.string)) + val umuser = jsonObj.get("umuser").toRight("Missing field 'umuser'").flatMap(_.as(JsonDecoder.long)) + val usename = jsonObj.get("usename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val umoptions = jsonObj.get("umoptions").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + if (umid.isRight && srvid.isRight && srvname.isRight && umuser.isRight && usename.isRight && umoptions.isRight) + Right(PgUserMappingsViewRow(umid = umid.toOption.get, srvid = srvid.toOption.get, srvname = srvname.toOption.get, umuser = umuser.toOption.get, usename = usename.toOption.get, umoptions = umoptions.toOption.get)) + else Left(List[Either[String, Any]](umid, srvid, srvname, umuser, usename, umoptions).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgUserMappingsViewRow] = new JsonEncoder[PgUserMappingsViewRow] { + override def unsafeEncode(a: PgUserMappingsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""umid":""") + PgUserMappingId.jsonEncoder.unsafeEncode(a.umid, indent, out) + out.write(",") + out.write(""""srvid":""") + PgForeignServerId.jsonEncoder.unsafeEncode(a.srvid, indent, out) + out.write(",") + out.write(""""srvname":""") + JsonEncoder.string.unsafeEncode(a.srvname, indent, out) + out.write(",") + out.write(""""umuser":""") + JsonEncoder.long.unsafeEncode(a.umuser, indent, out) + out.write(",") + out.write(""""usename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.usename, indent, out) + out.write(",") + out.write(""""umoptions":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.umoptions, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewStructure.scala new file mode 100644 index 0000000000..3f088cd34a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_user_mappings/PgUserMappingsViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_user_mappings + +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgUserMappingsViewStructure[Row](val prefix: Option[String], val extract: Row => PgUserMappingsViewRow, val merge: (Row, PgUserMappingsViewRow) => Row) + extends Relation[PgUserMappingsViewFields, PgUserMappingsViewRow, Row] + with PgUserMappingsViewFields[Row] { outer => + + override val umid = new Field[PgUserMappingId, Row](prefix, "umid", None, None)(x => extract(x).umid, (row, value) => merge(row, extract(row).copy(umid = value))) + override val srvid = new Field[PgForeignServerId, Row](prefix, "srvid", None, None)(x => extract(x).srvid, (row, value) => merge(row, extract(row).copy(srvid = value))) + override val srvname = new Field[String, Row](prefix, "srvname", None, None)(x => extract(x).srvname, (row, value) => merge(row, extract(row).copy(srvname = value))) + override val umuser = new Field[/* oid */ Long, Row](prefix, "umuser", None, None)(x => extract(x).umuser, (row, value) => merge(row, extract(row).copy(umuser = value))) + override val usename = new OptField[String, Row](prefix, "usename", None, None)(x => extract(x).usename, (row, value) => merge(row, extract(row).copy(usename = value))) + override val umoptions = new OptField[Array[String], Row](prefix, "umoptions", None, None)(x => extract(x).umoptions, (row, value) => merge(row, extract(row).copy(umoptions = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](umid, srvid, srvname, umuser, usename, umoptions) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgUserMappingsViewRow, merge: (NewRow, PgUserMappingsViewRow) => NewRow): PgUserMappingsViewStructure[NewRow] = + new PgUserMappingsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewFields.scala new file mode 100644 index 0000000000..142121905b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewFields.scala @@ -0,0 +1,20 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_views + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PgViewsViewFields[Row] { + val schemaname: OptField[String, Row] + val viewname: Field[String, Row] + val viewowner: OptField[String, Row] + val definition: OptField[String, Row] +} +object PgViewsViewFields extends PgViewsViewStructure[PgViewsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepo.scala new file mode 100644 index 0000000000..a488d5526c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_views + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgViewsViewRepo { + def select: SelectBuilder[PgViewsViewFields, PgViewsViewRow] + def selectAll: ZStream[ZConnection, Throwable, PgViewsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepoImpl.scala new file mode 100644 index 0000000000..bb588871be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_views + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgViewsViewRepoImpl extends PgViewsViewRepo { + override def select: SelectBuilder[PgViewsViewFields, PgViewsViewRow] = { + SelectBuilderSql("pg_catalog.pg_views", PgViewsViewFields, PgViewsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgViewsViewRow] = { + sql"""select "schemaname", "viewname", "viewowner", "definition" from pg_catalog.pg_views""".query(PgViewsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRow.scala new file mode 100644 index 0000000000..ae38b6ccc0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewRow.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_views + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgViewsViewRow( + /** Points to [[pg_namespace.PgNamespaceRow.nspname]] */ + schemaname: Option[String], + /** Points to [[pg_class.PgClassRow.relname]] */ + viewname: String, + viewowner: /* nullability unknown */ Option[String], + definition: /* nullability unknown */ Option[String] +) + +object PgViewsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgViewsViewRow] = new JdbcDecoder[PgViewsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgViewsViewRow) = + columIndex + 3 -> + PgViewsViewRow( + schemaname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 0, rs)._2, + viewname = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + viewowner = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + definition = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgViewsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val schemaname = jsonObj.get("schemaname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val viewname = jsonObj.get("viewname").toRight("Missing field 'viewname'").flatMap(_.as(JsonDecoder.string)) + val viewowner = jsonObj.get("viewowner").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val definition = jsonObj.get("definition").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + if (schemaname.isRight && viewname.isRight && viewowner.isRight && definition.isRight) + Right(PgViewsViewRow(schemaname = schemaname.toOption.get, viewname = viewname.toOption.get, viewowner = viewowner.toOption.get, definition = definition.toOption.get)) + else Left(List[Either[String, Any]](schemaname, viewname, viewowner, definition).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgViewsViewRow] = new JsonEncoder[PgViewsViewRow] { + override def unsafeEncode(a: PgViewsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""schemaname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.schemaname, indent, out) + out.write(",") + out.write(""""viewname":""") + JsonEncoder.string.unsafeEncode(a.viewname, indent, out) + out.write(",") + out.write(""""viewowner":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.viewowner, indent, out) + out.write(",") + out.write(""""definition":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.definition, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewStructure.scala new file mode 100644 index 0000000000..84b49996b1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pg_catalog/pg_views/PgViewsViewStructure.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pg_catalog +package pg_views + +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgViewsViewStructure[Row](val prefix: Option[String], val extract: Row => PgViewsViewRow, val merge: (Row, PgViewsViewRow) => Row) + extends Relation[PgViewsViewFields, PgViewsViewRow, Row] + with PgViewsViewFields[Row] { outer => + + override val schemaname = new OptField[String, Row](prefix, "schemaname", None, None)(x => extract(x).schemaname, (row, value) => merge(row, extract(row).copy(schemaname = value))) + override val viewname = new Field[String, Row](prefix, "viewname", None, None)(x => extract(x).viewname, (row, value) => merge(row, extract(row).copy(viewname = value))) + override val viewowner = new OptField[String, Row](prefix, "viewowner", None, None)(x => extract(x).viewowner, (row, value) => merge(row, extract(row).copy(viewowner = value))) + override val definition = new OptField[String, Row](prefix, "definition", None, None)(x => extract(x).definition, (row, value) => merge(row, extract(row).copy(definition = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](schemaname, viewname, viewowner, definition) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgViewsViewRow, merge: (NewRow, PgViewsViewRow) => NewRow): PgViewsViewStructure[NewRow] = + new PgViewsViewStructure(prefix, extract, merge) +} 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 new file mode 100644 index 0000000000..17cc54864e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +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 productassemblyid: OptField[ProductId, Row] + val componentid: Field[ProductId, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val unitmeasurecode: Field[UnitmeasureId, Row] + val bomlevel: Field[TypoShort, Row] + val perassemblyqty: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BomViewFields extends BomViewStructure[BomViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepo.scala new file mode 100644 index 0000000000..9653ba3f6d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package bom + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BomViewRepo { + def select: SelectBuilder[BomViewFields, BomViewRow] + def selectAll: ZStream[ZConnection, Throwable, BomViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepoImpl.scala new file mode 100644 index 0000000000..47230e5b39 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package bom + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object BomViewRepoImpl extends BomViewRepo { + override def select: SelectBuilder[BomViewFields, BomViewRow] = { + SelectBuilderSql("pr.bom", BomViewFields, BomViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, BomViewRow] = { + sql"""select "id", "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text from pr.bom""".query(BomViewRow.jdbcDecoder).selectStream + } +} 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 new file mode 100644 index 0000000000..27a260492c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewRow.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +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 +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BomViewRow( + /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ + id: BillofmaterialsId, + /** Points to [[production.billofmaterials.BillofmaterialsRow.billofmaterialsid]] */ + billofmaterialsid: BillofmaterialsId, + /** Points to [[production.billofmaterials.BillofmaterialsRow.productassemblyid]] */ + productassemblyid: Option[ProductId], + /** Points to [[production.billofmaterials.BillofmaterialsRow.componentid]] */ + componentid: ProductId, + /** Points to [[production.billofmaterials.BillofmaterialsRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[production.billofmaterials.BillofmaterialsRow.enddate]] */ + enddate: Option[TypoLocalDateTime], + /** Points to [[production.billofmaterials.BillofmaterialsRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Points to [[production.billofmaterials.BillofmaterialsRow.bomlevel]] */ + bomlevel: TypoShort, + /** Points to [[production.billofmaterials.BillofmaterialsRow.perassemblyqty]] */ + perassemblyqty: BigDecimal, + /** Points to [[production.billofmaterials.BillofmaterialsRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object BomViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BomViewRow] = new JdbcDecoder[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, + 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, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + bomlevel = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + perassemblyqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + 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 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)) + 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 perassemblyqty = jsonObj.get("perassemblyqty").toRight("Missing field 'perassemblyqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && billofmaterialsid.isRight && productassemblyid.isRight && componentid.isRight && startdate.isRight && enddate.isRight && unitmeasurecode.isRight && bomlevel.isRight && perassemblyqty.isRight && modifieddate.isRight) + Right(BomViewRow(id = id.toOption.get, billofmaterialsid = billofmaterialsid.toOption.get, productassemblyid = productassemblyid.toOption.get, componentid = componentid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, bomlevel = bomlevel.toOption.get, perassemblyqty = perassemblyqty.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, billofmaterialsid, productassemblyid, componentid, startdate, enddate, unitmeasurecode, bomlevel, perassemblyqty, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BomViewRow] = new JsonEncoder[BomViewRow] { + override def unsafeEncode(a: BomViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BillofmaterialsId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""billofmaterialsid":""") + BillofmaterialsId.jsonEncoder.unsafeEncode(a.billofmaterialsid, indent, out) + out.write(",") + out.write(""""productassemblyid":""") + JsonEncoder.option(ProductId.jsonEncoder).unsafeEncode(a.productassemblyid, indent, out) + out.write(",") + out.write(""""componentid":""") + ProductId.jsonEncoder.unsafeEncode(a.componentid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""bomlevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.bomlevel, indent, out) + out.write(",") + out.write(""""perassemblyqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.perassemblyqty, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} 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 new file mode 100644 index 0000000000..2536eb9061 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/bom/BomViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +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.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class BomViewStructure[Row](val prefix: Option[String], val extract: Row => BomViewRow, val merge: (Row, BomViewRow) => Row) + 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 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val unitmeasurecode = new Field[UnitmeasureId, Row](prefix, "unitmeasurecode", None, None)(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val bomlevel = new Field[TypoShort, Row](prefix, "bomlevel", None, None)(x => extract(x).bomlevel, (row, value) => merge(row, extract(row).copy(bomlevel = value))) + override val perassemblyqty = new Field[BigDecimal, Row](prefix, "perassemblyqty", None, None)(x => extract(x).perassemblyqty, (row, value) => merge(row, extract(row).copy(perassemblyqty = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, billofmaterialsid, productassemblyid, componentid, startdate, enddate, unitmeasurecode, bomlevel, perassemblyqty, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BomViewRow, merge: (NewRow, BomViewRow) => NewRow): BomViewStructure[NewRow] = + new BomViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewFields.scala new file mode 100644 index 0000000000..78024cc012 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait CViewFields[Row] { + val id: Field[CultureId, Row] + val cultureid: Field[CultureId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CViewFields extends CViewStructure[CViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepo.scala new file mode 100644 index 0000000000..4dd11b571f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package c + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CViewRepo { + def select: SelectBuilder[CViewFields, CViewRow] + def selectAll: ZStream[ZConnection, Throwable, CViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepoImpl.scala new file mode 100644 index 0000000000..15f1728573 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package c + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CViewRepoImpl extends CViewRepo { + override def select: SelectBuilder[CViewFields, CViewRow] = { + SelectBuilderSql("pr.c", CViewFields, CViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CViewRow] = { + sql"""select "id", "cultureid", "name", "modifieddate"::text from pr.c""".query(CViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRow.scala new file mode 100644 index 0000000000..5c66f6d065 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CViewRow( + /** Points to [[production.culture.CultureRow.cultureid]] */ + id: CultureId, + /** Points to [[production.culture.CultureRow.cultureid]] */ + cultureid: CultureId, + /** Points to [[production.culture.CultureRow.name]] */ + name: Name, + /** Points to [[production.culture.CultureRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CViewRow] = new JdbcDecoder[CViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CViewRow) = + columIndex + 3 -> + CViewRow( + id = CultureId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + cultureid = CultureId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(CultureId.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && cultureid.isRight && name.isRight && modifieddate.isRight) + Right(CViewRow(id = id.toOption.get, cultureid = cultureid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, cultureid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CViewRow] = new JsonEncoder[CViewRow] { + override def unsafeEncode(a: CViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + CultureId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewStructure.scala new file mode 100644 index 0000000000..126337859a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/c/CViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CViewStructure[Row](val prefix: Option[String], val extract: Row => CViewRow, val merge: (Row, CViewRow) => Row) + extends Relation[CViewFields, CViewRow, Row] + with CViewFields[Row] { outer => + + override val id = new Field[CultureId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val cultureid = new Field[CultureId, Row](prefix, "cultureid", None, None)(x => extract(x).cultureid, (row, value) => merge(row, extract(row).copy(cultureid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, cultureid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CViewRow, merge: (NewRow, CViewRow) => NewRow): CViewStructure[NewRow] = + new CViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewFields.scala new file mode 100644 index 0000000000..943ce0ca8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewFields.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package d + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.document.DocumentId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait DViewFields[Row] { + val title: Field[/* max 50 chars */ String, Row] + val owner: Field[BusinessentityId, Row] + val folderflag: Field[Flag, Row] + val filename: Field[/* max 400 chars */ String, Row] + val fileextension: OptField[/* max 8 chars */ String, Row] + val revision: Field[/* bpchar, max 5 chars */ String, Row] + val changenumber: Field[Int, Row] + val status: Field[TypoShort, Row] + val documentsummary: OptField[String, Row] + val document: OptField[TypoBytea, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val documentnode: Field[DocumentId, Row] +} +object DViewFields extends DViewStructure[DViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepo.scala new file mode 100644 index 0000000000..7891a19c77 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package d + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DViewRepo { + def select: SelectBuilder[DViewFields, DViewRow] + def selectAll: ZStream[ZConnection, Throwable, DViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepoImpl.scala new file mode 100644 index 0000000000..123d3578ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package d + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DViewRepoImpl extends DViewRepo { + override def select: SelectBuilder[DViewFields, DViewRow] = { + SelectBuilderSql("pr.d", DViewFields, DViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DViewRow] = { + sql"""select "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" from pr.d""".query(DViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRow.scala new file mode 100644 index 0000000000..046ef4f178 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewRow.scala @@ -0,0 +1,135 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package d + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.document.DocumentId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DViewRow( + /** Points to [[production.document.DocumentRow.title]] */ + title: /* max 50 chars */ String, + /** Points to [[production.document.DocumentRow.owner]] */ + owner: BusinessentityId, + /** Points to [[production.document.DocumentRow.folderflag]] */ + folderflag: Flag, + /** Points to [[production.document.DocumentRow.filename]] */ + filename: /* max 400 chars */ String, + /** Points to [[production.document.DocumentRow.fileextension]] */ + fileextension: Option[/* max 8 chars */ String], + /** Points to [[production.document.DocumentRow.revision]] */ + revision: /* bpchar, max 5 chars */ String, + /** Points to [[production.document.DocumentRow.changenumber]] */ + changenumber: Int, + /** Points to [[production.document.DocumentRow.status]] */ + status: TypoShort, + /** Points to [[production.document.DocumentRow.documentsummary]] */ + documentsummary: Option[String], + /** Points to [[production.document.DocumentRow.document]] */ + document: Option[TypoBytea], + /** Points to [[production.document.DocumentRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.document.DocumentRow.modifieddate]] */ + modifieddate: TypoLocalDateTime, + /** Points to [[production.document.DocumentRow.documentnode]] */ + documentnode: DocumentId +) + +object DViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DViewRow] = new JdbcDecoder[DViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DViewRow) = + columIndex + 12 -> + DViewRow( + title = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + owner = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + folderflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + filename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + fileextension = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + revision = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + changenumber = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + documentsummary = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + document = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + documentnode = DocumentId.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val title = jsonObj.get("title").toRight("Missing field 'title'").flatMap(_.as(JsonDecoder.string)) + val owner = jsonObj.get("owner").toRight("Missing field 'owner'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val folderflag = jsonObj.get("folderflag").toRight("Missing field 'folderflag'").flatMap(_.as(Flag.jsonDecoder)) + val filename = jsonObj.get("filename").toRight("Missing field 'filename'").flatMap(_.as(JsonDecoder.string)) + val fileextension = jsonObj.get("fileextension").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val revision = jsonObj.get("revision").toRight("Missing field 'revision'").flatMap(_.as(JsonDecoder.string)) + val changenumber = jsonObj.get("changenumber").toRight("Missing field 'changenumber'").flatMap(_.as(JsonDecoder.int)) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val documentsummary = jsonObj.get("documentsummary").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val document = jsonObj.get("document").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(DocumentId.jsonDecoder)) + if (title.isRight && owner.isRight && folderflag.isRight && filename.isRight && fileextension.isRight && revision.isRight && changenumber.isRight && status.isRight && documentsummary.isRight && document.isRight && rowguid.isRight && modifieddate.isRight && documentnode.isRight) + Right(DViewRow(title = title.toOption.get, owner = owner.toOption.get, folderflag = folderflag.toOption.get, filename = filename.toOption.get, fileextension = fileextension.toOption.get, revision = revision.toOption.get, changenumber = changenumber.toOption.get, status = status.toOption.get, documentsummary = documentsummary.toOption.get, document = document.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](title, owner, folderflag, filename, fileextension, revision, changenumber, status, documentsummary, document, rowguid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DViewRow] = new JsonEncoder[DViewRow] { + override def unsafeEncode(a: DViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""title":""") + JsonEncoder.string.unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""owner":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.owner, indent, out) + out.write(",") + out.write(""""folderflag":""") + Flag.jsonEncoder.unsafeEncode(a.folderflag, indent, out) + out.write(",") + out.write(""""filename":""") + JsonEncoder.string.unsafeEncode(a.filename, indent, out) + out.write(",") + out.write(""""fileextension":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.fileextension, indent, out) + out.write(",") + out.write(""""revision":""") + JsonEncoder.string.unsafeEncode(a.revision, indent, out) + out.write(",") + out.write(""""changenumber":""") + JsonEncoder.int.unsafeEncode(a.changenumber, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""documentsummary":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.documentsummary, indent, out) + out.write(",") + out.write(""""document":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.document, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + DocumentId.jsonEncoder.unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewStructure.scala new file mode 100644 index 0000000000..d6d8e8a044 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/d/DViewStructure.scala @@ -0,0 +1,45 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package d + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.document.DocumentId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DViewStructure[Row](val prefix: Option[String], val extract: Row => DViewRow, val merge: (Row, DViewRow) => Row) + extends Relation[DViewFields, DViewRow, Row] + with DViewFields[Row] { outer => + + override val title = new Field[/* max 50 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val owner = new Field[BusinessentityId, Row](prefix, "owner", None, None)(x => extract(x).owner, (row, value) => merge(row, extract(row).copy(owner = value))) + override val folderflag = new Field[Flag, Row](prefix, "folderflag", None, None)(x => extract(x).folderflag, (row, value) => merge(row, extract(row).copy(folderflag = value))) + override val filename = new Field[/* max 400 chars */ String, Row](prefix, "filename", None, None)(x => extract(x).filename, (row, value) => merge(row, extract(row).copy(filename = value))) + override val fileextension = new OptField[/* max 8 chars */ String, Row](prefix, "fileextension", None, None)(x => extract(x).fileextension, (row, value) => merge(row, extract(row).copy(fileextension = value))) + override val revision = new Field[/* bpchar, max 5 chars */ String, Row](prefix, "revision", None, None)(x => extract(x).revision, (row, value) => merge(row, extract(row).copy(revision = value))) + override val changenumber = new Field[Int, Row](prefix, "changenumber", None, None)(x => extract(x).changenumber, (row, value) => merge(row, extract(row).copy(changenumber = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, None)(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val documentsummary = new OptField[String, Row](prefix, "documentsummary", None, None)(x => extract(x).documentsummary, (row, value) => merge(row, extract(row).copy(documentsummary = value))) + override val document = new OptField[TypoBytea, Row](prefix, "document", None, None)(x => extract(x).document, (row, value) => merge(row, extract(row).copy(document = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val documentnode = new Field[DocumentId, Row](prefix, "documentnode", None, None)(x => extract(x).documentnode, (row, value) => merge(row, extract(row).copy(documentnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](title, owner, folderflag, filename, fileextension, revision, changenumber, status, documentsummary, document, rowguid, modifieddate, documentnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DViewRow, merge: (NewRow, DViewRow) => NewRow): DViewStructure[NewRow] = + new DViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewFields.scala new file mode 100644 index 0000000000..1842ac7f71 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package i + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.production.illustration.IllustrationId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait IViewFields[Row] { + val id: Field[IllustrationId, Row] + val illustrationid: Field[IllustrationId, Row] + val diagram: OptField[TypoXml, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object IViewFields extends IViewStructure[IViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepo.scala new file mode 100644 index 0000000000..5605b79362 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package i + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait IViewRepo { + def select: SelectBuilder[IViewFields, IViewRow] + def selectAll: ZStream[ZConnection, Throwable, IViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepoImpl.scala new file mode 100644 index 0000000000..2180a70bd5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package i + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object IViewRepoImpl extends IViewRepo { + override def select: SelectBuilder[IViewFields, IViewRow] = { + SelectBuilderSql("pr.i", IViewFields, IViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, IViewRow] = { + sql"""select "id", "illustrationid", "diagram", "modifieddate"::text from pr.i""".query(IViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRow.scala new file mode 100644 index 0000000000..01b890ae59 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package i + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.production.illustration.IllustrationId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class IViewRow( + /** Points to [[production.illustration.IllustrationRow.illustrationid]] */ + id: IllustrationId, + /** Points to [[production.illustration.IllustrationRow.illustrationid]] */ + illustrationid: IllustrationId, + /** Points to [[production.illustration.IllustrationRow.diagram]] */ + diagram: Option[TypoXml], + /** Points to [[production.illustration.IllustrationRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object IViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[IViewRow] = new JdbcDecoder[IViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, IViewRow) = + columIndex + 3 -> + IViewRow( + id = IllustrationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + illustrationid = IllustrationId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + diagram = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[IViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(IllustrationId.jsonDecoder)) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + val diagram = jsonObj.get("diagram").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && illustrationid.isRight && diagram.isRight && modifieddate.isRight) + Right(IViewRow(id = id.toOption.get, illustrationid = illustrationid.toOption.get, diagram = diagram.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, illustrationid, diagram, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[IViewRow] = new JsonEncoder[IViewRow] { + override def unsafeEncode(a: IViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + IllustrationId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""diagram":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.diagram, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewStructure.scala new file mode 100644 index 0000000000..7b45575a14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/i/IViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package i + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import adventureworks.production.illustration.IllustrationId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class IViewStructure[Row](val prefix: Option[String], val extract: Row => IViewRow, val merge: (Row, IViewRow) => Row) + extends Relation[IViewFields, IViewRow, Row] + with IViewFields[Row] { outer => + + override val id = new Field[IllustrationId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val illustrationid = new Field[IllustrationId, Row](prefix, "illustrationid", None, None)(x => extract(x).illustrationid, (row, value) => merge(row, extract(row).copy(illustrationid = value))) + override val diagram = new OptField[TypoXml, Row](prefix, "diagram", None, None)(x => extract(x).diagram, (row, value) => merge(row, extract(row).copy(diagram = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, illustrationid, diagram, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => IViewRow, merge: (NewRow, IViewRow) => NewRow): IViewStructure[NewRow] = + new IViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewFields.scala new file mode 100644 index 0000000000..acb810ccab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package l + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.location.LocationId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait LViewFields[Row] { + val id: Field[LocationId, Row] + val locationid: Field[LocationId, Row] + val name: Field[Name, Row] + val costrate: Field[BigDecimal, Row] + val availability: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object LViewFields extends LViewStructure[LViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepo.scala new file mode 100644 index 0000000000..556ede3478 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package l + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait LViewRepo { + def select: SelectBuilder[LViewFields, LViewRow] + def selectAll: ZStream[ZConnection, Throwable, LViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepoImpl.scala new file mode 100644 index 0000000000..7e36bb084d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package l + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object LViewRepoImpl extends LViewRepo { + override def select: SelectBuilder[LViewFields, LViewRow] = { + SelectBuilderSql("pr.l", LViewFields, LViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, LViewRow] = { + sql"""select "id", "locationid", "name", "costrate", "availability", "modifieddate"::text from pr.l""".query(LViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRow.scala new file mode 100644 index 0000000000..7904326537 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package l + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.location.LocationId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class LViewRow( + /** Points to [[production.location.LocationRow.locationid]] */ + id: LocationId, + /** Points to [[production.location.LocationRow.locationid]] */ + locationid: LocationId, + /** Points to [[production.location.LocationRow.name]] */ + name: Name, + /** Points to [[production.location.LocationRow.costrate]] */ + costrate: BigDecimal, + /** Points to [[production.location.LocationRow.availability]] */ + availability: BigDecimal, + /** Points to [[production.location.LocationRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object LViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[LViewRow] = new JdbcDecoder[LViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, LViewRow) = + columIndex + 5 -> + LViewRow( + id = LocationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + costrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + availability = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[LViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(LocationId.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val costrate = jsonObj.get("costrate").toRight("Missing field 'costrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val availability = jsonObj.get("availability").toRight("Missing field 'availability'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && locationid.isRight && name.isRight && costrate.isRight && availability.isRight && modifieddate.isRight) + Right(LViewRow(id = id.toOption.get, locationid = locationid.toOption.get, name = name.toOption.get, costrate = costrate.toOption.get, availability = availability.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, locationid, name, costrate, availability, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[LViewRow] = new JsonEncoder[LViewRow] { + override def unsafeEncode(a: LViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + LocationId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""costrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costrate, indent, out) + out.write(",") + out.write(""""availability":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.availability, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewStructure.scala new file mode 100644 index 0000000000..72d2c67f72 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/l/LViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package l + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.location.LocationId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class LViewStructure[Row](val prefix: Option[String], val extract: Row => LViewRow, val merge: (Row, LViewRow) => Row) + extends Relation[LViewFields, LViewRow, Row] + with LViewFields[Row] { outer => + + override val id = new Field[LocationId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val locationid = new Field[LocationId, Row](prefix, "locationid", None, None)(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val costrate = new Field[BigDecimal, Row](prefix, "costrate", None, None)(x => extract(x).costrate, (row, value) => merge(row, extract(row).copy(costrate = value))) + override val availability = new Field[BigDecimal, Row](prefix, "availability", None, None)(x => extract(x).availability, (row, value) => merge(row, extract(row).copy(availability = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, locationid, name, costrate, availability, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => LViewRow, merge: (NewRow, LViewRow) => NewRow): LViewStructure[NewRow] = + new LViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewFields.scala new file mode 100644 index 0000000000..eee5a6bf77 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewFields.scala @@ -0,0 +1,51 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val name: Field[Name, Row] + val productnumber: Field[/* max 25 chars */ String, Row] + val makeflag: Field[Flag, Row] + val finishedgoodsflag: Field[Flag, Row] + val color: OptField[/* max 15 chars */ String, Row] + val safetystocklevel: Field[TypoShort, Row] + val reorderpoint: Field[TypoShort, Row] + val standardcost: Field[BigDecimal, Row] + val listprice: Field[BigDecimal, Row] + val size: OptField[/* max 5 chars */ String, Row] + val sizeunitmeasurecode: OptField[UnitmeasureId, Row] + val weightunitmeasurecode: OptField[UnitmeasureId, Row] + val weight: OptField[BigDecimal, Row] + val daystomanufacture: Field[Int, Row] + val productline: OptField[/* bpchar, max 2 chars */ String, Row] + val `class`: OptField[/* bpchar, max 2 chars */ String, Row] + val style: OptField[/* bpchar, max 2 chars */ String, Row] + val productsubcategoryid: OptField[ProductsubcategoryId, Row] + val productmodelid: OptField[ProductmodelId, Row] + val sellstartdate: Field[TypoLocalDateTime, Row] + val sellenddate: OptField[TypoLocalDateTime, Row] + val discontinueddate: OptField[TypoLocalDateTime, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PViewFields extends PViewStructure[PViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepo.scala new file mode 100644 index 0000000000..5b99d816ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package p + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PViewRepo { + def select: SelectBuilder[PViewFields, PViewRow] + def selectAll: ZStream[ZConnection, Throwable, PViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepoImpl.scala new file mode 100644 index 0000000000..db4fa302bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package p + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PViewRepoImpl extends PViewRepo { + override def select: SelectBuilder[PViewFields, PViewRow] = { + SelectBuilderSql("pr.p", PViewFields, PViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PViewRow] = { + sql"""select "id", "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text from pr.p""".query(PViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRow.scala new file mode 100644 index 0000000000..f9daba1c65 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewRow.scala @@ -0,0 +1,228 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PViewRow( + /** Points to [[production.product.ProductRow.productid]] */ + id: ProductId, + /** Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Points to [[production.product.ProductRow.name]] */ + name: Name, + /** Points to [[production.product.ProductRow.productnumber]] */ + productnumber: /* max 25 chars */ String, + /** Points to [[production.product.ProductRow.makeflag]] */ + makeflag: Flag, + /** Points to [[production.product.ProductRow.finishedgoodsflag]] */ + finishedgoodsflag: Flag, + /** Points to [[production.product.ProductRow.color]] */ + color: Option[/* max 15 chars */ String], + /** Points to [[production.product.ProductRow.safetystocklevel]] */ + safetystocklevel: TypoShort, + /** Points to [[production.product.ProductRow.reorderpoint]] */ + reorderpoint: TypoShort, + /** Points to [[production.product.ProductRow.standardcost]] */ + standardcost: BigDecimal, + /** Points to [[production.product.ProductRow.listprice]] */ + listprice: BigDecimal, + /** Points to [[production.product.ProductRow.size]] */ + size: Option[/* max 5 chars */ String], + /** Points to [[production.product.ProductRow.sizeunitmeasurecode]] */ + sizeunitmeasurecode: Option[UnitmeasureId], + /** Points to [[production.product.ProductRow.weightunitmeasurecode]] */ + weightunitmeasurecode: Option[UnitmeasureId], + /** Points to [[production.product.ProductRow.weight]] */ + weight: Option[BigDecimal], + /** Points to [[production.product.ProductRow.daystomanufacture]] */ + daystomanufacture: Int, + /** Points to [[production.product.ProductRow.productline]] */ + productline: Option[/* bpchar, max 2 chars */ String], + /** Points to [[production.product.ProductRow.class]] */ + `class`: Option[/* bpchar, max 2 chars */ String], + /** Points to [[production.product.ProductRow.style]] */ + style: Option[/* bpchar, max 2 chars */ String], + /** Points to [[production.product.ProductRow.productsubcategoryid]] */ + productsubcategoryid: Option[ProductsubcategoryId], + /** Points to [[production.product.ProductRow.productmodelid]] */ + productmodelid: Option[ProductmodelId], + /** Points to [[production.product.ProductRow.sellstartdate]] */ + sellstartdate: TypoLocalDateTime, + /** Points to [[production.product.ProductRow.sellenddate]] */ + sellenddate: Option[TypoLocalDateTime], + /** Points to [[production.product.ProductRow.discontinueddate]] */ + discontinueddate: Option[TypoLocalDateTime], + /** Points to [[production.product.ProductRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.product.ProductRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PViewRow] = new JdbcDecoder[PViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PViewRow) = + columIndex + 25 -> + PViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + productnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + makeflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + finishedgoodsflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + color = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + safetystocklevel = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + reorderpoint = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + standardcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 9, rs)._2, + listprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 10, rs)._2, + size = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + sizeunitmeasurecode = JdbcDecoder.optionDecoder(UnitmeasureId.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + weightunitmeasurecode = JdbcDecoder.optionDecoder(UnitmeasureId.jdbcDecoder).unsafeDecode(columIndex + 13, rs)._2, + weight = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 14, rs)._2, + daystomanufacture = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 15, rs)._2, + productline = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + `class` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + style = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + productsubcategoryid = JdbcDecoder.optionDecoder(ProductsubcategoryId.jdbcDecoder).unsafeDecode(columIndex + 19, rs)._2, + productmodelid = JdbcDecoder.optionDecoder(ProductmodelId.jdbcDecoder).unsafeDecode(columIndex + 20, rs)._2, + sellstartdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 21, rs)._2, + sellenddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 22, rs)._2, + discontinueddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 23, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 24, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 25, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productnumber = jsonObj.get("productnumber").toRight("Missing field 'productnumber'").flatMap(_.as(JsonDecoder.string)) + val makeflag = jsonObj.get("makeflag").toRight("Missing field 'makeflag'").flatMap(_.as(Flag.jsonDecoder)) + val finishedgoodsflag = jsonObj.get("finishedgoodsflag").toRight("Missing field 'finishedgoodsflag'").flatMap(_.as(Flag.jsonDecoder)) + val color = jsonObj.get("color").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val safetystocklevel = jsonObj.get("safetystocklevel").toRight("Missing field 'safetystocklevel'").flatMap(_.as(TypoShort.jsonDecoder)) + val reorderpoint = jsonObj.get("reorderpoint").toRight("Missing field 'reorderpoint'").flatMap(_.as(TypoShort.jsonDecoder)) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val size = jsonObj.get("size").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sizeunitmeasurecode = jsonObj.get("sizeunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weightunitmeasurecode = jsonObj.get("weightunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weight = jsonObj.get("weight").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val daystomanufacture = jsonObj.get("daystomanufacture").toRight("Missing field 'daystomanufacture'").flatMap(_.as(JsonDecoder.int)) + val productline = jsonObj.get("productline").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `class` = jsonObj.get("class").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val style = jsonObj.get("style").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productsubcategoryid = jsonObj.get("productsubcategoryid").fold[Either[String, Option[ProductsubcategoryId]]](Right(None))(_.as(JsonDecoder.option(ProductsubcategoryId.jsonDecoder))) + val productmodelid = jsonObj.get("productmodelid").fold[Either[String, Option[ProductmodelId]]](Right(None))(_.as(JsonDecoder.option(ProductmodelId.jsonDecoder))) + val sellstartdate = jsonObj.get("sellstartdate").toRight("Missing field 'sellstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val sellenddate = jsonObj.get("sellenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val discontinueddate = jsonObj.get("discontinueddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productid.isRight && name.isRight && productnumber.isRight && makeflag.isRight && finishedgoodsflag.isRight && color.isRight && safetystocklevel.isRight && reorderpoint.isRight && standardcost.isRight && listprice.isRight && size.isRight && sizeunitmeasurecode.isRight && weightunitmeasurecode.isRight && weight.isRight && daystomanufacture.isRight && productline.isRight && `class`.isRight && style.isRight && productsubcategoryid.isRight && productmodelid.isRight && sellstartdate.isRight && sellenddate.isRight && discontinueddate.isRight && rowguid.isRight && modifieddate.isRight) + Right(PViewRow(id = id.toOption.get, productid = productid.toOption.get, name = name.toOption.get, productnumber = productnumber.toOption.get, makeflag = makeflag.toOption.get, finishedgoodsflag = finishedgoodsflag.toOption.get, color = color.toOption.get, safetystocklevel = safetystocklevel.toOption.get, reorderpoint = reorderpoint.toOption.get, standardcost = standardcost.toOption.get, listprice = listprice.toOption.get, size = size.toOption.get, sizeunitmeasurecode = sizeunitmeasurecode.toOption.get, weightunitmeasurecode = weightunitmeasurecode.toOption.get, weight = weight.toOption.get, daystomanufacture = daystomanufacture.toOption.get, productline = productline.toOption.get, `class` = `class`.toOption.get, style = style.toOption.get, productsubcategoryid = productsubcategoryid.toOption.get, productmodelid = productmodelid.toOption.get, sellstartdate = sellstartdate.toOption.get, sellenddate = sellenddate.toOption.get, discontinueddate = discontinueddate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productid, name, productnumber, makeflag, finishedgoodsflag, color, safetystocklevel, reorderpoint, standardcost, listprice, size, sizeunitmeasurecode, weightunitmeasurecode, weight, daystomanufacture, productline, `class`, style, productsubcategoryid, productmodelid, sellstartdate, sellenddate, discontinueddate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PViewRow] = new JsonEncoder[PViewRow] { + override def unsafeEncode(a: PViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productnumber":""") + JsonEncoder.string.unsafeEncode(a.productnumber, indent, out) + out.write(",") + out.write(""""makeflag":""") + Flag.jsonEncoder.unsafeEncode(a.makeflag, indent, out) + out.write(",") + out.write(""""finishedgoodsflag":""") + Flag.jsonEncoder.unsafeEncode(a.finishedgoodsflag, indent, out) + out.write(",") + out.write(""""color":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.color, indent, out) + out.write(",") + out.write(""""safetystocklevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.safetystocklevel, indent, out) + out.write(",") + out.write(""""reorderpoint":""") + TypoShort.jsonEncoder.unsafeEncode(a.reorderpoint, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""size":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.size, indent, out) + out.write(",") + out.write(""""sizeunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.sizeunitmeasurecode, indent, out) + out.write(",") + out.write(""""weightunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.weightunitmeasurecode, indent, out) + out.write(",") + out.write(""""weight":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.weight, indent, out) + out.write(",") + out.write(""""daystomanufacture":""") + JsonEncoder.int.unsafeEncode(a.daystomanufacture, indent, out) + out.write(",") + out.write(""""productline":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.productline, indent, out) + out.write(",") + out.write(""""class":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`class`, indent, out) + out.write(",") + out.write(""""style":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.style, indent, out) + out.write(",") + out.write(""""productsubcategoryid":""") + JsonEncoder.option(ProductsubcategoryId.jsonEncoder).unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""productmodelid":""") + JsonEncoder.option(ProductmodelId.jsonEncoder).unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""sellstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.sellstartdate, indent, out) + out.write(",") + out.write(""""sellenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.sellenddate, indent, out) + out.write(",") + out.write(""""discontinueddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.discontinueddate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewStructure.scala new file mode 100644 index 0000000000..b249873603 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/p/PViewStructure.scala @@ -0,0 +1,60 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package p + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PViewStructure[Row](val prefix: Option[String], val extract: Row => PViewRow, val merge: (Row, PViewRow) => Row) + extends Relation[PViewFields, PViewRow, Row] + with PViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val productnumber = new Field[/* max 25 chars */ String, Row](prefix, "productnumber", None, None)(x => extract(x).productnumber, (row, value) => merge(row, extract(row).copy(productnumber = value))) + override val makeflag = new Field[Flag, Row](prefix, "makeflag", None, None)(x => extract(x).makeflag, (row, value) => merge(row, extract(row).copy(makeflag = value))) + override val finishedgoodsflag = new Field[Flag, Row](prefix, "finishedgoodsflag", None, None)(x => extract(x).finishedgoodsflag, (row, value) => merge(row, extract(row).copy(finishedgoodsflag = value))) + override val color = new OptField[/* max 15 chars */ String, Row](prefix, "color", None, None)(x => extract(x).color, (row, value) => merge(row, extract(row).copy(color = value))) + override val safetystocklevel = new Field[TypoShort, Row](prefix, "safetystocklevel", None, None)(x => extract(x).safetystocklevel, (row, value) => merge(row, extract(row).copy(safetystocklevel = value))) + override val reorderpoint = new Field[TypoShort, Row](prefix, "reorderpoint", None, None)(x => extract(x).reorderpoint, (row, value) => merge(row, extract(row).copy(reorderpoint = value))) + override val standardcost = new Field[BigDecimal, Row](prefix, "standardcost", None, None)(x => extract(x).standardcost, (row, value) => merge(row, extract(row).copy(standardcost = value))) + override val listprice = new Field[BigDecimal, Row](prefix, "listprice", None, None)(x => extract(x).listprice, (row, value) => merge(row, extract(row).copy(listprice = value))) + override val size = new OptField[/* max 5 chars */ String, Row](prefix, "size", None, None)(x => extract(x).size, (row, value) => merge(row, extract(row).copy(size = value))) + override val sizeunitmeasurecode = new OptField[UnitmeasureId, Row](prefix, "sizeunitmeasurecode", None, None)(x => extract(x).sizeunitmeasurecode, (row, value) => merge(row, extract(row).copy(sizeunitmeasurecode = value))) + override val weightunitmeasurecode = new OptField[UnitmeasureId, Row](prefix, "weightunitmeasurecode", None, None)(x => extract(x).weightunitmeasurecode, (row, value) => merge(row, extract(row).copy(weightunitmeasurecode = value))) + override val weight = new OptField[BigDecimal, Row](prefix, "weight", None, None)(x => extract(x).weight, (row, value) => merge(row, extract(row).copy(weight = value))) + override val daystomanufacture = new Field[Int, Row](prefix, "daystomanufacture", None, None)(x => extract(x).daystomanufacture, (row, value) => merge(row, extract(row).copy(daystomanufacture = value))) + override val productline = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "productline", None, None)(x => extract(x).productline, (row, value) => merge(row, extract(row).copy(productline = value))) + override val `class` = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "class", None, None)(x => extract(x).`class`, (row, value) => merge(row, extract(row).copy(`class` = value))) + override val style = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "style", None, None)(x => extract(x).style, (row, value) => merge(row, extract(row).copy(style = value))) + override val productsubcategoryid = new OptField[ProductsubcategoryId, Row](prefix, "productsubcategoryid", None, None)(x => extract(x).productsubcategoryid, (row, value) => merge(row, extract(row).copy(productsubcategoryid = value))) + override val productmodelid = new OptField[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val sellstartdate = new Field[TypoLocalDateTime, Row](prefix, "sellstartdate", Some("text"), None)(x => extract(x).sellstartdate, (row, value) => merge(row, extract(row).copy(sellstartdate = value))) + override val sellenddate = new OptField[TypoLocalDateTime, Row](prefix, "sellenddate", Some("text"), None)(x => extract(x).sellenddate, (row, value) => merge(row, extract(row).copy(sellenddate = value))) + override val discontinueddate = new OptField[TypoLocalDateTime, Row](prefix, "discontinueddate", Some("text"), None)(x => extract(x).discontinueddate, (row, value) => merge(row, extract(row).copy(discontinueddate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, name, productnumber, makeflag, finishedgoodsflag, color, safetystocklevel, reorderpoint, standardcost, listprice, size, sizeunitmeasurecode, weightunitmeasurecode, weight, daystomanufacture, productline, `class`, style, productsubcategoryid, productmodelid, sellstartdate, sellenddate, discontinueddate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PViewRow, merge: (NewRow, PViewRow) => NewRow): PViewStructure[NewRow] = + new PViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewFields.scala new file mode 100644 index 0000000000..f9a40218a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait PcViewFields[Row] { + val id: Field[ProductcategoryId, Row] + val productcategoryid: Field[ProductcategoryId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PcViewFields extends PcViewStructure[PcViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepo.scala new file mode 100644 index 0000000000..b498f29ee8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PcViewRepo { + def select: SelectBuilder[PcViewFields, PcViewRow] + def selectAll: ZStream[ZConnection, Throwable, PcViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepoImpl.scala new file mode 100644 index 0000000000..a653d77c73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PcViewRepoImpl extends PcViewRepo { + override def select: SelectBuilder[PcViewFields, PcViewRow] = { + SelectBuilderSql("pr.pc", PcViewFields, PcViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PcViewRow] = { + sql"""select "id", "productcategoryid", "name", "rowguid", "modifieddate"::text from pr.pc""".query(PcViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRow.scala new file mode 100644 index 0000000000..d2bb4ea1a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PcViewRow( + /** Points to [[production.productcategory.ProductcategoryRow.productcategoryid]] */ + id: ProductcategoryId, + /** Points to [[production.productcategory.ProductcategoryRow.productcategoryid]] */ + productcategoryid: ProductcategoryId, + /** Points to [[production.productcategory.ProductcategoryRow.name]] */ + name: Name, + /** Points to [[production.productcategory.ProductcategoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.productcategory.ProductcategoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PcViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PcViewRow] = new JdbcDecoder[PcViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PcViewRow) = + columIndex + 4 -> + PcViewRow( + id = ProductcategoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productcategoryid = ProductcategoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PcViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productcategoryid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(PcViewRow(id = id.toOption.get, productcategoryid = productcategoryid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productcategoryid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PcViewRow] = new JsonEncoder[PcViewRow] { + override def unsafeEncode(a: PcViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productcategoryid":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewStructure.scala new file mode 100644 index 0000000000..8e7f82241e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pc/PcViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PcViewStructure[Row](val prefix: Option[String], val extract: Row => PcViewRow, val merge: (Row, PcViewRow) => Row) + extends Relation[PcViewFields, PcViewRow, Row] + with PcViewFields[Row] { outer => + + override val id = new Field[ProductcategoryId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productcategoryid = new Field[ProductcategoryId, Row](prefix, "productcategoryid", None, None)(x => extract(x).productcategoryid, (row, value) => merge(row, extract(row).copy(productcategoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productcategoryid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PcViewRow, merge: (NewRow, PcViewRow) => NewRow): PcViewStructure[NewRow] = + new PcViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewFields.scala new file mode 100644 index 0000000000..01456464b1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pch + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PchViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val standardcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PchViewFields extends PchViewStructure[PchViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepo.scala new file mode 100644 index 0000000000..1507e6f5f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pch + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PchViewRepo { + def select: SelectBuilder[PchViewFields, PchViewRow] + def selectAll: ZStream[ZConnection, Throwable, PchViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepoImpl.scala new file mode 100644 index 0000000000..92fed01647 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pch + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PchViewRepoImpl extends PchViewRepo { + override def select: SelectBuilder[PchViewFields, PchViewRow] = { + SelectBuilderSql("pr.pch", PchViewFields, PchViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PchViewRow] = { + sql"""select "id", "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text from pr.pch""".query(PchViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRow.scala new file mode 100644 index 0000000000..9bcb2db816 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pch + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PchViewRow( + /** Points to [[production.productcosthistory.ProductcosthistoryRow.productid]] */ + id: ProductId, + /** Points to [[production.productcosthistory.ProductcosthistoryRow.productid]] */ + productid: ProductId, + /** Points to [[production.productcosthistory.ProductcosthistoryRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[production.productcosthistory.ProductcosthistoryRow.enddate]] */ + enddate: Option[TypoLocalDateTime], + /** Points to [[production.productcosthistory.ProductcosthistoryRow.standardcost]] */ + standardcost: BigDecimal, + /** Points to [[production.productcosthistory.ProductcosthistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PchViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PchViewRow] = new JdbcDecoder[PchViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PchViewRow) = + columIndex + 5 -> + PchViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + standardcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PchViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productid.isRight && startdate.isRight && enddate.isRight && standardcost.isRight && modifieddate.isRight) + Right(PchViewRow(id = id.toOption.get, productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, standardcost = standardcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productid, startdate, enddate, standardcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PchViewRow] = new JsonEncoder[PchViewRow] { + override def unsafeEncode(a: PchViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewStructure.scala new file mode 100644 index 0000000000..6d321e3d13 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pch/PchViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pch + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PchViewStructure[Row](val prefix: Option[String], val extract: Row => PchViewRow, val merge: (Row, PchViewRow) => Row) + extends Relation[PchViewFields, PchViewRow, Row] + with PchViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val standardcost = new Field[BigDecimal, Row](prefix, "standardcost", None, None)(x => extract(x).standardcost, (row, value) => merge(row, extract(row).copy(standardcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, startdate, enddate, standardcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PchViewRow, merge: (NewRow, PchViewRow) => NewRow): PchViewStructure[NewRow] = + new PchViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewFields.scala new file mode 100644 index 0000000000..19d97f3f8f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pd + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productdescription.ProductdescriptionId +import typo.dsl.SqlExpr.Field + +trait PdViewFields[Row] { + val id: Field[ProductdescriptionId, Row] + val productdescriptionid: Field[ProductdescriptionId, Row] + val description: Field[/* max 400 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PdViewFields extends PdViewStructure[PdViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepo.scala new file mode 100644 index 0000000000..4492e445dd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pd + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PdViewRepo { + def select: SelectBuilder[PdViewFields, PdViewRow] + def selectAll: ZStream[ZConnection, Throwable, PdViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepoImpl.scala new file mode 100644 index 0000000000..de450b5f52 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pd + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PdViewRepoImpl extends PdViewRepo { + override def select: SelectBuilder[PdViewFields, PdViewRow] = { + SelectBuilderSql("pr.pd", PdViewFields, PdViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PdViewRow] = { + sql"""select "id", "productdescriptionid", "description", "rowguid", "modifieddate"::text from pr.pd""".query(PdViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRow.scala new file mode 100644 index 0000000000..47b0c10ba0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pd + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productdescription.ProductdescriptionId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PdViewRow( + /** Points to [[production.productdescription.ProductdescriptionRow.productdescriptionid]] */ + id: ProductdescriptionId, + /** Points to [[production.productdescription.ProductdescriptionRow.productdescriptionid]] */ + productdescriptionid: ProductdescriptionId, + /** Points to [[production.productdescription.ProductdescriptionRow.description]] */ + description: /* max 400 chars */ String, + /** Points to [[production.productdescription.ProductdescriptionRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.productdescription.ProductdescriptionRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PdViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PdViewRow] = new JdbcDecoder[PdViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PdViewRow) = + columIndex + 4 -> + PdViewRow( + id = ProductdescriptionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productdescriptionid = ProductdescriptionId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PdViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productdescriptionid.isRight && description.isRight && rowguid.isRight && modifieddate.isRight) + Right(PdViewRow(id = id.toOption.get, productdescriptionid = productdescriptionid.toOption.get, description = description.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productdescriptionid, description, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PdViewRow] = new JsonEncoder[PdViewRow] { + override def unsafeEncode(a: PdViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewStructure.scala new file mode 100644 index 0000000000..a98b8bb146 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pd/PdViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pd + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productdescription.ProductdescriptionId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PdViewStructure[Row](val prefix: Option[String], val extract: Row => PdViewRow, val merge: (Row, PdViewRow) => Row) + extends Relation[PdViewFields, PdViewRow, Row] + with PdViewFields[Row] { outer => + + override val id = new Field[ProductdescriptionId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productdescriptionid = new Field[ProductdescriptionId, Row](prefix, "productdescriptionid", None, None)(x => extract(x).productdescriptionid, (row, value) => merge(row, extract(row).copy(productdescriptionid = value))) + override val description = new Field[/* max 400 chars */ String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productdescriptionid, description, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PdViewRow, merge: (NewRow, PdViewRow) => NewRow): PdViewStructure[NewRow] = + new PdViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewFields.scala new file mode 100644 index 0000000000..25cb9b3ba6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pdoc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field + +trait PdocViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val documentnode: Field[DocumentId, Row] +} +object PdocViewFields extends PdocViewStructure[PdocViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepo.scala new file mode 100644 index 0000000000..c3fcc0c619 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pdoc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PdocViewRepo { + def select: SelectBuilder[PdocViewFields, PdocViewRow] + def selectAll: ZStream[ZConnection, Throwable, PdocViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepoImpl.scala new file mode 100644 index 0000000000..c5141f0bd5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pdoc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PdocViewRepoImpl extends PdocViewRepo { + override def select: SelectBuilder[PdocViewFields, PdocViewRow] = { + SelectBuilderSql("pr.pdoc", PdocViewFields, PdocViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PdocViewRow] = { + sql"""select "id", "productid", "modifieddate"::text, "documentnode" from pr.pdoc""".query(PdocViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRow.scala new file mode 100644 index 0000000000..bee124e956 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pdoc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PdocViewRow( + /** Points to [[production.productdocument.ProductdocumentRow.productid]] */ + id: ProductId, + /** Points to [[production.productdocument.ProductdocumentRow.productid]] */ + productid: ProductId, + /** Points to [[production.productdocument.ProductdocumentRow.modifieddate]] */ + modifieddate: TypoLocalDateTime, + /** Points to [[production.productdocument.ProductdocumentRow.documentnode]] */ + documentnode: DocumentId +) + +object PdocViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PdocViewRow] = new JdbcDecoder[PdocViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PdocViewRow) = + columIndex + 3 -> + PdocViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + documentnode = DocumentId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PdocViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(DocumentId.jsonDecoder)) + if (id.isRight && productid.isRight && modifieddate.isRight && documentnode.isRight) + Right(PdocViewRow(id = id.toOption.get, productid = productid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](id, productid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PdocViewRow] = new JsonEncoder[PdocViewRow] { + override def unsafeEncode(a: PdocViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + DocumentId.jsonEncoder.unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewStructure.scala new file mode 100644 index 0000000000..6769d2541e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pdoc/PdocViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pdoc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PdocViewStructure[Row](val prefix: Option[String], val extract: Row => PdocViewRow, val merge: (Row, PdocViewRow) => Row) + extends Relation[PdocViewFields, PdocViewRow, Row] + with PdocViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val documentnode = new Field[DocumentId, Row](prefix, "documentnode", None, None)(x => extract(x).documentnode, (row, value) => merge(row, extract(row).copy(documentnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, modifieddate, documentnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PdocViewRow, merge: (NewRow, PdocViewRow) => NewRow): PdocViewStructure[NewRow] = + new PdocViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewFields.scala new file mode 100644 index 0000000000..5a54d4bb67 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field + +trait PiViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val locationid: Field[LocationId, Row] + val shelf: Field[/* max 10 chars */ String, Row] + val bin: Field[TypoShort, Row] + val quantity: Field[TypoShort, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PiViewFields extends PiViewStructure[PiViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepo.scala new file mode 100644 index 0000000000..bd34f38832 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pi + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PiViewRepo { + def select: SelectBuilder[PiViewFields, PiViewRow] + def selectAll: ZStream[ZConnection, Throwable, PiViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepoImpl.scala new file mode 100644 index 0000000000..397ae179ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pi + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PiViewRepoImpl extends PiViewRepo { + override def select: SelectBuilder[PiViewFields, PiViewRow] = { + SelectBuilderSql("pr.pi", PiViewFields, PiViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PiViewRow] = { + sql"""select "id", "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text from pr.pi""".query(PiViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRow.scala new file mode 100644 index 0000000000..7f5d9b3e45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewRow.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PiViewRow( + /** Points to [[production.productinventory.ProductinventoryRow.productid]] */ + id: ProductId, + /** Points to [[production.productinventory.ProductinventoryRow.productid]] */ + productid: ProductId, + /** Points to [[production.productinventory.ProductinventoryRow.locationid]] */ + locationid: LocationId, + /** Points to [[production.productinventory.ProductinventoryRow.shelf]] */ + shelf: /* max 10 chars */ String, + /** Points to [[production.productinventory.ProductinventoryRow.bin]] */ + bin: TypoShort, + /** Points to [[production.productinventory.ProductinventoryRow.quantity]] */ + quantity: TypoShort, + /** Points to [[production.productinventory.ProductinventoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.productinventory.ProductinventoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PiViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PiViewRow] = new JdbcDecoder[PiViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PiViewRow) = + columIndex + 7 -> + PiViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + shelf = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + bin = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + quantity = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PiViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val shelf = jsonObj.get("shelf").toRight("Missing field 'shelf'").flatMap(_.as(JsonDecoder.string)) + val bin = jsonObj.get("bin").toRight("Missing field 'bin'").flatMap(_.as(TypoShort.jsonDecoder)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(TypoShort.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productid.isRight && locationid.isRight && shelf.isRight && bin.isRight && quantity.isRight && rowguid.isRight && modifieddate.isRight) + Right(PiViewRow(id = id.toOption.get, productid = productid.toOption.get, locationid = locationid.toOption.get, shelf = shelf.toOption.get, bin = bin.toOption.get, quantity = quantity.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productid, locationid, shelf, bin, quantity, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PiViewRow] = new JsonEncoder[PiViewRow] { + override def unsafeEncode(a: PiViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""shelf":""") + JsonEncoder.string.unsafeEncode(a.shelf, indent, out) + out.write(",") + out.write(""""bin":""") + TypoShort.jsonEncoder.unsafeEncode(a.bin, indent, out) + out.write(",") + out.write(""""quantity":""") + TypoShort.jsonEncoder.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewStructure.scala new file mode 100644 index 0000000000..dcebe88794 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pi/PiViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PiViewStructure[Row](val prefix: Option[String], val extract: Row => PiViewRow, val merge: (Row, PiViewRow) => Row) + extends Relation[PiViewFields, PiViewRow, Row] + with PiViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val locationid = new Field[LocationId, Row](prefix, "locationid", None, None)(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val shelf = new Field[/* max 10 chars */ String, Row](prefix, "shelf", None, None)(x => extract(x).shelf, (row, value) => merge(row, extract(row).copy(shelf = value))) + override val bin = new Field[TypoShort, Row](prefix, "bin", None, None)(x => extract(x).bin, (row, value) => merge(row, extract(row).copy(bin = value))) + override val quantity = new Field[TypoShort, Row](prefix, "quantity", None, None)(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, locationid, shelf, bin, quantity, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PiViewRow, merge: (NewRow, PiViewRow) => NewRow): PiViewStructure[NewRow] = + new PiViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewFields.scala new file mode 100644 index 0000000000..f43dea551c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package plph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PlphViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val listprice: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PlphViewFields extends PlphViewStructure[PlphViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepo.scala new file mode 100644 index 0000000000..95d16d8743 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package plph + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PlphViewRepo { + def select: SelectBuilder[PlphViewFields, PlphViewRow] + def selectAll: ZStream[ZConnection, Throwable, PlphViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepoImpl.scala new file mode 100644 index 0000000000..32368a9827 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package plph + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PlphViewRepoImpl extends PlphViewRepo { + override def select: SelectBuilder[PlphViewFields, PlphViewRow] = { + SelectBuilderSql("pr.plph", PlphViewFields, PlphViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PlphViewRow] = { + sql"""select "id", "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text from pr.plph""".query(PlphViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRow.scala new file mode 100644 index 0000000000..bec0932718 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package plph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PlphViewRow( + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.productid]] */ + id: ProductId, + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.productid]] */ + productid: ProductId, + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.enddate]] */ + enddate: Option[TypoLocalDateTime], + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.listprice]] */ + listprice: BigDecimal, + /** Points to [[production.productlistpricehistory.ProductlistpricehistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PlphViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PlphViewRow] = new JdbcDecoder[PlphViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PlphViewRow) = + columIndex + 5 -> + PlphViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + listprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PlphViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productid.isRight && startdate.isRight && enddate.isRight && listprice.isRight && modifieddate.isRight) + Right(PlphViewRow(id = id.toOption.get, productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, listprice = listprice.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productid, startdate, enddate, listprice, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PlphViewRow] = new JsonEncoder[PlphViewRow] { + override def unsafeEncode(a: PlphViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewStructure.scala new file mode 100644 index 0000000000..feed6246a5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/plph/PlphViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package plph + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PlphViewStructure[Row](val prefix: Option[String], val extract: Row => PlphViewRow, val merge: (Row, PlphViewRow) => Row) + extends Relation[PlphViewFields, PlphViewRow, Row] + with PlphViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val listprice = new Field[BigDecimal, Row](prefix, "listprice", None, None)(x => extract(x).listprice, (row, value) => merge(row, extract(row).copy(listprice = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, startdate, enddate, listprice, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PlphViewRow, merge: (NewRow, PlphViewRow) => NewRow): PlphViewStructure[NewRow] = + new PlphViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewFields.scala new file mode 100644 index 0000000000..b06665c868 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PmViewFields[Row] { + val id: Field[ProductmodelId, Row] + val productmodelid: Field[ProductmodelId, Row] + val name: Field[Name, Row] + val catalogdescription: OptField[TypoXml, Row] + val instructions: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PmViewFields extends PmViewStructure[PmViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepo.scala new file mode 100644 index 0000000000..740a8a0b5b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pm + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PmViewRepo { + def select: SelectBuilder[PmViewFields, PmViewRow] + def selectAll: ZStream[ZConnection, Throwable, PmViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepoImpl.scala new file mode 100644 index 0000000000..84ddbbca8f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pm + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PmViewRepoImpl extends PmViewRepo { + override def select: SelectBuilder[PmViewFields, PmViewRow] = { + SelectBuilderSql("pr.pm", PmViewFields, PmViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PmViewRow] = { + sql"""select "id", "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text from pr.pm""".query(PmViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRow.scala new file mode 100644 index 0000000000..b3c5af6b96 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PmViewRow( + /** Points to [[production.productmodel.ProductmodelRow.productmodelid]] */ + id: ProductmodelId, + /** Points to [[production.productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Points to [[production.productmodel.ProductmodelRow.name]] */ + name: Name, + /** Points to [[production.productmodel.ProductmodelRow.catalogdescription]] */ + catalogdescription: Option[TypoXml], + /** Points to [[production.productmodel.ProductmodelRow.instructions]] */ + instructions: Option[TypoXml], + /** Points to [[production.productmodel.ProductmodelRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.productmodel.ProductmodelRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PmViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PmViewRow] = new JdbcDecoder[PmViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PmViewRow) = + columIndex + 6 -> + PmViewRow( + id = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + catalogdescription = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + instructions = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PmViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val catalogdescription = jsonObj.get("catalogdescription").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val instructions = jsonObj.get("instructions").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productmodelid.isRight && name.isRight && catalogdescription.isRight && instructions.isRight && rowguid.isRight && modifieddate.isRight) + Right(PmViewRow(id = id.toOption.get, productmodelid = productmodelid.toOption.get, name = name.toOption.get, catalogdescription = catalogdescription.toOption.get, instructions = instructions.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productmodelid, name, catalogdescription, instructions, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PmViewRow] = new JsonEncoder[PmViewRow] { + override def unsafeEncode(a: PmViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""catalogdescription":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.catalogdescription, indent, out) + out.write(",") + out.write(""""instructions":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.instructions, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewStructure.scala new file mode 100644 index 0000000000..3197df10d2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pm/PmViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PmViewStructure[Row](val prefix: Option[String], val extract: Row => PmViewRow, val merge: (Row, PmViewRow) => Row) + extends Relation[PmViewFields, PmViewRow, Row] + with PmViewFields[Row] { outer => + + override val id = new Field[ProductmodelId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productmodelid = new Field[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val catalogdescription = new OptField[TypoXml, Row](prefix, "catalogdescription", None, None)(x => extract(x).catalogdescription, (row, value) => merge(row, extract(row).copy(catalogdescription = value))) + override val instructions = new OptField[TypoXml, Row](prefix, "instructions", None, None)(x => extract(x).instructions, (row, value) => merge(row, extract(row).copy(instructions = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productmodelid, name, catalogdescription, instructions, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PmViewRow, merge: (NewRow, PmViewRow) => NewRow): PmViewStructure[NewRow] = + new PmViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewFields.scala new file mode 100644 index 0000000000..2d29d5ad64 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field + +trait PmiViewFields[Row] { + val productmodelid: Field[ProductmodelId, Row] + val illustrationid: Field[IllustrationId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PmiViewFields extends PmiViewStructure[PmiViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepo.scala new file mode 100644 index 0000000000..011e97e1df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmi + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PmiViewRepo { + def select: SelectBuilder[PmiViewFields, PmiViewRow] + def selectAll: ZStream[ZConnection, Throwable, PmiViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepoImpl.scala new file mode 100644 index 0000000000..c3da3bc22c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmi + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PmiViewRepoImpl extends PmiViewRepo { + override def select: SelectBuilder[PmiViewFields, PmiViewRow] = { + SelectBuilderSql("pr.pmi", PmiViewFields, PmiViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PmiViewRow] = { + sql"""select "productmodelid", "illustrationid", "modifieddate"::text from pr.pmi""".query(PmiViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRow.scala new file mode 100644 index 0000000000..61965b1485 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PmiViewRow( + /** Points to [[production.productmodelillustration.ProductmodelillustrationRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Points to [[production.productmodelillustration.ProductmodelillustrationRow.illustrationid]] */ + illustrationid: IllustrationId, + /** Points to [[production.productmodelillustration.ProductmodelillustrationRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PmiViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PmiViewRow] = new JdbcDecoder[PmiViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PmiViewRow) = + columIndex + 2 -> + PmiViewRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + illustrationid = IllustrationId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PmiViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && illustrationid.isRight && modifieddate.isRight) + Right(PmiViewRow(productmodelid = productmodelid.toOption.get, illustrationid = illustrationid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, illustrationid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PmiViewRow] = new JsonEncoder[PmiViewRow] { + override def unsafeEncode(a: PmiViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewStructure.scala new file mode 100644 index 0000000000..03c692bb06 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmi/PmiViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmi + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PmiViewStructure[Row](val prefix: Option[String], val extract: Row => PmiViewRow, val merge: (Row, PmiViewRow) => Row) + extends Relation[PmiViewFields, PmiViewRow, Row] + with PmiViewFields[Row] { outer => + + override val productmodelid = new Field[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val illustrationid = new Field[IllustrationId, Row](prefix, "illustrationid", None, None)(x => extract(x).illustrationid, (row, value) => merge(row, extract(row).copy(illustrationid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, illustrationid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PmiViewRow, merge: (NewRow, PmiViewRow) => NewRow): PmiViewStructure[NewRow] = + new PmiViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewFields.scala new file mode 100644 index 0000000000..ab1d72e3bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmpdc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field + +trait PmpdcViewFields[Row] { + val productmodelid: Field[ProductmodelId, Row] + val productdescriptionid: Field[ProductdescriptionId, Row] + val cultureid: Field[CultureId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PmpdcViewFields extends PmpdcViewStructure[PmpdcViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepo.scala new file mode 100644 index 0000000000..26fd045f6b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmpdc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PmpdcViewRepo { + def select: SelectBuilder[PmpdcViewFields, PmpdcViewRow] + def selectAll: ZStream[ZConnection, Throwable, PmpdcViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepoImpl.scala new file mode 100644 index 0000000000..bbdee40e73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmpdc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PmpdcViewRepoImpl extends PmpdcViewRepo { + override def select: SelectBuilder[PmpdcViewFields, PmpdcViewRow] = { + SelectBuilderSql("pr.pmpdc", PmpdcViewFields, PmpdcViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PmpdcViewRow] = { + sql"""select "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text from pr.pmpdc""".query(PmpdcViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRow.scala new file mode 100644 index 0000000000..6a719916c9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewRow.scala @@ -0,0 +1,69 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmpdc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PmpdcViewRow( + /** Points to [[production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Points to [[production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow.productdescriptionid]] */ + productdescriptionid: ProductdescriptionId, + /** Points to [[production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow.cultureid]] */ + cultureid: CultureId, + /** Points to [[production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PmpdcViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PmpdcViewRow] = new JdbcDecoder[PmpdcViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PmpdcViewRow) = + columIndex + 3 -> + PmpdcViewRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productdescriptionid = ProductdescriptionId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + cultureid = CultureId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PmpdcViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && productdescriptionid.isRight && cultureid.isRight && modifieddate.isRight) + Right(PmpdcViewRow(productmodelid = productmodelid.toOption.get, productdescriptionid = productdescriptionid.toOption.get, cultureid = cultureid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, productdescriptionid, cultureid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PmpdcViewRow] = new JsonEncoder[PmpdcViewRow] { + override def unsafeEncode(a: PmpdcViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewStructure.scala new file mode 100644 index 0000000000..a96593a81b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pmpdc/PmpdcViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pmpdc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PmpdcViewStructure[Row](val prefix: Option[String], val extract: Row => PmpdcViewRow, val merge: (Row, PmpdcViewRow) => Row) + extends Relation[PmpdcViewFields, PmpdcViewRow, Row] + with PmpdcViewFields[Row] { outer => + + override val productmodelid = new Field[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val productdescriptionid = new Field[ProductdescriptionId, Row](prefix, "productdescriptionid", None, None)(x => extract(x).productdescriptionid, (row, value) => merge(row, extract(row).copy(productdescriptionid = value))) + override val cultureid = new Field[CultureId, Row](prefix, "cultureid", None, None)(x => extract(x).cultureid, (row, value) => merge(row, extract(row).copy(cultureid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, productdescriptionid, cultureid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PmpdcViewRow, merge: (NewRow, PmpdcViewRow) => NewRow): PmpdcViewStructure[NewRow] = + new PmpdcViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewFields.scala new file mode 100644 index 0000000000..50c9cbab5b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pp + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.productphoto.ProductphotoId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PpViewFields[Row] { + val id: Field[ProductphotoId, Row] + val productphotoid: Field[ProductphotoId, Row] + val thumbnailphoto: OptField[TypoBytea, Row] + val thumbnailphotofilename: OptField[/* max 50 chars */ String, Row] + val largephoto: OptField[TypoBytea, Row] + val largephotofilename: OptField[/* max 50 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PpViewFields extends PpViewStructure[PpViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepo.scala new file mode 100644 index 0000000000..038ea9f3ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pp + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PpViewRepo { + def select: SelectBuilder[PpViewFields, PpViewRow] + def selectAll: ZStream[ZConnection, Throwable, PpViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepoImpl.scala new file mode 100644 index 0000000000..855219bc45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pp + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PpViewRepoImpl extends PpViewRepo { + override def select: SelectBuilder[PpViewFields, PpViewRow] = { + SelectBuilderSql("pr.pp", PpViewFields, PpViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PpViewRow] = { + sql"""select "id", "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text from pr.pp""".query(PpViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRow.scala new file mode 100644 index 0000000000..706832fda5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pp + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.productphoto.ProductphotoId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PpViewRow( + /** Points to [[production.productphoto.ProductphotoRow.productphotoid]] */ + id: ProductphotoId, + /** Points to [[production.productphoto.ProductphotoRow.productphotoid]] */ + productphotoid: ProductphotoId, + /** Points to [[production.productphoto.ProductphotoRow.thumbnailphoto]] */ + thumbnailphoto: Option[TypoBytea], + /** Points to [[production.productphoto.ProductphotoRow.thumbnailphotofilename]] */ + thumbnailphotofilename: Option[/* max 50 chars */ String], + /** Points to [[production.productphoto.ProductphotoRow.largephoto]] */ + largephoto: Option[TypoBytea], + /** Points to [[production.productphoto.ProductphotoRow.largephotofilename]] */ + largephotofilename: Option[/* max 50 chars */ String], + /** Points to [[production.productphoto.ProductphotoRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PpViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PpViewRow] = new JdbcDecoder[PpViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PpViewRow) = + columIndex + 6 -> + PpViewRow( + id = ProductphotoId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productphotoid = ProductphotoId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + thumbnailphoto = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + thumbnailphotofilename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + largephoto = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + largephotofilename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PpViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val thumbnailphoto = jsonObj.get("thumbnailphoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val thumbnailphotofilename = jsonObj.get("thumbnailphotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val largephoto = jsonObj.get("largephoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val largephotofilename = jsonObj.get("largephotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productphotoid.isRight && thumbnailphoto.isRight && thumbnailphotofilename.isRight && largephoto.isRight && largephotofilename.isRight && modifieddate.isRight) + Right(PpViewRow(id = id.toOption.get, productphotoid = productphotoid.toOption.get, thumbnailphoto = thumbnailphoto.toOption.get, thumbnailphotofilename = thumbnailphotofilename.toOption.get, largephoto = largephoto.toOption.get, largephotofilename = largephotofilename.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productphotoid, thumbnailphoto, thumbnailphotofilename, largephoto, largephotofilename, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PpViewRow] = new JsonEncoder[PpViewRow] { + override def unsafeEncode(a: PpViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""thumbnailphoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.thumbnailphoto, indent, out) + out.write(",") + out.write(""""thumbnailphotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.thumbnailphotofilename, indent, out) + out.write(",") + out.write(""""largephoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.largephoto, indent, out) + out.write(",") + out.write(""""largephotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.largephotofilename, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewStructure.scala new file mode 100644 index 0000000000..2d84dc92fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pp/PpViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pp + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.productphoto.ProductphotoId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PpViewStructure[Row](val prefix: Option[String], val extract: Row => PpViewRow, val merge: (Row, PpViewRow) => Row) + extends Relation[PpViewFields, PpViewRow, Row] + with PpViewFields[Row] { outer => + + override val id = new Field[ProductphotoId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productphotoid = new Field[ProductphotoId, Row](prefix, "productphotoid", None, None)(x => extract(x).productphotoid, (row, value) => merge(row, extract(row).copy(productphotoid = value))) + override val thumbnailphoto = new OptField[TypoBytea, Row](prefix, "thumbnailphoto", None, None)(x => extract(x).thumbnailphoto, (row, value) => merge(row, extract(row).copy(thumbnailphoto = value))) + override val thumbnailphotofilename = new OptField[/* max 50 chars */ String, Row](prefix, "thumbnailphotofilename", None, None)(x => extract(x).thumbnailphotofilename, (row, value) => merge(row, extract(row).copy(thumbnailphotofilename = value))) + override val largephoto = new OptField[TypoBytea, Row](prefix, "largephoto", None, None)(x => extract(x).largephoto, (row, value) => merge(row, extract(row).copy(largephoto = value))) + override val largephotofilename = new OptField[/* max 50 chars */ String, Row](prefix, "largephotofilename", None, None)(x => extract(x).largephotofilename, (row, value) => merge(row, extract(row).copy(largephotofilename = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productphotoid, thumbnailphoto, thumbnailphotofilename, largephoto, largephotofilename, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PpViewRow, merge: (NewRow, PpViewRow) => NewRow): PpViewStructure[NewRow] = + new PpViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewFields.scala new file mode 100644 index 0000000000..c7d4a423a0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package ppp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field + +trait PppViewFields[Row] { + val productid: Field[ProductId, Row] + val productphotoid: Field[ProductphotoId, Row] + val primary: Field[Flag, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PppViewFields extends PppViewStructure[PppViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepo.scala new file mode 100644 index 0000000000..53f24e202a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package ppp + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PppViewRepo { + def select: SelectBuilder[PppViewFields, PppViewRow] + def selectAll: ZStream[ZConnection, Throwable, PppViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepoImpl.scala new file mode 100644 index 0000000000..f92547a0df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package ppp + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PppViewRepoImpl extends PppViewRepo { + override def select: SelectBuilder[PppViewFields, PppViewRow] = { + SelectBuilderSql("pr.ppp", PppViewFields, PppViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PppViewRow] = { + sql"""select "productid", "productphotoid", "primary", "modifieddate"::text from pr.ppp""".query(PppViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRow.scala new file mode 100644 index 0000000000..0859b0e7eb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewRow.scala @@ -0,0 +1,69 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package ppp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PppViewRow( + /** Points to [[production.productproductphoto.ProductproductphotoRow.productid]] */ + productid: ProductId, + /** Points to [[production.productproductphoto.ProductproductphotoRow.productphotoid]] */ + productphotoid: ProductphotoId, + /** Points to [[production.productproductphoto.ProductproductphotoRow.primary]] */ + primary: Flag, + /** Points to [[production.productproductphoto.ProductproductphotoRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PppViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PppViewRow] = new JdbcDecoder[PppViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PppViewRow) = + columIndex + 3 -> + PppViewRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productphotoid = ProductphotoId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + primary = Flag.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PppViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val primary = jsonObj.get("primary").toRight("Missing field 'primary'").flatMap(_.as(Flag.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && productphotoid.isRight && primary.isRight && modifieddate.isRight) + Right(PppViewRow(productid = productid.toOption.get, productphotoid = productphotoid.toOption.get, primary = primary.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, productphotoid, primary, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PppViewRow] = new JsonEncoder[PppViewRow] { + override def unsafeEncode(a: PppViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""primary":""") + Flag.jsonEncoder.unsafeEncode(a.primary, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewStructure.scala new file mode 100644 index 0000000000..146a003b99 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/ppp/PppViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package ppp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PppViewStructure[Row](val prefix: Option[String], val extract: Row => PppViewRow, val merge: (Row, PppViewRow) => Row) + extends Relation[PppViewFields, PppViewRow, Row] + with PppViewFields[Row] { outer => + + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val productphotoid = new Field[ProductphotoId, Row](prefix, "productphotoid", None, None)(x => extract(x).productphotoid, (row, value) => merge(row, extract(row).copy(productphotoid = value))) + override val primary = new Field[Flag, Row](prefix, "primary", None, None)(x => extract(x).primary, (row, value) => merge(row, extract(row).copy(primary = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, productphotoid, primary, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PppViewRow, merge: (NewRow, PppViewRow) => NewRow): PppViewStructure[NewRow] = + new PppViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewFields.scala new file mode 100644 index 0000000000..2114439bc5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productreview.ProductreviewId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PrViewFields[Row] { + val id: Field[ProductreviewId, Row] + val productreviewid: Field[ProductreviewId, Row] + val productid: Field[ProductId, Row] + val reviewername: Field[Name, Row] + val reviewdate: Field[TypoLocalDateTime, Row] + val emailaddress: Field[/* max 50 chars */ String, Row] + val rating: Field[Int, Row] + val comments: OptField[/* max 3850 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PrViewFields extends PrViewStructure[PrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepo.scala new file mode 100644 index 0000000000..3116cc7533 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PrViewRepo { + def select: SelectBuilder[PrViewFields, PrViewRow] + def selectAll: ZStream[ZConnection, Throwable, PrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepoImpl.scala new file mode 100644 index 0000000000..76c59731e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PrViewRepoImpl extends PrViewRepo { + override def select: SelectBuilder[PrViewFields, PrViewRow] = { + SelectBuilderSql("pr.pr", PrViewFields, PrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PrViewRow] = { + sql"""select "id", "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text from pr.pr""".query(PrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRow.scala new file mode 100644 index 0000000000..c576f0877d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewRow.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productreview.ProductreviewId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PrViewRow( + /** Points to [[production.productreview.ProductreviewRow.productreviewid]] */ + id: ProductreviewId, + /** Points to [[production.productreview.ProductreviewRow.productreviewid]] */ + productreviewid: ProductreviewId, + /** Points to [[production.productreview.ProductreviewRow.productid]] */ + productid: ProductId, + /** Points to [[production.productreview.ProductreviewRow.reviewername]] */ + reviewername: Name, + /** Points to [[production.productreview.ProductreviewRow.reviewdate]] */ + reviewdate: TypoLocalDateTime, + /** Points to [[production.productreview.ProductreviewRow.emailaddress]] */ + emailaddress: /* max 50 chars */ String, + /** Points to [[production.productreview.ProductreviewRow.rating]] */ + rating: Int, + /** Points to [[production.productreview.ProductreviewRow.comments]] */ + comments: Option[/* max 3850 chars */ String], + /** Points to [[production.productreview.ProductreviewRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PrViewRow] = new JdbcDecoder[PrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PrViewRow) = + columIndex + 8 -> + PrViewRow( + id = ProductreviewId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productreviewid = ProductreviewId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + reviewername = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + reviewdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + emailaddress = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + rating = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + comments = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductreviewId.jsonDecoder)) + val productreviewid = jsonObj.get("productreviewid").toRight("Missing field 'productreviewid'").flatMap(_.as(ProductreviewId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val reviewername = jsonObj.get("reviewername").toRight("Missing field 'reviewername'").flatMap(_.as(Name.jsonDecoder)) + val reviewdate = jsonObj.get("reviewdate").toRight("Missing field 'reviewdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val emailaddress = jsonObj.get("emailaddress").toRight("Missing field 'emailaddress'").flatMap(_.as(JsonDecoder.string)) + val rating = jsonObj.get("rating").toRight("Missing field 'rating'").flatMap(_.as(JsonDecoder.int)) + val comments = jsonObj.get("comments").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productreviewid.isRight && productid.isRight && reviewername.isRight && reviewdate.isRight && emailaddress.isRight && rating.isRight && comments.isRight && modifieddate.isRight) + Right(PrViewRow(id = id.toOption.get, productreviewid = productreviewid.toOption.get, productid = productid.toOption.get, reviewername = reviewername.toOption.get, reviewdate = reviewdate.toOption.get, emailaddress = emailaddress.toOption.get, rating = rating.toOption.get, comments = comments.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productreviewid, productid, reviewername, reviewdate, emailaddress, rating, comments, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PrViewRow] = new JsonEncoder[PrViewRow] { + override def unsafeEncode(a: PrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductreviewId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productreviewid":""") + ProductreviewId.jsonEncoder.unsafeEncode(a.productreviewid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""reviewername":""") + Name.jsonEncoder.unsafeEncode(a.reviewername, indent, out) + out.write(",") + out.write(""""reviewdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.reviewdate, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.string.unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""rating":""") + JsonEncoder.int.unsafeEncode(a.rating, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comments, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewStructure.scala new file mode 100644 index 0000000000..f0f8b095c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/pr/PrViewStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package pr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productreview.ProductreviewId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PrViewStructure[Row](val prefix: Option[String], val extract: Row => PrViewRow, val merge: (Row, PrViewRow) => Row) + extends Relation[PrViewFields, PrViewRow, Row] + with PrViewFields[Row] { outer => + + override val id = new Field[ProductreviewId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productreviewid = new Field[ProductreviewId, Row](prefix, "productreviewid", None, None)(x => extract(x).productreviewid, (row, value) => merge(row, extract(row).copy(productreviewid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val reviewername = new Field[Name, Row](prefix, "reviewername", None, None)(x => extract(x).reviewername, (row, value) => merge(row, extract(row).copy(reviewername = value))) + override val reviewdate = new Field[TypoLocalDateTime, Row](prefix, "reviewdate", Some("text"), None)(x => extract(x).reviewdate, (row, value) => merge(row, extract(row).copy(reviewdate = value))) + override val emailaddress = new Field[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val rating = new Field[Int, Row](prefix, "rating", None, None)(x => extract(x).rating, (row, value) => merge(row, extract(row).copy(rating = value))) + override val comments = new OptField[/* max 3850 chars */ String, Row](prefix, "comments", None, None)(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productreviewid, productid, reviewername, reviewdate, emailaddress, rating, comments, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PrViewRow, merge: (NewRow, PrViewRow) => NewRow): PrViewStructure[NewRow] = + new PrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewFields.scala new file mode 100644 index 0000000000..86ad4f55ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package psc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait PscViewFields[Row] { + val id: Field[ProductsubcategoryId, Row] + val productsubcategoryid: Field[ProductsubcategoryId, Row] + val productcategoryid: Field[ProductcategoryId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PscViewFields extends PscViewStructure[PscViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepo.scala new file mode 100644 index 0000000000..b29dd41726 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package psc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PscViewRepo { + def select: SelectBuilder[PscViewFields, PscViewRow] + def selectAll: ZStream[ZConnection, Throwable, PscViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepoImpl.scala new file mode 100644 index 0000000000..8559c94e27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package psc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PscViewRepoImpl extends PscViewRepo { + override def select: SelectBuilder[PscViewFields, PscViewRow] = { + SelectBuilderSql("pr.psc", PscViewFields, PscViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PscViewRow] = { + sql"""select "id", "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text from pr.psc""".query(PscViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRow.scala new file mode 100644 index 0000000000..bbc1a4dbf3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewRow.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package psc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PscViewRow( + /** Points to [[production.productsubcategory.ProductsubcategoryRow.productsubcategoryid]] */ + id: ProductsubcategoryId, + /** Points to [[production.productsubcategory.ProductsubcategoryRow.productsubcategoryid]] */ + productsubcategoryid: ProductsubcategoryId, + /** Points to [[production.productsubcategory.ProductsubcategoryRow.productcategoryid]] */ + productcategoryid: ProductcategoryId, + /** Points to [[production.productsubcategory.ProductsubcategoryRow.name]] */ + name: Name, + /** Points to [[production.productsubcategory.ProductsubcategoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[production.productsubcategory.ProductsubcategoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PscViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PscViewRow] = new JdbcDecoder[PscViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PscViewRow) = + columIndex + 5 -> + PscViewRow( + id = ProductsubcategoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productsubcategoryid = ProductsubcategoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productcategoryid = ProductcategoryId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PscViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductsubcategoryId.jsonDecoder)) + val productsubcategoryid = jsonObj.get("productsubcategoryid").toRight("Missing field 'productsubcategoryid'").flatMap(_.as(ProductsubcategoryId.jsonDecoder)) + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productsubcategoryid.isRight && productcategoryid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(PscViewRow(id = id.toOption.get, productsubcategoryid = productsubcategoryid.toOption.get, productcategoryid = productcategoryid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productsubcategoryid, productcategoryid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PscViewRow] = new JsonEncoder[PscViewRow] { + override def unsafeEncode(a: PscViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductsubcategoryId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productsubcategoryid":""") + ProductsubcategoryId.jsonEncoder.unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""productcategoryid":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewStructure.scala new file mode 100644 index 0000000000..136e30a01b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/psc/PscViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package psc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PscViewStructure[Row](val prefix: Option[String], val extract: Row => PscViewRow, val merge: (Row, PscViewRow) => Row) + extends Relation[PscViewFields, PscViewRow, Row] + with PscViewFields[Row] { outer => + + override val id = new Field[ProductsubcategoryId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productsubcategoryid = new Field[ProductsubcategoryId, Row](prefix, "productsubcategoryid", None, None)(x => extract(x).productsubcategoryid, (row, value) => merge(row, extract(row).copy(productsubcategoryid = value))) + override val productcategoryid = new Field[ProductcategoryId, Row](prefix, "productcategoryid", None, None)(x => extract(x).productcategoryid, (row, value) => merge(row, extract(row).copy(productcategoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productsubcategoryid, productcategoryid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PscViewRow, merge: (NewRow, PscViewRow) => NewRow): PscViewStructure[NewRow] = + new PscViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewFields.scala new file mode 100644 index 0000000000..3e4dca91bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait SrViewFields[Row] { + val id: Field[ScrapreasonId, Row] + val scrapreasonid: Field[ScrapreasonId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SrViewFields extends SrViewStructure[SrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepo.scala new file mode 100644 index 0000000000..ff24477c64 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package sr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SrViewRepo { + def select: SelectBuilder[SrViewFields, SrViewRow] + def selectAll: ZStream[ZConnection, Throwable, SrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepoImpl.scala new file mode 100644 index 0000000000..6090ccbb5f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package sr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SrViewRepoImpl extends SrViewRepo { + override def select: SelectBuilder[SrViewFields, SrViewRow] = { + SelectBuilderSql("pr.sr", SrViewFields, SrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SrViewRow] = { + sql"""select "id", "scrapreasonid", "name", "modifieddate"::text from pr.sr""".query(SrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRow.scala new file mode 100644 index 0000000000..d16080060b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SrViewRow( + /** Points to [[production.scrapreason.ScrapreasonRow.scrapreasonid]] */ + id: ScrapreasonId, + /** Points to [[production.scrapreason.ScrapreasonRow.scrapreasonid]] */ + scrapreasonid: ScrapreasonId, + /** Points to [[production.scrapreason.ScrapreasonRow.name]] */ + name: Name, + /** Points to [[production.scrapreason.ScrapreasonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SrViewRow] = new JdbcDecoder[SrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SrViewRow) = + columIndex + 3 -> + SrViewRow( + id = ScrapreasonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + scrapreasonid = ScrapreasonId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ScrapreasonId.jsonDecoder)) + val scrapreasonid = jsonObj.get("scrapreasonid").toRight("Missing field 'scrapreasonid'").flatMap(_.as(ScrapreasonId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && scrapreasonid.isRight && name.isRight && modifieddate.isRight) + Right(SrViewRow(id = id.toOption.get, scrapreasonid = scrapreasonid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, scrapreasonid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SrViewRow] = new JsonEncoder[SrViewRow] { + override def unsafeEncode(a: SrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ScrapreasonId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""scrapreasonid":""") + ScrapreasonId.jsonEncoder.unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewStructure.scala new file mode 100644 index 0000000000..9355670f37 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/sr/SrViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SrViewStructure[Row](val prefix: Option[String], val extract: Row => SrViewRow, val merge: (Row, SrViewRow) => Row) + extends Relation[SrViewFields, SrViewRow, Row] + with SrViewFields[Row] { outer => + + override val id = new Field[ScrapreasonId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val scrapreasonid = new Field[ScrapreasonId, Row](prefix, "scrapreasonid", None, None)(x => extract(x).scrapreasonid, (row, value) => merge(row, extract(row).copy(scrapreasonid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, scrapreasonid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SrViewRow, merge: (NewRow, SrViewRow) => NewRow): SrViewStructure[NewRow] = + new SrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewFields.scala new file mode 100644 index 0000000000..ec2fbac470 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package th + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.transactionhistory.TransactionhistoryId +import typo.dsl.SqlExpr.Field + +trait ThViewFields[Row] { + val id: Field[TransactionhistoryId, Row] + val transactionid: Field[TransactionhistoryId, Row] + val productid: Field[ProductId, Row] + val referenceorderid: Field[Int, Row] + val referenceorderlineid: Field[Int, Row] + val transactiondate: Field[TypoLocalDateTime, Row] + val transactiontype: Field[/* bpchar, max 1 chars */ String, Row] + val quantity: Field[Int, Row] + val actualcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ThViewFields extends ThViewStructure[ThViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepo.scala new file mode 100644 index 0000000000..4acd15d67e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package th + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ThViewRepo { + def select: SelectBuilder[ThViewFields, ThViewRow] + def selectAll: ZStream[ZConnection, Throwable, ThViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepoImpl.scala new file mode 100644 index 0000000000..51e1ea3460 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package th + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ThViewRepoImpl extends ThViewRepo { + override def select: SelectBuilder[ThViewFields, ThViewRow] = { + SelectBuilderSql("pr.th", ThViewFields, ThViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ThViewRow] = { + sql"""select "id", "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from pr.th""".query(ThViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRow.scala new file mode 100644 index 0000000000..b5f299ca49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewRow.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package th + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.transactionhistory.TransactionhistoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ThViewRow( + /** Points to [[production.transactionhistory.TransactionhistoryRow.transactionid]] */ + id: TransactionhistoryId, + /** Points to [[production.transactionhistory.TransactionhistoryRow.transactionid]] */ + transactionid: TransactionhistoryId, + /** Points to [[production.transactionhistory.TransactionhistoryRow.productid]] */ + productid: ProductId, + /** Points to [[production.transactionhistory.TransactionhistoryRow.referenceorderid]] */ + referenceorderid: Int, + /** Points to [[production.transactionhistory.TransactionhistoryRow.referenceorderlineid]] */ + referenceorderlineid: Int, + /** Points to [[production.transactionhistory.TransactionhistoryRow.transactiondate]] */ + transactiondate: TypoLocalDateTime, + /** Points to [[production.transactionhistory.TransactionhistoryRow.transactiontype]] */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Points to [[production.transactionhistory.TransactionhistoryRow.quantity]] */ + quantity: Int, + /** Points to [[production.transactionhistory.TransactionhistoryRow.actualcost]] */ + actualcost: BigDecimal, + /** Points to [[production.transactionhistory.TransactionhistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object ThViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ThViewRow] = new JdbcDecoder[ThViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ThViewRow) = + columIndex + 9 -> + ThViewRow( + id = TransactionhistoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + transactionid = TransactionhistoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + referenceorderid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + referenceorderlineid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 4, rs)._2, + transactiondate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + transactiontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + actualcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ThViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(TransactionhistoryId.jsonDecoder)) + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(TransactionhistoryId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(JsonDecoder.int)) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && transactionid.isRight && productid.isRight && referenceorderid.isRight && referenceorderlineid.isRight && transactiondate.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && modifieddate.isRight) + Right(ThViewRow(id = id.toOption.get, transactionid = transactionid.toOption.get, productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ThViewRow] = new JsonEncoder[ThViewRow] { + override def unsafeEncode(a: ThViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + TransactionhistoryId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""transactionid":""") + TransactionhistoryId.jsonEncoder.unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewStructure.scala new file mode 100644 index 0000000000..715ac72ef2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/th/ThViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package th + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.transactionhistory.TransactionhistoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class ThViewStructure[Row](val prefix: Option[String], val extract: Row => ThViewRow, val merge: (Row, ThViewRow) => Row) + extends Relation[ThViewFields, ThViewRow, Row] + with ThViewFields[Row] { outer => + + override val id = new Field[TransactionhistoryId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val transactionid = new Field[TransactionhistoryId, Row](prefix, "transactionid", None, None)(x => extract(x).transactionid, (row, value) => merge(row, extract(row).copy(transactionid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val referenceorderid = new Field[Int, Row](prefix, "referenceorderid", None, None)(x => extract(x).referenceorderid, (row, value) => merge(row, extract(row).copy(referenceorderid = value))) + override val referenceorderlineid = new Field[Int, Row](prefix, "referenceorderlineid", None, None)(x => extract(x).referenceorderlineid, (row, value) => merge(row, extract(row).copy(referenceorderlineid = value))) + override val transactiondate = new Field[TypoLocalDateTime, Row](prefix, "transactiondate", Some("text"), None)(x => extract(x).transactiondate, (row, value) => merge(row, extract(row).copy(transactiondate = value))) + override val transactiontype = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "transactiontype", None, None)(x => extract(x).transactiontype, (row, value) => merge(row, extract(row).copy(transactiontype = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, None)(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val actualcost = new Field[BigDecimal, Row](prefix, "actualcost", None, None)(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ThViewRow, merge: (NewRow, ThViewRow) => NewRow): ThViewStructure[NewRow] = + new ThViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewFields.scala new file mode 100644 index 0000000000..0e2c704519 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package tha + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveId +import typo.dsl.SqlExpr.Field + +trait ThaViewFields[Row] { + val id: Field[TransactionhistoryarchiveId, Row] + val transactionid: Field[TransactionhistoryarchiveId, Row] + val productid: Field[Int, Row] + val referenceorderid: Field[Int, Row] + val referenceorderlineid: Field[Int, Row] + val transactiondate: Field[TypoLocalDateTime, Row] + val transactiontype: Field[/* bpchar, max 1 chars */ String, Row] + val quantity: Field[Int, Row] + val actualcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ThaViewFields extends ThaViewStructure[ThaViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepo.scala new file mode 100644 index 0000000000..47055a0dff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package tha + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ThaViewRepo { + def select: SelectBuilder[ThaViewFields, ThaViewRow] + def selectAll: ZStream[ZConnection, Throwable, ThaViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepoImpl.scala new file mode 100644 index 0000000000..1319a2ed04 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package tha + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ThaViewRepoImpl extends ThaViewRepo { + override def select: SelectBuilder[ThaViewFields, ThaViewRow] = { + SelectBuilderSql("pr.tha", ThaViewFields, ThaViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ThaViewRow] = { + sql"""select "id", "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from pr.tha""".query(ThaViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRow.scala new file mode 100644 index 0000000000..debbff7121 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package tha + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ThaViewRow( + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.transactionid]] */ + id: TransactionhistoryarchiveId, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.transactionid]] */ + transactionid: TransactionhistoryarchiveId, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.productid]] */ + productid: Int, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.referenceorderid]] */ + referenceorderid: Int, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.referenceorderlineid]] */ + referenceorderlineid: Int, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.transactiondate]] */ + transactiondate: TypoLocalDateTime, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.transactiontype]] */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.quantity]] */ + quantity: Int, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.actualcost]] */ + actualcost: BigDecimal, + /** Points to [[production.transactionhistoryarchive.TransactionhistoryarchiveRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object ThaViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ThaViewRow] = new JdbcDecoder[ThaViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ThaViewRow) = + columIndex + 9 -> + ThaViewRow( + id = TransactionhistoryarchiveId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + transactionid = TransactionhistoryarchiveId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + referenceorderid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + referenceorderlineid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 4, rs)._2, + transactiondate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + transactiontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + actualcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ThaViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(TransactionhistoryarchiveId.jsonDecoder)) + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(TransactionhistoryarchiveId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(JsonDecoder.int)) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && transactionid.isRight && productid.isRight && referenceorderid.isRight && referenceorderlineid.isRight && transactiondate.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && modifieddate.isRight) + Right(ThaViewRow(id = id.toOption.get, transactionid = transactionid.toOption.get, productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ThaViewRow] = new JsonEncoder[ThaViewRow] { + override def unsafeEncode(a: ThaViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + TransactionhistoryarchiveId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""transactionid":""") + TransactionhistoryarchiveId.jsonEncoder.unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewStructure.scala new file mode 100644 index 0000000000..21ed397cc7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/tha/ThaViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package tha + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class ThaViewStructure[Row](val prefix: Option[String], val extract: Row => ThaViewRow, val merge: (Row, ThaViewRow) => Row) + extends Relation[ThaViewFields, ThaViewRow, Row] + with ThaViewFields[Row] { outer => + + override val id = new Field[TransactionhistoryarchiveId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val transactionid = new Field[TransactionhistoryarchiveId, Row](prefix, "transactionid", None, None)(x => extract(x).transactionid, (row, value) => merge(row, extract(row).copy(transactionid = value))) + override val productid = new Field[Int, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val referenceorderid = new Field[Int, Row](prefix, "referenceorderid", None, None)(x => extract(x).referenceorderid, (row, value) => merge(row, extract(row).copy(referenceorderid = value))) + override val referenceorderlineid = new Field[Int, Row](prefix, "referenceorderlineid", None, None)(x => extract(x).referenceorderlineid, (row, value) => merge(row, extract(row).copy(referenceorderlineid = value))) + override val transactiondate = new Field[TypoLocalDateTime, Row](prefix, "transactiondate", Some("text"), None)(x => extract(x).transactiondate, (row, value) => merge(row, extract(row).copy(transactiondate = value))) + override val transactiontype = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "transactiontype", None, None)(x => extract(x).transactiontype, (row, value) => merge(row, extract(row).copy(transactiontype = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, None)(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val actualcost = new Field[BigDecimal, Row](prefix, "actualcost", None, None)(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ThaViewRow, merge: (NewRow, ThaViewRow) => NewRow): ThaViewStructure[NewRow] = + new ThaViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewFields.scala new file mode 100644 index 0000000000..b4cd755285 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package um + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait UmViewFields[Row] { + val id: Field[UnitmeasureId, Row] + val unitmeasurecode: Field[UnitmeasureId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object UmViewFields extends UmViewStructure[UmViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepo.scala new file mode 100644 index 0000000000..334764fc0a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package um + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UmViewRepo { + def select: SelectBuilder[UmViewFields, UmViewRow] + def selectAll: ZStream[ZConnection, Throwable, UmViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepoImpl.scala new file mode 100644 index 0000000000..9a1d9f4df4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package um + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UmViewRepoImpl extends UmViewRepo { + override def select: SelectBuilder[UmViewFields, UmViewRow] = { + SelectBuilderSql("pr.um", UmViewFields, UmViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UmViewRow] = { + sql"""select "id", "unitmeasurecode", "name", "modifieddate"::text from pr.um""".query(UmViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRow.scala new file mode 100644 index 0000000000..2cb8ad8540 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package um + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UmViewRow( + /** Points to [[production.unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + id: UnitmeasureId, + /** Points to [[production.unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Points to [[production.unitmeasure.UnitmeasureRow.name]] */ + name: Name, + /** Points to [[production.unitmeasure.UnitmeasureRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object UmViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UmViewRow] = new JdbcDecoder[UmViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UmViewRow) = + columIndex + 3 -> + UmViewRow( + id = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UmViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && unitmeasurecode.isRight && name.isRight && modifieddate.isRight) + Right(UmViewRow(id = id.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, unitmeasurecode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UmViewRow] = new JsonEncoder[UmViewRow] { + override def unsafeEncode(a: UmViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewStructure.scala new file mode 100644 index 0000000000..8d78e17361 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/um/UmViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package um + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class UmViewStructure[Row](val prefix: Option[String], val extract: Row => UmViewRow, val merge: (Row, UmViewRow) => Row) + extends Relation[UmViewFields, UmViewRow, Row] + with UmViewFields[Row] { outer => + + override val id = new Field[UnitmeasureId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val unitmeasurecode = new Field[UnitmeasureId, Row](prefix, "unitmeasurecode", None, None)(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, unitmeasurecode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UmViewRow, merge: (NewRow, UmViewRow) => NewRow): UmViewStructure[NewRow] = + new UmViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewFields.scala new file mode 100644 index 0000000000..ea86753bf7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package w + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait WViewFields[Row] { + val id: Field[WorkorderId, Row] + val workorderid: Field[WorkorderId, Row] + val productid: Field[ProductId, Row] + val orderqty: Field[Int, Row] + val scrappedqty: Field[TypoShort, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val duedate: Field[TypoLocalDateTime, Row] + val scrapreasonid: OptField[ScrapreasonId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object WViewFields extends WViewStructure[WViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepo.scala new file mode 100644 index 0000000000..864d503d92 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package w + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait WViewRepo { + def select: SelectBuilder[WViewFields, WViewRow] + def selectAll: ZStream[ZConnection, Throwable, WViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepoImpl.scala new file mode 100644 index 0000000000..c1c69a6f28 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package w + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object WViewRepoImpl extends WViewRepo { + override def select: SelectBuilder[WViewFields, WViewRow] = { + SelectBuilderSql("pr.w", WViewFields, WViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, WViewRow] = { + sql"""select "id", "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text from pr.w""".query(WViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRow.scala new file mode 100644 index 0000000000..c0c22cf5ad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewRow.scala @@ -0,0 +1,112 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package w + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.production.workorder.WorkorderId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class WViewRow( + /** Points to [[production.workorder.WorkorderRow.workorderid]] */ + id: WorkorderId, + /** Points to [[production.workorder.WorkorderRow.workorderid]] */ + workorderid: WorkorderId, + /** Points to [[production.workorder.WorkorderRow.productid]] */ + productid: ProductId, + /** Points to [[production.workorder.WorkorderRow.orderqty]] */ + orderqty: Int, + /** Points to [[production.workorder.WorkorderRow.scrappedqty]] */ + scrappedqty: TypoShort, + /** Points to [[production.workorder.WorkorderRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[production.workorder.WorkorderRow.enddate]] */ + enddate: Option[TypoLocalDateTime], + /** Points to [[production.workorder.WorkorderRow.duedate]] */ + duedate: TypoLocalDateTime, + /** Points to [[production.workorder.WorkorderRow.scrapreasonid]] */ + scrapreasonid: Option[ScrapreasonId], + /** Points to [[production.workorder.WorkorderRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object WViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[WViewRow] = new JdbcDecoder[WViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, WViewRow) = + columIndex + 9 -> + WViewRow( + id = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + workorderid = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + orderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + scrappedqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + scrapreasonid = JdbcDecoder.optionDecoder(ScrapreasonId.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[WViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(WorkorderId.jsonDecoder)) + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(JsonDecoder.int)) + val scrappedqty = jsonObj.get("scrappedqty").toRight("Missing field 'scrappedqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scrapreasonid = jsonObj.get("scrapreasonid").fold[Either[String, Option[ScrapreasonId]]](Right(None))(_.as(JsonDecoder.option(ScrapreasonId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && workorderid.isRight && productid.isRight && orderqty.isRight && scrappedqty.isRight && startdate.isRight && enddate.isRight && duedate.isRight && scrapreasonid.isRight && modifieddate.isRight) + Right(WViewRow(id = id.toOption.get, workorderid = workorderid.toOption.get, productid = productid.toOption.get, orderqty = orderqty.toOption.get, scrappedqty = scrappedqty.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, duedate = duedate.toOption.get, scrapreasonid = scrapreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, workorderid, productid, orderqty, scrappedqty, startdate, enddate, duedate, scrapreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WViewRow] = new JsonEncoder[WViewRow] { + override def unsafeEncode(a: WViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + WorkorderId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""orderqty":""") + JsonEncoder.int.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""scrappedqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.scrappedqty, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""scrapreasonid":""") + JsonEncoder.option(ScrapreasonId.jsonEncoder).unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewStructure.scala new file mode 100644 index 0000000000..93b4ed0475 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/w/WViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package w + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class WViewStructure[Row](val prefix: Option[String], val extract: Row => WViewRow, val merge: (Row, WViewRow) => Row) + extends Relation[WViewFields, WViewRow, Row] + with WViewFields[Row] { outer => + + override val id = new Field[WorkorderId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val workorderid = new Field[WorkorderId, Row](prefix, "workorderid", None, None)(x => extract(x).workorderid, (row, value) => merge(row, extract(row).copy(workorderid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val orderqty = new Field[Int, Row](prefix, "orderqty", None, None)(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val scrappedqty = new Field[TypoShort, Row](prefix, "scrappedqty", None, None)(x => extract(x).scrappedqty, (row, value) => merge(row, extract(row).copy(scrappedqty = 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), None)(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val scrapreasonid = new OptField[ScrapreasonId, Row](prefix, "scrapreasonid", None, None)(x => extract(x).scrapreasonid, (row, value) => merge(row, extract(row).copy(scrapreasonid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, workorderid, productid, orderqty, scrappedqty, startdate, enddate, duedate, scrapreasonid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => WViewRow, merge: (NewRow, WViewRow) => NewRow): WViewStructure[NewRow] = + new WViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewFields.scala new file mode 100644 index 0000000000..641cbd9976 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package wr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait WrViewFields[Row] { + val id: Field[WorkorderId, Row] + val workorderid: Field[WorkorderId, Row] + val productid: Field[Int, Row] + val operationsequence: Field[TypoShort, Row] + val locationid: Field[LocationId, Row] + val scheduledstartdate: Field[TypoLocalDateTime, Row] + val scheduledenddate: Field[TypoLocalDateTime, Row] + val actualstartdate: OptField[TypoLocalDateTime, Row] + val actualenddate: OptField[TypoLocalDateTime, Row] + val actualresourcehrs: OptField[BigDecimal, Row] + val plannedcost: Field[BigDecimal, Row] + val actualcost: OptField[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object WrViewFields extends WrViewStructure[WrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepo.scala new file mode 100644 index 0000000000..f35cfbdf27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package wr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait WrViewRepo { + def select: SelectBuilder[WrViewFields, WrViewRow] + def selectAll: ZStream[ZConnection, Throwable, WrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepoImpl.scala new file mode 100644 index 0000000000..05548e8d5c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package wr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object WrViewRepoImpl extends WrViewRepo { + override def select: SelectBuilder[WrViewFields, WrViewRow] = { + SelectBuilderSql("pr.wr", WrViewFields, WrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, WrViewRow] = { + sql"""select "id", "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text from pr.wr""".query(WrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRow.scala new file mode 100644 index 0000000000..4bcae701da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewRow.scala @@ -0,0 +1,132 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package wr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class WrViewRow( + /** Points to [[production.workorderrouting.WorkorderroutingRow.workorderid]] */ + id: WorkorderId, + /** Points to [[production.workorderrouting.WorkorderroutingRow.workorderid]] */ + workorderid: WorkorderId, + /** Points to [[production.workorderrouting.WorkorderroutingRow.productid]] */ + productid: Int, + /** Points to [[production.workorderrouting.WorkorderroutingRow.operationsequence]] */ + operationsequence: TypoShort, + /** Points to [[production.workorderrouting.WorkorderroutingRow.locationid]] */ + locationid: LocationId, + /** Points to [[production.workorderrouting.WorkorderroutingRow.scheduledstartdate]] */ + scheduledstartdate: TypoLocalDateTime, + /** Points to [[production.workorderrouting.WorkorderroutingRow.scheduledenddate]] */ + scheduledenddate: TypoLocalDateTime, + /** Points to [[production.workorderrouting.WorkorderroutingRow.actualstartdate]] */ + actualstartdate: Option[TypoLocalDateTime], + /** Points to [[production.workorderrouting.WorkorderroutingRow.actualenddate]] */ + actualenddate: Option[TypoLocalDateTime], + /** Points to [[production.workorderrouting.WorkorderroutingRow.actualresourcehrs]] */ + actualresourcehrs: Option[BigDecimal], + /** Points to [[production.workorderrouting.WorkorderroutingRow.plannedcost]] */ + plannedcost: BigDecimal, + /** Points to [[production.workorderrouting.WorkorderroutingRow.actualcost]] */ + actualcost: Option[BigDecimal], + /** Points to [[production.workorderrouting.WorkorderroutingRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object WrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[WrViewRow] = new JdbcDecoder[WrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, WrViewRow) = + columIndex + 12 -> + WrViewRow( + id = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + workorderid = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + operationsequence = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + scheduledstartdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + scheduledenddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + actualstartdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + actualenddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + actualresourcehrs = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 9, rs)._2, + plannedcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 10, rs)._2, + actualcost = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 11, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[WrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(WorkorderId.jsonDecoder)) + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val operationsequence = jsonObj.get("operationsequence").toRight("Missing field 'operationsequence'").flatMap(_.as(TypoShort.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val scheduledstartdate = jsonObj.get("scheduledstartdate").toRight("Missing field 'scheduledstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scheduledenddate = jsonObj.get("scheduledenddate").toRight("Missing field 'scheduledenddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val actualstartdate = jsonObj.get("actualstartdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualenddate = jsonObj.get("actualenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualresourcehrs = jsonObj.get("actualresourcehrs").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val plannedcost = jsonObj.get("plannedcost").toRight("Missing field 'plannedcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val actualcost = jsonObj.get("actualcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && workorderid.isRight && productid.isRight && operationsequence.isRight && locationid.isRight && scheduledstartdate.isRight && scheduledenddate.isRight && actualstartdate.isRight && actualenddate.isRight && actualresourcehrs.isRight && plannedcost.isRight && actualcost.isRight && modifieddate.isRight) + Right(WrViewRow(id = id.toOption.get, workorderid = workorderid.toOption.get, productid = productid.toOption.get, operationsequence = operationsequence.toOption.get, locationid = locationid.toOption.get, scheduledstartdate = scheduledstartdate.toOption.get, scheduledenddate = scheduledenddate.toOption.get, actualstartdate = actualstartdate.toOption.get, actualenddate = actualenddate.toOption.get, actualresourcehrs = actualresourcehrs.toOption.get, plannedcost = plannedcost.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, workorderid, productid, operationsequence, locationid, scheduledstartdate, scheduledenddate, actualstartdate, actualenddate, actualresourcehrs, plannedcost, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WrViewRow] = new JsonEncoder[WrViewRow] { + override def unsafeEncode(a: WrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + WorkorderId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""operationsequence":""") + TypoShort.jsonEncoder.unsafeEncode(a.operationsequence, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""scheduledstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledstartdate, indent, out) + out.write(",") + out.write(""""scheduledenddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledenddate, indent, out) + out.write(",") + out.write(""""actualstartdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualstartdate, indent, out) + out.write(",") + out.write(""""actualenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualenddate, indent, out) + out.write(",") + out.write(""""actualresourcehrs":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualresourcehrs, indent, out) + out.write(",") + out.write(""""plannedcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.plannedcost, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewStructure.scala new file mode 100644 index 0000000000..4d1eac32cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pr/wr/WrViewStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pr +package wr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class WrViewStructure[Row](val prefix: Option[String], val extract: Row => WrViewRow, val merge: (Row, WrViewRow) => Row) + extends Relation[WrViewFields, WrViewRow, Row] + with WrViewFields[Row] { outer => + + override val id = new Field[WorkorderId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val workorderid = new Field[WorkorderId, Row](prefix, "workorderid", None, None)(x => extract(x).workorderid, (row, value) => merge(row, extract(row).copy(workorderid = value))) + override val productid = new Field[Int, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val operationsequence = new Field[TypoShort, Row](prefix, "operationsequence", None, None)(x => extract(x).operationsequence, (row, value) => merge(row, extract(row).copy(operationsequence = value))) + override val locationid = new Field[LocationId, Row](prefix, "locationid", None, None)(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val scheduledstartdate = new Field[TypoLocalDateTime, Row](prefix, "scheduledstartdate", Some("text"), None)(x => extract(x).scheduledstartdate, (row, value) => merge(row, extract(row).copy(scheduledstartdate = value))) + override val scheduledenddate = new Field[TypoLocalDateTime, Row](prefix, "scheduledenddate", Some("text"), None)(x => extract(x).scheduledenddate, (row, value) => merge(row, extract(row).copy(scheduledenddate = value))) + override val actualstartdate = new OptField[TypoLocalDateTime, Row](prefix, "actualstartdate", Some("text"), None)(x => extract(x).actualstartdate, (row, value) => merge(row, extract(row).copy(actualstartdate = value))) + override val actualenddate = new OptField[TypoLocalDateTime, Row](prefix, "actualenddate", Some("text"), None)(x => extract(x).actualenddate, (row, value) => merge(row, extract(row).copy(actualenddate = value))) + override val actualresourcehrs = new OptField[BigDecimal, Row](prefix, "actualresourcehrs", None, None)(x => extract(x).actualresourcehrs, (row, value) => merge(row, extract(row).copy(actualresourcehrs = value))) + override val plannedcost = new Field[BigDecimal, Row](prefix, "plannedcost", None, None)(x => extract(x).plannedcost, (row, value) => merge(row, extract(row).copy(plannedcost = value))) + override val actualcost = new OptField[BigDecimal, Row](prefix, "actualcost", None, None)(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, workorderid, productid, operationsequence, locationid, scheduledstartdate, scheduledenddate, actualstartdate, actualenddate, actualresourcehrs, plannedcost, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => WrViewRow, merge: (NewRow, WrViewRow) => NewRow): WrViewStructure[NewRow] = + new WrViewStructure(prefix, extract, merge) +} 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 new file mode 100644 index 0000000000..d1e5d179dd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsFields.scala @@ -0,0 +1,30 @@ +/** + * 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.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait BillofmaterialsFields[Row] { + val billofmaterialsid: IdField[BillofmaterialsId, Row] + val productassemblyid: OptField[ProductId, Row] + val componentid: Field[ProductId, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val unitmeasurecode: Field[UnitmeasureId, Row] + val bomlevel: Field[TypoShort, Row] + val perassemblyqty: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object BillofmaterialsFields extends BillofmaterialsStructure[BillofmaterialsRow](None, identity, (_, x) => x) + 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 new file mode 100644 index 0000000000..397a6836c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package billofmaterials + +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) +} 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 new file mode 100644 index 0000000000..ff070477eb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package billofmaterials + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait BillofmaterialsRepo { + def delete(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] + def insert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, BillofmaterialsRow] + def insert(unsaved: BillofmaterialsRowUnsaved): ZIO[ZConnection, Throwable, BillofmaterialsRow] + 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 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 new file mode 100644 index 0000000000..337c9d3f40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoImpl.scala @@ -0,0 +1,131 @@ +/** + * 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.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object 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: 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) + returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text + """.insertReturning(BillofmaterialsRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: BillofmaterialsRowUnsaved): ZIO[ZConnection, Throwable, BillofmaterialsRow] = { + val fs = List( + Some((sql""""productassemblyid"""", sql"${Segment.paramSegment(unsaved.productassemblyid)(Setter.optionParamSetter(ProductId.setter))}::int4")), + Some((sql""""componentid"""", sql"${Segment.paramSegment(unsaved.componentid)(ProductId.setter)}::int4")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""unitmeasurecode"""", sql"${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar")), + 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")) + }, + unsaved.startdate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""startdate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.perassemblyqty match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""perassemblyqty"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.billofmaterials default values + returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.billofmaterials($names) values ($values) returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text""" + } + q.insertReturning(BillofmaterialsRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[BillofmaterialsFields, BillofmaterialsRow] = { + SelectBuilderSql("production.billofmaterials", BillofmaterialsFields, BillofmaterialsRow.jdbcDecoder) + } + 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 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 update(row: BillofmaterialsRow): ZIO[ZConnection, Throwable, Boolean] = { + val billofmaterialsid = row.billofmaterialsid + sql"""update production.billofmaterials + set "productassemblyid" = ${Segment.paramSegment(row.productassemblyid)(Setter.optionParamSetter(ProductId.setter))}::int4, + "componentid" = ${Segment.paramSegment(row.componentid)(ProductId.setter)}::int4, + "startdate" = ${Segment.paramSegment(row.startdate)(TypoLocalDateTime.setter)}::timestamp, + "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "unitmeasurecode" = ${Segment.paramSegment(row.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, + "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) + } + override def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] = { + UpdateBuilder("production.billofmaterials", BillofmaterialsFields, BillofmaterialsRow.jdbcDecoder) + } + 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.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 + ) + on conflict ("billofmaterialsid") + do update set + "productassemblyid" = EXCLUDED."productassemblyid", + "componentid" = EXCLUDED."componentid", + "startdate" = EXCLUDED."startdate", + "enddate" = EXCLUDED."enddate", + "unitmeasurecode" = EXCLUDED."unitmeasurecode", + "bomlevel" = EXCLUDED."bomlevel", + "perassemblyqty" = EXCLUDED."perassemblyqty", + "modifieddate" = EXCLUDED."modifieddate" + returning "billofmaterialsid", "productassemblyid", "componentid", "startdate"::text, "enddate"::text, "unitmeasurecode", "bomlevel", "perassemblyqty", "modifieddate"::text""".insertReturning(BillofmaterialsRow.jdbcDecoder) + } +} 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 new file mode 100644 index 0000000000..487422cc33 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package billofmaterials + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +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] = { + ZIO.succeed(map.remove(billofmaterialsid).isDefined) + } + override def delete: DeleteBuilder[BillofmaterialsFields, BillofmaterialsRow] = { + DeleteBuilderMock(DeleteParams.empty, BillofmaterialsFields, map) + } + override def insert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, BillofmaterialsRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.billofmaterialsid)) + sys.error(s"id ${unsaved.billofmaterialsid} already exists") + else + map.put(unsaved.billofmaterialsid, unsaved) + + unsaved + } + } + override def insert(unsaved: BillofmaterialsRowUnsaved): ZIO[ZConnection, Throwable, BillofmaterialsRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[BillofmaterialsFields, BillofmaterialsRow] = { + SelectBuilderMock(BillofmaterialsFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, BillofmaterialsRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(billofmaterialsid: BillofmaterialsId): ZIO[ZConnection, Throwable, Option[BillofmaterialsRow]] = { + ZIO.succeed(map.get(billofmaterialsid)) + } + override def selectByIds(billofmaterialsids: Array[BillofmaterialsId]): ZStream[ZConnection, Throwable, BillofmaterialsRow] = { + ZStream.fromIterable(billofmaterialsids.flatMap(map.get)) + } + override def update(row: BillofmaterialsRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.billofmaterialsid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.billofmaterialsid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[BillofmaterialsFields, BillofmaterialsRow] = { + UpdateBuilderMock(UpdateParams.empty, BillofmaterialsFields, map) + } + override def upsert(unsaved: BillofmaterialsRow): ZIO[ZConnection, Throwable, UpdateResult[BillofmaterialsRow]] = { + ZIO.succeed { + map.put(unsaved.billofmaterialsid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} 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 new file mode 100644 index 0000000000..91af94e624 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRow.scala @@ -0,0 +1,114 @@ +/** + * 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.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class BillofmaterialsRow( + /** Primary key for BillOfMaterials records. */ + billofmaterialsid: BillofmaterialsId, + /** 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)))) + Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "componentid", "productassemblyid": ((productassemblyid <> componentid)) */ + productassemblyid: Option[ProductId], + /** Component identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] + Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "componentid", "productassemblyid": ((productassemblyid <> componentid)) */ + componentid: ProductId, + /** Date the component started being used in the assembly item. + Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Date the component stopped being used in the assembly item. + Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Standard code identifying the unit of measure for the quantity. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Indicates the depth the component is from its parent (AssemblyID). + 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)))) */ + bomlevel: TypoShort, + /** Quantity of the component needed to create the assembly. + 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)))) + Constraint CK_BillOfMaterials_PerAssemblyQty affecting columns "perassemblyqty": ((perassemblyqty >= 1.00)) */ + perassemblyqty: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object BillofmaterialsRow { + implicit lazy val jdbcDecoder: JdbcDecoder[BillofmaterialsRow] = new JdbcDecoder[BillofmaterialsRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, BillofmaterialsRow) = + columIndex + 8 -> + BillofmaterialsRow( + billofmaterialsid = BillofmaterialsId.jdbcDecoder.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, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + bomlevel = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + perassemblyqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + 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 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)) + 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 perassemblyqty = jsonObj.get("perassemblyqty").toRight("Missing field 'perassemblyqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (billofmaterialsid.isRight && productassemblyid.isRight && componentid.isRight && startdate.isRight && enddate.isRight && unitmeasurecode.isRight && bomlevel.isRight && perassemblyqty.isRight && modifieddate.isRight) + Right(BillofmaterialsRow(billofmaterialsid = billofmaterialsid.toOption.get, productassemblyid = productassemblyid.toOption.get, componentid = componentid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, bomlevel = bomlevel.toOption.get, perassemblyqty = perassemblyqty.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](billofmaterialsid, productassemblyid, componentid, startdate, enddate, unitmeasurecode, bomlevel, perassemblyqty, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BillofmaterialsRow] = new JsonEncoder[BillofmaterialsRow] { + override def unsafeEncode(a: BillofmaterialsRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""billofmaterialsid":""") + BillofmaterialsId.jsonEncoder.unsafeEncode(a.billofmaterialsid, indent, out) + out.write(",") + out.write(""""productassemblyid":""") + JsonEncoder.option(ProductId.jsonEncoder).unsafeEncode(a.productassemblyid, indent, out) + out.write(",") + out.write(""""componentid":""") + ProductId.jsonEncoder.unsafeEncode(a.componentid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""bomlevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.bomlevel, indent, out) + out.write(",") + out.write(""""perassemblyqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.perassemblyqty, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} 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 new file mode 100644 index 0000000000..c3e75dd1bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsRowUnsaved.scala @@ -0,0 +1,127 @@ +/** + * 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.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.billofmaterials` which has not been persisted yet */ +case class BillofmaterialsRowUnsaved( + /** 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)))) + Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "componentid", "productassemblyid": ((productassemblyid <> componentid)) */ + productassemblyid: Option[ProductId], + /** Component identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] + Constraint CK_BillOfMaterials_ProductAssemblyID affecting columns "componentid", "productassemblyid": ((productassemblyid <> componentid)) */ + componentid: ProductId, + /** Date the component stopped being used in the assembly item. + Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Standard code identifying the unit of measure for the quantity. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Indicates the depth the component is from its parent (AssemblyID). + 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)))) */ + bomlevel: TypoShort, + /** Default: nextval('production.billofmaterials_billofmaterialsid_seq'::regclass) + Primary key for BillOfMaterials records. */ + billofmaterialsid: Defaulted[BillofmaterialsId] = Defaulted.UseDefault, + /** Default: now() + Date the component started being used in the assembly item. + Constraint CK_BillOfMaterials_EndDate affecting columns "enddate", "startdate": (((enddate > startdate) OR (enddate IS NULL))) */ + startdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: 1.00 + Quantity of the component needed to create the assembly. + 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)))) + Constraint CK_BillOfMaterials_PerAssemblyQty affecting columns "perassemblyqty": ((perassemblyqty >= 1.00)) */ + perassemblyqty: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(billofmaterialsidDefault: => BillofmaterialsId, startdateDefault: => TypoLocalDateTime, perassemblyqtyDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): BillofmaterialsRow = + BillofmaterialsRow( + productassemblyid = productassemblyid, + componentid = componentid, + enddate = enddate, + unitmeasurecode = unitmeasurecode, + bomlevel = bomlevel, + billofmaterialsid = billofmaterialsid match { + case Defaulted.UseDefault => billofmaterialsidDefault + case Defaulted.Provided(value) => value + }, + startdate = startdate match { + case Defaulted.UseDefault => startdateDefault + case Defaulted.Provided(value) => value + }, + perassemblyqty = perassemblyqty match { + case Defaulted.UseDefault => perassemblyqtyDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object BillofmaterialsRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[BillofmaterialsRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + 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 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 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))) + if (productassemblyid.isRight && componentid.isRight && enddate.isRight && unitmeasurecode.isRight && bomlevel.isRight && billofmaterialsid.isRight && startdate.isRight && perassemblyqty.isRight && modifieddate.isRight) + Right(BillofmaterialsRowUnsaved(productassemblyid = productassemblyid.toOption.get, componentid = componentid.toOption.get, enddate = enddate.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, bomlevel = bomlevel.toOption.get, billofmaterialsid = billofmaterialsid.toOption.get, startdate = startdate.toOption.get, perassemblyqty = perassemblyqty.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productassemblyid, componentid, enddate, unitmeasurecode, bomlevel, billofmaterialsid, startdate, perassemblyqty, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[BillofmaterialsRowUnsaved] = new JsonEncoder[BillofmaterialsRowUnsaved] { + override def unsafeEncode(a: BillofmaterialsRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productassemblyid":""") + JsonEncoder.option(ProductId.jsonEncoder).unsafeEncode(a.productassemblyid, indent, out) + out.write(",") + out.write(""""componentid":""") + ProductId.jsonEncoder.unsafeEncode(a.componentid, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""bomlevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.bomlevel, indent, out) + out.write(",") + out.write(""""billofmaterialsid":""") + Defaulted.jsonEncoder(BillofmaterialsId.jsonEncoder).unsafeEncode(a.billofmaterialsid, indent, out) + out.write(",") + out.write(""""startdate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""perassemblyqty":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.perassemblyqty, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} 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 new file mode 100644 index 0000000000..48a762775b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/billofmaterials/BillofmaterialsStructure.scala @@ -0,0 +1,39 @@ +/** + * 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.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class BillofmaterialsStructure[Row](val prefix: Option[String], val extract: Row => BillofmaterialsRow, val merge: (Row, BillofmaterialsRow) => 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 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val unitmeasurecode = new Field[UnitmeasureId, Row](prefix, "unitmeasurecode", None, Some("bpchar"))(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val bomlevel = new Field[TypoShort, Row](prefix, "bomlevel", None, Some("int2"))(x => extract(x).bomlevel, (row, value) => merge(row, extract(row).copy(bomlevel = value))) + override val perassemblyqty = new Field[BigDecimal, Row](prefix, "perassemblyqty", None, Some("numeric"))(x => extract(x).perassemblyqty, (row, value) => merge(row, extract(row).copy(perassemblyqty = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](billofmaterialsid, productassemblyid, componentid, startdate, enddate, unitmeasurecode, bomlevel, perassemblyqty, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => BillofmaterialsRow, merge: (NewRow, BillofmaterialsRow) => NewRow): BillofmaterialsStructure[NewRow] = + new BillofmaterialsStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureFields.scala new file mode 100644 index 0000000000..ffaacc2a52 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CultureFields[Row] { + val cultureid: IdField[CultureId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CultureFields extends CultureStructure[CultureRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureId.scala new file mode 100644 index 0000000000..cc7761ba45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +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.culture` */ +case class CultureId(value: /* bpchar, max 6 chars */ String) extends AnyVal +object CultureId { + implicit lazy val arraySetter: Setter[Array[CultureId]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CultureId, /* bpchar, max 6 chars */ String] = Bijection[CultureId, /* bpchar, max 6 chars */ String](_.value)(CultureId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CultureId] = JdbcDecoder.stringDecoder.map(CultureId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CultureId] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CultureId] = JsonDecoder.string.map(CultureId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CultureId] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[CultureId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CultureId] = ParameterMetaData.instance[CultureId](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CultureId] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepo.scala new file mode 100644 index 0000000000..e9a20db205 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CultureRepo { + def delete(cultureid: CultureId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CultureFields, CultureRow] + def insert(unsaved: CultureRow): ZIO[ZConnection, Throwable, CultureRow] + def insert(unsaved: CultureRowUnsaved): ZIO[ZConnection, Throwable, CultureRow] + def select: SelectBuilder[CultureFields, CultureRow] + def selectAll: ZStream[ZConnection, Throwable, CultureRow] + def selectById(cultureid: CultureId): ZIO[ZConnection, Throwable, Option[CultureRow]] + def selectByIds(cultureids: Array[CultureId]): ZStream[ZConnection, Throwable, CultureRow] + def update(row: CultureRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CultureFields, CultureRow] + def upsert(unsaved: CultureRow): ZIO[ZConnection, Throwable, UpdateResult[CultureRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoImpl.scala new file mode 100644 index 0000000000..3158dc2b7b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoImpl.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CultureRepoImpl extends CultureRepo { + override def delete(cultureid: CultureId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.culture where "cultureid" = ${Segment.paramSegment(cultureid)(CultureId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CultureFields, CultureRow] = { + DeleteBuilder("production.culture", CultureFields) + } + override def insert(unsaved: CultureRow): ZIO[ZConnection, Throwable, CultureRow] = { + sql"""insert into production.culture("cultureid", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "cultureid", "name", "modifieddate"::text + """.insertReturning(CultureRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CultureRowUnsaved): ZIO[ZConnection, Throwable, CultureRow] = { + val fs = List( + Some((sql""""cultureid"""", sql"${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.culture default values + returning "cultureid", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.culture($names) values ($values) returning "cultureid", "name", "modifieddate"::text""" + } + q.insertReturning(CultureRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CultureFields, CultureRow] = { + SelectBuilderSql("production.culture", CultureFields, CultureRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CultureRow] = { + sql"""select "cultureid", "name", "modifieddate"::text from production.culture""".query(CultureRow.jdbcDecoder).selectStream + } + override def selectById(cultureid: CultureId): ZIO[ZConnection, Throwable, Option[CultureRow]] = { + sql"""select "cultureid", "name", "modifieddate"::text from production.culture where "cultureid" = ${Segment.paramSegment(cultureid)(CultureId.setter)}""".query(CultureRow.jdbcDecoder).selectOne + } + override def selectByIds(cultureids: Array[CultureId]): ZStream[ZConnection, Throwable, CultureRow] = { + sql"""select "cultureid", "name", "modifieddate"::text from production.culture where "cultureid" = ANY(${Segment.paramSegment(cultureids)(CultureId.arraySetter)})""".query(CultureRow.jdbcDecoder).selectStream + } + override def update(row: CultureRow): ZIO[ZConnection, Throwable, Boolean] = { + val cultureid = row.cultureid + sql"""update production.culture + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "cultureid" = ${Segment.paramSegment(cultureid)(CultureId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CultureFields, CultureRow] = { + UpdateBuilder("production.culture", CultureFields, CultureRow.jdbcDecoder) + } + override def upsert(unsaved: CultureRow): ZIO[ZConnection, Throwable, UpdateResult[CultureRow]] = { + sql"""insert into production.culture("cultureid", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("cultureid") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "cultureid", "name", "modifieddate"::text""".insertReturning(CultureRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoMock.scala new file mode 100644 index 0000000000..51db21105b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CultureRepoMock(toRow: Function1[CultureRowUnsaved, CultureRow], + map: scala.collection.mutable.Map[CultureId, CultureRow] = scala.collection.mutable.Map.empty) extends CultureRepo { + override def delete(cultureid: CultureId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(cultureid).isDefined) + } + override def delete: DeleteBuilder[CultureFields, CultureRow] = { + DeleteBuilderMock(DeleteParams.empty, CultureFields, map) + } + override def insert(unsaved: CultureRow): ZIO[ZConnection, Throwable, CultureRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.cultureid)) + sys.error(s"id ${unsaved.cultureid} already exists") + else + map.put(unsaved.cultureid, unsaved) + + unsaved + } + } + override def insert(unsaved: CultureRowUnsaved): ZIO[ZConnection, Throwable, CultureRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CultureFields, CultureRow] = { + SelectBuilderMock(CultureFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CultureRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(cultureid: CultureId): ZIO[ZConnection, Throwable, Option[CultureRow]] = { + ZIO.succeed(map.get(cultureid)) + } + override def selectByIds(cultureids: Array[CultureId]): ZStream[ZConnection, Throwable, CultureRow] = { + ZStream.fromIterable(cultureids.flatMap(map.get)) + } + override def update(row: CultureRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.cultureid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.cultureid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CultureFields, CultureRow] = { + UpdateBuilderMock(UpdateParams.empty, CultureFields, map) + } + override def upsert(unsaved: CultureRow): ZIO[ZConnection, Throwable, UpdateResult[CultureRow]] = { + ZIO.succeed { + map.put(unsaved.cultureid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRow.scala new file mode 100644 index 0000000000..d80aefb479 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CultureRow( + /** Primary key for Culture records. */ + cultureid: CultureId, + /** Culture description. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object CultureRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CultureRow] = new JdbcDecoder[CultureRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CultureRow) = + columIndex + 2 -> + CultureRow( + cultureid = CultureId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CultureRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (cultureid.isRight && name.isRight && modifieddate.isRight) + Right(CultureRow(cultureid = cultureid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](cultureid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CultureRow] = new JsonEncoder[CultureRow] { + override def unsafeEncode(a: CultureRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRowUnsaved.scala new file mode 100644 index 0000000000..6085f939ba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureRowUnsaved.scala @@ -0,0 +1,60 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.culture` which has not been persisted yet */ +case class CultureRowUnsaved( + /** Primary key for Culture records. */ + cultureid: CultureId, + /** Culture description. */ + name: Name, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): CultureRow = + CultureRow( + cultureid = cultureid, + name = name, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CultureRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CultureRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (cultureid.isRight && name.isRight && modifieddate.isRight) + Right(CultureRowUnsaved(cultureid = cultureid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](cultureid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CultureRowUnsaved] = new JsonEncoder[CultureRowUnsaved] { + override def unsafeEncode(a: CultureRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureStructure.scala new file mode 100644 index 0000000000..6267bec327 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/culture/CultureStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package culture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CultureStructure[Row](val prefix: Option[String], val extract: Row => CultureRow, val merge: (Row, CultureRow) => Row) + extends Relation[CultureFields, CultureRow, Row] + with CultureFields[Row] { outer => + + override val cultureid = new IdField[CultureId, Row](prefix, "cultureid", None, Some("bpchar"))(x => extract(x).cultureid, (row, value) => merge(row, extract(row).copy(cultureid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](cultureid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CultureRow, merge: (NewRow, CultureRow) => NewRow): CultureStructure[NewRow] = + new CultureStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentFields.scala new file mode 100644 index 0000000000..1731128fa6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentFields.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait DocumentFields[Row] { + val title: Field[/* max 50 chars */ String, Row] + val owner: Field[BusinessentityId, Row] + val folderflag: Field[Flag, Row] + val filename: Field[/* max 400 chars */ String, Row] + val fileextension: OptField[/* max 8 chars */ String, Row] + val revision: Field[/* bpchar, max 5 chars */ String, Row] + val changenumber: Field[Int, Row] + val status: Field[TypoShort, Row] + val documentsummary: OptField[String, Row] + val document: OptField[TypoBytea, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val documentnode: IdField[DocumentId, Row] +} +object DocumentFields extends DocumentStructure[DocumentRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentId.scala new file mode 100644 index 0000000000..14ed4d77b1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +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.document` */ +case class DocumentId(value: String) extends AnyVal +object DocumentId { + implicit lazy val arraySetter: Setter[Array[DocumentId]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[DocumentId, String] = Bijection[DocumentId, String](_.value)(DocumentId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[DocumentId] = JdbcDecoder.stringDecoder.map(DocumentId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[DocumentId] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[DocumentId] = JsonDecoder.string.map(DocumentId.apply) + implicit lazy val jsonEncoder: JsonEncoder[DocumentId] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[DocumentId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[DocumentId] = ParameterMetaData.instance[DocumentId](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[DocumentId] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepo.scala new file mode 100644 index 0000000000..72834428cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepo.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.TypoUUID +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait DocumentRepo { + def delete(documentnode: DocumentId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[DocumentFields, DocumentRow] + def insert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, DocumentRow] + def insert(unsaved: DocumentRowUnsaved): ZIO[ZConnection, Throwable, DocumentRow] + def select: SelectBuilder[DocumentFields, DocumentRow] + def selectAll: ZStream[ZConnection, Throwable, DocumentRow] + def selectById(documentnode: DocumentId): ZIO[ZConnection, Throwable, Option[DocumentRow]] + def selectByIds(documentnodes: Array[DocumentId]): ZStream[ZConnection, Throwable, DocumentRow] + def selectByUnique(rowguid: TypoUUID): ZIO[ZConnection, Throwable, Option[DocumentRow]] + def update(row: DocumentRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[DocumentFields, DocumentRow] + def upsert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, UpdateResult[DocumentRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoImpl.scala new file mode 100644 index 0000000000..7531b45418 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoImpl.scala @@ -0,0 +1,158 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object DocumentRepoImpl extends DocumentRepo { + override def delete(documentnode: DocumentId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.document where "documentnode" = ${Segment.paramSegment(documentnode)(DocumentId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[DocumentFields, DocumentRow] = { + DeleteBuilder("production.document", DocumentFields) + } + override def insert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, DocumentRow] = { + sql"""insert into production.document("title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate", "documentnode") + values (${Segment.paramSegment(unsaved.title)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.owner)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.folderflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.filename)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.fileextension)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.revision)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.changenumber)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.documentsummary)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.document)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.documentnode)(DocumentId.setter)}) + returning "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" + """.insertReturning(DocumentRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: DocumentRowUnsaved): ZIO[ZConnection, Throwable, DocumentRow] = { + val fs = List( + Some((sql""""title"""", sql"${Segment.paramSegment(unsaved.title)(Setter.stringSetter)}")), + Some((sql""""owner"""", sql"${Segment.paramSegment(unsaved.owner)(BusinessentityId.setter)}::int4")), + Some((sql""""filename"""", sql"${Segment.paramSegment(unsaved.filename)(Setter.stringSetter)}")), + Some((sql""""fileextension"""", sql"${Segment.paramSegment(unsaved.fileextension)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""revision"""", sql"${Segment.paramSegment(unsaved.revision)(Setter.stringSetter)}::bpchar")), + Some((sql""""status"""", sql"${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2")), + Some((sql""""documentsummary"""", sql"${Segment.paramSegment(unsaved.documentsummary)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""document"""", sql"${Segment.paramSegment(unsaved.document)(Setter.optionParamSetter(TypoBytea.setter))}::bytea")), + unsaved.folderflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""folderflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.changenumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""changenumber"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.documentnode match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""documentnode"""", sql"${Segment.paramSegment(value: DocumentId)(DocumentId.setter)}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.document default values + returning "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.document($names) values ($values) returning "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode"""" + } + q.insertReturning(DocumentRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[DocumentFields, DocumentRow] = { + SelectBuilderSql("production.document", DocumentFields, DocumentRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, DocumentRow] = { + sql"""select "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" from production.document""".query(DocumentRow.jdbcDecoder).selectStream + } + override def selectById(documentnode: DocumentId): ZIO[ZConnection, Throwable, Option[DocumentRow]] = { + sql"""select "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" from production.document where "documentnode" = ${Segment.paramSegment(documentnode)(DocumentId.setter)}""".query(DocumentRow.jdbcDecoder).selectOne + } + override def selectByIds(documentnodes: Array[DocumentId]): ZStream[ZConnection, Throwable, DocumentRow] = { + sql"""select "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode" from production.document where "documentnode" = ANY(${Segment.paramSegment(documentnodes)(DocumentId.arraySetter)})""".query(DocumentRow.jdbcDecoder).selectStream + } + override def selectByUnique(rowguid: TypoUUID): ZIO[ZConnection, Throwable, Option[DocumentRow]] = { + sql"""select "rowguid" + from production.document + where "rowguid" = ${Segment.paramSegment(rowguid)(TypoUUID.setter)} + """.query(DocumentRow.jdbcDecoder).selectOne + } + override def update(row: DocumentRow): ZIO[ZConnection, Throwable, Boolean] = { + val documentnode = row.documentnode + sql"""update production.document + set "title" = ${Segment.paramSegment(row.title)(Setter.stringSetter)}, + "owner" = ${Segment.paramSegment(row.owner)(BusinessentityId.setter)}::int4, + "folderflag" = ${Segment.paramSegment(row.folderflag)(Flag.setter)}::bool, + "filename" = ${Segment.paramSegment(row.filename)(Setter.stringSetter)}, + "fileextension" = ${Segment.paramSegment(row.fileextension)(Setter.optionParamSetter(Setter.stringSetter))}, + "revision" = ${Segment.paramSegment(row.revision)(Setter.stringSetter)}::bpchar, + "changenumber" = ${Segment.paramSegment(row.changenumber)(Setter.intSetter)}::int4, + "status" = ${Segment.paramSegment(row.status)(TypoShort.setter)}::int2, + "documentsummary" = ${Segment.paramSegment(row.documentsummary)(Setter.optionParamSetter(Setter.stringSetter))}, + "document" = ${Segment.paramSegment(row.document)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "documentnode" = ${Segment.paramSegment(documentnode)(DocumentId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[DocumentFields, DocumentRow] = { + UpdateBuilder("production.document", DocumentFields, DocumentRow.jdbcDecoder) + } + override def upsert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, UpdateResult[DocumentRow]] = { + sql"""insert into production.document("title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate", "documentnode") + values ( + ${Segment.paramSegment(unsaved.title)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.owner)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.folderflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.filename)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.fileextension)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.revision)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.changenumber)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.documentsummary)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.document)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.documentnode)(DocumentId.setter)} + ) + on conflict ("documentnode") + do update set + "title" = EXCLUDED."title", + "owner" = EXCLUDED."owner", + "folderflag" = EXCLUDED."folderflag", + "filename" = EXCLUDED."filename", + "fileextension" = EXCLUDED."fileextension", + "revision" = EXCLUDED."revision", + "changenumber" = EXCLUDED."changenumber", + "status" = EXCLUDED."status", + "documentsummary" = EXCLUDED."documentsummary", + "document" = EXCLUDED."document", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "title", "owner", "folderflag", "filename", "fileextension", "revision", "changenumber", "status", "documentsummary", "document", "rowguid", "modifieddate"::text, "documentnode"""".insertReturning(DocumentRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoMock.scala new file mode 100644 index 0000000000..d20e0d1b83 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRepoMock.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.TypoUUID +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class DocumentRepoMock(toRow: Function1[DocumentRowUnsaved, DocumentRow], + map: scala.collection.mutable.Map[DocumentId, DocumentRow] = scala.collection.mutable.Map.empty) extends DocumentRepo { + override def delete(documentnode: DocumentId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(documentnode).isDefined) + } + override def delete: DeleteBuilder[DocumentFields, DocumentRow] = { + DeleteBuilderMock(DeleteParams.empty, DocumentFields, map) + } + override def insert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, DocumentRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.documentnode)) + sys.error(s"id ${unsaved.documentnode} already exists") + else + map.put(unsaved.documentnode, unsaved) + + unsaved + } + } + override def insert(unsaved: DocumentRowUnsaved): ZIO[ZConnection, Throwable, DocumentRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[DocumentFields, DocumentRow] = { + SelectBuilderMock(DocumentFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, DocumentRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(documentnode: DocumentId): ZIO[ZConnection, Throwable, Option[DocumentRow]] = { + ZIO.succeed(map.get(documentnode)) + } + override def selectByIds(documentnodes: Array[DocumentId]): ZStream[ZConnection, Throwable, DocumentRow] = { + ZStream.fromIterable(documentnodes.flatMap(map.get)) + } + override def selectByUnique(rowguid: TypoUUID): ZIO[ZConnection, Throwable, Option[DocumentRow]] = { + ZIO.succeed(map.values.find(v => rowguid == v.rowguid)) + } + override def update(row: DocumentRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.documentnode) match { + case Some(`row`) => false + case Some(_) => + map.put(row.documentnode, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[DocumentFields, DocumentRow] = { + UpdateBuilderMock(UpdateParams.empty, DocumentFields, map) + } + override def upsert(unsaved: DocumentRow): ZIO[ZConnection, Throwable, UpdateResult[DocumentRow]] = { + ZIO.succeed { + map.put(unsaved.documentnode, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRow.scala new file mode 100644 index 0000000000..228063d461 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRow.scala @@ -0,0 +1,135 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class DocumentRow( + /** Title of the document. */ + title: /* max 50 chars */ String, + /** Employee who controls the document. Foreign key to Employee.BusinessEntityID + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + owner: BusinessentityId, + /** 0 = This is a folder, 1 = This is a document. */ + folderflag: Flag, + /** File name of the document */ + filename: /* max 400 chars */ String, + /** File extension indicating the document type. For example, .doc or .txt. */ + fileextension: Option[/* max 8 chars */ String], + /** Revision number of the document. */ + revision: /* bpchar, max 5 chars */ String, + /** Engineering change approval number. */ + changenumber: Int, + /** 1 = Pending approval, 2 = Approved, 3 = Obsolete + Constraint CK_Document_Status affecting columns "status": (((status >= 1) AND (status <= 3))) */ + status: TypoShort, + /** Document abstract. */ + documentsummary: Option[String], + /** Complete document. */ + document: Option[TypoBytea], + /** ROWGUIDCOL number uniquely identifying the record. Required for FileStream. */ + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime, + /** Primary key for Document records. */ + documentnode: DocumentId +) + +object DocumentRow { + implicit lazy val jdbcDecoder: JdbcDecoder[DocumentRow] = new JdbcDecoder[DocumentRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, DocumentRow) = + columIndex + 12 -> + DocumentRow( + title = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 0, rs)._2, + owner = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + folderflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + filename = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + fileextension = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + revision = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + changenumber = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + documentsummary = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + document = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + documentnode = DocumentId.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[DocumentRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val title = jsonObj.get("title").toRight("Missing field 'title'").flatMap(_.as(JsonDecoder.string)) + val owner = jsonObj.get("owner").toRight("Missing field 'owner'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val folderflag = jsonObj.get("folderflag").toRight("Missing field 'folderflag'").flatMap(_.as(Flag.jsonDecoder)) + val filename = jsonObj.get("filename").toRight("Missing field 'filename'").flatMap(_.as(JsonDecoder.string)) + val fileextension = jsonObj.get("fileextension").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val revision = jsonObj.get("revision").toRight("Missing field 'revision'").flatMap(_.as(JsonDecoder.string)) + val changenumber = jsonObj.get("changenumber").toRight("Missing field 'changenumber'").flatMap(_.as(JsonDecoder.int)) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val documentsummary = jsonObj.get("documentsummary").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val document = jsonObj.get("document").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(DocumentId.jsonDecoder)) + if (title.isRight && owner.isRight && folderflag.isRight && filename.isRight && fileextension.isRight && revision.isRight && changenumber.isRight && status.isRight && documentsummary.isRight && document.isRight && rowguid.isRight && modifieddate.isRight && documentnode.isRight) + Right(DocumentRow(title = title.toOption.get, owner = owner.toOption.get, folderflag = folderflag.toOption.get, filename = filename.toOption.get, fileextension = fileextension.toOption.get, revision = revision.toOption.get, changenumber = changenumber.toOption.get, status = status.toOption.get, documentsummary = documentsummary.toOption.get, document = document.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](title, owner, folderflag, filename, fileextension, revision, changenumber, status, documentsummary, document, rowguid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DocumentRow] = new JsonEncoder[DocumentRow] { + override def unsafeEncode(a: DocumentRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""title":""") + JsonEncoder.string.unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""owner":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.owner, indent, out) + out.write(",") + out.write(""""folderflag":""") + Flag.jsonEncoder.unsafeEncode(a.folderflag, indent, out) + out.write(",") + out.write(""""filename":""") + JsonEncoder.string.unsafeEncode(a.filename, indent, out) + out.write(",") + out.write(""""fileextension":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.fileextension, indent, out) + out.write(",") + out.write(""""revision":""") + JsonEncoder.string.unsafeEncode(a.revision, indent, out) + out.write(",") + out.write(""""changenumber":""") + JsonEncoder.int.unsafeEncode(a.changenumber, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""documentsummary":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.documentsummary, indent, out) + out.write(",") + out.write(""""document":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.document, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + DocumentId.jsonEncoder.unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRowUnsaved.scala new file mode 100644 index 0000000000..2d1bdb5ae3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentRowUnsaved.scala @@ -0,0 +1,152 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.document` which has not been persisted yet */ +case class DocumentRowUnsaved( + /** Title of the document. */ + title: /* max 50 chars */ String, + /** Employee who controls the document. Foreign key to Employee.BusinessEntityID + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + owner: BusinessentityId, + /** File name of the document */ + filename: /* max 400 chars */ String, + /** File extension indicating the document type. For example, .doc or .txt. */ + fileextension: Option[/* max 8 chars */ String], + /** Revision number of the document. */ + revision: /* bpchar, max 5 chars */ String, + /** 1 = Pending approval, 2 = Approved, 3 = Obsolete + Constraint CK_Document_Status affecting columns "status": (((status >= 1) AND (status <= 3))) */ + status: TypoShort, + /** Document abstract. */ + documentsummary: Option[String], + /** Complete document. */ + document: Option[TypoBytea], + /** Default: false + 0 = This is a folder, 1 = This is a document. */ + folderflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: 0 + Engineering change approval number. */ + changenumber: Defaulted[Int] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() + ROWGUIDCOL number uniquely identifying the record. Required for FileStream. */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: '/'::character varying + Primary key for Document records. */ + documentnode: Defaulted[DocumentId] = Defaulted.UseDefault +) { + def toRow(folderflagDefault: => Flag, changenumberDefault: => Int, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime, documentnodeDefault: => DocumentId): DocumentRow = + DocumentRow( + title = title, + owner = owner, + filename = filename, + fileextension = fileextension, + revision = revision, + status = status, + documentsummary = documentsummary, + document = document, + folderflag = folderflag match { + case Defaulted.UseDefault => folderflagDefault + case Defaulted.Provided(value) => value + }, + changenumber = changenumber match { + case Defaulted.UseDefault => changenumberDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + }, + documentnode = documentnode match { + case Defaulted.UseDefault => documentnodeDefault + case Defaulted.Provided(value) => value + } + ) +} +object DocumentRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[DocumentRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val title = jsonObj.get("title").toRight("Missing field 'title'").flatMap(_.as(JsonDecoder.string)) + val owner = jsonObj.get("owner").toRight("Missing field 'owner'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val filename = jsonObj.get("filename").toRight("Missing field 'filename'").flatMap(_.as(JsonDecoder.string)) + val fileextension = jsonObj.get("fileextension").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val revision = jsonObj.get("revision").toRight("Missing field 'revision'").flatMap(_.as(JsonDecoder.string)) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val documentsummary = jsonObj.get("documentsummary").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val document = jsonObj.get("document").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val folderflag = jsonObj.get("folderflag").toRight("Missing field 'folderflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val changenumber = jsonObj.get("changenumber").toRight("Missing field 'changenumber'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(Defaulted.jsonDecoder(DocumentId.jsonDecoder))) + if (title.isRight && owner.isRight && filename.isRight && fileextension.isRight && revision.isRight && status.isRight && documentsummary.isRight && document.isRight && folderflag.isRight && changenumber.isRight && rowguid.isRight && modifieddate.isRight && documentnode.isRight) + Right(DocumentRowUnsaved(title = title.toOption.get, owner = owner.toOption.get, filename = filename.toOption.get, fileextension = fileextension.toOption.get, revision = revision.toOption.get, status = status.toOption.get, documentsummary = documentsummary.toOption.get, document = document.toOption.get, folderflag = folderflag.toOption.get, changenumber = changenumber.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](title, owner, filename, fileextension, revision, status, documentsummary, document, folderflag, changenumber, rowguid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[DocumentRowUnsaved] = new JsonEncoder[DocumentRowUnsaved] { + override def unsafeEncode(a: DocumentRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""title":""") + JsonEncoder.string.unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""owner":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.owner, indent, out) + out.write(",") + out.write(""""filename":""") + JsonEncoder.string.unsafeEncode(a.filename, indent, out) + out.write(",") + out.write(""""fileextension":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.fileextension, indent, out) + out.write(",") + out.write(""""revision":""") + JsonEncoder.string.unsafeEncode(a.revision, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""documentsummary":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.documentsummary, indent, out) + out.write(",") + out.write(""""document":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.document, indent, out) + out.write(",") + out.write(""""folderflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.folderflag, indent, out) + out.write(",") + out.write(""""changenumber":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.changenumber, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + Defaulted.jsonEncoder(DocumentId.jsonEncoder).unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentStructure.scala new file mode 100644 index 0000000000..2f58d1e1d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/document/DocumentStructure.scala @@ -0,0 +1,45 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package document + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class DocumentStructure[Row](val prefix: Option[String], val extract: Row => DocumentRow, val merge: (Row, DocumentRow) => Row) + extends Relation[DocumentFields, DocumentRow, Row] + with DocumentFields[Row] { outer => + + override val title = new Field[/* max 50 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val owner = new Field[BusinessentityId, Row](prefix, "owner", None, Some("int4"))(x => extract(x).owner, (row, value) => merge(row, extract(row).copy(owner = value))) + override val folderflag = new Field[Flag, Row](prefix, "folderflag", None, Some("bool"))(x => extract(x).folderflag, (row, value) => merge(row, extract(row).copy(folderflag = value))) + override val filename = new Field[/* max 400 chars */ String, Row](prefix, "filename", None, None)(x => extract(x).filename, (row, value) => merge(row, extract(row).copy(filename = value))) + override val fileextension = new OptField[/* max 8 chars */ String, Row](prefix, "fileextension", None, None)(x => extract(x).fileextension, (row, value) => merge(row, extract(row).copy(fileextension = value))) + override val revision = new Field[/* bpchar, max 5 chars */ String, Row](prefix, "revision", None, Some("bpchar"))(x => extract(x).revision, (row, value) => merge(row, extract(row).copy(revision = value))) + override val changenumber = new Field[Int, Row](prefix, "changenumber", None, Some("int4"))(x => extract(x).changenumber, (row, value) => merge(row, extract(row).copy(changenumber = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, Some("int2"))(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val documentsummary = new OptField[String, Row](prefix, "documentsummary", None, None)(x => extract(x).documentsummary, (row, value) => merge(row, extract(row).copy(documentsummary = value))) + override val document = new OptField[TypoBytea, Row](prefix, "document", None, Some("bytea"))(x => extract(x).document, (row, value) => merge(row, extract(row).copy(document = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val documentnode = new IdField[DocumentId, Row](prefix, "documentnode", None, None)(x => extract(x).documentnode, (row, value) => merge(row, extract(row).copy(documentnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](title, owner, folderflag, filename, fileextension, revision, changenumber, status, documentsummary, document, rowguid, modifieddate, documentnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => DocumentRow, merge: (NewRow, DocumentRow) => NewRow): DocumentStructure[NewRow] = + new DocumentStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationFields.scala new file mode 100644 index 0000000000..7c45043058 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait IllustrationFields[Row] { + val illustrationid: IdField[IllustrationId, Row] + val diagram: OptField[TypoXml, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object IllustrationFields extends IllustrationStructure[IllustrationRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationId.scala new file mode 100644 index 0000000000..c6733f04fb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +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.illustration` */ +case class IllustrationId(value: Int) extends AnyVal +object IllustrationId { + implicit lazy val arraySetter: Setter[Array[IllustrationId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[IllustrationId, Int] = Bijection[IllustrationId, Int](_.value)(IllustrationId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[IllustrationId] = JdbcDecoder.intDecoder.map(IllustrationId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[IllustrationId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[IllustrationId] = JsonDecoder.int.map(IllustrationId.apply) + implicit lazy val jsonEncoder: JsonEncoder[IllustrationId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[IllustrationId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[IllustrationId] = ParameterMetaData.instance[IllustrationId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[IllustrationId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepo.scala new file mode 100644 index 0000000000..bdc37eb80a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait IllustrationRepo { + def delete(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[IllustrationFields, IllustrationRow] + def insert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, IllustrationRow] + def insert(unsaved: IllustrationRowUnsaved): ZIO[ZConnection, Throwable, IllustrationRow] + def select: SelectBuilder[IllustrationFields, IllustrationRow] + def selectAll: ZStream[ZConnection, Throwable, IllustrationRow] + def selectById(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Option[IllustrationRow]] + def selectByIds(illustrationids: Array[IllustrationId]): ZStream[ZConnection, Throwable, IllustrationRow] + def update(row: IllustrationRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[IllustrationFields, IllustrationRow] + def upsert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, UpdateResult[IllustrationRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoImpl.scala new file mode 100644 index 0000000000..f9f83d7b6e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoImpl.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object IllustrationRepoImpl extends IllustrationRepo { + override def delete(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.illustration where "illustrationid" = ${Segment.paramSegment(illustrationid)(IllustrationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[IllustrationFields, IllustrationRow] = { + DeleteBuilder("production.illustration", IllustrationFields) + } + override def insert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, IllustrationRow] = { + sql"""insert into production.illustration("illustrationid", "diagram", "modifieddate") + values (${Segment.paramSegment(unsaved.illustrationid)(IllustrationId.setter)}::int4, ${Segment.paramSegment(unsaved.diagram)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "illustrationid", "diagram", "modifieddate"::text + """.insertReturning(IllustrationRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: IllustrationRowUnsaved): ZIO[ZConnection, Throwable, IllustrationRow] = { + val fs = List( + Some((sql""""diagram"""", sql"${Segment.paramSegment(unsaved.diagram)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + unsaved.illustrationid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""illustrationid"""", sql"${Segment.paramSegment(value: IllustrationId)(IllustrationId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.illustration default values + returning "illustrationid", "diagram", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.illustration($names) values ($values) returning "illustrationid", "diagram", "modifieddate"::text""" + } + q.insertReturning(IllustrationRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[IllustrationFields, IllustrationRow] = { + SelectBuilderSql("production.illustration", IllustrationFields, IllustrationRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, IllustrationRow] = { + sql"""select "illustrationid", "diagram", "modifieddate"::text from production.illustration""".query(IllustrationRow.jdbcDecoder).selectStream + } + override def selectById(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Option[IllustrationRow]] = { + sql"""select "illustrationid", "diagram", "modifieddate"::text from production.illustration where "illustrationid" = ${Segment.paramSegment(illustrationid)(IllustrationId.setter)}""".query(IllustrationRow.jdbcDecoder).selectOne + } + override def selectByIds(illustrationids: Array[IllustrationId]): ZStream[ZConnection, Throwable, IllustrationRow] = { + sql"""select "illustrationid", "diagram", "modifieddate"::text from production.illustration where "illustrationid" = ANY(${Segment.paramSegment(illustrationids)(IllustrationId.arraySetter)})""".query(IllustrationRow.jdbcDecoder).selectStream + } + override def update(row: IllustrationRow): ZIO[ZConnection, Throwable, Boolean] = { + val illustrationid = row.illustrationid + sql"""update production.illustration + set "diagram" = ${Segment.paramSegment(row.diagram)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "illustrationid" = ${Segment.paramSegment(illustrationid)(IllustrationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[IllustrationFields, IllustrationRow] = { + UpdateBuilder("production.illustration", IllustrationFields, IllustrationRow.jdbcDecoder) + } + override def upsert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, UpdateResult[IllustrationRow]] = { + sql"""insert into production.illustration("illustrationid", "diagram", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.illustrationid)(IllustrationId.setter)}::int4, + ${Segment.paramSegment(unsaved.diagram)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("illustrationid") + do update set + "diagram" = EXCLUDED."diagram", + "modifieddate" = EXCLUDED."modifieddate" + returning "illustrationid", "diagram", "modifieddate"::text""".insertReturning(IllustrationRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoMock.scala new file mode 100644 index 0000000000..b0ec0a401e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class IllustrationRepoMock(toRow: Function1[IllustrationRowUnsaved, IllustrationRow], + map: scala.collection.mutable.Map[IllustrationId, IllustrationRow] = scala.collection.mutable.Map.empty) extends IllustrationRepo { + override def delete(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(illustrationid).isDefined) + } + override def delete: DeleteBuilder[IllustrationFields, IllustrationRow] = { + DeleteBuilderMock(DeleteParams.empty, IllustrationFields, map) + } + override def insert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, IllustrationRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.illustrationid)) + sys.error(s"id ${unsaved.illustrationid} already exists") + else + map.put(unsaved.illustrationid, unsaved) + + unsaved + } + } + override def insert(unsaved: IllustrationRowUnsaved): ZIO[ZConnection, Throwable, IllustrationRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[IllustrationFields, IllustrationRow] = { + SelectBuilderMock(IllustrationFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, IllustrationRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(illustrationid: IllustrationId): ZIO[ZConnection, Throwable, Option[IllustrationRow]] = { + ZIO.succeed(map.get(illustrationid)) + } + override def selectByIds(illustrationids: Array[IllustrationId]): ZStream[ZConnection, Throwable, IllustrationRow] = { + ZStream.fromIterable(illustrationids.flatMap(map.get)) + } + override def update(row: IllustrationRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.illustrationid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.illustrationid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[IllustrationFields, IllustrationRow] = { + UpdateBuilderMock(UpdateParams.empty, IllustrationFields, map) + } + override def upsert(unsaved: IllustrationRow): ZIO[ZConnection, Throwable, UpdateResult[IllustrationRow]] = { + ZIO.succeed { + map.put(unsaved.illustrationid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRow.scala new file mode 100644 index 0000000000..6a19203353 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class IllustrationRow( + /** Primary key for Illustration records. */ + illustrationid: IllustrationId, + /** Illustrations used in manufacturing instructions. Stored as XML. */ + diagram: Option[TypoXml], + modifieddate: TypoLocalDateTime +) + +object IllustrationRow { + implicit lazy val jdbcDecoder: JdbcDecoder[IllustrationRow] = new JdbcDecoder[IllustrationRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, IllustrationRow) = + columIndex + 2 -> + IllustrationRow( + illustrationid = IllustrationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + diagram = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[IllustrationRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + val diagram = jsonObj.get("diagram").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (illustrationid.isRight && diagram.isRight && modifieddate.isRight) + Right(IllustrationRow(illustrationid = illustrationid.toOption.get, diagram = diagram.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](illustrationid, diagram, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[IllustrationRow] = new JsonEncoder[IllustrationRow] { + override def unsafeEncode(a: IllustrationRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""diagram":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.diagram, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRowUnsaved.scala new file mode 100644 index 0000000000..1181bbce10 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationRowUnsaved.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.illustration` which has not been persisted yet */ +case class IllustrationRowUnsaved( + /** Illustrations used in manufacturing instructions. Stored as XML. */ + diagram: Option[TypoXml], + /** Default: nextval('production.illustration_illustrationid_seq'::regclass) + Primary key for Illustration records. */ + illustrationid: Defaulted[IllustrationId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(illustrationidDefault: => IllustrationId, modifieddateDefault: => TypoLocalDateTime): IllustrationRow = + IllustrationRow( + diagram = diagram, + illustrationid = illustrationid match { + case Defaulted.UseDefault => illustrationidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object IllustrationRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[IllustrationRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val diagram = jsonObj.get("diagram").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(Defaulted.jsonDecoder(IllustrationId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (diagram.isRight && illustrationid.isRight && modifieddate.isRight) + Right(IllustrationRowUnsaved(diagram = diagram.toOption.get, illustrationid = illustrationid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](diagram, illustrationid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[IllustrationRowUnsaved] = new JsonEncoder[IllustrationRowUnsaved] { + override def unsafeEncode(a: IllustrationRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""diagram":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.diagram, indent, out) + out.write(",") + out.write(""""illustrationid":""") + Defaulted.jsonEncoder(IllustrationId.jsonEncoder).unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationStructure.scala new file mode 100644 index 0000000000..9258b270be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/illustration/IllustrationStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package illustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoXml +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class IllustrationStructure[Row](val prefix: Option[String], val extract: Row => IllustrationRow, val merge: (Row, IllustrationRow) => Row) + extends Relation[IllustrationFields, IllustrationRow, Row] + with IllustrationFields[Row] { outer => + + override val illustrationid = new IdField[IllustrationId, Row](prefix, "illustrationid", None, Some("int4"))(x => extract(x).illustrationid, (row, value) => merge(row, extract(row).copy(illustrationid = value))) + override val diagram = new OptField[TypoXml, Row](prefix, "diagram", None, Some("xml"))(x => extract(x).diagram, (row, value) => merge(row, extract(row).copy(diagram = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](illustrationid, diagram, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => IllustrationRow, merge: (NewRow, IllustrationRow) => NewRow): IllustrationStructure[NewRow] = + new IllustrationStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationFields.scala new file mode 100644 index 0000000000..447ab8fcfd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait LocationFields[Row] { + val locationid: IdField[LocationId, Row] + val name: Field[Name, Row] + val costrate: Field[BigDecimal, Row] + val availability: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object LocationFields extends LocationStructure[LocationRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationId.scala new file mode 100644 index 0000000000..30d21ac8f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +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.location` */ +case class LocationId(value: Int) extends AnyVal +object LocationId { + implicit lazy val arraySetter: Setter[Array[LocationId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[LocationId, Int] = Bijection[LocationId, Int](_.value)(LocationId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[LocationId] = JdbcDecoder.intDecoder.map(LocationId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[LocationId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[LocationId] = JsonDecoder.int.map(LocationId.apply) + implicit lazy val jsonEncoder: JsonEncoder[LocationId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[LocationId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[LocationId] = ParameterMetaData.instance[LocationId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[LocationId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepo.scala new file mode 100644 index 0000000000..b839e327f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait LocationRepo { + def delete(locationid: LocationId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[LocationFields, LocationRow] + def insert(unsaved: LocationRow): ZIO[ZConnection, Throwable, LocationRow] + def insert(unsaved: LocationRowUnsaved): ZIO[ZConnection, Throwable, LocationRow] + def select: SelectBuilder[LocationFields, LocationRow] + def selectAll: ZStream[ZConnection, Throwable, LocationRow] + def selectById(locationid: LocationId): ZIO[ZConnection, Throwable, Option[LocationRow]] + def selectByIds(locationids: Array[LocationId]): ZStream[ZConnection, Throwable, LocationRow] + def update(row: LocationRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[LocationFields, LocationRow] + def upsert(unsaved: LocationRow): ZIO[ZConnection, Throwable, UpdateResult[LocationRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoImpl.scala new file mode 100644 index 0000000000..9ec7371b7f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoImpl.scala @@ -0,0 +1,113 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object LocationRepoImpl extends LocationRepo { + override def delete(locationid: LocationId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.location where "locationid" = ${Segment.paramSegment(locationid)(LocationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[LocationFields, LocationRow] = { + DeleteBuilder("production.location", LocationFields) + } + override def insert(unsaved: LocationRow): ZIO[ZConnection, Throwable, LocationRow] = { + sql"""insert into production.location("locationid", "name", "costrate", "availability", "modifieddate") + values (${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.costrate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.availability)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "locationid", "name", "costrate", "availability", "modifieddate"::text + """.insertReturning(LocationRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: LocationRowUnsaved): ZIO[ZConnection, Throwable, LocationRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.locationid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""locationid"""", sql"${Segment.paramSegment(value: LocationId)(LocationId.setter)}::int4")) + }, + unsaved.costrate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""costrate"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.availability match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""availability"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.location default values + returning "locationid", "name", "costrate", "availability", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.location($names) values ($values) returning "locationid", "name", "costrate", "availability", "modifieddate"::text""" + } + q.insertReturning(LocationRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[LocationFields, LocationRow] = { + SelectBuilderSql("production.location", LocationFields, LocationRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, LocationRow] = { + sql"""select "locationid", "name", "costrate", "availability", "modifieddate"::text from production.location""".query(LocationRow.jdbcDecoder).selectStream + } + override def selectById(locationid: LocationId): ZIO[ZConnection, Throwable, Option[LocationRow]] = { + sql"""select "locationid", "name", "costrate", "availability", "modifieddate"::text from production.location where "locationid" = ${Segment.paramSegment(locationid)(LocationId.setter)}""".query(LocationRow.jdbcDecoder).selectOne + } + override def selectByIds(locationids: Array[LocationId]): ZStream[ZConnection, Throwable, LocationRow] = { + sql"""select "locationid", "name", "costrate", "availability", "modifieddate"::text from production.location where "locationid" = ANY(${Segment.paramSegment(locationids)(LocationId.arraySetter)})""".query(LocationRow.jdbcDecoder).selectStream + } + override def update(row: LocationRow): ZIO[ZConnection, Throwable, Boolean] = { + val locationid = row.locationid + sql"""update production.location + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "costrate" = ${Segment.paramSegment(row.costrate)(Setter.bigDecimalScalaSetter)}::numeric, + "availability" = ${Segment.paramSegment(row.availability)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "locationid" = ${Segment.paramSegment(locationid)(LocationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[LocationFields, LocationRow] = { + UpdateBuilder("production.location", LocationFields, LocationRow.jdbcDecoder) + } + override def upsert(unsaved: LocationRow): ZIO[ZConnection, Throwable, UpdateResult[LocationRow]] = { + sql"""insert into production.location("locationid", "name", "costrate", "availability", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.costrate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.availability)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("locationid") + do update set + "name" = EXCLUDED."name", + "costrate" = EXCLUDED."costrate", + "availability" = EXCLUDED."availability", + "modifieddate" = EXCLUDED."modifieddate" + returning "locationid", "name", "costrate", "availability", "modifieddate"::text""".insertReturning(LocationRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoMock.scala new file mode 100644 index 0000000000..3e897e9039 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class LocationRepoMock(toRow: Function1[LocationRowUnsaved, LocationRow], + map: scala.collection.mutable.Map[LocationId, LocationRow] = scala.collection.mutable.Map.empty) extends LocationRepo { + override def delete(locationid: LocationId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(locationid).isDefined) + } + override def delete: DeleteBuilder[LocationFields, LocationRow] = { + DeleteBuilderMock(DeleteParams.empty, LocationFields, map) + } + override def insert(unsaved: LocationRow): ZIO[ZConnection, Throwable, LocationRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.locationid)) + sys.error(s"id ${unsaved.locationid} already exists") + else + map.put(unsaved.locationid, unsaved) + + unsaved + } + } + override def insert(unsaved: LocationRowUnsaved): ZIO[ZConnection, Throwable, LocationRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[LocationFields, LocationRow] = { + SelectBuilderMock(LocationFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, LocationRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(locationid: LocationId): ZIO[ZConnection, Throwable, Option[LocationRow]] = { + ZIO.succeed(map.get(locationid)) + } + override def selectByIds(locationids: Array[LocationId]): ZStream[ZConnection, Throwable, LocationRow] = { + ZStream.fromIterable(locationids.flatMap(map.get)) + } + override def update(row: LocationRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.locationid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.locationid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[LocationFields, LocationRow] = { + UpdateBuilderMock(UpdateParams.empty, LocationFields, map) + } + override def upsert(unsaved: LocationRow): ZIO[ZConnection, Throwable, UpdateResult[LocationRow]] = { + ZIO.succeed { + map.put(unsaved.locationid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRow.scala new file mode 100644 index 0000000000..9e0b25b003 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class LocationRow( + /** Primary key for Location records. */ + locationid: LocationId, + /** Location description. */ + name: Name, + /** Standard hourly cost of the manufacturing location. + Constraint CK_Location_CostRate affecting columns "costrate": ((costrate >= 0.00)) */ + costrate: BigDecimal, + /** Work capacity (in hours) of the manufacturing location. + Constraint CK_Location_Availability affecting columns "availability": ((availability >= 0.00)) */ + availability: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object LocationRow { + implicit lazy val jdbcDecoder: JdbcDecoder[LocationRow] = new JdbcDecoder[LocationRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, LocationRow) = + columIndex + 4 -> + LocationRow( + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + costrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 2, rs)._2, + availability = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[LocationRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val costrate = jsonObj.get("costrate").toRight("Missing field 'costrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val availability = jsonObj.get("availability").toRight("Missing field 'availability'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (locationid.isRight && name.isRight && costrate.isRight && availability.isRight && modifieddate.isRight) + Right(LocationRow(locationid = locationid.toOption.get, name = name.toOption.get, costrate = costrate.toOption.get, availability = availability.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](locationid, name, costrate, availability, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[LocationRow] = new JsonEncoder[LocationRow] { + override def unsafeEncode(a: LocationRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""costrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costrate, indent, out) + out.write(",") + out.write(""""availability":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.availability, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRowUnsaved.scala new file mode 100644 index 0000000000..6a2c35ee45 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationRowUnsaved.scala @@ -0,0 +1,88 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.location` which has not been persisted yet */ +case class LocationRowUnsaved( + /** Location description. */ + name: Name, + /** Default: nextval('production.location_locationid_seq'::regclass) + Primary key for Location records. */ + locationid: Defaulted[LocationId] = Defaulted.UseDefault, + /** Default: 0.00 + Standard hourly cost of the manufacturing location. + Constraint CK_Location_CostRate affecting columns "costrate": ((costrate >= 0.00)) */ + costrate: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Work capacity (in hours) of the manufacturing location. + Constraint CK_Location_Availability affecting columns "availability": ((availability >= 0.00)) */ + availability: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(locationidDefault: => LocationId, costrateDefault: => BigDecimal, availabilityDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): LocationRow = + LocationRow( + name = name, + locationid = locationid match { + case Defaulted.UseDefault => locationidDefault + case Defaulted.Provided(value) => value + }, + costrate = costrate match { + case Defaulted.UseDefault => costrateDefault + case Defaulted.Provided(value) => value + }, + availability = availability match { + case Defaulted.UseDefault => availabilityDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object LocationRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[LocationRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(Defaulted.jsonDecoder(LocationId.jsonDecoder))) + val costrate = jsonObj.get("costrate").toRight("Missing field 'costrate'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val availability = jsonObj.get("availability").toRight("Missing field 'availability'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && locationid.isRight && costrate.isRight && availability.isRight && modifieddate.isRight) + Right(LocationRowUnsaved(name = name.toOption.get, locationid = locationid.toOption.get, costrate = costrate.toOption.get, availability = availability.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, locationid, costrate, availability, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[LocationRowUnsaved] = new JsonEncoder[LocationRowUnsaved] { + override def unsafeEncode(a: LocationRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""locationid":""") + Defaulted.jsonEncoder(LocationId.jsonEncoder).unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""costrate":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.costrate, indent, out) + out.write(",") + out.write(""""availability":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.availability, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationStructure.scala new file mode 100644 index 0000000000..09cb5efc34 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/location/LocationStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package location + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class LocationStructure[Row](val prefix: Option[String], val extract: Row => LocationRow, val merge: (Row, LocationRow) => Row) + extends Relation[LocationFields, LocationRow, Row] + with LocationFields[Row] { outer => + + override val locationid = new IdField[LocationId, Row](prefix, "locationid", None, Some("int4"))(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val costrate = new Field[BigDecimal, Row](prefix, "costrate", None, Some("numeric"))(x => extract(x).costrate, (row, value) => merge(row, extract(row).copy(costrate = value))) + override val availability = new Field[BigDecimal, Row](prefix, "availability", None, Some("numeric"))(x => extract(x).availability, (row, value) => merge(row, extract(row).copy(availability = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](locationid, name, costrate, availability, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => LocationRow, merge: (NewRow, LocationRow) => NewRow): LocationStructure[NewRow] = + new LocationStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductFields.scala new file mode 100644 index 0000000000..1a5d92a40f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductFields.scala @@ -0,0 +1,50 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductFields[Row] { + val productid: IdField[ProductId, Row] + val name: Field[Name, Row] + val productnumber: Field[/* max 25 chars */ String, Row] + val makeflag: Field[Flag, Row] + val finishedgoodsflag: Field[Flag, Row] + val color: OptField[/* max 15 chars */ String, Row] + val safetystocklevel: Field[TypoShort, Row] + val reorderpoint: Field[TypoShort, Row] + val standardcost: Field[BigDecimal, Row] + val listprice: Field[BigDecimal, Row] + val size: OptField[/* max 5 chars */ String, Row] + val sizeunitmeasurecode: OptField[UnitmeasureId, Row] + val weightunitmeasurecode: OptField[UnitmeasureId, Row] + val weight: OptField[BigDecimal, Row] + val daystomanufacture: Field[Int, Row] + val productline: OptField[/* bpchar, max 2 chars */ String, Row] + val `class`: OptField[/* bpchar, max 2 chars */ String, Row] + val style: OptField[/* bpchar, max 2 chars */ String, Row] + val productsubcategoryid: OptField[ProductsubcategoryId, Row] + val productmodelid: OptField[ProductmodelId, Row] + val sellstartdate: Field[TypoLocalDateTime, Row] + val sellenddate: OptField[TypoLocalDateTime, Row] + val discontinueddate: OptField[TypoLocalDateTime, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductFields extends ProductStructure[ProductRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductId.scala new file mode 100644 index 0000000000..86fc64425f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +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.product` */ +case class ProductId(value: Int) extends AnyVal +object ProductId { + implicit lazy val arraySetter: Setter[Array[ProductId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductId, Int] = Bijection[ProductId, Int](_.value)(ProductId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductId] = JdbcDecoder.intDecoder.map(ProductId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductId] = JsonDecoder.int.map(ProductId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductId] = ParameterMetaData.instance[ProductId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepo.scala new file mode 100644 index 0000000000..d0e6e88825 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductRepo { + def delete(productid: ProductId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductFields, ProductRow] + def insert(unsaved: ProductRow): ZIO[ZConnection, Throwable, ProductRow] + def insert(unsaved: ProductRowUnsaved): ZIO[ZConnection, Throwable, ProductRow] + def select: SelectBuilder[ProductFields, ProductRow] + def selectAll: ZStream[ZConnection, Throwable, ProductRow] + def selectById(productid: ProductId): ZIO[ZConnection, Throwable, Option[ProductRow]] + def selectByIds(productids: Array[ProductId]): ZStream[ZConnection, Throwable, ProductRow] + def update(row: ProductRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductFields, ProductRow] + def upsert(unsaved: ProductRow): ZIO[ZConnection, Throwable, UpdateResult[ProductRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoImpl.scala new file mode 100644 index 0000000000..336efbd784 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoImpl.scala @@ -0,0 +1,202 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductRepoImpl extends ProductRepo { + override def delete(productid: ProductId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.product where "productid" = ${Segment.paramSegment(productid)(ProductId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductFields, ProductRow] = { + DeleteBuilder("production.product", ProductFields) + } + override def insert(unsaved: ProductRow): ZIO[ZConnection, Throwable, ProductRow] = { + sql"""insert into production.product("productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate", "sellenddate", "discontinueddate", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.productnumber)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.makeflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.finishedgoodsflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.color)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.safetystocklevel)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.reorderpoint)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.size)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.sizeunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, ${Segment.paramSegment(unsaved.weightunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, ${Segment.paramSegment(unsaved.weight)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.daystomanufacture)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.productline)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, ${Segment.paramSegment(unsaved.`class`)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, ${Segment.paramSegment(unsaved.style)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, ${Segment.paramSegment(unsaved.productsubcategoryid)(Setter.optionParamSetter(ProductsubcategoryId.setter))}::int4, ${Segment.paramSegment(unsaved.productmodelid)(Setter.optionParamSetter(ProductmodelId.setter))}::int4, ${Segment.paramSegment(unsaved.sellstartdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.sellenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.discontinueddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text + """.insertReturning(ProductRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductRowUnsaved): ZIO[ZConnection, Throwable, ProductRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""productnumber"""", sql"${Segment.paramSegment(unsaved.productnumber)(Setter.stringSetter)}")), + Some((sql""""color"""", sql"${Segment.paramSegment(unsaved.color)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""safetystocklevel"""", sql"${Segment.paramSegment(unsaved.safetystocklevel)(TypoShort.setter)}::int2")), + Some((sql""""reorderpoint"""", sql"${Segment.paramSegment(unsaved.reorderpoint)(TypoShort.setter)}::int2")), + Some((sql""""standardcost"""", sql"${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""listprice"""", sql"${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""size"""", sql"${Segment.paramSegment(unsaved.size)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""sizeunitmeasurecode"""", sql"${Segment.paramSegment(unsaved.sizeunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar")), + Some((sql""""weightunitmeasurecode"""", sql"${Segment.paramSegment(unsaved.weightunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar")), + Some((sql""""weight"""", sql"${Segment.paramSegment(unsaved.weight)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + Some((sql""""daystomanufacture"""", sql"${Segment.paramSegment(unsaved.daystomanufacture)(Setter.intSetter)}::int4")), + Some((sql""""productline"""", sql"${Segment.paramSegment(unsaved.productline)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar")), + Some((sql""""class"""", sql"${Segment.paramSegment(unsaved.`class`)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar")), + Some((sql""""style"""", sql"${Segment.paramSegment(unsaved.style)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar")), + Some((sql""""productsubcategoryid"""", sql"${Segment.paramSegment(unsaved.productsubcategoryid)(Setter.optionParamSetter(ProductsubcategoryId.setter))}::int4")), + Some((sql""""productmodelid"""", sql"${Segment.paramSegment(unsaved.productmodelid)(Setter.optionParamSetter(ProductmodelId.setter))}::int4")), + Some((sql""""sellstartdate"""", sql"${Segment.paramSegment(unsaved.sellstartdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""sellenddate"""", sql"${Segment.paramSegment(unsaved.sellenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""discontinueddate"""", sql"${Segment.paramSegment(unsaved.discontinueddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + unsaved.productid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productid"""", sql"${Segment.paramSegment(value: ProductId)(ProductId.setter)}::int4")) + }, + unsaved.makeflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""makeflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.finishedgoodsflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""finishedgoodsflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.product default values + returning "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.product($names) values ($values) returning "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductFields, ProductRow] = { + SelectBuilderSql("production.product", ProductFields, ProductRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductRow] = { + sql"""select "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text from production.product""".query(ProductRow.jdbcDecoder).selectStream + } + override def selectById(productid: ProductId): ZIO[ZConnection, Throwable, Option[ProductRow]] = { + sql"""select "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text from production.product where "productid" = ${Segment.paramSegment(productid)(ProductId.setter)}""".query(ProductRow.jdbcDecoder).selectOne + } + override def selectByIds(productids: Array[ProductId]): ZStream[ZConnection, Throwable, ProductRow] = { + sql"""select "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text from production.product where "productid" = ANY(${Segment.paramSegment(productids)(ProductId.arraySetter)})""".query(ProductRow.jdbcDecoder).selectStream + } + override def update(row: ProductRow): ZIO[ZConnection, Throwable, Boolean] = { + val productid = row.productid + sql"""update production.product + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "productnumber" = ${Segment.paramSegment(row.productnumber)(Setter.stringSetter)}, + "makeflag" = ${Segment.paramSegment(row.makeflag)(Flag.setter)}::bool, + "finishedgoodsflag" = ${Segment.paramSegment(row.finishedgoodsflag)(Flag.setter)}::bool, + "color" = ${Segment.paramSegment(row.color)(Setter.optionParamSetter(Setter.stringSetter))}, + "safetystocklevel" = ${Segment.paramSegment(row.safetystocklevel)(TypoShort.setter)}::int2, + "reorderpoint" = ${Segment.paramSegment(row.reorderpoint)(TypoShort.setter)}::int2, + "standardcost" = ${Segment.paramSegment(row.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, + "listprice" = ${Segment.paramSegment(row.listprice)(Setter.bigDecimalScalaSetter)}::numeric, + "size" = ${Segment.paramSegment(row.size)(Setter.optionParamSetter(Setter.stringSetter))}, + "sizeunitmeasurecode" = ${Segment.paramSegment(row.sizeunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, + "weightunitmeasurecode" = ${Segment.paramSegment(row.weightunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, + "weight" = ${Segment.paramSegment(row.weight)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "daystomanufacture" = ${Segment.paramSegment(row.daystomanufacture)(Setter.intSetter)}::int4, + "productline" = ${Segment.paramSegment(row.productline)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + "class" = ${Segment.paramSegment(row.`class`)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + "style" = ${Segment.paramSegment(row.style)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + "productsubcategoryid" = ${Segment.paramSegment(row.productsubcategoryid)(Setter.optionParamSetter(ProductsubcategoryId.setter))}::int4, + "productmodelid" = ${Segment.paramSegment(row.productmodelid)(Setter.optionParamSetter(ProductmodelId.setter))}::int4, + "sellstartdate" = ${Segment.paramSegment(row.sellstartdate)(TypoLocalDateTime.setter)}::timestamp, + "sellenddate" = ${Segment.paramSegment(row.sellenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "discontinueddate" = ${Segment.paramSegment(row.discontinueddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(productid)(ProductId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductFields, ProductRow] = { + UpdateBuilder("production.product", ProductFields, ProductRow.jdbcDecoder) + } + override def upsert(unsaved: ProductRow): ZIO[ZConnection, Throwable, UpdateResult[ProductRow]] = { + sql"""insert into production.product("productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate", "sellenddate", "discontinueddate", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.productnumber)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.makeflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.finishedgoodsflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.color)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.safetystocklevel)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.reorderpoint)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.size)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.sizeunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, + ${Segment.paramSegment(unsaved.weightunitmeasurecode)(Setter.optionParamSetter(UnitmeasureId.setter))}::bpchar, + ${Segment.paramSegment(unsaved.weight)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.daystomanufacture)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.productline)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + ${Segment.paramSegment(unsaved.`class`)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + ${Segment.paramSegment(unsaved.style)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, + ${Segment.paramSegment(unsaved.productsubcategoryid)(Setter.optionParamSetter(ProductsubcategoryId.setter))}::int4, + ${Segment.paramSegment(unsaved.productmodelid)(Setter.optionParamSetter(ProductmodelId.setter))}::int4, + ${Segment.paramSegment(unsaved.sellstartdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.sellenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.discontinueddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid") + do update set + "name" = EXCLUDED."name", + "productnumber" = EXCLUDED."productnumber", + "makeflag" = EXCLUDED."makeflag", + "finishedgoodsflag" = EXCLUDED."finishedgoodsflag", + "color" = EXCLUDED."color", + "safetystocklevel" = EXCLUDED."safetystocklevel", + "reorderpoint" = EXCLUDED."reorderpoint", + "standardcost" = EXCLUDED."standardcost", + "listprice" = EXCLUDED."listprice", + "size" = EXCLUDED."size", + "sizeunitmeasurecode" = EXCLUDED."sizeunitmeasurecode", + "weightunitmeasurecode" = EXCLUDED."weightunitmeasurecode", + "weight" = EXCLUDED."weight", + "daystomanufacture" = EXCLUDED."daystomanufacture", + "productline" = EXCLUDED."productline", + "class" = EXCLUDED."class", + "style" = EXCLUDED."style", + "productsubcategoryid" = EXCLUDED."productsubcategoryid", + "productmodelid" = EXCLUDED."productmodelid", + "sellstartdate" = EXCLUDED."sellstartdate", + "sellenddate" = EXCLUDED."sellenddate", + "discontinueddate" = EXCLUDED."discontinueddate", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "name", "productnumber", "makeflag", "finishedgoodsflag", "color", "safetystocklevel", "reorderpoint", "standardcost", "listprice", "size", "sizeunitmeasurecode", "weightunitmeasurecode", "weight", "daystomanufacture", "productline", "class", "style", "productsubcategoryid", "productmodelid", "sellstartdate"::text, "sellenddate"::text, "discontinueddate"::text, "rowguid", "modifieddate"::text""".insertReturning(ProductRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoMock.scala new file mode 100644 index 0000000000..57f8363ab2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductRepoMock(toRow: Function1[ProductRowUnsaved, ProductRow], + map: scala.collection.mutable.Map[ProductId, ProductRow] = scala.collection.mutable.Map.empty) extends ProductRepo { + override def delete(productid: ProductId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productid).isDefined) + } + override def delete: DeleteBuilder[ProductFields, ProductRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductFields, map) + } + override def insert(unsaved: ProductRow): ZIO[ZConnection, Throwable, ProductRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productid)) + sys.error(s"id ${unsaved.productid} already exists") + else + map.put(unsaved.productid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductRowUnsaved): ZIO[ZConnection, Throwable, ProductRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductFields, ProductRow] = { + SelectBuilderMock(ProductFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productid: ProductId): ZIO[ZConnection, Throwable, Option[ProductRow]] = { + ZIO.succeed(map.get(productid)) + } + override def selectByIds(productids: Array[ProductId]): ZStream[ZConnection, Throwable, ProductRow] = { + ZStream.fromIterable(productids.flatMap(map.get)) + } + override def update(row: ProductRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductFields, ProductRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductFields, map) + } + override def upsert(unsaved: ProductRow): ZIO[ZConnection, Throwable, UpdateResult[ProductRow]] = { + ZIO.succeed { + map.put(unsaved.productid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRow.scala new file mode 100644 index 0000000000..4a38e8b632 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRow.scala @@ -0,0 +1,233 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductRow( + /** Primary key for Product records. */ + productid: ProductId, + /** Name of the product. */ + name: Name, + /** Unique product identification number. */ + productnumber: /* max 25 chars */ String, + /** 0 = Product is purchased, 1 = Product is manufactured in-house. */ + makeflag: Flag, + /** 0 = Product is not a salable item. 1 = Product is salable. */ + finishedgoodsflag: Flag, + /** Product color. */ + color: Option[/* max 15 chars */ String], + /** Minimum inventory quantity. + Constraint CK_Product_SafetyStockLevel affecting columns "safetystocklevel": ((safetystocklevel > 0)) */ + safetystocklevel: TypoShort, + /** Inventory level that triggers a purchase order or work order. + Constraint CK_Product_ReorderPoint affecting columns "reorderpoint": ((reorderpoint > 0)) */ + reorderpoint: TypoShort, + /** Standard cost of the product. + Constraint CK_Product_StandardCost affecting columns "standardcost": ((standardcost >= 0.00)) */ + standardcost: BigDecimal, + /** Selling price. + Constraint CK_Product_ListPrice affecting columns "listprice": ((listprice >= 0.00)) */ + listprice: BigDecimal, + /** Product size. */ + size: Option[/* max 5 chars */ String], + /** Unit of measure for Size column. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + sizeunitmeasurecode: Option[UnitmeasureId], + /** Unit of measure for Weight column. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + weightunitmeasurecode: Option[UnitmeasureId], + /** Product weight. + Constraint CK_Product_Weight affecting columns "weight": ((weight > 0.00)) */ + weight: Option[BigDecimal], + /** Number of days required to manufacture the product. + Constraint CK_Product_DaysToManufacture affecting columns "daystomanufacture": ((daystomanufacture >= 0)) */ + daystomanufacture: Int, + /** R = Road, M = Mountain, T = Touring, S = Standard + Constraint CK_Product_ProductLine affecting columns "productline": (((upper((productline)::text) = ANY (ARRAY['S'::text, 'T'::text, 'M'::text, 'R'::text])) OR (productline IS NULL))) */ + productline: Option[/* bpchar, max 2 chars */ String], + /** H = High, M = Medium, L = Low + Constraint CK_Product_Class affecting columns "class": (((upper((class)::text) = ANY (ARRAY['L'::text, 'M'::text, 'H'::text])) OR (class IS NULL))) */ + `class`: Option[/* bpchar, max 2 chars */ String], + /** W = Womens, M = Mens, U = Universal + Constraint CK_Product_Style affecting columns "style": (((upper((style)::text) = ANY (ARRAY['W'::text, 'M'::text, 'U'::text])) OR (style IS NULL))) */ + style: Option[/* bpchar, max 2 chars */ String], + /** Product is a member of this product subcategory. Foreign key to ProductSubCategory.ProductSubCategoryID. + Points to [[productsubcategory.ProductsubcategoryRow.productsubcategoryid]] */ + productsubcategoryid: Option[ProductsubcategoryId], + /** Product is a member of this product model. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: Option[ProductmodelId], + /** Date the product was available for sale. + Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */ + sellstartdate: TypoLocalDateTime, + /** Date the product was no longer available for sale. + Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */ + sellenddate: Option[TypoLocalDateTime], + /** Date the product was discontinued. */ + discontinueddate: Option[TypoLocalDateTime], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ProductRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductRow] = new JdbcDecoder[ProductRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductRow) = + columIndex + 24 -> + ProductRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + makeflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + finishedgoodsflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + color = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + safetystocklevel = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + reorderpoint = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + standardcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + listprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 9, rs)._2, + size = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + sizeunitmeasurecode = JdbcDecoder.optionDecoder(UnitmeasureId.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + weightunitmeasurecode = JdbcDecoder.optionDecoder(UnitmeasureId.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + weight = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 13, rs)._2, + daystomanufacture = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 14, rs)._2, + productline = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + `class` = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + style = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + productsubcategoryid = JdbcDecoder.optionDecoder(ProductsubcategoryId.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + productmodelid = JdbcDecoder.optionDecoder(ProductmodelId.jdbcDecoder).unsafeDecode(columIndex + 19, rs)._2, + sellstartdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 20, rs)._2, + sellenddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 21, rs)._2, + discontinueddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 22, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 23, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 24, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productnumber = jsonObj.get("productnumber").toRight("Missing field 'productnumber'").flatMap(_.as(JsonDecoder.string)) + val makeflag = jsonObj.get("makeflag").toRight("Missing field 'makeflag'").flatMap(_.as(Flag.jsonDecoder)) + val finishedgoodsflag = jsonObj.get("finishedgoodsflag").toRight("Missing field 'finishedgoodsflag'").flatMap(_.as(Flag.jsonDecoder)) + val color = jsonObj.get("color").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val safetystocklevel = jsonObj.get("safetystocklevel").toRight("Missing field 'safetystocklevel'").flatMap(_.as(TypoShort.jsonDecoder)) + val reorderpoint = jsonObj.get("reorderpoint").toRight("Missing field 'reorderpoint'").flatMap(_.as(TypoShort.jsonDecoder)) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val size = jsonObj.get("size").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sizeunitmeasurecode = jsonObj.get("sizeunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weightunitmeasurecode = jsonObj.get("weightunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weight = jsonObj.get("weight").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val daystomanufacture = jsonObj.get("daystomanufacture").toRight("Missing field 'daystomanufacture'").flatMap(_.as(JsonDecoder.int)) + val productline = jsonObj.get("productline").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `class` = jsonObj.get("class").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val style = jsonObj.get("style").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productsubcategoryid = jsonObj.get("productsubcategoryid").fold[Either[String, Option[ProductsubcategoryId]]](Right(None))(_.as(JsonDecoder.option(ProductsubcategoryId.jsonDecoder))) + val productmodelid = jsonObj.get("productmodelid").fold[Either[String, Option[ProductmodelId]]](Right(None))(_.as(JsonDecoder.option(ProductmodelId.jsonDecoder))) + val sellstartdate = jsonObj.get("sellstartdate").toRight("Missing field 'sellstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val sellenddate = jsonObj.get("sellenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val discontinueddate = jsonObj.get("discontinueddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && name.isRight && productnumber.isRight && makeflag.isRight && finishedgoodsflag.isRight && color.isRight && safetystocklevel.isRight && reorderpoint.isRight && standardcost.isRight && listprice.isRight && size.isRight && sizeunitmeasurecode.isRight && weightunitmeasurecode.isRight && weight.isRight && daystomanufacture.isRight && productline.isRight && `class`.isRight && style.isRight && productsubcategoryid.isRight && productmodelid.isRight && sellstartdate.isRight && sellenddate.isRight && discontinueddate.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductRow(productid = productid.toOption.get, name = name.toOption.get, productnumber = productnumber.toOption.get, makeflag = makeflag.toOption.get, finishedgoodsflag = finishedgoodsflag.toOption.get, color = color.toOption.get, safetystocklevel = safetystocklevel.toOption.get, reorderpoint = reorderpoint.toOption.get, standardcost = standardcost.toOption.get, listprice = listprice.toOption.get, size = size.toOption.get, sizeunitmeasurecode = sizeunitmeasurecode.toOption.get, weightunitmeasurecode = weightunitmeasurecode.toOption.get, weight = weight.toOption.get, daystomanufacture = daystomanufacture.toOption.get, productline = productline.toOption.get, `class` = `class`.toOption.get, style = style.toOption.get, productsubcategoryid = productsubcategoryid.toOption.get, productmodelid = productmodelid.toOption.get, sellstartdate = sellstartdate.toOption.get, sellenddate = sellenddate.toOption.get, discontinueddate = discontinueddate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, name, productnumber, makeflag, finishedgoodsflag, color, safetystocklevel, reorderpoint, standardcost, listprice, size, sizeunitmeasurecode, weightunitmeasurecode, weight, daystomanufacture, productline, `class`, style, productsubcategoryid, productmodelid, sellstartdate, sellenddate, discontinueddate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductRow] = new JsonEncoder[ProductRow] { + override def unsafeEncode(a: ProductRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productnumber":""") + JsonEncoder.string.unsafeEncode(a.productnumber, indent, out) + out.write(",") + out.write(""""makeflag":""") + Flag.jsonEncoder.unsafeEncode(a.makeflag, indent, out) + out.write(",") + out.write(""""finishedgoodsflag":""") + Flag.jsonEncoder.unsafeEncode(a.finishedgoodsflag, indent, out) + out.write(",") + out.write(""""color":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.color, indent, out) + out.write(",") + out.write(""""safetystocklevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.safetystocklevel, indent, out) + out.write(",") + out.write(""""reorderpoint":""") + TypoShort.jsonEncoder.unsafeEncode(a.reorderpoint, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""size":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.size, indent, out) + out.write(",") + out.write(""""sizeunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.sizeunitmeasurecode, indent, out) + out.write(",") + out.write(""""weightunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.weightunitmeasurecode, indent, out) + out.write(",") + out.write(""""weight":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.weight, indent, out) + out.write(",") + out.write(""""daystomanufacture":""") + JsonEncoder.int.unsafeEncode(a.daystomanufacture, indent, out) + out.write(",") + out.write(""""productline":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.productline, indent, out) + out.write(",") + out.write(""""class":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`class`, indent, out) + out.write(",") + out.write(""""style":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.style, indent, out) + out.write(",") + out.write(""""productsubcategoryid":""") + JsonEncoder.option(ProductsubcategoryId.jsonEncoder).unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""productmodelid":""") + JsonEncoder.option(ProductmodelId.jsonEncoder).unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""sellstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.sellstartdate, indent, out) + out.write(",") + out.write(""""sellenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.sellenddate, indent, out) + out.write(",") + out.write(""""discontinueddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.discontinueddate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRowUnsaved.scala new file mode 100644 index 0000000000..9fd3747bdb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductRowUnsaved.scala @@ -0,0 +1,250 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.product` which has not been persisted yet */ +case class ProductRowUnsaved( + /** Name of the product. */ + name: Name, + /** Unique product identification number. */ + productnumber: /* max 25 chars */ String, + /** Product color. */ + color: Option[/* max 15 chars */ String], + /** Minimum inventory quantity. + Constraint CK_Product_SafetyStockLevel affecting columns "safetystocklevel": ((safetystocklevel > 0)) */ + safetystocklevel: TypoShort, + /** Inventory level that triggers a purchase order or work order. + Constraint CK_Product_ReorderPoint affecting columns "reorderpoint": ((reorderpoint > 0)) */ + reorderpoint: TypoShort, + /** Standard cost of the product. + Constraint CK_Product_StandardCost affecting columns "standardcost": ((standardcost >= 0.00)) */ + standardcost: BigDecimal, + /** Selling price. + Constraint CK_Product_ListPrice affecting columns "listprice": ((listprice >= 0.00)) */ + listprice: BigDecimal, + /** Product size. */ + size: Option[/* max 5 chars */ String], + /** Unit of measure for Size column. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + sizeunitmeasurecode: Option[UnitmeasureId], + /** Unit of measure for Weight column. + Points to [[unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + weightunitmeasurecode: Option[UnitmeasureId], + /** Product weight. + Constraint CK_Product_Weight affecting columns "weight": ((weight > 0.00)) */ + weight: Option[BigDecimal], + /** Number of days required to manufacture the product. + Constraint CK_Product_DaysToManufacture affecting columns "daystomanufacture": ((daystomanufacture >= 0)) */ + daystomanufacture: Int, + /** R = Road, M = Mountain, T = Touring, S = Standard + Constraint CK_Product_ProductLine affecting columns "productline": (((upper((productline)::text) = ANY (ARRAY['S'::text, 'T'::text, 'M'::text, 'R'::text])) OR (productline IS NULL))) */ + productline: Option[/* bpchar, max 2 chars */ String], + /** H = High, M = Medium, L = Low + Constraint CK_Product_Class affecting columns "class": (((upper((class)::text) = ANY (ARRAY['L'::text, 'M'::text, 'H'::text])) OR (class IS NULL))) */ + `class`: Option[/* bpchar, max 2 chars */ String], + /** W = Womens, M = Mens, U = Universal + Constraint CK_Product_Style affecting columns "style": (((upper((style)::text) = ANY (ARRAY['W'::text, 'M'::text, 'U'::text])) OR (style IS NULL))) */ + style: Option[/* bpchar, max 2 chars */ String], + /** Product is a member of this product subcategory. Foreign key to ProductSubCategory.ProductSubCategoryID. + Points to [[productsubcategory.ProductsubcategoryRow.productsubcategoryid]] */ + productsubcategoryid: Option[ProductsubcategoryId], + /** Product is a member of this product model. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: Option[ProductmodelId], + /** Date the product was available for sale. + Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */ + sellstartdate: TypoLocalDateTime, + /** Date the product was no longer available for sale. + Constraint CK_Product_SellEndDate affecting columns "sellenddate", "sellstartdate": (((sellenddate >= sellstartdate) OR (sellenddate IS NULL))) */ + sellenddate: Option[TypoLocalDateTime], + /** Date the product was discontinued. */ + discontinueddate: Option[TypoLocalDateTime], + /** Default: nextval('production.product_productid_seq'::regclass) + Primary key for Product records. */ + productid: Defaulted[ProductId] = Defaulted.UseDefault, + /** Default: true + 0 = Product is purchased, 1 = Product is manufactured in-house. */ + makeflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: true + 0 = Product is not a salable item. 1 = Product is salable. */ + finishedgoodsflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productidDefault: => ProductId, makeflagDefault: => Flag, finishedgoodsflagDefault: => Flag, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductRow = + ProductRow( + name = name, + productnumber = productnumber, + color = color, + safetystocklevel = safetystocklevel, + reorderpoint = reorderpoint, + standardcost = standardcost, + listprice = listprice, + size = size, + sizeunitmeasurecode = sizeunitmeasurecode, + weightunitmeasurecode = weightunitmeasurecode, + weight = weight, + daystomanufacture = daystomanufacture, + productline = productline, + `class` = `class`, + style = style, + productsubcategoryid = productsubcategoryid, + productmodelid = productmodelid, + sellstartdate = sellstartdate, + sellenddate = sellenddate, + discontinueddate = discontinueddate, + productid = productid match { + case Defaulted.UseDefault => productidDefault + case Defaulted.Provided(value) => value + }, + makeflag = makeflag match { + case Defaulted.UseDefault => makeflagDefault + case Defaulted.Provided(value) => value + }, + finishedgoodsflag = finishedgoodsflag match { + case Defaulted.UseDefault => finishedgoodsflagDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productnumber = jsonObj.get("productnumber").toRight("Missing field 'productnumber'").flatMap(_.as(JsonDecoder.string)) + val color = jsonObj.get("color").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val safetystocklevel = jsonObj.get("safetystocklevel").toRight("Missing field 'safetystocklevel'").flatMap(_.as(TypoShort.jsonDecoder)) + val reorderpoint = jsonObj.get("reorderpoint").toRight("Missing field 'reorderpoint'").flatMap(_.as(TypoShort.jsonDecoder)) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val size = jsonObj.get("size").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val sizeunitmeasurecode = jsonObj.get("sizeunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weightunitmeasurecode = jsonObj.get("weightunitmeasurecode").fold[Either[String, Option[UnitmeasureId]]](Right(None))(_.as(JsonDecoder.option(UnitmeasureId.jsonDecoder))) + val weight = jsonObj.get("weight").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val daystomanufacture = jsonObj.get("daystomanufacture").toRight("Missing field 'daystomanufacture'").flatMap(_.as(JsonDecoder.int)) + val productline = jsonObj.get("productline").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `class` = jsonObj.get("class").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val style = jsonObj.get("style").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productsubcategoryid = jsonObj.get("productsubcategoryid").fold[Either[String, Option[ProductsubcategoryId]]](Right(None))(_.as(JsonDecoder.option(ProductsubcategoryId.jsonDecoder))) + val productmodelid = jsonObj.get("productmodelid").fold[Either[String, Option[ProductmodelId]]](Right(None))(_.as(JsonDecoder.option(ProductmodelId.jsonDecoder))) + val sellstartdate = jsonObj.get("sellstartdate").toRight("Missing field 'sellstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val sellenddate = jsonObj.get("sellenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val discontinueddate = jsonObj.get("discontinueddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(Defaulted.jsonDecoder(ProductId.jsonDecoder))) + val makeflag = jsonObj.get("makeflag").toRight("Missing field 'makeflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val finishedgoodsflag = jsonObj.get("finishedgoodsflag").toRight("Missing field 'finishedgoodsflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && productnumber.isRight && color.isRight && safetystocklevel.isRight && reorderpoint.isRight && standardcost.isRight && listprice.isRight && size.isRight && sizeunitmeasurecode.isRight && weightunitmeasurecode.isRight && weight.isRight && daystomanufacture.isRight && productline.isRight && `class`.isRight && style.isRight && productsubcategoryid.isRight && productmodelid.isRight && sellstartdate.isRight && sellenddate.isRight && discontinueddate.isRight && productid.isRight && makeflag.isRight && finishedgoodsflag.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductRowUnsaved(name = name.toOption.get, productnumber = productnumber.toOption.get, color = color.toOption.get, safetystocklevel = safetystocklevel.toOption.get, reorderpoint = reorderpoint.toOption.get, standardcost = standardcost.toOption.get, listprice = listprice.toOption.get, size = size.toOption.get, sizeunitmeasurecode = sizeunitmeasurecode.toOption.get, weightunitmeasurecode = weightunitmeasurecode.toOption.get, weight = weight.toOption.get, daystomanufacture = daystomanufacture.toOption.get, productline = productline.toOption.get, `class` = `class`.toOption.get, style = style.toOption.get, productsubcategoryid = productsubcategoryid.toOption.get, productmodelid = productmodelid.toOption.get, sellstartdate = sellstartdate.toOption.get, sellenddate = sellenddate.toOption.get, discontinueddate = discontinueddate.toOption.get, productid = productid.toOption.get, makeflag = makeflag.toOption.get, finishedgoodsflag = finishedgoodsflag.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, productnumber, color, safetystocklevel, reorderpoint, standardcost, listprice, size, sizeunitmeasurecode, weightunitmeasurecode, weight, daystomanufacture, productline, `class`, style, productsubcategoryid, productmodelid, sellstartdate, sellenddate, discontinueddate, productid, makeflag, finishedgoodsflag, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductRowUnsaved] = new JsonEncoder[ProductRowUnsaved] { + override def unsafeEncode(a: ProductRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productnumber":""") + JsonEncoder.string.unsafeEncode(a.productnumber, indent, out) + out.write(",") + out.write(""""color":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.color, indent, out) + out.write(",") + out.write(""""safetystocklevel":""") + TypoShort.jsonEncoder.unsafeEncode(a.safetystocklevel, indent, out) + out.write(",") + out.write(""""reorderpoint":""") + TypoShort.jsonEncoder.unsafeEncode(a.reorderpoint, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""size":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.size, indent, out) + out.write(",") + out.write(""""sizeunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.sizeunitmeasurecode, indent, out) + out.write(",") + out.write(""""weightunitmeasurecode":""") + JsonEncoder.option(UnitmeasureId.jsonEncoder).unsafeEncode(a.weightunitmeasurecode, indent, out) + out.write(",") + out.write(""""weight":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.weight, indent, out) + out.write(",") + out.write(""""daystomanufacture":""") + JsonEncoder.int.unsafeEncode(a.daystomanufacture, indent, out) + out.write(",") + out.write(""""productline":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.productline, indent, out) + out.write(",") + out.write(""""class":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.`class`, indent, out) + out.write(",") + out.write(""""style":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.style, indent, out) + out.write(",") + out.write(""""productsubcategoryid":""") + JsonEncoder.option(ProductsubcategoryId.jsonEncoder).unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""productmodelid":""") + JsonEncoder.option(ProductmodelId.jsonEncoder).unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""sellstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.sellstartdate, indent, out) + out.write(",") + out.write(""""sellenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.sellenddate, indent, out) + out.write(",") + out.write(""""discontinueddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.discontinueddate, indent, out) + out.write(",") + out.write(""""productid":""") + Defaulted.jsonEncoder(ProductId.jsonEncoder).unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""makeflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.makeflag, indent, out) + out.write(",") + out.write(""""finishedgoodsflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.finishedgoodsflag, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductStructure.scala new file mode 100644 index 0000000000..76c4f296d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/product/ProductStructure.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package product + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductStructure[Row](val prefix: Option[String], val extract: Row => ProductRow, val merge: (Row, ProductRow) => Row) + extends Relation[ProductFields, ProductRow, Row] + with ProductFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val productnumber = new Field[/* max 25 chars */ String, Row](prefix, "productnumber", None, None)(x => extract(x).productnumber, (row, value) => merge(row, extract(row).copy(productnumber = value))) + override val makeflag = new Field[Flag, Row](prefix, "makeflag", None, Some("bool"))(x => extract(x).makeflag, (row, value) => merge(row, extract(row).copy(makeflag = value))) + override val finishedgoodsflag = new Field[Flag, Row](prefix, "finishedgoodsflag", None, Some("bool"))(x => extract(x).finishedgoodsflag, (row, value) => merge(row, extract(row).copy(finishedgoodsflag = value))) + override val color = new OptField[/* max 15 chars */ String, Row](prefix, "color", None, None)(x => extract(x).color, (row, value) => merge(row, extract(row).copy(color = value))) + override val safetystocklevel = new Field[TypoShort, Row](prefix, "safetystocklevel", None, Some("int2"))(x => extract(x).safetystocklevel, (row, value) => merge(row, extract(row).copy(safetystocklevel = value))) + override val reorderpoint = new Field[TypoShort, Row](prefix, "reorderpoint", None, Some("int2"))(x => extract(x).reorderpoint, (row, value) => merge(row, extract(row).copy(reorderpoint = value))) + override val standardcost = new Field[BigDecimal, Row](prefix, "standardcost", None, Some("numeric"))(x => extract(x).standardcost, (row, value) => merge(row, extract(row).copy(standardcost = value))) + override val listprice = new Field[BigDecimal, Row](prefix, "listprice", None, Some("numeric"))(x => extract(x).listprice, (row, value) => merge(row, extract(row).copy(listprice = value))) + override val size = new OptField[/* max 5 chars */ String, Row](prefix, "size", None, None)(x => extract(x).size, (row, value) => merge(row, extract(row).copy(size = value))) + override val sizeunitmeasurecode = new OptField[UnitmeasureId, Row](prefix, "sizeunitmeasurecode", None, Some("bpchar"))(x => extract(x).sizeunitmeasurecode, (row, value) => merge(row, extract(row).copy(sizeunitmeasurecode = value))) + override val weightunitmeasurecode = new OptField[UnitmeasureId, Row](prefix, "weightunitmeasurecode", None, Some("bpchar"))(x => extract(x).weightunitmeasurecode, (row, value) => merge(row, extract(row).copy(weightunitmeasurecode = value))) + override val weight = new OptField[BigDecimal, Row](prefix, "weight", None, Some("numeric"))(x => extract(x).weight, (row, value) => merge(row, extract(row).copy(weight = value))) + override val daystomanufacture = new Field[Int, Row](prefix, "daystomanufacture", None, Some("int4"))(x => extract(x).daystomanufacture, (row, value) => merge(row, extract(row).copy(daystomanufacture = value))) + override val productline = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "productline", None, Some("bpchar"))(x => extract(x).productline, (row, value) => merge(row, extract(row).copy(productline = value))) + override val `class` = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "class", None, Some("bpchar"))(x => extract(x).`class`, (row, value) => merge(row, extract(row).copy(`class` = value))) + override val style = new OptField[/* bpchar, max 2 chars */ String, Row](prefix, "style", None, Some("bpchar"))(x => extract(x).style, (row, value) => merge(row, extract(row).copy(style = value))) + override val productsubcategoryid = new OptField[ProductsubcategoryId, Row](prefix, "productsubcategoryid", None, Some("int4"))(x => extract(x).productsubcategoryid, (row, value) => merge(row, extract(row).copy(productsubcategoryid = value))) + override val productmodelid = new OptField[ProductmodelId, Row](prefix, "productmodelid", None, Some("int4"))(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val sellstartdate = new Field[TypoLocalDateTime, Row](prefix, "sellstartdate", Some("text"), Some("timestamp"))(x => extract(x).sellstartdate, (row, value) => merge(row, extract(row).copy(sellstartdate = value))) + override val sellenddate = new OptField[TypoLocalDateTime, Row](prefix, "sellenddate", Some("text"), Some("timestamp"))(x => extract(x).sellenddate, (row, value) => merge(row, extract(row).copy(sellenddate = value))) + override val discontinueddate = new OptField[TypoLocalDateTime, Row](prefix, "discontinueddate", Some("text"), Some("timestamp"))(x => extract(x).discontinueddate, (row, value) => merge(row, extract(row).copy(discontinueddate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, name, productnumber, makeflag, finishedgoodsflag, color, safetystocklevel, reorderpoint, standardcost, listprice, size, sizeunitmeasurecode, weightunitmeasurecode, weight, daystomanufacture, productline, `class`, style, productsubcategoryid, productmodelid, sellstartdate, sellenddate, discontinueddate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductRow, merge: (NewRow, ProductRow) => NewRow): ProductStructure[NewRow] = + new ProductStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryFields.scala new file mode 100644 index 0000000000..d0503b3cac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductcategoryFields[Row] { + val productcategoryid: IdField[ProductcategoryId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductcategoryFields extends ProductcategoryStructure[ProductcategoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryId.scala new file mode 100644 index 0000000000..a0c8937924 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +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.productcategory` */ +case class ProductcategoryId(value: Int) extends AnyVal +object ProductcategoryId { + implicit lazy val arraySetter: Setter[Array[ProductcategoryId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductcategoryId, Int] = Bijection[ProductcategoryId, Int](_.value)(ProductcategoryId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductcategoryId] = JdbcDecoder.intDecoder.map(ProductcategoryId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductcategoryId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductcategoryId] = JsonDecoder.int.map(ProductcategoryId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductcategoryId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductcategoryId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductcategoryId] = ParameterMetaData.instance[ProductcategoryId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductcategoryId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepo.scala new file mode 100644 index 0000000000..369c747c1d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductcategoryRepo { + def delete(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductcategoryFields, ProductcategoryRow] + def insert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, ProductcategoryRow] + def insert(unsaved: ProductcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcategoryRow] + def select: SelectBuilder[ProductcategoryFields, ProductcategoryRow] + def selectAll: ZStream[ZConnection, Throwable, ProductcategoryRow] + def selectById(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Option[ProductcategoryRow]] + def selectByIds(productcategoryids: Array[ProductcategoryId]): ZStream[ZConnection, Throwable, ProductcategoryRow] + def update(row: ProductcategoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductcategoryFields, ProductcategoryRow] + def upsert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcategoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoImpl.scala new file mode 100644 index 0000000000..37d579862b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoImpl.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductcategoryRepoImpl extends ProductcategoryRepo { + override def delete(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productcategory where "productcategoryid" = ${Segment.paramSegment(productcategoryid)(ProductcategoryId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductcategoryFields, ProductcategoryRow] = { + DeleteBuilder("production.productcategory", ProductcategoryFields) + } + override def insert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, ProductcategoryRow] = { + sql"""insert into production.productcategory("productcategoryid", "name", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productcategoryid)(ProductcategoryId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productcategoryid", "name", "rowguid", "modifieddate"::text + """.insertReturning(ProductcategoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcategoryRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.productcategoryid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productcategoryid"""", sql"${Segment.paramSegment(value: ProductcategoryId)(ProductcategoryId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productcategory default values + returning "productcategoryid", "name", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productcategory($names) values ($values) returning "productcategoryid", "name", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductcategoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductcategoryFields, ProductcategoryRow] = { + SelectBuilderSql("production.productcategory", ProductcategoryFields, ProductcategoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductcategoryRow] = { + sql"""select "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productcategory""".query(ProductcategoryRow.jdbcDecoder).selectStream + } + override def selectById(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Option[ProductcategoryRow]] = { + sql"""select "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productcategory where "productcategoryid" = ${Segment.paramSegment(productcategoryid)(ProductcategoryId.setter)}""".query(ProductcategoryRow.jdbcDecoder).selectOne + } + override def selectByIds(productcategoryids: Array[ProductcategoryId]): ZStream[ZConnection, Throwable, ProductcategoryRow] = { + sql"""select "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productcategory where "productcategoryid" = ANY(${Segment.paramSegment(productcategoryids)(ProductcategoryId.arraySetter)})""".query(ProductcategoryRow.jdbcDecoder).selectStream + } + override def update(row: ProductcategoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val productcategoryid = row.productcategoryid + sql"""update production.productcategory + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productcategoryid" = ${Segment.paramSegment(productcategoryid)(ProductcategoryId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductcategoryFields, ProductcategoryRow] = { + UpdateBuilder("production.productcategory", ProductcategoryFields, ProductcategoryRow.jdbcDecoder) + } + override def upsert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcategoryRow]] = { + sql"""insert into production.productcategory("productcategoryid", "name", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productcategoryid)(ProductcategoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productcategoryid") + do update set + "name" = EXCLUDED."name", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productcategoryid", "name", "rowguid", "modifieddate"::text""".insertReturning(ProductcategoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoMock.scala new file mode 100644 index 0000000000..1ec23a96f5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductcategoryRepoMock(toRow: Function1[ProductcategoryRowUnsaved, ProductcategoryRow], + map: scala.collection.mutable.Map[ProductcategoryId, ProductcategoryRow] = scala.collection.mutable.Map.empty) extends ProductcategoryRepo { + override def delete(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productcategoryid).isDefined) + } + override def delete: DeleteBuilder[ProductcategoryFields, ProductcategoryRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductcategoryFields, map) + } + override def insert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, ProductcategoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productcategoryid)) + sys.error(s"id ${unsaved.productcategoryid} already exists") + else + map.put(unsaved.productcategoryid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcategoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductcategoryFields, ProductcategoryRow] = { + SelectBuilderMock(ProductcategoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductcategoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productcategoryid: ProductcategoryId): ZIO[ZConnection, Throwable, Option[ProductcategoryRow]] = { + ZIO.succeed(map.get(productcategoryid)) + } + override def selectByIds(productcategoryids: Array[ProductcategoryId]): ZStream[ZConnection, Throwable, ProductcategoryRow] = { + ZStream.fromIterable(productcategoryids.flatMap(map.get)) + } + override def update(row: ProductcategoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productcategoryid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productcategoryid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductcategoryFields, ProductcategoryRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductcategoryFields, map) + } + override def upsert(unsaved: ProductcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcategoryRow]] = { + ZIO.succeed { + map.put(unsaved.productcategoryid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRow.scala new file mode 100644 index 0000000000..a636b4f874 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRow.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductcategoryRow( + /** Primary key for ProductCategory records. */ + productcategoryid: ProductcategoryId, + /** Category description. */ + name: Name, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ProductcategoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductcategoryRow] = new JdbcDecoder[ProductcategoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductcategoryRow) = + columIndex + 3 -> + ProductcategoryRow( + productcategoryid = ProductcategoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductcategoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productcategoryid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductcategoryRow(productcategoryid = productcategoryid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productcategoryid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductcategoryRow] = new JsonEncoder[ProductcategoryRow] { + override def unsafeEncode(a: ProductcategoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productcategoryid":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRowUnsaved.scala new file mode 100644 index 0000000000..b810740cd0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryRowUnsaved.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productcategory` which has not been persisted yet */ +case class ProductcategoryRowUnsaved( + /** Category description. */ + name: Name, + /** Default: nextval('production.productcategory_productcategoryid_seq'::regclass) + Primary key for ProductCategory records. */ + productcategoryid: Defaulted[ProductcategoryId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productcategoryidDefault: => ProductcategoryId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductcategoryRow = + ProductcategoryRow( + name = name, + productcategoryid = productcategoryid match { + case Defaulted.UseDefault => productcategoryidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductcategoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductcategoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(Defaulted.jsonDecoder(ProductcategoryId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && productcategoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductcategoryRowUnsaved(name = name.toOption.get, productcategoryid = productcategoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, productcategoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductcategoryRowUnsaved] = new JsonEncoder[ProductcategoryRowUnsaved] { + override def unsafeEncode(a: ProductcategoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productcategoryid":""") + Defaulted.jsonEncoder(ProductcategoryId.jsonEncoder).unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryStructure.scala new file mode 100644 index 0000000000..64c9e81a9e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcategory/ProductcategoryStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductcategoryStructure[Row](val prefix: Option[String], val extract: Row => ProductcategoryRow, val merge: (Row, ProductcategoryRow) => Row) + extends Relation[ProductcategoryFields, ProductcategoryRow, Row] + with ProductcategoryFields[Row] { outer => + + override val productcategoryid = new IdField[ProductcategoryId, Row](prefix, "productcategoryid", None, Some("int4"))(x => extract(x).productcategoryid, (row, value) => merge(row, extract(row).copy(productcategoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productcategoryid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductcategoryRow, merge: (NewRow, ProductcategoryRow) => NewRow): ProductcategoryStructure[NewRow] = + new ProductcategoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryFields.scala new file mode 100644 index 0000000000..cf5ff0d103 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductcosthistoryFields[Row] { + val productid: IdField[ProductId, Row] + val startdate: IdField[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val standardcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductcosthistoryFields extends ProductcosthistoryStructure[ProductcosthistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryId.scala new file mode 100644 index 0000000000..2acd0fee81 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productcosthistory` */ +case class ProductcosthistoryId(productid: ProductId, startdate: TypoLocalDateTime) +object ProductcosthistoryId { + implicit lazy val jsonDecoder: JsonDecoder[ProductcosthistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && startdate.isRight) + Right(ProductcosthistoryId(productid = productid.toOption.get, startdate = startdate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductcosthistoryId] = new JsonEncoder[ProductcosthistoryId] { + override def unsafeEncode(a: ProductcosthistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDateTime]): Ordering[ProductcosthistoryId] = Ordering.by(x => (x.productid, x.startdate)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepo.scala new file mode 100644 index 0000000000..9e633829d5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductcosthistoryRepo { + def delete(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductcosthistoryFields, ProductcosthistoryRow] + def insert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, ProductcosthistoryRow] + def insert(unsaved: ProductcosthistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcosthistoryRow] + def select: SelectBuilder[ProductcosthistoryFields, ProductcosthistoryRow] + def selectAll: ZStream[ZConnection, Throwable, ProductcosthistoryRow] + def selectById(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Option[ProductcosthistoryRow]] + def update(row: ProductcosthistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductcosthistoryFields, ProductcosthistoryRow] + def upsert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcosthistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoImpl.scala new file mode 100644 index 0000000000..102155e247 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoImpl.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductcosthistoryRepoImpl extends ProductcosthistoryRepo { + override def delete(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productcosthistory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + DeleteBuilder("production.productcosthistory", ProductcosthistoryFields) + } + override def insert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, ProductcosthistoryRow] = { + sql"""insert into production.productcosthistory("productid", "startdate", "enddate", "standardcost", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text + """.insertReturning(ProductcosthistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductcosthistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcosthistoryRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""standardcost"""", sql"${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productcosthistory default values + returning "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productcosthistory($names) values ($values) returning "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text""" + } + q.insertReturning(ProductcosthistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + SelectBuilderSql("production.productcosthistory", ProductcosthistoryFields, ProductcosthistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductcosthistoryRow] = { + sql"""select "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text from production.productcosthistory""".query(ProductcosthistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Option[ProductcosthistoryRow]] = { + sql"""select "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text from production.productcosthistory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".query(ProductcosthistoryRow.jdbcDecoder).selectOne + } + override def update(row: ProductcosthistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productcosthistory + set "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "standardcost" = ${Segment.paramSegment(row.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + UpdateBuilder("production.productcosthistory", ProductcosthistoryFields, ProductcosthistoryRow.jdbcDecoder) + } + override def upsert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcosthistoryRow]] = { + sql"""insert into production.productcosthistory("productid", "startdate", "enddate", "standardcost", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.standardcost)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid", "startdate") + do update set + "enddate" = EXCLUDED."enddate", + "standardcost" = EXCLUDED."standardcost", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "startdate"::text, "enddate"::text, "standardcost", "modifieddate"::text""".insertReturning(ProductcosthistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoMock.scala new file mode 100644 index 0000000000..3bd5058572 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductcosthistoryRepoMock(toRow: Function1[ProductcosthistoryRowUnsaved, ProductcosthistoryRow], + map: scala.collection.mutable.Map[ProductcosthistoryId, ProductcosthistoryRow] = scala.collection.mutable.Map.empty) extends ProductcosthistoryRepo { + override def delete(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductcosthistoryFields, map) + } + override def insert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, ProductcosthistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductcosthistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductcosthistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + SelectBuilderMock(ProductcosthistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductcosthistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductcosthistoryId): ZIO[ZConnection, Throwable, Option[ProductcosthistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductcosthistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductcosthistoryFields, ProductcosthistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductcosthistoryFields, map) + } + override def upsert(unsaved: ProductcosthistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductcosthistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRow.scala new file mode 100644 index 0000000000..a5c5e05af0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductcosthistoryRow( + /** Product identification number. Foreign key to Product.ProductID + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product cost start date. + Constraint CK_ProductCostHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Product cost end date. + Constraint CK_ProductCostHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Standard cost of the product. + Constraint CK_ProductCostHistory_StandardCost affecting columns "standardcost": ((standardcost >= 0.00)) */ + standardcost: BigDecimal, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductcosthistoryId = ProductcosthistoryId(productid, startdate) + } + +object ProductcosthistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductcosthistoryRow] = new JdbcDecoder[ProductcosthistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductcosthistoryRow) = + columIndex + 4 -> + ProductcosthistoryRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + standardcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductcosthistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && startdate.isRight && enddate.isRight && standardcost.isRight && modifieddate.isRight) + Right(ProductcosthistoryRow(productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, standardcost = standardcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate, enddate, standardcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductcosthistoryRow] = new JsonEncoder[ProductcosthistoryRow] { + override def unsafeEncode(a: ProductcosthistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRowUnsaved.scala new file mode 100644 index 0000000000..abf87edf2f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryRowUnsaved.scala @@ -0,0 +1,78 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productcosthistory` which has not been persisted yet */ +case class ProductcosthistoryRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product cost start date. + Constraint CK_ProductCostHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Product cost end date. + Constraint CK_ProductCostHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Standard cost of the product. + Constraint CK_ProductCostHistory_StandardCost affecting columns "standardcost": ((standardcost >= 0.00)) */ + standardcost: BigDecimal, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): ProductcosthistoryRow = + ProductcosthistoryRow( + productid = productid, + startdate = startdate, + enddate = enddate, + standardcost = standardcost, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductcosthistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductcosthistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val standardcost = jsonObj.get("standardcost").toRight("Missing field 'standardcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && startdate.isRight && enddate.isRight && standardcost.isRight && modifieddate.isRight) + Right(ProductcosthistoryRowUnsaved(productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, standardcost = standardcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate, enddate, standardcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductcosthistoryRowUnsaved] = new JsonEncoder[ProductcosthistoryRowUnsaved] { + override def unsafeEncode(a: ProductcosthistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""standardcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryStructure.scala new file mode 100644 index 0000000000..3ea558bcaa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productcosthistory/ProductcosthistoryStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productcosthistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductcosthistoryStructure[Row](val prefix: Option[String], val extract: Row => ProductcosthistoryRow, val merge: (Row, ProductcosthistoryRow) => Row) + extends Relation[ProductcosthistoryFields, ProductcosthistoryRow, Row] + with ProductcosthistoryFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val startdate = new IdField[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val standardcost = new Field[BigDecimal, Row](prefix, "standardcost", None, Some("numeric"))(x => extract(x).standardcost, (row, value) => merge(row, extract(row).copy(standardcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, startdate, enddate, standardcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductcosthistoryRow, merge: (NewRow, ProductcosthistoryRow) => NewRow): ProductcosthistoryStructure[NewRow] = + new ProductcosthistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionFields.scala new file mode 100644 index 0000000000..e1a2b59269 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductdescriptionFields[Row] { + val productdescriptionid: IdField[ProductdescriptionId, Row] + val description: Field[/* max 400 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductdescriptionFields extends ProductdescriptionStructure[ProductdescriptionRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionId.scala new file mode 100644 index 0000000000..806f5f5f00 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +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.productdescription` */ +case class ProductdescriptionId(value: Int) extends AnyVal +object ProductdescriptionId { + implicit lazy val arraySetter: Setter[Array[ProductdescriptionId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductdescriptionId, Int] = Bijection[ProductdescriptionId, Int](_.value)(ProductdescriptionId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductdescriptionId] = JdbcDecoder.intDecoder.map(ProductdescriptionId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductdescriptionId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductdescriptionId] = JsonDecoder.int.map(ProductdescriptionId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductdescriptionId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductdescriptionId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductdescriptionId] = ParameterMetaData.instance[ProductdescriptionId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductdescriptionId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepo.scala new file mode 100644 index 0000000000..f9439ef842 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductdescriptionRepo { + def delete(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductdescriptionFields, ProductdescriptionRow] + def insert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, ProductdescriptionRow] + def insert(unsaved: ProductdescriptionRowUnsaved): ZIO[ZConnection, Throwable, ProductdescriptionRow] + def select: SelectBuilder[ProductdescriptionFields, ProductdescriptionRow] + def selectAll: ZStream[ZConnection, Throwable, ProductdescriptionRow] + def selectById(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Option[ProductdescriptionRow]] + def selectByIds(productdescriptionids: Array[ProductdescriptionId]): ZStream[ZConnection, Throwable, ProductdescriptionRow] + def update(row: ProductdescriptionRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductdescriptionFields, ProductdescriptionRow] + def upsert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdescriptionRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoImpl.scala new file mode 100644 index 0000000000..0fee44165d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoImpl.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductdescriptionRepoImpl extends ProductdescriptionRepo { + override def delete(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productdescription where "productdescriptionid" = ${Segment.paramSegment(productdescriptionid)(ProductdescriptionId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + DeleteBuilder("production.productdescription", ProductdescriptionFields) + } + override def insert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, ProductdescriptionRow] = { + sql"""insert into production.productdescription("productdescriptionid", "description", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productdescriptionid)(ProductdescriptionId.setter)}::int4, ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productdescriptionid", "description", "rowguid", "modifieddate"::text + """.insertReturning(ProductdescriptionRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductdescriptionRowUnsaved): ZIO[ZConnection, Throwable, ProductdescriptionRow] = { + val fs = List( + Some((sql""""description"""", sql"${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}")), + unsaved.productdescriptionid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productdescriptionid"""", sql"${Segment.paramSegment(value: ProductdescriptionId)(ProductdescriptionId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productdescription default values + returning "productdescriptionid", "description", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productdescription($names) values ($values) returning "productdescriptionid", "description", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductdescriptionRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + SelectBuilderSql("production.productdescription", ProductdescriptionFields, ProductdescriptionRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductdescriptionRow] = { + sql"""select "productdescriptionid", "description", "rowguid", "modifieddate"::text from production.productdescription""".query(ProductdescriptionRow.jdbcDecoder).selectStream + } + override def selectById(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Option[ProductdescriptionRow]] = { + sql"""select "productdescriptionid", "description", "rowguid", "modifieddate"::text from production.productdescription where "productdescriptionid" = ${Segment.paramSegment(productdescriptionid)(ProductdescriptionId.setter)}""".query(ProductdescriptionRow.jdbcDecoder).selectOne + } + override def selectByIds(productdescriptionids: Array[ProductdescriptionId]): ZStream[ZConnection, Throwable, ProductdescriptionRow] = { + sql"""select "productdescriptionid", "description", "rowguid", "modifieddate"::text from production.productdescription where "productdescriptionid" = ANY(${Segment.paramSegment(productdescriptionids)(ProductdescriptionId.arraySetter)})""".query(ProductdescriptionRow.jdbcDecoder).selectStream + } + override def update(row: ProductdescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + val productdescriptionid = row.productdescriptionid + sql"""update production.productdescription + set "description" = ${Segment.paramSegment(row.description)(Setter.stringSetter)}, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productdescriptionid" = ${Segment.paramSegment(productdescriptionid)(ProductdescriptionId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + UpdateBuilder("production.productdescription", ProductdescriptionFields, ProductdescriptionRow.jdbcDecoder) + } + override def upsert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdescriptionRow]] = { + sql"""insert into production.productdescription("productdescriptionid", "description", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productdescriptionid)(ProductdescriptionId.setter)}::int4, + ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productdescriptionid") + do update set + "description" = EXCLUDED."description", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productdescriptionid", "description", "rowguid", "modifieddate"::text""".insertReturning(ProductdescriptionRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoMock.scala new file mode 100644 index 0000000000..2209d59505 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductdescriptionRepoMock(toRow: Function1[ProductdescriptionRowUnsaved, ProductdescriptionRow], + map: scala.collection.mutable.Map[ProductdescriptionId, ProductdescriptionRow] = scala.collection.mutable.Map.empty) extends ProductdescriptionRepo { + override def delete(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productdescriptionid).isDefined) + } + override def delete: DeleteBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductdescriptionFields, map) + } + override def insert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, ProductdescriptionRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productdescriptionid)) + sys.error(s"id ${unsaved.productdescriptionid} already exists") + else + map.put(unsaved.productdescriptionid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductdescriptionRowUnsaved): ZIO[ZConnection, Throwable, ProductdescriptionRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + SelectBuilderMock(ProductdescriptionFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductdescriptionRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productdescriptionid: ProductdescriptionId): ZIO[ZConnection, Throwable, Option[ProductdescriptionRow]] = { + ZIO.succeed(map.get(productdescriptionid)) + } + override def selectByIds(productdescriptionids: Array[ProductdescriptionId]): ZStream[ZConnection, Throwable, ProductdescriptionRow] = { + ZStream.fromIterable(productdescriptionids.flatMap(map.get)) + } + override def update(row: ProductdescriptionRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productdescriptionid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productdescriptionid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductdescriptionFields, ProductdescriptionRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductdescriptionFields, map) + } + override def upsert(unsaved: ProductdescriptionRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdescriptionRow]] = { + ZIO.succeed { + map.put(unsaved.productdescriptionid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRow.scala new file mode 100644 index 0000000000..f1733f5cc7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRow.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductdescriptionRow( + /** Primary key for ProductDescription records. */ + productdescriptionid: ProductdescriptionId, + /** Description of the product. */ + description: /* max 400 chars */ String, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ProductdescriptionRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductdescriptionRow] = new JdbcDecoder[ProductdescriptionRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductdescriptionRow) = + columIndex + 3 -> + ProductdescriptionRow( + productdescriptionid = ProductdescriptionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductdescriptionRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productdescriptionid.isRight && description.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductdescriptionRow(productdescriptionid = productdescriptionid.toOption.get, description = description.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productdescriptionid, description, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductdescriptionRow] = new JsonEncoder[ProductdescriptionRow] { + override def unsafeEncode(a: ProductdescriptionRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRowUnsaved.scala new file mode 100644 index 0000000000..363237aa33 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionRowUnsaved.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productdescription` which has not been persisted yet */ +case class ProductdescriptionRowUnsaved( + /** Description of the product. */ + description: /* max 400 chars */ String, + /** Default: nextval('production.productdescription_productdescriptionid_seq'::regclass) + Primary key for ProductDescription records. */ + productdescriptionid: Defaulted[ProductdescriptionId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productdescriptionidDefault: => ProductdescriptionId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductdescriptionRow = + ProductdescriptionRow( + description = description, + productdescriptionid = productdescriptionid match { + case Defaulted.UseDefault => productdescriptionidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductdescriptionRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductdescriptionRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(Defaulted.jsonDecoder(ProductdescriptionId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (description.isRight && productdescriptionid.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductdescriptionRowUnsaved(description = description.toOption.get, productdescriptionid = productdescriptionid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](description, productdescriptionid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductdescriptionRowUnsaved] = new JsonEncoder[ProductdescriptionRowUnsaved] { + override def unsafeEncode(a: ProductdescriptionRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + Defaulted.jsonEncoder(ProductdescriptionId.jsonEncoder).unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionStructure.scala new file mode 100644 index 0000000000..fa0869f21a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdescription/ProductdescriptionStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductdescriptionStructure[Row](val prefix: Option[String], val extract: Row => ProductdescriptionRow, val merge: (Row, ProductdescriptionRow) => Row) + extends Relation[ProductdescriptionFields, ProductdescriptionRow, Row] + with ProductdescriptionFields[Row] { outer => + + override val productdescriptionid = new IdField[ProductdescriptionId, Row](prefix, "productdescriptionid", None, Some("int4"))(x => extract(x).productdescriptionid, (row, value) => merge(row, extract(row).copy(productdescriptionid = value))) + override val description = new Field[/* max 400 chars */ String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productdescriptionid, description, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductdescriptionRow, merge: (NewRow, ProductdescriptionRow) => NewRow): ProductdescriptionStructure[NewRow] = + new ProductdescriptionStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentFields.scala new file mode 100644 index 0000000000..2f7d55f952 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductdocumentFields[Row] { + val productid: IdField[ProductId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] + val documentnode: IdField[DocumentId, Row] +} +object ProductdocumentFields extends ProductdocumentStructure[ProductdocumentRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentId.scala new file mode 100644 index 0000000000..21f187968b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productdocument` */ +case class ProductdocumentId(productid: ProductId, documentnode: DocumentId) +object ProductdocumentId { + implicit lazy val jsonDecoder: JsonDecoder[ProductdocumentId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(DocumentId.jsonDecoder)) + if (productid.isRight && documentnode.isRight) + Right(ProductdocumentId(productid = productid.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](productid, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductdocumentId] = new JsonEncoder[ProductdocumentId] { + override def unsafeEncode(a: ProductdocumentId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""documentnode":""") + DocumentId.jsonEncoder.unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductdocumentId] = Ordering.by(x => (x.productid, x.documentnode)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepo.scala new file mode 100644 index 0000000000..20d7320fba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductdocumentRepo { + def delete(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductdocumentFields, ProductdocumentRow] + def insert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, ProductdocumentRow] + def insert(unsaved: ProductdocumentRowUnsaved): ZIO[ZConnection, Throwable, ProductdocumentRow] + def select: SelectBuilder[ProductdocumentFields, ProductdocumentRow] + def selectAll: ZStream[ZConnection, Throwable, ProductdocumentRow] + def selectById(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Option[ProductdocumentRow]] + def update(row: ProductdocumentRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductdocumentFields, ProductdocumentRow] + def upsert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdocumentRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoImpl.scala new file mode 100644 index 0000000000..2066797615 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductdocumentRepoImpl extends ProductdocumentRepo { + override def delete(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productdocument where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "documentnode" = ${Segment.paramSegment(compositeId.documentnode)(DocumentId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductdocumentFields, ProductdocumentRow] = { + DeleteBuilder("production.productdocument", ProductdocumentFields) + } + override def insert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, ProductdocumentRow] = { + sql"""insert into production.productdocument("productid", "modifieddate", "documentnode") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.documentnode)(DocumentId.setter)}) + returning "productid", "modifieddate"::text, "documentnode" + """.insertReturning(ProductdocumentRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductdocumentRowUnsaved): ZIO[ZConnection, Throwable, ProductdocumentRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.documentnode match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""documentnode"""", sql"${Segment.paramSegment(value: DocumentId)(DocumentId.setter)}")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productdocument default values + returning "productid", "modifieddate"::text, "documentnode" + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productdocument($names) values ($values) returning "productid", "modifieddate"::text, "documentnode"""" + } + q.insertReturning(ProductdocumentRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductdocumentFields, ProductdocumentRow] = { + SelectBuilderSql("production.productdocument", ProductdocumentFields, ProductdocumentRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductdocumentRow] = { + sql"""select "productid", "modifieddate"::text, "documentnode" from production.productdocument""".query(ProductdocumentRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Option[ProductdocumentRow]] = { + sql"""select "productid", "modifieddate"::text, "documentnode" from production.productdocument where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "documentnode" = ${Segment.paramSegment(compositeId.documentnode)(DocumentId.setter)}""".query(ProductdocumentRow.jdbcDecoder).selectOne + } + override def update(row: ProductdocumentRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productdocument + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "documentnode" = ${Segment.paramSegment(compositeId.documentnode)(DocumentId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductdocumentFields, ProductdocumentRow] = { + UpdateBuilder("production.productdocument", ProductdocumentFields, ProductdocumentRow.jdbcDecoder) + } + override def upsert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdocumentRow]] = { + sql"""insert into production.productdocument("productid", "modifieddate", "documentnode") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.documentnode)(DocumentId.setter)} + ) + on conflict ("productid", "documentnode") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "modifieddate"::text, "documentnode"""".insertReturning(ProductdocumentRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoMock.scala new file mode 100644 index 0000000000..9d71243181 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductdocumentRepoMock(toRow: Function1[ProductdocumentRowUnsaved, ProductdocumentRow], + map: scala.collection.mutable.Map[ProductdocumentId, ProductdocumentRow] = scala.collection.mutable.Map.empty) extends ProductdocumentRepo { + override def delete(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductdocumentFields, ProductdocumentRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductdocumentFields, map) + } + override def insert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, ProductdocumentRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductdocumentRowUnsaved): ZIO[ZConnection, Throwable, ProductdocumentRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductdocumentFields, ProductdocumentRow] = { + SelectBuilderMock(ProductdocumentFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductdocumentRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductdocumentId): ZIO[ZConnection, Throwable, Option[ProductdocumentRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductdocumentRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductdocumentFields, ProductdocumentRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductdocumentFields, map) + } + override def upsert(unsaved: ProductdocumentRow): ZIO[ZConnection, Throwable, UpdateResult[ProductdocumentRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRow.scala new file mode 100644 index 0000000000..1e220d5194 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductdocumentRow( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + modifieddate: TypoLocalDateTime, + /** Document identification number. Foreign key to Document.DocumentNode. + Points to [[document.DocumentRow.documentnode]] */ + documentnode: DocumentId +){ + val compositeId: ProductdocumentId = ProductdocumentId(productid, documentnode) + } + +object ProductdocumentRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductdocumentRow] = new JdbcDecoder[ProductdocumentRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductdocumentRow) = + columIndex + 2 -> + ProductdocumentRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + documentnode = DocumentId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductdocumentRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(DocumentId.jsonDecoder)) + if (productid.isRight && modifieddate.isRight && documentnode.isRight) + Right(ProductdocumentRow(productid = productid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](productid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductdocumentRow] = new JsonEncoder[ProductdocumentRow] { + override def unsafeEncode(a: ProductdocumentRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + DocumentId.jsonEncoder.unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRowUnsaved.scala new file mode 100644 index 0000000000..483297cd5a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentRowUnsaved.scala @@ -0,0 +1,67 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productdocument` which has not been persisted yet */ +case class ProductdocumentRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: '/'::character varying + Document identification number. Foreign key to Document.DocumentNode. + Points to [[document.DocumentRow.documentnode]] */ + documentnode: Defaulted[DocumentId] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime, documentnodeDefault: => DocumentId): ProductdocumentRow = + ProductdocumentRow( + productid = productid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + }, + documentnode = documentnode match { + case Defaulted.UseDefault => documentnodeDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductdocumentRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductdocumentRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val documentnode = jsonObj.get("documentnode").toRight("Missing field 'documentnode'").flatMap(_.as(Defaulted.jsonDecoder(DocumentId.jsonDecoder))) + if (productid.isRight && modifieddate.isRight && documentnode.isRight) + Right(ProductdocumentRowUnsaved(productid = productid.toOption.get, modifieddate = modifieddate.toOption.get, documentnode = documentnode.toOption.get)) + else Left(List[Either[String, Any]](productid, modifieddate, documentnode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductdocumentRowUnsaved] = new JsonEncoder[ProductdocumentRowUnsaved] { + override def unsafeEncode(a: ProductdocumentRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write(",") + out.write(""""documentnode":""") + Defaulted.jsonEncoder(DocumentId.jsonEncoder).unsafeEncode(a.documentnode, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentStructure.scala new file mode 100644 index 0000000000..552a4d3bd0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productdocument/ProductdocumentStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productdocument + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.document.DocumentId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductdocumentStructure[Row](val prefix: Option[String], val extract: Row => ProductdocumentRow, val merge: (Row, ProductdocumentRow) => Row) + extends Relation[ProductdocumentFields, ProductdocumentRow, Row] + with ProductdocumentFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + override val documentnode = new IdField[DocumentId, Row](prefix, "documentnode", None, None)(x => extract(x).documentnode, (row, value) => merge(row, extract(row).copy(documentnode = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, modifieddate, documentnode) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductdocumentRow, merge: (NewRow, ProductdocumentRow) => NewRow): ProductdocumentStructure[NewRow] = + new ProductdocumentStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryFields.scala new file mode 100644 index 0000000000..c295edd540 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductinventoryFields[Row] { + val productid: IdField[ProductId, Row] + val locationid: IdField[LocationId, Row] + val shelf: Field[/* max 10 chars */ String, Row] + val bin: Field[TypoShort, Row] + val quantity: Field[TypoShort, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductinventoryFields extends ProductinventoryStructure[ProductinventoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryId.scala new file mode 100644 index 0000000000..4216666167 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productinventory` */ +case class ProductinventoryId(productid: ProductId, locationid: LocationId) +object ProductinventoryId { + implicit lazy val jsonDecoder: JsonDecoder[ProductinventoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + if (productid.isRight && locationid.isRight) + Right(ProductinventoryId(productid = productid.toOption.get, locationid = locationid.toOption.get)) + else Left(List[Either[String, Any]](productid, locationid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductinventoryId] = new JsonEncoder[ProductinventoryId] { + override def unsafeEncode(a: ProductinventoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductinventoryId] = Ordering.by(x => (x.productid, x.locationid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepo.scala new file mode 100644 index 0000000000..a3c16f5c4c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductinventoryRepo { + def delete(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductinventoryFields, ProductinventoryRow] + def insert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, ProductinventoryRow] + def insert(unsaved: ProductinventoryRowUnsaved): ZIO[ZConnection, Throwable, ProductinventoryRow] + def select: SelectBuilder[ProductinventoryFields, ProductinventoryRow] + def selectAll: ZStream[ZConnection, Throwable, ProductinventoryRow] + def selectById(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Option[ProductinventoryRow]] + def update(row: ProductinventoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductinventoryFields, ProductinventoryRow] + def upsert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductinventoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoImpl.scala new file mode 100644 index 0000000000..8eca48d442 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoImpl.scala @@ -0,0 +1,116 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductinventoryRepoImpl extends ProductinventoryRepo { + override def delete(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productinventory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "locationid" = ${Segment.paramSegment(compositeId.locationid)(LocationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductinventoryFields, ProductinventoryRow] = { + DeleteBuilder("production.productinventory", ProductinventoryFields) + } + override def insert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, ProductinventoryRow] = { + sql"""insert into production.productinventory("productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2, ${Segment.paramSegment(unsaved.shelf)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.bin)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.quantity)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text + """.insertReturning(ProductinventoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductinventoryRowUnsaved): ZIO[ZConnection, Throwable, ProductinventoryRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""locationid"""", sql"${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2")), + Some((sql""""shelf"""", sql"${Segment.paramSegment(unsaved.shelf)(Setter.stringSetter)}")), + Some((sql""""bin"""", sql"${Segment.paramSegment(unsaved.bin)(TypoShort.setter)}::int2")), + unsaved.quantity match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""quantity"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productinventory default values + returning "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productinventory($names) values ($values) returning "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductinventoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductinventoryFields, ProductinventoryRow] = { + SelectBuilderSql("production.productinventory", ProductinventoryFields, ProductinventoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductinventoryRow] = { + sql"""select "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text from production.productinventory""".query(ProductinventoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Option[ProductinventoryRow]] = { + sql"""select "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text from production.productinventory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "locationid" = ${Segment.paramSegment(compositeId.locationid)(LocationId.setter)}""".query(ProductinventoryRow.jdbcDecoder).selectOne + } + override def update(row: ProductinventoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productinventory + set "shelf" = ${Segment.paramSegment(row.shelf)(Setter.stringSetter)}, + "bin" = ${Segment.paramSegment(row.bin)(TypoShort.setter)}::int2, + "quantity" = ${Segment.paramSegment(row.quantity)(TypoShort.setter)}::int2, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "locationid" = ${Segment.paramSegment(compositeId.locationid)(LocationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductinventoryFields, ProductinventoryRow] = { + UpdateBuilder("production.productinventory", ProductinventoryFields, ProductinventoryRow.jdbcDecoder) + } + override def upsert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductinventoryRow]] = { + sql"""insert into production.productinventory("productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2, + ${Segment.paramSegment(unsaved.shelf)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.bin)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.quantity)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid", "locationid") + do update set + "shelf" = EXCLUDED."shelf", + "bin" = EXCLUDED."bin", + "quantity" = EXCLUDED."quantity", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "locationid", "shelf", "bin", "quantity", "rowguid", "modifieddate"::text""".insertReturning(ProductinventoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoMock.scala new file mode 100644 index 0000000000..9cc05b3c53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductinventoryRepoMock(toRow: Function1[ProductinventoryRowUnsaved, ProductinventoryRow], + map: scala.collection.mutable.Map[ProductinventoryId, ProductinventoryRow] = scala.collection.mutable.Map.empty) extends ProductinventoryRepo { + override def delete(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductinventoryFields, ProductinventoryRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductinventoryFields, map) + } + override def insert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, ProductinventoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductinventoryRowUnsaved): ZIO[ZConnection, Throwable, ProductinventoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductinventoryFields, ProductinventoryRow] = { + SelectBuilderMock(ProductinventoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductinventoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductinventoryId): ZIO[ZConnection, Throwable, Option[ProductinventoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductinventoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductinventoryFields, ProductinventoryRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductinventoryFields, map) + } + override def upsert(unsaved: ProductinventoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductinventoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRow.scala new file mode 100644 index 0000000000..85d9e4641f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRow.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductinventoryRow( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Inventory location identification number. Foreign key to Location.LocationID. + Points to [[location.LocationRow.locationid]] */ + locationid: LocationId, + /** Storage compartment within an inventory location. */ + shelf: /* max 10 chars */ String, + /** Storage container on a shelf in an inventory location. + Constraint CK_ProductInventory_Bin affecting columns "bin": (((bin >= 0) AND (bin <= 100))) */ + bin: TypoShort, + /** Quantity of products in the inventory location. */ + quantity: TypoShort, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductinventoryId = ProductinventoryId(productid, locationid) + } + +object ProductinventoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductinventoryRow] = new JdbcDecoder[ProductinventoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductinventoryRow) = + columIndex + 6 -> + ProductinventoryRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + shelf = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + bin = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + quantity = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductinventoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val shelf = jsonObj.get("shelf").toRight("Missing field 'shelf'").flatMap(_.as(JsonDecoder.string)) + val bin = jsonObj.get("bin").toRight("Missing field 'bin'").flatMap(_.as(TypoShort.jsonDecoder)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(TypoShort.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && locationid.isRight && shelf.isRight && bin.isRight && quantity.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductinventoryRow(productid = productid.toOption.get, locationid = locationid.toOption.get, shelf = shelf.toOption.get, bin = bin.toOption.get, quantity = quantity.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, locationid, shelf, bin, quantity, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductinventoryRow] = new JsonEncoder[ProductinventoryRow] { + override def unsafeEncode(a: ProductinventoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""shelf":""") + JsonEncoder.string.unsafeEncode(a.shelf, indent, out) + out.write(",") + out.write(""""bin":""") + TypoShort.jsonEncoder.unsafeEncode(a.bin, indent, out) + out.write(",") + out.write(""""quantity":""") + TypoShort.jsonEncoder.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRowUnsaved.scala new file mode 100644 index 0000000000..7cc66a841f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryRowUnsaved.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productinventory` which has not been persisted yet */ +case class ProductinventoryRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Inventory location identification number. Foreign key to Location.LocationID. + Points to [[location.LocationRow.locationid]] */ + locationid: LocationId, + /** Storage compartment within an inventory location. */ + shelf: /* max 10 chars */ String, + /** Storage container on a shelf in an inventory location. + Constraint CK_ProductInventory_Bin affecting columns "bin": (((bin >= 0) AND (bin <= 100))) */ + bin: TypoShort, + /** Default: 0 + Quantity of products in the inventory location. */ + quantity: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(quantityDefault: => TypoShort, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductinventoryRow = + ProductinventoryRow( + productid = productid, + locationid = locationid, + shelf = shelf, + bin = bin, + quantity = quantity match { + case Defaulted.UseDefault => quantityDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductinventoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductinventoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val shelf = jsonObj.get("shelf").toRight("Missing field 'shelf'").flatMap(_.as(JsonDecoder.string)) + val bin = jsonObj.get("bin").toRight("Missing field 'bin'").flatMap(_.as(TypoShort.jsonDecoder)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && locationid.isRight && shelf.isRight && bin.isRight && quantity.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductinventoryRowUnsaved(productid = productid.toOption.get, locationid = locationid.toOption.get, shelf = shelf.toOption.get, bin = bin.toOption.get, quantity = quantity.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, locationid, shelf, bin, quantity, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductinventoryRowUnsaved] = new JsonEncoder[ProductinventoryRowUnsaved] { + override def unsafeEncode(a: ProductinventoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""shelf":""") + JsonEncoder.string.unsafeEncode(a.shelf, indent, out) + out.write(",") + out.write(""""bin":""") + TypoShort.jsonEncoder.unsafeEncode(a.bin, indent, out) + out.write(",") + out.write(""""quantity":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryStructure.scala new file mode 100644 index 0000000000..d900c732e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productinventory/ProductinventoryStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productinventory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.location.LocationId +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductinventoryStructure[Row](val prefix: Option[String], val extract: Row => ProductinventoryRow, val merge: (Row, ProductinventoryRow) => Row) + extends Relation[ProductinventoryFields, ProductinventoryRow, Row] + with ProductinventoryFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val locationid = new IdField[LocationId, Row](prefix, "locationid", None, Some("int2"))(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val shelf = new Field[/* max 10 chars */ String, Row](prefix, "shelf", None, None)(x => extract(x).shelf, (row, value) => merge(row, extract(row).copy(shelf = value))) + override val bin = new Field[TypoShort, Row](prefix, "bin", None, Some("int2"))(x => extract(x).bin, (row, value) => merge(row, extract(row).copy(bin = value))) + override val quantity = new Field[TypoShort, Row](prefix, "quantity", None, Some("int2"))(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, locationid, shelf, bin, quantity, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductinventoryRow, merge: (NewRow, ProductinventoryRow) => NewRow): ProductinventoryStructure[NewRow] = + new ProductinventoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryFields.scala new file mode 100644 index 0000000000..260089c642 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductlistpricehistoryFields[Row] { + val productid: IdField[ProductId, Row] + val startdate: IdField[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val listprice: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductlistpricehistoryFields extends ProductlistpricehistoryStructure[ProductlistpricehistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryId.scala new file mode 100644 index 0000000000..961833d5d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productlistpricehistory` */ +case class ProductlistpricehistoryId(productid: ProductId, startdate: TypoLocalDateTime) +object ProductlistpricehistoryId { + implicit lazy val jsonDecoder: JsonDecoder[ProductlistpricehistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && startdate.isRight) + Right(ProductlistpricehistoryId(productid = productid.toOption.get, startdate = startdate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductlistpricehistoryId] = new JsonEncoder[ProductlistpricehistoryId] { + override def unsafeEncode(a: ProductlistpricehistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDateTime]): Ordering[ProductlistpricehistoryId] = Ordering.by(x => (x.productid, x.startdate)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepo.scala new file mode 100644 index 0000000000..85a60fc8ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductlistpricehistoryRepo { + def delete(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] + def insert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] + def insert(unsaved: ProductlistpricehistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] + def select: SelectBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] + def selectAll: ZStream[ZConnection, Throwable, ProductlistpricehistoryRow] + def selectById(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Option[ProductlistpricehistoryRow]] + def update(row: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] + def upsert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductlistpricehistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoImpl.scala new file mode 100644 index 0000000000..ccdb406443 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoImpl.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductlistpricehistoryRepoImpl extends ProductlistpricehistoryRepo { + override def delete(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productlistpricehistory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + DeleteBuilder("production.productlistpricehistory", ProductlistpricehistoryFields) + } + override def insert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] = { + sql"""insert into production.productlistpricehistory("productid", "startdate", "enddate", "listprice", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text + """.insertReturning(ProductlistpricehistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductlistpricehistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""listprice"""", sql"${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productlistpricehistory default values + returning "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productlistpricehistory($names) values ($values) returning "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text""" + } + q.insertReturning(ProductlistpricehistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + SelectBuilderSql("production.productlistpricehistory", ProductlistpricehistoryFields, ProductlistpricehistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductlistpricehistoryRow] = { + sql"""select "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text from production.productlistpricehistory""".query(ProductlistpricehistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Option[ProductlistpricehistoryRow]] = { + sql"""select "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text from production.productlistpricehistory where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".query(ProductlistpricehistoryRow.jdbcDecoder).selectOne + } + override def update(row: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productlistpricehistory + set "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "listprice" = ${Segment.paramSegment(row.listprice)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + UpdateBuilder("production.productlistpricehistory", ProductlistpricehistoryFields, ProductlistpricehistoryRow.jdbcDecoder) + } + override def upsert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductlistpricehistoryRow]] = { + sql"""insert into production.productlistpricehistory("productid", "startdate", "enddate", "listprice", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.listprice)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid", "startdate") + do update set + "enddate" = EXCLUDED."enddate", + "listprice" = EXCLUDED."listprice", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "startdate"::text, "enddate"::text, "listprice", "modifieddate"::text""".insertReturning(ProductlistpricehistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoMock.scala new file mode 100644 index 0000000000..5ff6397172 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductlistpricehistoryRepoMock(toRow: Function1[ProductlistpricehistoryRowUnsaved, ProductlistpricehistoryRow], + map: scala.collection.mutable.Map[ProductlistpricehistoryId, ProductlistpricehistoryRow] = scala.collection.mutable.Map.empty) extends ProductlistpricehistoryRepo { + override def delete(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductlistpricehistoryFields, map) + } + override def insert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductlistpricehistoryRowUnsaved): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + SelectBuilderMock(ProductlistpricehistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductlistpricehistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductlistpricehistoryId): ZIO[ZConnection, Throwable, Option[ProductlistpricehistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductlistpricehistoryFields, ProductlistpricehistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductlistpricehistoryFields, map) + } + override def upsert(unsaved: ProductlistpricehistoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductlistpricehistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRow.scala new file mode 100644 index 0000000000..240c656afa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductlistpricehistoryRow( + /** Product identification number. Foreign key to Product.ProductID + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** List price start date. + Constraint CK_ProductListPriceHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** List price end date + Constraint CK_ProductListPriceHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Product list price. + Constraint CK_ProductListPriceHistory_ListPrice affecting columns "listprice": ((listprice > 0.00)) */ + listprice: BigDecimal, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductlistpricehistoryId = ProductlistpricehistoryId(productid, startdate) + } + +object ProductlistpricehistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductlistpricehistoryRow] = new JdbcDecoder[ProductlistpricehistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductlistpricehistoryRow) = + columIndex + 4 -> + ProductlistpricehistoryRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + listprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductlistpricehistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && startdate.isRight && enddate.isRight && listprice.isRight && modifieddate.isRight) + Right(ProductlistpricehistoryRow(productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, listprice = listprice.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate, enddate, listprice, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductlistpricehistoryRow] = new JsonEncoder[ProductlistpricehistoryRow] { + override def unsafeEncode(a: ProductlistpricehistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRowUnsaved.scala new file mode 100644 index 0000000000..93d7f6529d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryRowUnsaved.scala @@ -0,0 +1,78 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productlistpricehistory` which has not been persisted yet */ +case class ProductlistpricehistoryRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** List price start date. + Constraint CK_ProductListPriceHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** List price end date + Constraint CK_ProductListPriceHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Product list price. + Constraint CK_ProductListPriceHistory_ListPrice affecting columns "listprice": ((listprice > 0.00)) */ + listprice: BigDecimal, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): ProductlistpricehistoryRow = + ProductlistpricehistoryRow( + productid = productid, + startdate = startdate, + enddate = enddate, + listprice = listprice, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductlistpricehistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductlistpricehistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val listprice = jsonObj.get("listprice").toRight("Missing field 'listprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && startdate.isRight && enddate.isRight && listprice.isRight && modifieddate.isRight) + Right(ProductlistpricehistoryRowUnsaved(productid = productid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, listprice = listprice.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, startdate, enddate, listprice, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductlistpricehistoryRowUnsaved] = new JsonEncoder[ProductlistpricehistoryRowUnsaved] { + override def unsafeEncode(a: ProductlistpricehistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""listprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.listprice, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryStructure.scala new file mode 100644 index 0000000000..042698e344 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productlistpricehistory/ProductlistpricehistoryStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productlistpricehistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductlistpricehistoryStructure[Row](val prefix: Option[String], val extract: Row => ProductlistpricehistoryRow, val merge: (Row, ProductlistpricehistoryRow) => Row) + extends Relation[ProductlistpricehistoryFields, ProductlistpricehistoryRow, Row] + with ProductlistpricehistoryFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val startdate = new IdField[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val listprice = new Field[BigDecimal, Row](prefix, "listprice", None, Some("numeric"))(x => extract(x).listprice, (row, value) => merge(row, extract(row).copy(listprice = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, startdate, enddate, listprice, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductlistpricehistoryRow, merge: (NewRow, ProductlistpricehistoryRow) => NewRow): ProductlistpricehistoryStructure[NewRow] = + new ProductlistpricehistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelFields.scala new file mode 100644 index 0000000000..2437f0c667 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductmodelFields[Row] { + val productmodelid: IdField[ProductmodelId, Row] + val name: Field[Name, Row] + val catalogdescription: OptField[TypoXml, Row] + val instructions: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductmodelFields extends ProductmodelStructure[ProductmodelRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelId.scala new file mode 100644 index 0000000000..7b50dad513 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +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.productmodel` */ +case class ProductmodelId(value: Int) extends AnyVal +object ProductmodelId { + implicit lazy val arraySetter: Setter[Array[ProductmodelId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductmodelId, Int] = Bijection[ProductmodelId, Int](_.value)(ProductmodelId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductmodelId] = JdbcDecoder.intDecoder.map(ProductmodelId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductmodelId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelId] = JsonDecoder.int.map(ProductmodelId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductmodelId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductmodelId] = ParameterMetaData.instance[ProductmodelId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductmodelId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepo.scala new file mode 100644 index 0000000000..65f3432fd3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductmodelRepo { + def delete(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductmodelFields, ProductmodelRow] + def insert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, ProductmodelRow] + def insert(unsaved: ProductmodelRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelRow] + def select: SelectBuilder[ProductmodelFields, ProductmodelRow] + def selectAll: ZStream[ZConnection, Throwable, ProductmodelRow] + def selectById(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Option[ProductmodelRow]] + def selectByIds(productmodelids: Array[ProductmodelId]): ZStream[ZConnection, Throwable, ProductmodelRow] + def update(row: ProductmodelRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductmodelFields, ProductmodelRow] + def upsert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoImpl.scala new file mode 100644 index 0000000000..2102972d60 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoImpl.scala @@ -0,0 +1,116 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductmodelRepoImpl extends ProductmodelRepo { + override def delete(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productmodel where "productmodelid" = ${Segment.paramSegment(productmodelid)(ProductmodelId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductmodelFields, ProductmodelRow] = { + DeleteBuilder("production.productmodel", ProductmodelFields) + } + override def insert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, ProductmodelRow] = { + sql"""insert into production.productmodel("productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.catalogdescription)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.instructions)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text + """.insertReturning(ProductmodelRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductmodelRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""catalogdescription"""", sql"${Segment.paramSegment(unsaved.catalogdescription)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + Some((sql""""instructions"""", sql"${Segment.paramSegment(unsaved.instructions)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + unsaved.productmodelid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productmodelid"""", sql"${Segment.paramSegment(value: ProductmodelId)(ProductmodelId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productmodel default values + returning "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productmodel($names) values ($values) returning "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductmodelRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductmodelFields, ProductmodelRow] = { + SelectBuilderSql("production.productmodel", ProductmodelFields, ProductmodelRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelRow] = { + sql"""select "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text from production.productmodel""".query(ProductmodelRow.jdbcDecoder).selectStream + } + override def selectById(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Option[ProductmodelRow]] = { + sql"""select "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text from production.productmodel where "productmodelid" = ${Segment.paramSegment(productmodelid)(ProductmodelId.setter)}""".query(ProductmodelRow.jdbcDecoder).selectOne + } + override def selectByIds(productmodelids: Array[ProductmodelId]): ZStream[ZConnection, Throwable, ProductmodelRow] = { + sql"""select "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text from production.productmodel where "productmodelid" = ANY(${Segment.paramSegment(productmodelids)(ProductmodelId.arraySetter)})""".query(ProductmodelRow.jdbcDecoder).selectStream + } + override def update(row: ProductmodelRow): ZIO[ZConnection, Throwable, Boolean] = { + val productmodelid = row.productmodelid + sql"""update production.productmodel + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "catalogdescription" = ${Segment.paramSegment(row.catalogdescription)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "instructions" = ${Segment.paramSegment(row.instructions)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productmodelid" = ${Segment.paramSegment(productmodelid)(ProductmodelId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductmodelFields, ProductmodelRow] = { + UpdateBuilder("production.productmodel", ProductmodelFields, ProductmodelRow.jdbcDecoder) + } + override def upsert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelRow]] = { + sql"""insert into production.productmodel("productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.catalogdescription)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.instructions)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productmodelid") + do update set + "name" = EXCLUDED."name", + "catalogdescription" = EXCLUDED."catalogdescription", + "instructions" = EXCLUDED."instructions", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productmodelid", "name", "catalogdescription", "instructions", "rowguid", "modifieddate"::text""".insertReturning(ProductmodelRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoMock.scala new file mode 100644 index 0000000000..18a30909a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductmodelRepoMock(toRow: Function1[ProductmodelRowUnsaved, ProductmodelRow], + map: scala.collection.mutable.Map[ProductmodelId, ProductmodelRow] = scala.collection.mutable.Map.empty) extends ProductmodelRepo { + override def delete(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productmodelid).isDefined) + } + override def delete: DeleteBuilder[ProductmodelFields, ProductmodelRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductmodelFields, map) + } + override def insert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, ProductmodelRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productmodelid)) + sys.error(s"id ${unsaved.productmodelid} already exists") + else + map.put(unsaved.productmodelid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductmodelRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductmodelFields, ProductmodelRow] = { + SelectBuilderMock(ProductmodelFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productmodelid: ProductmodelId): ZIO[ZConnection, Throwable, Option[ProductmodelRow]] = { + ZIO.succeed(map.get(productmodelid)) + } + override def selectByIds(productmodelids: Array[ProductmodelId]): ZStream[ZConnection, Throwable, ProductmodelRow] = { + ZStream.fromIterable(productmodelids.flatMap(map.get)) + } + override def update(row: ProductmodelRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productmodelid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productmodelid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductmodelFields, ProductmodelRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductmodelFields, map) + } + override def upsert(unsaved: ProductmodelRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelRow]] = { + ZIO.succeed { + map.put(unsaved.productmodelid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRow.scala new file mode 100644 index 0000000000..6e5207f258 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductmodelRow( + /** Primary key for ProductModel records. */ + productmodelid: ProductmodelId, + /** Product model description. */ + name: Name, + /** Detailed product catalog information in xml format. */ + catalogdescription: Option[TypoXml], + /** Manufacturing instructions in xml format. */ + instructions: Option[TypoXml], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ProductmodelRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductmodelRow] = new JdbcDecoder[ProductmodelRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductmodelRow) = + columIndex + 5 -> + ProductmodelRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + catalogdescription = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + instructions = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val catalogdescription = jsonObj.get("catalogdescription").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val instructions = jsonObj.get("instructions").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && name.isRight && catalogdescription.isRight && instructions.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductmodelRow(productmodelid = productmodelid.toOption.get, name = name.toOption.get, catalogdescription = catalogdescription.toOption.get, instructions = instructions.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, name, catalogdescription, instructions, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelRow] = new JsonEncoder[ProductmodelRow] { + override def unsafeEncode(a: ProductmodelRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""catalogdescription":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.catalogdescription, indent, out) + out.write(",") + out.write(""""instructions":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.instructions, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRowUnsaved.scala new file mode 100644 index 0000000000..338725dac1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelRowUnsaved.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productmodel` which has not been persisted yet */ +case class ProductmodelRowUnsaved( + /** Product model description. */ + name: Name, + /** Detailed product catalog information in xml format. */ + catalogdescription: Option[TypoXml], + /** Manufacturing instructions in xml format. */ + instructions: Option[TypoXml], + /** Default: nextval('production.productmodel_productmodelid_seq'::regclass) + Primary key for ProductModel records. */ + productmodelid: Defaulted[ProductmodelId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productmodelidDefault: => ProductmodelId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductmodelRow = + ProductmodelRow( + name = name, + catalogdescription = catalogdescription, + instructions = instructions, + productmodelid = productmodelid match { + case Defaulted.UseDefault => productmodelidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductmodelRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val catalogdescription = jsonObj.get("catalogdescription").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val instructions = jsonObj.get("instructions").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(Defaulted.jsonDecoder(ProductmodelId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && catalogdescription.isRight && instructions.isRight && productmodelid.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductmodelRowUnsaved(name = name.toOption.get, catalogdescription = catalogdescription.toOption.get, instructions = instructions.toOption.get, productmodelid = productmodelid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, catalogdescription, instructions, productmodelid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelRowUnsaved] = new JsonEncoder[ProductmodelRowUnsaved] { + override def unsafeEncode(a: ProductmodelRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""catalogdescription":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.catalogdescription, indent, out) + out.write(",") + out.write(""""instructions":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.instructions, indent, out) + out.write(",") + out.write(""""productmodelid":""") + Defaulted.jsonEncoder(ProductmodelId.jsonEncoder).unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelStructure.scala new file mode 100644 index 0000000000..a1285ade93 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodel/ProductmodelStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodel + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductmodelStructure[Row](val prefix: Option[String], val extract: Row => ProductmodelRow, val merge: (Row, ProductmodelRow) => Row) + extends Relation[ProductmodelFields, ProductmodelRow, Row] + with ProductmodelFields[Row] { outer => + + override val productmodelid = new IdField[ProductmodelId, Row](prefix, "productmodelid", None, Some("int4"))(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val catalogdescription = new OptField[TypoXml, Row](prefix, "catalogdescription", None, Some("xml"))(x => extract(x).catalogdescription, (row, value) => merge(row, extract(row).copy(catalogdescription = value))) + override val instructions = new OptField[TypoXml, Row](prefix, "instructions", None, Some("xml"))(x => extract(x).instructions, (row, value) => merge(row, extract(row).copy(instructions = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, name, catalogdescription, instructions, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductmodelRow, merge: (NewRow, ProductmodelRow) => NewRow): ProductmodelStructure[NewRow] = + new ProductmodelStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationFields.scala new file mode 100644 index 0000000000..dbdfb81ca0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductmodelillustrationFields[Row] { + val productmodelid: IdField[ProductmodelId, Row] + val illustrationid: IdField[IllustrationId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductmodelillustrationFields extends ProductmodelillustrationStructure[ProductmodelillustrationRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationId.scala new file mode 100644 index 0000000000..678ac7f59e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productmodelillustration` */ +case class ProductmodelillustrationId(productmodelid: ProductmodelId, illustrationid: IllustrationId) +object ProductmodelillustrationId { + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelillustrationId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + if (productmodelid.isRight && illustrationid.isRight) + Right(ProductmodelillustrationId(productmodelid = productmodelid.toOption.get, illustrationid = illustrationid.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, illustrationid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelillustrationId] = new JsonEncoder[ProductmodelillustrationId] { + override def unsafeEncode(a: ProductmodelillustrationId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductmodelillustrationId] = Ordering.by(x => (x.productmodelid, x.illustrationid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepo.scala new file mode 100644 index 0000000000..e9653fcb57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductmodelillustrationRepo { + def delete(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] + def insert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] + def insert(unsaved: ProductmodelillustrationRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] + def select: SelectBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] + def selectAll: ZStream[ZConnection, Throwable, ProductmodelillustrationRow] + def selectById(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Option[ProductmodelillustrationRow]] + def update(row: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] + def upsert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelillustrationRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoImpl.scala new file mode 100644 index 0000000000..ca455f2adf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoImpl.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductmodelillustrationRepoImpl extends ProductmodelillustrationRepo { + override def delete(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productmodelillustration where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "illustrationid" = ${Segment.paramSegment(compositeId.illustrationid)(IllustrationId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + DeleteBuilder("production.productmodelillustration", ProductmodelillustrationFields) + } + override def insert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] = { + sql"""insert into production.productmodelillustration("productmodelid", "illustrationid", "modifieddate") + values (${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, ${Segment.paramSegment(unsaved.illustrationid)(IllustrationId.setter)}::int4, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productmodelid", "illustrationid", "modifieddate"::text + """.insertReturning(ProductmodelillustrationRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductmodelillustrationRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] = { + val fs = List( + Some((sql""""productmodelid"""", sql"${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4")), + Some((sql""""illustrationid"""", sql"${Segment.paramSegment(unsaved.illustrationid)(IllustrationId.setter)}::int4")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productmodelillustration default values + returning "productmodelid", "illustrationid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productmodelillustration($names) values ($values) returning "productmodelid", "illustrationid", "modifieddate"::text""" + } + q.insertReturning(ProductmodelillustrationRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + SelectBuilderSql("production.productmodelillustration", ProductmodelillustrationFields, ProductmodelillustrationRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelillustrationRow] = { + sql"""select "productmodelid", "illustrationid", "modifieddate"::text from production.productmodelillustration""".query(ProductmodelillustrationRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Option[ProductmodelillustrationRow]] = { + sql"""select "productmodelid", "illustrationid", "modifieddate"::text from production.productmodelillustration where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "illustrationid" = ${Segment.paramSegment(compositeId.illustrationid)(IllustrationId.setter)}""".query(ProductmodelillustrationRow.jdbcDecoder).selectOne + } + override def update(row: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productmodelillustration + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "illustrationid" = ${Segment.paramSegment(compositeId.illustrationid)(IllustrationId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + UpdateBuilder("production.productmodelillustration", ProductmodelillustrationFields, ProductmodelillustrationRow.jdbcDecoder) + } + override def upsert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelillustrationRow]] = { + sql"""insert into production.productmodelillustration("productmodelid", "illustrationid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, + ${Segment.paramSegment(unsaved.illustrationid)(IllustrationId.setter)}::int4, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productmodelid", "illustrationid") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "productmodelid", "illustrationid", "modifieddate"::text""".insertReturning(ProductmodelillustrationRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoMock.scala new file mode 100644 index 0000000000..4334ce42ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductmodelillustrationRepoMock(toRow: Function1[ProductmodelillustrationRowUnsaved, ProductmodelillustrationRow], + map: scala.collection.mutable.Map[ProductmodelillustrationId, ProductmodelillustrationRow] = scala.collection.mutable.Map.empty) extends ProductmodelillustrationRepo { + override def delete(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductmodelillustrationFields, map) + } + override def insert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductmodelillustrationRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + SelectBuilderMock(ProductmodelillustrationFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelillustrationRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductmodelillustrationId): ZIO[ZConnection, Throwable, Option[ProductmodelillustrationRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductmodelillustrationFields, ProductmodelillustrationRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductmodelillustrationFields, map) + } + override def upsert(unsaved: ProductmodelillustrationRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelillustrationRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRow.scala new file mode 100644 index 0000000000..9a33007e97 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductmodelillustrationRow( + /** Primary key. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Primary key. Foreign key to Illustration.IllustrationID. + Points to [[illustration.IllustrationRow.illustrationid]] */ + illustrationid: IllustrationId, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductmodelillustrationId = ProductmodelillustrationId(productmodelid, illustrationid) + } + +object ProductmodelillustrationRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductmodelillustrationRow] = new JdbcDecoder[ProductmodelillustrationRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductmodelillustrationRow) = + columIndex + 2 -> + ProductmodelillustrationRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + illustrationid = IllustrationId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelillustrationRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && illustrationid.isRight && modifieddate.isRight) + Right(ProductmodelillustrationRow(productmodelid = productmodelid.toOption.get, illustrationid = illustrationid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, illustrationid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelillustrationRow] = new JsonEncoder[ProductmodelillustrationRow] { + override def unsafeEncode(a: ProductmodelillustrationRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRowUnsaved.scala new file mode 100644 index 0000000000..2a24af2bb7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationRowUnsaved.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productmodelillustration` which has not been persisted yet */ +case class ProductmodelillustrationRowUnsaved( + /** Primary key. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Primary key. Foreign key to Illustration.IllustrationID. + Points to [[illustration.IllustrationRow.illustrationid]] */ + illustrationid: IllustrationId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): ProductmodelillustrationRow = + ProductmodelillustrationRow( + productmodelid = productmodelid, + illustrationid = illustrationid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductmodelillustrationRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelillustrationRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val illustrationid = jsonObj.get("illustrationid").toRight("Missing field 'illustrationid'").flatMap(_.as(IllustrationId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productmodelid.isRight && illustrationid.isRight && modifieddate.isRight) + Right(ProductmodelillustrationRowUnsaved(productmodelid = productmodelid.toOption.get, illustrationid = illustrationid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, illustrationid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelillustrationRowUnsaved] = new JsonEncoder[ProductmodelillustrationRowUnsaved] { + override def unsafeEncode(a: ProductmodelillustrationRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""illustrationid":""") + IllustrationId.jsonEncoder.unsafeEncode(a.illustrationid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationStructure.scala new file mode 100644 index 0000000000..e5e930457e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelillustration/ProductmodelillustrationStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelillustration + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductmodelillustrationStructure[Row](val prefix: Option[String], val extract: Row => ProductmodelillustrationRow, val merge: (Row, ProductmodelillustrationRow) => Row) + extends Relation[ProductmodelillustrationFields, ProductmodelillustrationRow, Row] + with ProductmodelillustrationFields[Row] { outer => + + override val productmodelid = new IdField[ProductmodelId, Row](prefix, "productmodelid", None, Some("int4"))(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val illustrationid = new IdField[IllustrationId, Row](prefix, "illustrationid", None, Some("int4"))(x => extract(x).illustrationid, (row, value) => merge(row, extract(row).copy(illustrationid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, illustrationid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductmodelillustrationRow, merge: (NewRow, ProductmodelillustrationRow) => NewRow): ProductmodelillustrationStructure[NewRow] = + new ProductmodelillustrationStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureFields.scala new file mode 100644 index 0000000000..bf16342ec5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductmodelproductdescriptioncultureFields[Row] { + val productmodelid: IdField[ProductmodelId, Row] + val productdescriptionid: IdField[ProductdescriptionId, Row] + val cultureid: IdField[CultureId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductmodelproductdescriptioncultureFields extends ProductmodelproductdescriptioncultureStructure[ProductmodelproductdescriptioncultureRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureId.scala new file mode 100644 index 0000000000..1cf04b4cd9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureId.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productmodelproductdescriptionculture` */ +case class ProductmodelproductdescriptioncultureId(productmodelid: ProductmodelId, productdescriptionid: ProductdescriptionId, cultureid: CultureId) +object ProductmodelproductdescriptioncultureId { + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelproductdescriptioncultureId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + if (productmodelid.isRight && productdescriptionid.isRight && cultureid.isRight) + Right(ProductmodelproductdescriptioncultureId(productmodelid = productmodelid.toOption.get, productdescriptionid = productdescriptionid.toOption.get, cultureid = cultureid.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, productdescriptionid, cultureid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelproductdescriptioncultureId] = new JsonEncoder[ProductmodelproductdescriptioncultureId] { + override def unsafeEncode(a: ProductmodelproductdescriptioncultureId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductmodelproductdescriptioncultureId] = Ordering.by(x => (x.productmodelid, x.productdescriptionid, x.cultureid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepo.scala new file mode 100644 index 0000000000..02aeb31102 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductmodelproductdescriptioncultureRepo { + def delete(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] + def insert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] + def insert(unsaved: ProductmodelproductdescriptioncultureRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] + def select: SelectBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] + def selectAll: ZStream[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] + def selectById(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Option[ProductmodelproductdescriptioncultureRow]] + def update(row: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] + def upsert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelproductdescriptioncultureRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoImpl.scala new file mode 100644 index 0000000000..9853ed58ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoImpl.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductmodelproductdescriptioncultureRepoImpl extends ProductmodelproductdescriptioncultureRepo { + override def delete(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productmodelproductdescriptionculture where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "productdescriptionid" = ${Segment.paramSegment(compositeId.productdescriptionid)(ProductdescriptionId.setter)} AND "cultureid" = ${Segment.paramSegment(compositeId.cultureid)(CultureId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + DeleteBuilder("production.productmodelproductdescriptionculture", ProductmodelproductdescriptioncultureFields) + } + override def insert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + sql"""insert into production.productmodelproductdescriptionculture("productmodelid", "productdescriptionid", "cultureid", "modifieddate") + values (${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, ${Segment.paramSegment(unsaved.productdescriptionid)(ProductdescriptionId.setter)}::int4, ${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text + """.insertReturning(ProductmodelproductdescriptioncultureRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductmodelproductdescriptioncultureRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + val fs = List( + Some((sql""""productmodelid"""", sql"${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4")), + Some((sql""""productdescriptionid"""", sql"${Segment.paramSegment(unsaved.productdescriptionid)(ProductdescriptionId.setter)}::int4")), + Some((sql""""cultureid"""", sql"${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productmodelproductdescriptionculture default values + returning "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productmodelproductdescriptionculture($names) values ($values) returning "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text""" + } + q.insertReturning(ProductmodelproductdescriptioncultureRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + SelectBuilderSql("production.productmodelproductdescriptionculture", ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + sql"""select "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text from production.productmodelproductdescriptionculture""".query(ProductmodelproductdescriptioncultureRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Option[ProductmodelproductdescriptioncultureRow]] = { + sql"""select "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text from production.productmodelproductdescriptionculture where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "productdescriptionid" = ${Segment.paramSegment(compositeId.productdescriptionid)(ProductdescriptionId.setter)} AND "cultureid" = ${Segment.paramSegment(compositeId.cultureid)(CultureId.setter)}""".query(ProductmodelproductdescriptioncultureRow.jdbcDecoder).selectOne + } + override def update(row: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productmodelproductdescriptionculture + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productmodelid" = ${Segment.paramSegment(compositeId.productmodelid)(ProductmodelId.setter)} AND "productdescriptionid" = ${Segment.paramSegment(compositeId.productdescriptionid)(ProductdescriptionId.setter)} AND "cultureid" = ${Segment.paramSegment(compositeId.cultureid)(CultureId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + UpdateBuilder("production.productmodelproductdescriptionculture", ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow.jdbcDecoder) + } + override def upsert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelproductdescriptioncultureRow]] = { + sql"""insert into production.productmodelproductdescriptionculture("productmodelid", "productdescriptionid", "cultureid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productmodelid)(ProductmodelId.setter)}::int4, + ${Segment.paramSegment(unsaved.productdescriptionid)(ProductdescriptionId.setter)}::int4, + ${Segment.paramSegment(unsaved.cultureid)(CultureId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productmodelid", "productdescriptionid", "cultureid") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "productmodelid", "productdescriptionid", "cultureid", "modifieddate"::text""".insertReturning(ProductmodelproductdescriptioncultureRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoMock.scala new file mode 100644 index 0000000000..b8ccc55e8a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductmodelproductdescriptioncultureRepoMock(toRow: Function1[ProductmodelproductdescriptioncultureRowUnsaved, ProductmodelproductdescriptioncultureRow], + map: scala.collection.mutable.Map[ProductmodelproductdescriptioncultureId, ProductmodelproductdescriptioncultureRow] = scala.collection.mutable.Map.empty) extends ProductmodelproductdescriptioncultureRepo { + override def delete(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductmodelproductdescriptioncultureFields, map) + } + override def insert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductmodelproductdescriptioncultureRowUnsaved): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + SelectBuilderMock(ProductmodelproductdescriptioncultureFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductmodelproductdescriptioncultureId): ZIO[ZConnection, Throwable, Option[ProductmodelproductdescriptioncultureRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductmodelproductdescriptioncultureFields, map) + } + override def upsert(unsaved: ProductmodelproductdescriptioncultureRow): ZIO[ZConnection, Throwable, UpdateResult[ProductmodelproductdescriptioncultureRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRow.scala new file mode 100644 index 0000000000..5abb189a4d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRow.scala @@ -0,0 +1,73 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductmodelproductdescriptioncultureRow( + /** Primary key. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Primary key. Foreign key to ProductDescription.ProductDescriptionID. + Points to [[productdescription.ProductdescriptionRow.productdescriptionid]] */ + productdescriptionid: ProductdescriptionId, + /** Culture identification number. Foreign key to Culture.CultureID. + Points to [[culture.CultureRow.cultureid]] */ + cultureid: CultureId, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductmodelproductdescriptioncultureId = ProductmodelproductdescriptioncultureId(productmodelid, productdescriptionid, cultureid) + } + +object ProductmodelproductdescriptioncultureRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductmodelproductdescriptioncultureRow] = new JdbcDecoder[ProductmodelproductdescriptioncultureRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductmodelproductdescriptioncultureRow) = + columIndex + 3 -> + ProductmodelproductdescriptioncultureRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productdescriptionid = ProductdescriptionId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + cultureid = CultureId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelproductdescriptioncultureRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && productdescriptionid.isRight && cultureid.isRight && modifieddate.isRight) + Right(ProductmodelproductdescriptioncultureRow(productmodelid = productmodelid.toOption.get, productdescriptionid = productdescriptionid.toOption.get, cultureid = cultureid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, productdescriptionid, cultureid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelproductdescriptioncultureRow] = new JsonEncoder[ProductmodelproductdescriptioncultureRow] { + override def unsafeEncode(a: ProductmodelproductdescriptioncultureRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRowUnsaved.scala new file mode 100644 index 0000000000..290e6f57af --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureRowUnsaved.scala @@ -0,0 +1,72 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productmodelproductdescriptionculture` which has not been persisted yet */ +case class ProductmodelproductdescriptioncultureRowUnsaved( + /** Primary key. Foreign key to ProductModel.ProductModelID. + Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Primary key. Foreign key to ProductDescription.ProductDescriptionID. + Points to [[productdescription.ProductdescriptionRow.productdescriptionid]] */ + productdescriptionid: ProductdescriptionId, + /** Culture identification number. Foreign key to Culture.CultureID. + Points to [[culture.CultureRow.cultureid]] */ + cultureid: CultureId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): ProductmodelproductdescriptioncultureRow = + ProductmodelproductdescriptioncultureRow( + productmodelid = productmodelid, + productdescriptionid = productdescriptionid, + cultureid = cultureid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductmodelproductdescriptioncultureRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductmodelproductdescriptioncultureRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val productdescriptionid = jsonObj.get("productdescriptionid").toRight("Missing field 'productdescriptionid'").flatMap(_.as(ProductdescriptionId.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productmodelid.isRight && productdescriptionid.isRight && cultureid.isRight && modifieddate.isRight) + Right(ProductmodelproductdescriptioncultureRowUnsaved(productmodelid = productmodelid.toOption.get, productdescriptionid = productdescriptionid.toOption.get, cultureid = cultureid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, productdescriptionid, cultureid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductmodelproductdescriptioncultureRowUnsaved] = new JsonEncoder[ProductmodelproductdescriptioncultureRowUnsaved] { + override def unsafeEncode(a: ProductmodelproductdescriptioncultureRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""productdescriptionid":""") + ProductdescriptionId.jsonEncoder.unsafeEncode(a.productdescriptionid, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureStructure.scala new file mode 100644 index 0000000000..68bba1a170 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productmodelproductdescriptionculture/ProductmodelproductdescriptioncultureStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productmodelproductdescriptionculture + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.culture.CultureId +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productmodel.ProductmodelId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductmodelproductdescriptioncultureStructure[Row](val prefix: Option[String], val extract: Row => ProductmodelproductdescriptioncultureRow, val merge: (Row, ProductmodelproductdescriptioncultureRow) => Row) + extends Relation[ProductmodelproductdescriptioncultureFields, ProductmodelproductdescriptioncultureRow, Row] + with ProductmodelproductdescriptioncultureFields[Row] { outer => + + override val productmodelid = new IdField[ProductmodelId, Row](prefix, "productmodelid", None, Some("int4"))(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val productdescriptionid = new IdField[ProductdescriptionId, Row](prefix, "productdescriptionid", None, Some("int4"))(x => extract(x).productdescriptionid, (row, value) => merge(row, extract(row).copy(productdescriptionid = value))) + override val cultureid = new IdField[CultureId, Row](prefix, "cultureid", None, Some("bpchar"))(x => extract(x).cultureid, (row, value) => merge(row, extract(row).copy(cultureid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, productdescriptionid, cultureid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductmodelproductdescriptioncultureRow, merge: (NewRow, ProductmodelproductdescriptioncultureRow) => NewRow): ProductmodelproductdescriptioncultureStructure[NewRow] = + new ProductmodelproductdescriptioncultureStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoFields.scala new file mode 100644 index 0000000000..1629445e71 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductphotoFields[Row] { + val productphotoid: IdField[ProductphotoId, Row] + val thumbnailphoto: OptField[TypoBytea, Row] + val thumbnailphotofilename: OptField[/* max 50 chars */ String, Row] + val largephoto: OptField[TypoBytea, Row] + val largephotofilename: OptField[/* max 50 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductphotoFields extends ProductphotoStructure[ProductphotoRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoId.scala new file mode 100644 index 0000000000..f3b1a4b616 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +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.productphoto` */ +case class ProductphotoId(value: Int) extends AnyVal +object ProductphotoId { + implicit lazy val arraySetter: Setter[Array[ProductphotoId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductphotoId, Int] = Bijection[ProductphotoId, Int](_.value)(ProductphotoId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductphotoId] = JdbcDecoder.intDecoder.map(ProductphotoId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductphotoId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductphotoId] = JsonDecoder.int.map(ProductphotoId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductphotoId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductphotoId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductphotoId] = ParameterMetaData.instance[ProductphotoId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductphotoId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepo.scala new file mode 100644 index 0000000000..889db69617 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductphotoRepo { + def delete(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductphotoFields, ProductphotoRow] + def insert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, ProductphotoRow] + def insert(unsaved: ProductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductphotoRow] + def select: SelectBuilder[ProductphotoFields, ProductphotoRow] + def selectAll: ZStream[ZConnection, Throwable, ProductphotoRow] + def selectById(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Option[ProductphotoRow]] + def selectByIds(productphotoids: Array[ProductphotoId]): ZStream[ZConnection, Throwable, ProductphotoRow] + def update(row: ProductphotoRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductphotoFields, ProductphotoRow] + def upsert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductphotoRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoImpl.scala new file mode 100644 index 0000000000..82ef67166e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoImpl.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductphotoRepoImpl extends ProductphotoRepo { + override def delete(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productphoto where "productphotoid" = ${Segment.paramSegment(productphotoid)(ProductphotoId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductphotoFields, ProductphotoRow] = { + DeleteBuilder("production.productphoto", ProductphotoFields) + } + override def insert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, ProductphotoRow] = { + sql"""insert into production.productphoto("productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate") + values (${Segment.paramSegment(unsaved.productphotoid)(ProductphotoId.setter)}::int4, ${Segment.paramSegment(unsaved.thumbnailphoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, ${Segment.paramSegment(unsaved.thumbnailphotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.largephoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, ${Segment.paramSegment(unsaved.largephotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text + """.insertReturning(ProductphotoRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductphotoRow] = { + val fs = List( + Some((sql""""thumbnailphoto"""", sql"${Segment.paramSegment(unsaved.thumbnailphoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea")), + Some((sql""""thumbnailphotofilename"""", sql"${Segment.paramSegment(unsaved.thumbnailphotofilename)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""largephoto"""", sql"${Segment.paramSegment(unsaved.largephoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea")), + Some((sql""""largephotofilename"""", sql"${Segment.paramSegment(unsaved.largephotofilename)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.productphotoid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productphotoid"""", sql"${Segment.paramSegment(value: ProductphotoId)(ProductphotoId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productphoto default values + returning "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productphoto($names) values ($values) returning "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text""" + } + q.insertReturning(ProductphotoRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductphotoFields, ProductphotoRow] = { + SelectBuilderSql("production.productphoto", ProductphotoFields, ProductphotoRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductphotoRow] = { + sql"""select "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text from production.productphoto""".query(ProductphotoRow.jdbcDecoder).selectStream + } + override def selectById(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Option[ProductphotoRow]] = { + sql"""select "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text from production.productphoto where "productphotoid" = ${Segment.paramSegment(productphotoid)(ProductphotoId.setter)}""".query(ProductphotoRow.jdbcDecoder).selectOne + } + override def selectByIds(productphotoids: Array[ProductphotoId]): ZStream[ZConnection, Throwable, ProductphotoRow] = { + sql"""select "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text from production.productphoto where "productphotoid" = ANY(${Segment.paramSegment(productphotoids)(ProductphotoId.arraySetter)})""".query(ProductphotoRow.jdbcDecoder).selectStream + } + override def update(row: ProductphotoRow): ZIO[ZConnection, Throwable, Boolean] = { + val productphotoid = row.productphotoid + sql"""update production.productphoto + set "thumbnailphoto" = ${Segment.paramSegment(row.thumbnailphoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + "thumbnailphotofilename" = ${Segment.paramSegment(row.thumbnailphotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, + "largephoto" = ${Segment.paramSegment(row.largephoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + "largephotofilename" = ${Segment.paramSegment(row.largephotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productphotoid" = ${Segment.paramSegment(productphotoid)(ProductphotoId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductphotoFields, ProductphotoRow] = { + UpdateBuilder("production.productphoto", ProductphotoFields, ProductphotoRow.jdbcDecoder) + } + override def upsert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductphotoRow]] = { + sql"""insert into production.productphoto("productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productphotoid)(ProductphotoId.setter)}::int4, + ${Segment.paramSegment(unsaved.thumbnailphoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + ${Segment.paramSegment(unsaved.thumbnailphotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.largephoto)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, + ${Segment.paramSegment(unsaved.largephotofilename)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productphotoid") + do update set + "thumbnailphoto" = EXCLUDED."thumbnailphoto", + "thumbnailphotofilename" = EXCLUDED."thumbnailphotofilename", + "largephoto" = EXCLUDED."largephoto", + "largephotofilename" = EXCLUDED."largephotofilename", + "modifieddate" = EXCLUDED."modifieddate" + returning "productphotoid", "thumbnailphoto", "thumbnailphotofilename", "largephoto", "largephotofilename", "modifieddate"::text""".insertReturning(ProductphotoRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoMock.scala new file mode 100644 index 0000000000..03e2513921 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductphotoRepoMock(toRow: Function1[ProductphotoRowUnsaved, ProductphotoRow], + map: scala.collection.mutable.Map[ProductphotoId, ProductphotoRow] = scala.collection.mutable.Map.empty) extends ProductphotoRepo { + override def delete(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productphotoid).isDefined) + } + override def delete: DeleteBuilder[ProductphotoFields, ProductphotoRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductphotoFields, map) + } + override def insert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, ProductphotoRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productphotoid)) + sys.error(s"id ${unsaved.productphotoid} already exists") + else + map.put(unsaved.productphotoid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductphotoRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductphotoFields, ProductphotoRow] = { + SelectBuilderMock(ProductphotoFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductphotoRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productphotoid: ProductphotoId): ZIO[ZConnection, Throwable, Option[ProductphotoRow]] = { + ZIO.succeed(map.get(productphotoid)) + } + override def selectByIds(productphotoids: Array[ProductphotoId]): ZStream[ZConnection, Throwable, ProductphotoRow] = { + ZStream.fromIterable(productphotoids.flatMap(map.get)) + } + override def update(row: ProductphotoRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productphotoid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productphotoid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductphotoFields, ProductphotoRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductphotoFields, map) + } + override def upsert(unsaved: ProductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductphotoRow]] = { + ZIO.succeed { + map.put(unsaved.productphotoid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRow.scala new file mode 100644 index 0000000000..74886c0970 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRow.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductphotoRow( + /** Primary key for ProductPhoto records. */ + productphotoid: ProductphotoId, + /** Small image of the product. */ + thumbnailphoto: Option[TypoBytea], + /** Small image file name. */ + thumbnailphotofilename: Option[/* max 50 chars */ String], + /** Large image of the product. */ + largephoto: Option[TypoBytea], + /** Large image file name. */ + largephotofilename: Option[/* max 50 chars */ String], + modifieddate: TypoLocalDateTime +) + +object ProductphotoRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductphotoRow] = new JdbcDecoder[ProductphotoRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductphotoRow) = + columIndex + 5 -> + ProductphotoRow( + productphotoid = ProductphotoId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + thumbnailphoto = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + thumbnailphotofilename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + largephoto = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + largephotofilename = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductphotoRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val thumbnailphoto = jsonObj.get("thumbnailphoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val thumbnailphotofilename = jsonObj.get("thumbnailphotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val largephoto = jsonObj.get("largephoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val largephotofilename = jsonObj.get("largephotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productphotoid.isRight && thumbnailphoto.isRight && thumbnailphotofilename.isRight && largephoto.isRight && largephotofilename.isRight && modifieddate.isRight) + Right(ProductphotoRow(productphotoid = productphotoid.toOption.get, thumbnailphoto = thumbnailphoto.toOption.get, thumbnailphotofilename = thumbnailphotofilename.toOption.get, largephoto = largephoto.toOption.get, largephotofilename = largephotofilename.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productphotoid, thumbnailphoto, thumbnailphotofilename, largephoto, largephotofilename, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductphotoRow] = new JsonEncoder[ProductphotoRow] { + override def unsafeEncode(a: ProductphotoRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""thumbnailphoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.thumbnailphoto, indent, out) + out.write(",") + out.write(""""thumbnailphotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.thumbnailphotofilename, indent, out) + out.write(",") + out.write(""""largephoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.largephoto, indent, out) + out.write(",") + out.write(""""largephotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.largephotofilename, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRowUnsaved.scala new file mode 100644 index 0000000000..03f4907e03 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoRowUnsaved.scala @@ -0,0 +1,85 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productphoto` which has not been persisted yet */ +case class ProductphotoRowUnsaved( + /** Small image of the product. */ + thumbnailphoto: Option[TypoBytea], + /** Small image file name. */ + thumbnailphotofilename: Option[/* max 50 chars */ String], + /** Large image of the product. */ + largephoto: Option[TypoBytea], + /** Large image file name. */ + largephotofilename: Option[/* max 50 chars */ String], + /** Default: nextval('production.productphoto_productphotoid_seq'::regclass) + Primary key for ProductPhoto records. */ + productphotoid: Defaulted[ProductphotoId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productphotoidDefault: => ProductphotoId, modifieddateDefault: => TypoLocalDateTime): ProductphotoRow = + ProductphotoRow( + thumbnailphoto = thumbnailphoto, + thumbnailphotofilename = thumbnailphotofilename, + largephoto = largephoto, + largephotofilename = largephotofilename, + productphotoid = productphotoid match { + case Defaulted.UseDefault => productphotoidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductphotoRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductphotoRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val thumbnailphoto = jsonObj.get("thumbnailphoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val thumbnailphotofilename = jsonObj.get("thumbnailphotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val largephoto = jsonObj.get("largephoto").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val largephotofilename = jsonObj.get("largephotofilename").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(Defaulted.jsonDecoder(ProductphotoId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (thumbnailphoto.isRight && thumbnailphotofilename.isRight && largephoto.isRight && largephotofilename.isRight && productphotoid.isRight && modifieddate.isRight) + Right(ProductphotoRowUnsaved(thumbnailphoto = thumbnailphoto.toOption.get, thumbnailphotofilename = thumbnailphotofilename.toOption.get, largephoto = largephoto.toOption.get, largephotofilename = largephotofilename.toOption.get, productphotoid = productphotoid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](thumbnailphoto, thumbnailphotofilename, largephoto, largephotofilename, productphotoid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductphotoRowUnsaved] = new JsonEncoder[ProductphotoRowUnsaved] { + override def unsafeEncode(a: ProductphotoRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""thumbnailphoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.thumbnailphoto, indent, out) + out.write(",") + out.write(""""thumbnailphotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.thumbnailphotofilename, indent, out) + out.write(",") + out.write(""""largephoto":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.largephoto, indent, out) + out.write(",") + out.write(""""largephotofilename":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.largephotofilename, indent, out) + out.write(",") + out.write(""""productphotoid":""") + Defaulted.jsonEncoder(ProductphotoId.jsonEncoder).unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoStructure.scala new file mode 100644 index 0000000000..5d6d6be4d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productphoto/ProductphotoStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productphoto + +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductphotoStructure[Row](val prefix: Option[String], val extract: Row => ProductphotoRow, val merge: (Row, ProductphotoRow) => Row) + extends Relation[ProductphotoFields, ProductphotoRow, Row] + with ProductphotoFields[Row] { outer => + + override val productphotoid = new IdField[ProductphotoId, Row](prefix, "productphotoid", None, Some("int4"))(x => extract(x).productphotoid, (row, value) => merge(row, extract(row).copy(productphotoid = value))) + override val thumbnailphoto = new OptField[TypoBytea, Row](prefix, "thumbnailphoto", None, Some("bytea"))(x => extract(x).thumbnailphoto, (row, value) => merge(row, extract(row).copy(thumbnailphoto = value))) + override val thumbnailphotofilename = new OptField[/* max 50 chars */ String, Row](prefix, "thumbnailphotofilename", None, None)(x => extract(x).thumbnailphotofilename, (row, value) => merge(row, extract(row).copy(thumbnailphotofilename = value))) + override val largephoto = new OptField[TypoBytea, Row](prefix, "largephoto", None, Some("bytea"))(x => extract(x).largephoto, (row, value) => merge(row, extract(row).copy(largephoto = value))) + override val largephotofilename = new OptField[/* max 50 chars */ String, Row](prefix, "largephotofilename", None, None)(x => extract(x).largephotofilename, (row, value) => merge(row, extract(row).copy(largephotofilename = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productphotoid, thumbnailphoto, thumbnailphotofilename, largephoto, largephotofilename, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductphotoRow, merge: (NewRow, ProductphotoRow) => NewRow): ProductphotoStructure[NewRow] = + new ProductphotoStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoFields.scala new file mode 100644 index 0000000000..4890db8c2f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductproductphotoFields[Row] { + val productid: IdField[ProductId, Row] + val productphotoid: IdField[ProductphotoId, Row] + val primary: Field[Flag, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductproductphotoFields extends ProductproductphotoStructure[ProductproductphotoRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoId.scala new file mode 100644 index 0000000000..337f1bf816 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.productproductphoto` */ +case class ProductproductphotoId(productid: ProductId, productphotoid: ProductphotoId) +object ProductproductphotoId { + implicit lazy val jsonDecoder: JsonDecoder[ProductproductphotoId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + if (productid.isRight && productphotoid.isRight) + Right(ProductproductphotoId(productid = productid.toOption.get, productphotoid = productphotoid.toOption.get)) + else Left(List[Either[String, Any]](productid, productphotoid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductproductphotoId] = new JsonEncoder[ProductproductphotoId] { + override def unsafeEncode(a: ProductproductphotoId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductproductphotoId] = Ordering.by(x => (x.productid, x.productphotoid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepo.scala new file mode 100644 index 0000000000..0eff3117ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductproductphotoRepo { + def delete(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductproductphotoFields, ProductproductphotoRow] + def insert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, ProductproductphotoRow] + def insert(unsaved: ProductproductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductproductphotoRow] + def select: SelectBuilder[ProductproductphotoFields, ProductproductphotoRow] + def selectAll: ZStream[ZConnection, Throwable, ProductproductphotoRow] + def selectById(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Option[ProductproductphotoRow]] + def update(row: ProductproductphotoRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductproductphotoFields, ProductproductphotoRow] + def upsert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductproductphotoRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoImpl.scala new file mode 100644 index 0000000000..78803ed455 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoImpl.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductproductphotoRepoImpl extends ProductproductphotoRepo { + override def delete(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productproductphoto where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "productphotoid" = ${Segment.paramSegment(compositeId.productphotoid)(ProductphotoId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + DeleteBuilder("production.productproductphoto", ProductproductphotoFields) + } + override def insert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, ProductproductphotoRow] = { + sql"""insert into production.productproductphoto("productid", "productphotoid", "primary", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.productphotoid)(ProductphotoId.setter)}::int4, ${Segment.paramSegment(unsaved.primary)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "productphotoid", "primary", "modifieddate"::text + """.insertReturning(ProductproductphotoRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductproductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductproductphotoRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""productphotoid"""", sql"${Segment.paramSegment(unsaved.productphotoid)(ProductphotoId.setter)}::int4")), + unsaved.primary match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""primary"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productproductphoto default values + returning "productid", "productphotoid", "primary", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productproductphoto($names) values ($values) returning "productid", "productphotoid", "primary", "modifieddate"::text""" + } + q.insertReturning(ProductproductphotoRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + SelectBuilderSql("production.productproductphoto", ProductproductphotoFields, ProductproductphotoRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductproductphotoRow] = { + sql"""select "productid", "productphotoid", "primary", "modifieddate"::text from production.productproductphoto""".query(ProductproductphotoRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Option[ProductproductphotoRow]] = { + sql"""select "productid", "productphotoid", "primary", "modifieddate"::text from production.productproductphoto where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "productphotoid" = ${Segment.paramSegment(compositeId.productphotoid)(ProductphotoId.setter)}""".query(ProductproductphotoRow.jdbcDecoder).selectOne + } + override def update(row: ProductproductphotoRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.productproductphoto + set "primary" = ${Segment.paramSegment(row.primary)(Flag.setter)}::bool, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "productphotoid" = ${Segment.paramSegment(compositeId.productphotoid)(ProductphotoId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + UpdateBuilder("production.productproductphoto", ProductproductphotoFields, ProductproductphotoRow.jdbcDecoder) + } + override def upsert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductproductphotoRow]] = { + sql"""insert into production.productproductphoto("productid", "productphotoid", "primary", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.productphotoid)(ProductphotoId.setter)}::int4, + ${Segment.paramSegment(unsaved.primary)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid", "productphotoid") + do update set + "primary" = EXCLUDED."primary", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "productphotoid", "primary", "modifieddate"::text""".insertReturning(ProductproductphotoRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoMock.scala new file mode 100644 index 0000000000..4ee2257b74 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductproductphotoRepoMock(toRow: Function1[ProductproductphotoRowUnsaved, ProductproductphotoRow], + map: scala.collection.mutable.Map[ProductproductphotoId, ProductproductphotoRow] = scala.collection.mutable.Map.empty) extends ProductproductphotoRepo { + override def delete(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductproductphotoFields, map) + } + override def insert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, ProductproductphotoRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductproductphotoRowUnsaved): ZIO[ZConnection, Throwable, ProductproductphotoRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + SelectBuilderMock(ProductproductphotoFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductproductphotoRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductproductphotoId): ZIO[ZConnection, Throwable, Option[ProductproductphotoRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductproductphotoRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductproductphotoFields, ProductproductphotoRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductproductphotoFields, map) + } + override def upsert(unsaved: ProductproductphotoRow): ZIO[ZConnection, Throwable, UpdateResult[ProductproductphotoRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRow.scala new file mode 100644 index 0000000000..4eb53830f8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRow.scala @@ -0,0 +1,72 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductproductphotoRow( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product photo identification number. Foreign key to ProductPhoto.ProductPhotoID. + Points to [[productphoto.ProductphotoRow.productphotoid]] */ + productphotoid: ProductphotoId, + /** 0 = Photo is not the principal image. 1 = Photo is the principal image. */ + primary: Flag, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductproductphotoId = ProductproductphotoId(productid, productphotoid) + } + +object ProductproductphotoRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductproductphotoRow] = new JdbcDecoder[ProductproductphotoRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductproductphotoRow) = + columIndex + 3 -> + ProductproductphotoRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productphotoid = ProductphotoId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + primary = Flag.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductproductphotoRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val primary = jsonObj.get("primary").toRight("Missing field 'primary'").flatMap(_.as(Flag.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && productphotoid.isRight && primary.isRight && modifieddate.isRight) + Right(ProductproductphotoRow(productid = productid.toOption.get, productphotoid = productphotoid.toOption.get, primary = primary.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, productphotoid, primary, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductproductphotoRow] = new JsonEncoder[ProductproductphotoRow] { + override def unsafeEncode(a: ProductproductphotoRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""primary":""") + Flag.jsonEncoder.unsafeEncode(a.primary, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRowUnsaved.scala new file mode 100644 index 0000000000..c83d20b706 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoRowUnsaved.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productproductphoto` which has not been persisted yet */ +case class ProductproductphotoRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product photo identification number. Foreign key to ProductPhoto.ProductPhotoID. + Points to [[productphoto.ProductphotoRow.productphotoid]] */ + productphotoid: ProductphotoId, + /** Default: false + 0 = Photo is not the principal image. 1 = Photo is the principal image. */ + primary: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(primaryDefault: => Flag, modifieddateDefault: => TypoLocalDateTime): ProductproductphotoRow = + ProductproductphotoRow( + productid = productid, + productphotoid = productphotoid, + primary = primary match { + case Defaulted.UseDefault => primaryDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductproductphotoRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductproductphotoRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val productphotoid = jsonObj.get("productphotoid").toRight("Missing field 'productphotoid'").flatMap(_.as(ProductphotoId.jsonDecoder)) + val primary = jsonObj.get("primary").toRight("Missing field 'primary'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && productphotoid.isRight && primary.isRight && modifieddate.isRight) + Right(ProductproductphotoRowUnsaved(productid = productid.toOption.get, productphotoid = productphotoid.toOption.get, primary = primary.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, productphotoid, primary, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductproductphotoRowUnsaved] = new JsonEncoder[ProductproductphotoRowUnsaved] { + override def unsafeEncode(a: ProductproductphotoRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""productphotoid":""") + ProductphotoId.jsonEncoder.unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""primary":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.primary, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoStructure.scala new file mode 100644 index 0000000000..2ddbdadac0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productproductphoto/ProductproductphotoStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productproductphoto + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.public.Flag +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductproductphotoStructure[Row](val prefix: Option[String], val extract: Row => ProductproductphotoRow, val merge: (Row, ProductproductphotoRow) => Row) + extends Relation[ProductproductphotoFields, ProductproductphotoRow, Row] + with ProductproductphotoFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val productphotoid = new IdField[ProductphotoId, Row](prefix, "productphotoid", None, Some("int4"))(x => extract(x).productphotoid, (row, value) => merge(row, extract(row).copy(productphotoid = value))) + override val primary = new Field[Flag, Row](prefix, "primary", None, Some("bool"))(x => extract(x).primary, (row, value) => merge(row, extract(row).copy(primary = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, productphotoid, primary, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductproductphotoRow, merge: (NewRow, ProductproductphotoRow) => NewRow): ProductproductphotoStructure[NewRow] = + new ProductproductphotoStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewFields.scala new file mode 100644 index 0000000000..7c631f3779 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductreviewFields[Row] { + val productreviewid: IdField[ProductreviewId, Row] + val productid: Field[ProductId, Row] + val reviewername: Field[Name, Row] + val reviewdate: Field[TypoLocalDateTime, Row] + val emailaddress: Field[/* max 50 chars */ String, Row] + val rating: Field[Int, Row] + val comments: OptField[/* max 3850 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductreviewFields extends ProductreviewStructure[ProductreviewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewId.scala new file mode 100644 index 0000000000..1752ff77de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +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.productreview` */ +case class ProductreviewId(value: Int) extends AnyVal +object ProductreviewId { + implicit lazy val arraySetter: Setter[Array[ProductreviewId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductreviewId, Int] = Bijection[ProductreviewId, Int](_.value)(ProductreviewId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductreviewId] = JdbcDecoder.intDecoder.map(ProductreviewId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductreviewId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductreviewId] = JsonDecoder.int.map(ProductreviewId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductreviewId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductreviewId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductreviewId] = ParameterMetaData.instance[ProductreviewId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductreviewId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepo.scala new file mode 100644 index 0000000000..a8dd7647f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductreviewRepo { + def delete(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductreviewFields, ProductreviewRow] + def insert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, ProductreviewRow] + def insert(unsaved: ProductreviewRowUnsaved): ZIO[ZConnection, Throwable, ProductreviewRow] + def select: SelectBuilder[ProductreviewFields, ProductreviewRow] + def selectAll: ZStream[ZConnection, Throwable, ProductreviewRow] + def selectById(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Option[ProductreviewRow]] + def selectByIds(productreviewids: Array[ProductreviewId]): ZStream[ZConnection, Throwable, ProductreviewRow] + def update(row: ProductreviewRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductreviewFields, ProductreviewRow] + def upsert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, UpdateResult[ProductreviewRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoImpl.scala new file mode 100644 index 0000000000..1da16c1c33 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoImpl.scala @@ -0,0 +1,123 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductreviewRepoImpl extends ProductreviewRepo { + override def delete(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productreview where "productreviewid" = ${Segment.paramSegment(productreviewid)(ProductreviewId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductreviewFields, ProductreviewRow] = { + DeleteBuilder("production.productreview", ProductreviewFields) + } + override def insert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, ProductreviewRow] = { + sql"""insert into production.productreview("productreviewid", "productid", "reviewername", "reviewdate", "emailaddress", "rating", "comments", "modifieddate") + values (${Segment.paramSegment(unsaved.productreviewid)(ProductreviewId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.reviewername)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.reviewdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.emailaddress)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.rating)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text + """.insertReturning(ProductreviewRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductreviewRowUnsaved): ZIO[ZConnection, Throwable, ProductreviewRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""reviewername"""", sql"${Segment.paramSegment(unsaved.reviewername)(Name.setter)}::varchar")), + Some((sql""""emailaddress"""", sql"${Segment.paramSegment(unsaved.emailaddress)(Setter.stringSetter)}")), + Some((sql""""rating"""", sql"${Segment.paramSegment(unsaved.rating)(Setter.intSetter)}::int4")), + Some((sql""""comments"""", sql"${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.productreviewid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productreviewid"""", sql"${Segment.paramSegment(value: ProductreviewId)(ProductreviewId.setter)}::int4")) + }, + unsaved.reviewdate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""reviewdate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productreview default values + returning "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productreview($names) values ($values) returning "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text""" + } + q.insertReturning(ProductreviewRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductreviewFields, ProductreviewRow] = { + SelectBuilderSql("production.productreview", ProductreviewFields, ProductreviewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductreviewRow] = { + sql"""select "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text from production.productreview""".query(ProductreviewRow.jdbcDecoder).selectStream + } + override def selectById(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Option[ProductreviewRow]] = { + sql"""select "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text from production.productreview where "productreviewid" = ${Segment.paramSegment(productreviewid)(ProductreviewId.setter)}""".query(ProductreviewRow.jdbcDecoder).selectOne + } + override def selectByIds(productreviewids: Array[ProductreviewId]): ZStream[ZConnection, Throwable, ProductreviewRow] = { + sql"""select "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text from production.productreview where "productreviewid" = ANY(${Segment.paramSegment(productreviewids)(ProductreviewId.arraySetter)})""".query(ProductreviewRow.jdbcDecoder).selectStream + } + override def update(row: ProductreviewRow): ZIO[ZConnection, Throwable, Boolean] = { + val productreviewid = row.productreviewid + sql"""update production.productreview + set "productid" = ${Segment.paramSegment(row.productid)(ProductId.setter)}::int4, + "reviewername" = ${Segment.paramSegment(row.reviewername)(Name.setter)}::varchar, + "reviewdate" = ${Segment.paramSegment(row.reviewdate)(TypoLocalDateTime.setter)}::timestamp, + "emailaddress" = ${Segment.paramSegment(row.emailaddress)(Setter.stringSetter)}, + "rating" = ${Segment.paramSegment(row.rating)(Setter.intSetter)}::int4, + "comments" = ${Segment.paramSegment(row.comments)(Setter.optionParamSetter(Setter.stringSetter))}, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productreviewid" = ${Segment.paramSegment(productreviewid)(ProductreviewId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductreviewFields, ProductreviewRow] = { + UpdateBuilder("production.productreview", ProductreviewFields, ProductreviewRow.jdbcDecoder) + } + override def upsert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, UpdateResult[ProductreviewRow]] = { + sql"""insert into production.productreview("productreviewid", "productid", "reviewername", "reviewdate", "emailaddress", "rating", "comments", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productreviewid)(ProductreviewId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.reviewername)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.reviewdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.emailaddress)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.rating)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.comments)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productreviewid") + do update set + "productid" = EXCLUDED."productid", + "reviewername" = EXCLUDED."reviewername", + "reviewdate" = EXCLUDED."reviewdate", + "emailaddress" = EXCLUDED."emailaddress", + "rating" = EXCLUDED."rating", + "comments" = EXCLUDED."comments", + "modifieddate" = EXCLUDED."modifieddate" + returning "productreviewid", "productid", "reviewername", "reviewdate"::text, "emailaddress", "rating", "comments", "modifieddate"::text""".insertReturning(ProductreviewRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoMock.scala new file mode 100644 index 0000000000..553b5f99b0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductreviewRepoMock(toRow: Function1[ProductreviewRowUnsaved, ProductreviewRow], + map: scala.collection.mutable.Map[ProductreviewId, ProductreviewRow] = scala.collection.mutable.Map.empty) extends ProductreviewRepo { + override def delete(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productreviewid).isDefined) + } + override def delete: DeleteBuilder[ProductreviewFields, ProductreviewRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductreviewFields, map) + } + override def insert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, ProductreviewRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productreviewid)) + sys.error(s"id ${unsaved.productreviewid} already exists") + else + map.put(unsaved.productreviewid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductreviewRowUnsaved): ZIO[ZConnection, Throwable, ProductreviewRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductreviewFields, ProductreviewRow] = { + SelectBuilderMock(ProductreviewFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductreviewRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productreviewid: ProductreviewId): ZIO[ZConnection, Throwable, Option[ProductreviewRow]] = { + ZIO.succeed(map.get(productreviewid)) + } + override def selectByIds(productreviewids: Array[ProductreviewId]): ZStream[ZConnection, Throwable, ProductreviewRow] = { + ZStream.fromIterable(productreviewids.flatMap(map.get)) + } + override def update(row: ProductreviewRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productreviewid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productreviewid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductreviewFields, ProductreviewRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductreviewFields, map) + } + override def upsert(unsaved: ProductreviewRow): ZIO[ZConnection, Throwable, UpdateResult[ProductreviewRow]] = { + ZIO.succeed { + map.put(unsaved.productreviewid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRow.scala new file mode 100644 index 0000000000..e4ee07cc15 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRow.scala @@ -0,0 +1,97 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductreviewRow( + /** Primary key for ProductReview records. */ + productreviewid: ProductreviewId, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Name of the reviewer. */ + reviewername: Name, + /** Date review was submitted. */ + reviewdate: TypoLocalDateTime, + /** Reviewer's e-mail address. */ + emailaddress: /* max 50 chars */ String, + /** Product rating given by the reviewer. Scale is 1 to 5 with 5 as the highest rating. + Constraint CK_ProductReview_Rating affecting columns "rating": (((rating >= 1) AND (rating <= 5))) */ + rating: Int, + /** Reviewer's comments */ + comments: Option[/* max 3850 chars */ String], + modifieddate: TypoLocalDateTime +) + +object ProductreviewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductreviewRow] = new JdbcDecoder[ProductreviewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductreviewRow) = + columIndex + 7 -> + ProductreviewRow( + productreviewid = ProductreviewId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + reviewername = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + reviewdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + emailaddress = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + rating = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 5, rs)._2, + comments = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductreviewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productreviewid = jsonObj.get("productreviewid").toRight("Missing field 'productreviewid'").flatMap(_.as(ProductreviewId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val reviewername = jsonObj.get("reviewername").toRight("Missing field 'reviewername'").flatMap(_.as(Name.jsonDecoder)) + val reviewdate = jsonObj.get("reviewdate").toRight("Missing field 'reviewdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val emailaddress = jsonObj.get("emailaddress").toRight("Missing field 'emailaddress'").flatMap(_.as(JsonDecoder.string)) + val rating = jsonObj.get("rating").toRight("Missing field 'rating'").flatMap(_.as(JsonDecoder.int)) + val comments = jsonObj.get("comments").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productreviewid.isRight && productid.isRight && reviewername.isRight && reviewdate.isRight && emailaddress.isRight && rating.isRight && comments.isRight && modifieddate.isRight) + Right(ProductreviewRow(productreviewid = productreviewid.toOption.get, productid = productid.toOption.get, reviewername = reviewername.toOption.get, reviewdate = reviewdate.toOption.get, emailaddress = emailaddress.toOption.get, rating = rating.toOption.get, comments = comments.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productreviewid, productid, reviewername, reviewdate, emailaddress, rating, comments, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductreviewRow] = new JsonEncoder[ProductreviewRow] { + override def unsafeEncode(a: ProductreviewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productreviewid":""") + ProductreviewId.jsonEncoder.unsafeEncode(a.productreviewid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""reviewername":""") + Name.jsonEncoder.unsafeEncode(a.reviewername, indent, out) + out.write(",") + out.write(""""reviewdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.reviewdate, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.string.unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""rating":""") + JsonEncoder.int.unsafeEncode(a.rating, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comments, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRowUnsaved.scala new file mode 100644 index 0000000000..4cdbf0a649 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewRowUnsaved.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productreview` which has not been persisted yet */ +case class ProductreviewRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Name of the reviewer. */ + reviewername: Name, + /** Reviewer's e-mail address. */ + emailaddress: /* max 50 chars */ String, + /** Product rating given by the reviewer. Scale is 1 to 5 with 5 as the highest rating. + Constraint CK_ProductReview_Rating affecting columns "rating": (((rating >= 1) AND (rating <= 5))) */ + rating: Int, + /** Reviewer's comments */ + comments: Option[/* max 3850 chars */ String], + /** Default: nextval('production.productreview_productreviewid_seq'::regclass) + Primary key for ProductReview records. */ + productreviewid: Defaulted[ProductreviewId] = Defaulted.UseDefault, + /** Default: now() + Date review was submitted. */ + reviewdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productreviewidDefault: => ProductreviewId, reviewdateDefault: => TypoLocalDateTime, modifieddateDefault: => TypoLocalDateTime): ProductreviewRow = + ProductreviewRow( + productid = productid, + reviewername = reviewername, + emailaddress = emailaddress, + rating = rating, + comments = comments, + productreviewid = productreviewid match { + case Defaulted.UseDefault => productreviewidDefault + case Defaulted.Provided(value) => value + }, + reviewdate = reviewdate match { + case Defaulted.UseDefault => reviewdateDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductreviewRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductreviewRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val reviewername = jsonObj.get("reviewername").toRight("Missing field 'reviewername'").flatMap(_.as(Name.jsonDecoder)) + val emailaddress = jsonObj.get("emailaddress").toRight("Missing field 'emailaddress'").flatMap(_.as(JsonDecoder.string)) + val rating = jsonObj.get("rating").toRight("Missing field 'rating'").flatMap(_.as(JsonDecoder.int)) + val comments = jsonObj.get("comments").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productreviewid = jsonObj.get("productreviewid").toRight("Missing field 'productreviewid'").flatMap(_.as(Defaulted.jsonDecoder(ProductreviewId.jsonDecoder))) + val reviewdate = jsonObj.get("reviewdate").toRight("Missing field 'reviewdate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && reviewername.isRight && emailaddress.isRight && rating.isRight && comments.isRight && productreviewid.isRight && reviewdate.isRight && modifieddate.isRight) + Right(ProductreviewRowUnsaved(productid = productid.toOption.get, reviewername = reviewername.toOption.get, emailaddress = emailaddress.toOption.get, rating = rating.toOption.get, comments = comments.toOption.get, productreviewid = productreviewid.toOption.get, reviewdate = reviewdate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, reviewername, emailaddress, rating, comments, productreviewid, reviewdate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductreviewRowUnsaved] = new JsonEncoder[ProductreviewRowUnsaved] { + override def unsafeEncode(a: ProductreviewRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""reviewername":""") + Name.jsonEncoder.unsafeEncode(a.reviewername, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.string.unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""rating":""") + JsonEncoder.int.unsafeEncode(a.rating, indent, out) + out.write(",") + out.write(""""comments":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comments, indent, out) + out.write(",") + out.write(""""productreviewid":""") + Defaulted.jsonEncoder(ProductreviewId.jsonEncoder).unsafeEncode(a.productreviewid, indent, out) + out.write(",") + out.write(""""reviewdate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.reviewdate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewStructure.scala new file mode 100644 index 0000000000..e7eca2f48d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productreview/ProductreviewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productreview + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductreviewStructure[Row](val prefix: Option[String], val extract: Row => ProductreviewRow, val merge: (Row, ProductreviewRow) => Row) + extends Relation[ProductreviewFields, ProductreviewRow, Row] + with ProductreviewFields[Row] { outer => + + override val productreviewid = new IdField[ProductreviewId, Row](prefix, "productreviewid", None, Some("int4"))(x => extract(x).productreviewid, (row, value) => merge(row, extract(row).copy(productreviewid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val reviewername = new Field[Name, Row](prefix, "reviewername", None, Some("varchar"))(x => extract(x).reviewername, (row, value) => merge(row, extract(row).copy(reviewername = value))) + override val reviewdate = new Field[TypoLocalDateTime, Row](prefix, "reviewdate", Some("text"), Some("timestamp"))(x => extract(x).reviewdate, (row, value) => merge(row, extract(row).copy(reviewdate = value))) + override val emailaddress = new Field[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val rating = new Field[Int, Row](prefix, "rating", None, Some("int4"))(x => extract(x).rating, (row, value) => merge(row, extract(row).copy(rating = value))) + override val comments = new OptField[/* max 3850 chars */ String, Row](prefix, "comments", None, None)(x => extract(x).comments, (row, value) => merge(row, extract(row).copy(comments = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productreviewid, productid, reviewername, reviewdate, emailaddress, rating, comments, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductreviewRow, merge: (NewRow, ProductreviewRow) => NewRow): ProductreviewStructure[NewRow] = + new ProductreviewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryFields.scala new file mode 100644 index 0000000000..7aaa9eaa8c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ProductsubcategoryFields[Row] { + val productsubcategoryid: IdField[ProductsubcategoryId, Row] + val productcategoryid: Field[ProductcategoryId, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductsubcategoryFields extends ProductsubcategoryStructure[ProductsubcategoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryId.scala new file mode 100644 index 0000000000..2b18c4259c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +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.productsubcategory` */ +case class ProductsubcategoryId(value: Int) extends AnyVal +object ProductsubcategoryId { + implicit lazy val arraySetter: Setter[Array[ProductsubcategoryId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ProductsubcategoryId, Int] = Bijection[ProductsubcategoryId, Int](_.value)(ProductsubcategoryId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ProductsubcategoryId] = JdbcDecoder.intDecoder.map(ProductsubcategoryId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ProductsubcategoryId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ProductsubcategoryId] = JsonDecoder.int.map(ProductsubcategoryId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ProductsubcategoryId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ProductsubcategoryId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ProductsubcategoryId] = ParameterMetaData.instance[ProductsubcategoryId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ProductsubcategoryId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepo.scala new file mode 100644 index 0000000000..50db56966b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductsubcategoryRepo { + def delete(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductsubcategoryFields, ProductsubcategoryRow] + def insert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, ProductsubcategoryRow] + def insert(unsaved: ProductsubcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductsubcategoryRow] + def select: SelectBuilder[ProductsubcategoryFields, ProductsubcategoryRow] + def selectAll: ZStream[ZConnection, Throwable, ProductsubcategoryRow] + def selectById(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Option[ProductsubcategoryRow]] + def selectByIds(productsubcategoryids: Array[ProductsubcategoryId]): ZStream[ZConnection, Throwable, ProductsubcategoryRow] + def update(row: ProductsubcategoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductsubcategoryFields, ProductsubcategoryRow] + def upsert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductsubcategoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoImpl.scala new file mode 100644 index 0000000000..198a1d532a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoImpl.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductsubcategoryRepoImpl extends ProductsubcategoryRepo { + override def delete(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.productsubcategory where "productsubcategoryid" = ${Segment.paramSegment(productsubcategoryid)(ProductsubcategoryId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + DeleteBuilder("production.productsubcategory", ProductsubcategoryFields) + } + override def insert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, ProductsubcategoryRow] = { + sql"""insert into production.productsubcategory("productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.productsubcategoryid)(ProductsubcategoryId.setter)}::int4, ${Segment.paramSegment(unsaved.productcategoryid)(ProductcategoryId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text + """.insertReturning(ProductsubcategoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductsubcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductsubcategoryRow] = { + val fs = List( + Some((sql""""productcategoryid"""", sql"${Segment.paramSegment(unsaved.productcategoryid)(ProductcategoryId.setter)}::int4")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.productsubcategoryid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""productsubcategoryid"""", sql"${Segment.paramSegment(value: ProductsubcategoryId)(ProductsubcategoryId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.productsubcategory default values + returning "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.productsubcategory($names) values ($values) returning "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ProductsubcategoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + SelectBuilderSql("production.productsubcategory", ProductsubcategoryFields, ProductsubcategoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductsubcategoryRow] = { + sql"""select "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productsubcategory""".query(ProductsubcategoryRow.jdbcDecoder).selectStream + } + override def selectById(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Option[ProductsubcategoryRow]] = { + sql"""select "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productsubcategory where "productsubcategoryid" = ${Segment.paramSegment(productsubcategoryid)(ProductsubcategoryId.setter)}""".query(ProductsubcategoryRow.jdbcDecoder).selectOne + } + override def selectByIds(productsubcategoryids: Array[ProductsubcategoryId]): ZStream[ZConnection, Throwable, ProductsubcategoryRow] = { + sql"""select "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text from production.productsubcategory where "productsubcategoryid" = ANY(${Segment.paramSegment(productsubcategoryids)(ProductsubcategoryId.arraySetter)})""".query(ProductsubcategoryRow.jdbcDecoder).selectStream + } + override def update(row: ProductsubcategoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val productsubcategoryid = row.productsubcategoryid + sql"""update production.productsubcategory + set "productcategoryid" = ${Segment.paramSegment(row.productcategoryid)(ProductcategoryId.setter)}::int4, + "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productsubcategoryid" = ${Segment.paramSegment(productsubcategoryid)(ProductsubcategoryId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + UpdateBuilder("production.productsubcategory", ProductsubcategoryFields, ProductsubcategoryRow.jdbcDecoder) + } + override def upsert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductsubcategoryRow]] = { + sql"""insert into production.productsubcategory("productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productsubcategoryid)(ProductsubcategoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.productcategoryid)(ProductcategoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productsubcategoryid") + do update set + "productcategoryid" = EXCLUDED."productcategoryid", + "name" = EXCLUDED."name", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "productsubcategoryid", "productcategoryid", "name", "rowguid", "modifieddate"::text""".insertReturning(ProductsubcategoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoMock.scala new file mode 100644 index 0000000000..73b8dbad00 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductsubcategoryRepoMock(toRow: Function1[ProductsubcategoryRowUnsaved, ProductsubcategoryRow], + map: scala.collection.mutable.Map[ProductsubcategoryId, ProductsubcategoryRow] = scala.collection.mutable.Map.empty) extends ProductsubcategoryRepo { + override def delete(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(productsubcategoryid).isDefined) + } + override def delete: DeleteBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductsubcategoryFields, map) + } + override def insert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, ProductsubcategoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.productsubcategoryid)) + sys.error(s"id ${unsaved.productsubcategoryid} already exists") + else + map.put(unsaved.productsubcategoryid, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductsubcategoryRowUnsaved): ZIO[ZConnection, Throwable, ProductsubcategoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + SelectBuilderMock(ProductsubcategoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductsubcategoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(productsubcategoryid: ProductsubcategoryId): ZIO[ZConnection, Throwable, Option[ProductsubcategoryRow]] = { + ZIO.succeed(map.get(productsubcategoryid)) + } + override def selectByIds(productsubcategoryids: Array[ProductsubcategoryId]): ZStream[ZConnection, Throwable, ProductsubcategoryRow] = { + ZStream.fromIterable(productsubcategoryids.flatMap(map.get)) + } + override def update(row: ProductsubcategoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.productsubcategoryid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.productsubcategoryid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductsubcategoryFields, ProductsubcategoryRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductsubcategoryFields, map) + } + override def upsert(unsaved: ProductsubcategoryRow): ZIO[ZConnection, Throwable, UpdateResult[ProductsubcategoryRow]] = { + ZIO.succeed { + map.put(unsaved.productsubcategoryid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRow.scala new file mode 100644 index 0000000000..b9095bfbd6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductsubcategoryRow( + /** Primary key for ProductSubcategory records. */ + productsubcategoryid: ProductsubcategoryId, + /** Product category identification number. Foreign key to ProductCategory.ProductCategoryID. + Points to [[productcategory.ProductcategoryRow.productcategoryid]] */ + productcategoryid: ProductcategoryId, + /** Subcategory description. */ + name: Name, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ProductsubcategoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductsubcategoryRow] = new JdbcDecoder[ProductsubcategoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductsubcategoryRow) = + columIndex + 4 -> + ProductsubcategoryRow( + productsubcategoryid = ProductsubcategoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productcategoryid = ProductcategoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductsubcategoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productsubcategoryid = jsonObj.get("productsubcategoryid").toRight("Missing field 'productsubcategoryid'").flatMap(_.as(ProductsubcategoryId.jsonDecoder)) + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productsubcategoryid.isRight && productcategoryid.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductsubcategoryRow(productsubcategoryid = productsubcategoryid.toOption.get, productcategoryid = productcategoryid.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productsubcategoryid, productcategoryid, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductsubcategoryRow] = new JsonEncoder[ProductsubcategoryRow] { + override def unsafeEncode(a: ProductsubcategoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productsubcategoryid":""") + ProductsubcategoryId.jsonEncoder.unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""productcategoryid":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRowUnsaved.scala new file mode 100644 index 0000000000..5a737c93e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryRowUnsaved.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.productsubcategory` which has not been persisted yet */ +case class ProductsubcategoryRowUnsaved( + /** Product category identification number. Foreign key to ProductCategory.ProductCategoryID. + Points to [[productcategory.ProductcategoryRow.productcategoryid]] */ + productcategoryid: ProductcategoryId, + /** Subcategory description. */ + name: Name, + /** Default: nextval('production.productsubcategory_productsubcategoryid_seq'::regclass) + Primary key for ProductSubcategory records. */ + productsubcategoryid: Defaulted[ProductsubcategoryId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(productsubcategoryidDefault: => ProductsubcategoryId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ProductsubcategoryRow = + ProductsubcategoryRow( + productcategoryid = productcategoryid, + name = name, + productsubcategoryid = productsubcategoryid match { + case Defaulted.UseDefault => productsubcategoryidDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductsubcategoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductsubcategoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productcategoryid = jsonObj.get("productcategoryid").toRight("Missing field 'productcategoryid'").flatMap(_.as(ProductcategoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productsubcategoryid = jsonObj.get("productsubcategoryid").toRight("Missing field 'productsubcategoryid'").flatMap(_.as(Defaulted.jsonDecoder(ProductsubcategoryId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productcategoryid.isRight && name.isRight && productsubcategoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(ProductsubcategoryRowUnsaved(productcategoryid = productcategoryid.toOption.get, name = name.toOption.get, productsubcategoryid = productsubcategoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productcategoryid, name, productsubcategoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductsubcategoryRowUnsaved] = new JsonEncoder[ProductsubcategoryRowUnsaved] { + override def unsafeEncode(a: ProductsubcategoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productcategoryid":""") + ProductcategoryId.jsonEncoder.unsafeEncode(a.productcategoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productsubcategoryid":""") + Defaulted.jsonEncoder(ProductsubcategoryId.jsonEncoder).unsafeEncode(a.productsubcategoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryStructure.scala new file mode 100644 index 0000000000..252d890975 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/productsubcategory/ProductsubcategoryStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package productsubcategory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ProductsubcategoryStructure[Row](val prefix: Option[String], val extract: Row => ProductsubcategoryRow, val merge: (Row, ProductsubcategoryRow) => Row) + extends Relation[ProductsubcategoryFields, ProductsubcategoryRow, Row] + with ProductsubcategoryFields[Row] { outer => + + override val productsubcategoryid = new IdField[ProductsubcategoryId, Row](prefix, "productsubcategoryid", None, Some("int4"))(x => extract(x).productsubcategoryid, (row, value) => merge(row, extract(row).copy(productsubcategoryid = value))) + override val productcategoryid = new Field[ProductcategoryId, Row](prefix, "productcategoryid", None, Some("int4"))(x => extract(x).productcategoryid, (row, value) => merge(row, extract(row).copy(productcategoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productsubcategoryid, productcategoryid, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductsubcategoryRow, merge: (NewRow, ProductsubcategoryRow) => NewRow): ProductsubcategoryStructure[NewRow] = + new ProductsubcategoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonFields.scala new file mode 100644 index 0000000000..ca072f007e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ScrapreasonFields[Row] { + val scrapreasonid: IdField[ScrapreasonId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ScrapreasonFields extends ScrapreasonStructure[ScrapreasonRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonId.scala new file mode 100644 index 0000000000..1590987554 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +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.scrapreason` */ +case class ScrapreasonId(value: Int) extends AnyVal +object ScrapreasonId { + implicit lazy val arraySetter: Setter[Array[ScrapreasonId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ScrapreasonId, Int] = Bijection[ScrapreasonId, Int](_.value)(ScrapreasonId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ScrapreasonId] = JdbcDecoder.intDecoder.map(ScrapreasonId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ScrapreasonId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ScrapreasonId] = JsonDecoder.int.map(ScrapreasonId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ScrapreasonId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ScrapreasonId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ScrapreasonId] = ParameterMetaData.instance[ScrapreasonId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ScrapreasonId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepo.scala new file mode 100644 index 0000000000..279f60a6dd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ScrapreasonRepo { + def delete(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ScrapreasonFields, ScrapreasonRow] + def insert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, ScrapreasonRow] + def insert(unsaved: ScrapreasonRowUnsaved): ZIO[ZConnection, Throwable, ScrapreasonRow] + def select: SelectBuilder[ScrapreasonFields, ScrapreasonRow] + def selectAll: ZStream[ZConnection, Throwable, ScrapreasonRow] + def selectById(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Option[ScrapreasonRow]] + def selectByIds(scrapreasonids: Array[ScrapreasonId]): ZStream[ZConnection, Throwable, ScrapreasonRow] + def update(row: ScrapreasonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ScrapreasonFields, ScrapreasonRow] + def upsert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, UpdateResult[ScrapreasonRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoImpl.scala new file mode 100644 index 0000000000..1ff40b4125 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoImpl.scala @@ -0,0 +1,98 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ScrapreasonRepoImpl extends ScrapreasonRepo { + override def delete(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.scrapreason where "scrapreasonid" = ${Segment.paramSegment(scrapreasonid)(ScrapreasonId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ScrapreasonFields, ScrapreasonRow] = { + DeleteBuilder("production.scrapreason", ScrapreasonFields) + } + override def insert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, ScrapreasonRow] = { + sql"""insert into production.scrapreason("scrapreasonid", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.scrapreasonid)(ScrapreasonId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "scrapreasonid", "name", "modifieddate"::text + """.insertReturning(ScrapreasonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ScrapreasonRowUnsaved): ZIO[ZConnection, Throwable, ScrapreasonRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.scrapreasonid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""scrapreasonid"""", sql"${Segment.paramSegment(value: ScrapreasonId)(ScrapreasonId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.scrapreason default values + returning "scrapreasonid", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.scrapreason($names) values ($values) returning "scrapreasonid", "name", "modifieddate"::text""" + } + q.insertReturning(ScrapreasonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ScrapreasonFields, ScrapreasonRow] = { + SelectBuilderSql("production.scrapreason", ScrapreasonFields, ScrapreasonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ScrapreasonRow] = { + sql"""select "scrapreasonid", "name", "modifieddate"::text from production.scrapreason""".query(ScrapreasonRow.jdbcDecoder).selectStream + } + override def selectById(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Option[ScrapreasonRow]] = { + sql"""select "scrapreasonid", "name", "modifieddate"::text from production.scrapreason where "scrapreasonid" = ${Segment.paramSegment(scrapreasonid)(ScrapreasonId.setter)}""".query(ScrapreasonRow.jdbcDecoder).selectOne + } + override def selectByIds(scrapreasonids: Array[ScrapreasonId]): ZStream[ZConnection, Throwable, ScrapreasonRow] = { + sql"""select "scrapreasonid", "name", "modifieddate"::text from production.scrapreason where "scrapreasonid" = ANY(${Segment.paramSegment(scrapreasonids)(ScrapreasonId.arraySetter)})""".query(ScrapreasonRow.jdbcDecoder).selectStream + } + override def update(row: ScrapreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + val scrapreasonid = row.scrapreasonid + sql"""update production.scrapreason + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "scrapreasonid" = ${Segment.paramSegment(scrapreasonid)(ScrapreasonId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ScrapreasonFields, ScrapreasonRow] = { + UpdateBuilder("production.scrapreason", ScrapreasonFields, ScrapreasonRow.jdbcDecoder) + } + override def upsert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, UpdateResult[ScrapreasonRow]] = { + sql"""insert into production.scrapreason("scrapreasonid", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.scrapreasonid)(ScrapreasonId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("scrapreasonid") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "scrapreasonid", "name", "modifieddate"::text""".insertReturning(ScrapreasonRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoMock.scala new file mode 100644 index 0000000000..633f2b1412 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ScrapreasonRepoMock(toRow: Function1[ScrapreasonRowUnsaved, ScrapreasonRow], + map: scala.collection.mutable.Map[ScrapreasonId, ScrapreasonRow] = scala.collection.mutable.Map.empty) extends ScrapreasonRepo { + override def delete(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(scrapreasonid).isDefined) + } + override def delete: DeleteBuilder[ScrapreasonFields, ScrapreasonRow] = { + DeleteBuilderMock(DeleteParams.empty, ScrapreasonFields, map) + } + override def insert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, ScrapreasonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.scrapreasonid)) + sys.error(s"id ${unsaved.scrapreasonid} already exists") + else + map.put(unsaved.scrapreasonid, unsaved) + + unsaved + } + } + override def insert(unsaved: ScrapreasonRowUnsaved): ZIO[ZConnection, Throwable, ScrapreasonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ScrapreasonFields, ScrapreasonRow] = { + SelectBuilderMock(ScrapreasonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ScrapreasonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(scrapreasonid: ScrapreasonId): ZIO[ZConnection, Throwable, Option[ScrapreasonRow]] = { + ZIO.succeed(map.get(scrapreasonid)) + } + override def selectByIds(scrapreasonids: Array[ScrapreasonId]): ZStream[ZConnection, Throwable, ScrapreasonRow] = { + ZStream.fromIterable(scrapreasonids.flatMap(map.get)) + } + override def update(row: ScrapreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.scrapreasonid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.scrapreasonid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ScrapreasonFields, ScrapreasonRow] = { + UpdateBuilderMock(UpdateParams.empty, ScrapreasonFields, map) + } + override def upsert(unsaved: ScrapreasonRow): ZIO[ZConnection, Throwable, UpdateResult[ScrapreasonRow]] = { + ZIO.succeed { + map.put(unsaved.scrapreasonid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRow.scala new file mode 100644 index 0000000000..d15bb4e620 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ScrapreasonRow( + /** Primary key for ScrapReason records. */ + scrapreasonid: ScrapreasonId, + /** Failure description. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object ScrapreasonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ScrapreasonRow] = new JdbcDecoder[ScrapreasonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ScrapreasonRow) = + columIndex + 2 -> + ScrapreasonRow( + scrapreasonid = ScrapreasonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ScrapreasonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val scrapreasonid = jsonObj.get("scrapreasonid").toRight("Missing field 'scrapreasonid'").flatMap(_.as(ScrapreasonId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (scrapreasonid.isRight && name.isRight && modifieddate.isRight) + Right(ScrapreasonRow(scrapreasonid = scrapreasonid.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](scrapreasonid, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ScrapreasonRow] = new JsonEncoder[ScrapreasonRow] { + override def unsafeEncode(a: ScrapreasonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""scrapreasonid":""") + ScrapreasonId.jsonEncoder.unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRowUnsaved.scala new file mode 100644 index 0000000000..264ee5a37b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonRowUnsaved.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.scrapreason` which has not been persisted yet */ +case class ScrapreasonRowUnsaved( + /** Failure description. */ + name: Name, + /** Default: nextval('production.scrapreason_scrapreasonid_seq'::regclass) + Primary key for ScrapReason records. */ + scrapreasonid: Defaulted[ScrapreasonId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(scrapreasonidDefault: => ScrapreasonId, modifieddateDefault: => TypoLocalDateTime): ScrapreasonRow = + ScrapreasonRow( + name = name, + scrapreasonid = scrapreasonid match { + case Defaulted.UseDefault => scrapreasonidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ScrapreasonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ScrapreasonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val scrapreasonid = jsonObj.get("scrapreasonid").toRight("Missing field 'scrapreasonid'").flatMap(_.as(Defaulted.jsonDecoder(ScrapreasonId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && scrapreasonid.isRight && modifieddate.isRight) + Right(ScrapreasonRowUnsaved(name = name.toOption.get, scrapreasonid = scrapreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, scrapreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ScrapreasonRowUnsaved] = new JsonEncoder[ScrapreasonRowUnsaved] { + override def unsafeEncode(a: ScrapreasonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""scrapreasonid":""") + Defaulted.jsonEncoder(ScrapreasonId.jsonEncoder).unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonStructure.scala new file mode 100644 index 0000000000..9d25018824 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/scrapreason/ScrapreasonStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package scrapreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ScrapreasonStructure[Row](val prefix: Option[String], val extract: Row => ScrapreasonRow, val merge: (Row, ScrapreasonRow) => Row) + extends Relation[ScrapreasonFields, ScrapreasonRow, Row] + with ScrapreasonFields[Row] { outer => + + override val scrapreasonid = new IdField[ScrapreasonId, Row](prefix, "scrapreasonid", None, Some("int4"))(x => extract(x).scrapreasonid, (row, value) => merge(row, extract(row).copy(scrapreasonid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](scrapreasonid, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ScrapreasonRow, merge: (NewRow, ScrapreasonRow) => NewRow): ScrapreasonStructure[NewRow] = + new ScrapreasonStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryFields.scala new file mode 100644 index 0000000000..9df57dd54b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait TransactionhistoryFields[Row] { + val transactionid: IdField[TransactionhistoryId, Row] + val productid: Field[ProductId, Row] + val referenceorderid: Field[Int, Row] + val referenceorderlineid: Field[Int, Row] + val transactiondate: Field[TypoLocalDateTime, Row] + val transactiontype: Field[/* bpchar, max 1 chars */ String, Row] + val quantity: Field[Int, Row] + val actualcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object TransactionhistoryFields extends TransactionhistoryStructure[TransactionhistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryId.scala new file mode 100644 index 0000000000..daa32525d5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +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.transactionhistory` */ +case class TransactionhistoryId(value: Int) extends AnyVal +object TransactionhistoryId { + implicit lazy val arraySetter: Setter[Array[TransactionhistoryId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[TransactionhistoryId, Int] = Bijection[TransactionhistoryId, Int](_.value)(TransactionhistoryId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TransactionhistoryId] = JdbcDecoder.intDecoder.map(TransactionhistoryId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[TransactionhistoryId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryId] = JsonDecoder.int.map(TransactionhistoryId.apply) + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[TransactionhistoryId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TransactionhistoryId] = ParameterMetaData.instance[TransactionhistoryId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[TransactionhistoryId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepo.scala new file mode 100644 index 0000000000..c104977afc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TransactionhistoryRepo { + def delete(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[TransactionhistoryFields, TransactionhistoryRow] + def insert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, TransactionhistoryRow] + def insert(unsaved: TransactionhistoryRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryRow] + def select: SelectBuilder[TransactionhistoryFields, TransactionhistoryRow] + def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryRow] + def selectById(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Option[TransactionhistoryRow]] + def selectByIds(transactionids: Array[TransactionhistoryId]): ZStream[ZConnection, Throwable, TransactionhistoryRow] + def update(row: TransactionhistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[TransactionhistoryFields, TransactionhistoryRow] + def upsert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoImpl.scala new file mode 100644 index 0000000000..1bc7ce9b53 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoImpl.scala @@ -0,0 +1,129 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TransactionhistoryRepoImpl extends TransactionhistoryRepo { + override def delete(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.transactionhistory where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + DeleteBuilder("production.transactionhistory", TransactionhistoryFields) + } + override def insert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, TransactionhistoryRow] = { + sql"""insert into production.transactionhistory("transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate", "transactiontype", "quantity", "actualcost", "modifieddate") + values (${Segment.paramSegment(unsaved.transactionid)(TransactionhistoryId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.referenceorderlineid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.transactiondate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text + """.insertReturning(TransactionhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: TransactionhistoryRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""referenceorderid"""", sql"${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4")), + Some((sql""""transactiontype"""", sql"${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar")), + Some((sql""""quantity"""", sql"${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4")), + Some((sql""""actualcost"""", sql"${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.transactionid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""transactionid"""", sql"${Segment.paramSegment(value: TransactionhistoryId)(TransactionhistoryId.setter)}::int4")) + }, + unsaved.referenceorderlineid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""referenceorderlineid"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.transactiondate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""transactiondate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.transactionhistory default values + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.transactionhistory($names) values ($values) returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text""" + } + q.insertReturning(TransactionhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + SelectBuilderSql("production.transactionhistory", TransactionhistoryFields, TransactionhistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryRow] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistory""".query(TransactionhistoryRow.jdbcDecoder).selectStream + } + override def selectById(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Option[TransactionhistoryRow]] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistory where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryId.setter)}""".query(TransactionhistoryRow.jdbcDecoder).selectOne + } + override def selectByIds(transactionids: Array[TransactionhistoryId]): ZStream[ZConnection, Throwable, TransactionhistoryRow] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistory where "transactionid" = ANY(${Segment.paramSegment(transactionids)(TransactionhistoryId.arraySetter)})""".query(TransactionhistoryRow.jdbcDecoder).selectStream + } + override def update(row: TransactionhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val transactionid = row.transactionid + sql"""update production.transactionhistory + set "productid" = ${Segment.paramSegment(row.productid)(ProductId.setter)}::int4, + "referenceorderid" = ${Segment.paramSegment(row.referenceorderid)(Setter.intSetter)}::int4, + "referenceorderlineid" = ${Segment.paramSegment(row.referenceorderlineid)(Setter.intSetter)}::int4, + "transactiondate" = ${Segment.paramSegment(row.transactiondate)(TypoLocalDateTime.setter)}::timestamp, + "transactiontype" = ${Segment.paramSegment(row.transactiontype)(Setter.stringSetter)}::bpchar, + "quantity" = ${Segment.paramSegment(row.quantity)(Setter.intSetter)}::int4, + "actualcost" = ${Segment.paramSegment(row.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + UpdateBuilder("production.transactionhistory", TransactionhistoryFields, TransactionhistoryRow.jdbcDecoder) + } + override def upsert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryRow]] = { + sql"""insert into production.transactionhistory("transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate", "transactiontype", "quantity", "actualcost", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.transactionid)(TransactionhistoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.referenceorderlineid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.transactiondate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("transactionid") + do update set + "productid" = EXCLUDED."productid", + "referenceorderid" = EXCLUDED."referenceorderid", + "referenceorderlineid" = EXCLUDED."referenceorderlineid", + "transactiondate" = EXCLUDED."transactiondate", + "transactiontype" = EXCLUDED."transactiontype", + "quantity" = EXCLUDED."quantity", + "actualcost" = EXCLUDED."actualcost", + "modifieddate" = EXCLUDED."modifieddate" + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text""".insertReturning(TransactionhistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoMock.scala new file mode 100644 index 0000000000..e77419c64d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class TransactionhistoryRepoMock(toRow: Function1[TransactionhistoryRowUnsaved, TransactionhistoryRow], + map: scala.collection.mutable.Map[TransactionhistoryId, TransactionhistoryRow] = scala.collection.mutable.Map.empty) extends TransactionhistoryRepo { + override def delete(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(transactionid).isDefined) + } + override def delete: DeleteBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, TransactionhistoryFields, map) + } + override def insert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, TransactionhistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.transactionid)) + sys.error(s"id ${unsaved.transactionid} already exists") + else + map.put(unsaved.transactionid, unsaved) + + unsaved + } + } + override def insert(unsaved: TransactionhistoryRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + SelectBuilderMock(TransactionhistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(transactionid: TransactionhistoryId): ZIO[ZConnection, Throwable, Option[TransactionhistoryRow]] = { + ZIO.succeed(map.get(transactionid)) + } + override def selectByIds(transactionids: Array[TransactionhistoryId]): ZStream[ZConnection, Throwable, TransactionhistoryRow] = { + ZStream.fromIterable(transactionids.flatMap(map.get)) + } + override def update(row: TransactionhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.transactionid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.transactionid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[TransactionhistoryFields, TransactionhistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, TransactionhistoryFields, map) + } + override def upsert(unsaved: TransactionhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryRow]] = { + ZIO.succeed { + map.put(unsaved.transactionid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRow.scala new file mode 100644 index 0000000000..d0abb906bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRow.scala @@ -0,0 +1,103 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TransactionhistoryRow( + /** Primary key for TransactionHistory records. */ + transactionid: TransactionhistoryId, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Purchase order, sales order, or work order identification number. */ + referenceorderid: Int, + /** Line number associated with the purchase order, sales order, or work order. */ + referenceorderlineid: Int, + /** Date and time of the transaction. */ + transactiondate: TypoLocalDateTime, + /** W = WorkOrder, S = SalesOrder, P = PurchaseOrder + Constraint CK_TransactionHistory_TransactionType affecting columns "transactiontype": ((upper((transactiontype)::text) = ANY (ARRAY['W'::text, 'S'::text, 'P'::text]))) */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Product quantity. */ + quantity: Int, + /** Product cost. */ + actualcost: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object TransactionhistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TransactionhistoryRow] = new JdbcDecoder[TransactionhistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TransactionhistoryRow) = + columIndex + 8 -> + TransactionhistoryRow( + transactionid = TransactionhistoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + referenceorderid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + referenceorderlineid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + transactiondate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + transactiontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + actualcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(TransactionhistoryId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(JsonDecoder.int)) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (transactionid.isRight && productid.isRight && referenceorderid.isRight && referenceorderlineid.isRight && transactiondate.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && modifieddate.isRight) + Right(TransactionhistoryRow(transactionid = transactionid.toOption.get, productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryRow] = new JsonEncoder[TransactionhistoryRow] { + override def unsafeEncode(a: TransactionhistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""transactionid":""") + TransactionhistoryId.jsonEncoder.unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRowUnsaved.scala new file mode 100644 index 0000000000..1d26ea2601 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryRowUnsaved.scala @@ -0,0 +1,116 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.transactionhistory` which has not been persisted yet */ +case class TransactionhistoryRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Purchase order, sales order, or work order identification number. */ + referenceorderid: Int, + /** W = WorkOrder, S = SalesOrder, P = PurchaseOrder + Constraint CK_TransactionHistory_TransactionType affecting columns "transactiontype": ((upper((transactiontype)::text) = ANY (ARRAY['W'::text, 'S'::text, 'P'::text]))) */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Product quantity. */ + quantity: Int, + /** Product cost. */ + actualcost: BigDecimal, + /** Default: nextval('production.transactionhistory_transactionid_seq'::regclass) + Primary key for TransactionHistory records. */ + transactionid: Defaulted[TransactionhistoryId] = Defaulted.UseDefault, + /** Default: 0 + Line number associated with the purchase order, sales order, or work order. */ + referenceorderlineid: Defaulted[Int] = Defaulted.UseDefault, + /** Default: now() + Date and time of the transaction. */ + transactiondate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(transactionidDefault: => TransactionhistoryId, referenceorderlineidDefault: => Int, transactiondateDefault: => TypoLocalDateTime, modifieddateDefault: => TypoLocalDateTime): TransactionhistoryRow = + TransactionhistoryRow( + productid = productid, + referenceorderid = referenceorderid, + transactiontype = transactiontype, + quantity = quantity, + actualcost = actualcost, + transactionid = transactionid match { + case Defaulted.UseDefault => transactionidDefault + case Defaulted.Provided(value) => value + }, + referenceorderlineid = referenceorderlineid match { + case Defaulted.UseDefault => referenceorderlineidDefault + case Defaulted.Provided(value) => value + }, + transactiondate = transactiondate match { + case Defaulted.UseDefault => transactiondateDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object TransactionhistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(Defaulted.jsonDecoder(TransactionhistoryId.jsonDecoder))) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && referenceorderid.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && transactionid.isRight && referenceorderlineid.isRight && transactiondate.isRight && modifieddate.isRight) + Right(TransactionhistoryRowUnsaved(productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, transactionid = transactionid.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, referenceorderid, transactiontype, quantity, actualcost, transactionid, referenceorderlineid, transactiondate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryRowUnsaved] = new JsonEncoder[TransactionhistoryRowUnsaved] { + override def unsafeEncode(a: TransactionhistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""transactionid":""") + Defaulted.jsonEncoder(TransactionhistoryId.jsonEncoder).unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryStructure.scala new file mode 100644 index 0000000000..f404fa5efa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistory/TransactionhistoryStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class TransactionhistoryStructure[Row](val prefix: Option[String], val extract: Row => TransactionhistoryRow, val merge: (Row, TransactionhistoryRow) => Row) + extends Relation[TransactionhistoryFields, TransactionhistoryRow, Row] + with TransactionhistoryFields[Row] { outer => + + override val transactionid = new IdField[TransactionhistoryId, Row](prefix, "transactionid", None, Some("int4"))(x => extract(x).transactionid, (row, value) => merge(row, extract(row).copy(transactionid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val referenceorderid = new Field[Int, Row](prefix, "referenceorderid", None, Some("int4"))(x => extract(x).referenceorderid, (row, value) => merge(row, extract(row).copy(referenceorderid = value))) + override val referenceorderlineid = new Field[Int, Row](prefix, "referenceorderlineid", None, Some("int4"))(x => extract(x).referenceorderlineid, (row, value) => merge(row, extract(row).copy(referenceorderlineid = value))) + override val transactiondate = new Field[TypoLocalDateTime, Row](prefix, "transactiondate", Some("text"), Some("timestamp"))(x => extract(x).transactiondate, (row, value) => merge(row, extract(row).copy(transactiondate = value))) + override val transactiontype = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "transactiontype", None, Some("bpchar"))(x => extract(x).transactiontype, (row, value) => merge(row, extract(row).copy(transactiontype = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, Some("int4"))(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val actualcost = new Field[BigDecimal, Row](prefix, "actualcost", None, Some("numeric"))(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TransactionhistoryRow, merge: (NewRow, TransactionhistoryRow) => NewRow): TransactionhistoryStructure[NewRow] = + new TransactionhistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveFields.scala new file mode 100644 index 0000000000..3719c19452 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait TransactionhistoryarchiveFields[Row] { + val transactionid: IdField[TransactionhistoryarchiveId, Row] + val productid: Field[Int, Row] + val referenceorderid: Field[Int, Row] + val referenceorderlineid: Field[Int, Row] + val transactiondate: Field[TypoLocalDateTime, Row] + val transactiontype: Field[/* bpchar, max 1 chars */ String, Row] + val quantity: Field[Int, Row] + val actualcost: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object TransactionhistoryarchiveFields extends TransactionhistoryarchiveStructure[TransactionhistoryarchiveRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveId.scala new file mode 100644 index 0000000000..a441cac037 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +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.transactionhistoryarchive` */ +case class TransactionhistoryarchiveId(value: Int) extends AnyVal +object TransactionhistoryarchiveId { + implicit lazy val arraySetter: Setter[Array[TransactionhistoryarchiveId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[TransactionhistoryarchiveId, Int] = Bijection[TransactionhistoryarchiveId, Int](_.value)(TransactionhistoryarchiveId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[TransactionhistoryarchiveId] = JdbcDecoder.intDecoder.map(TransactionhistoryarchiveId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[TransactionhistoryarchiveId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryarchiveId] = JsonDecoder.int.map(TransactionhistoryarchiveId.apply) + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryarchiveId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[TransactionhistoryarchiveId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[TransactionhistoryarchiveId] = ParameterMetaData.instance[TransactionhistoryarchiveId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[TransactionhistoryarchiveId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepo.scala new file mode 100644 index 0000000000..27ecccb09e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TransactionhistoryarchiveRepo { + def delete(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] + def insert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] + def insert(unsaved: TransactionhistoryarchiveRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] + def select: SelectBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] + def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] + def selectById(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Option[TransactionhistoryarchiveRow]] + def selectByIds(transactionids: Array[TransactionhistoryarchiveId]): ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] + def update(row: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] + def upsert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryarchiveRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoImpl.scala new file mode 100644 index 0000000000..60a351237a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoImpl.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TransactionhistoryarchiveRepoImpl extends TransactionhistoryarchiveRepo { + override def delete(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.transactionhistoryarchive where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryarchiveId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + DeleteBuilder("production.transactionhistoryarchive", TransactionhistoryarchiveFields) + } + override def insert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + sql"""insert into production.transactionhistoryarchive("transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate", "transactiontype", "quantity", "actualcost", "modifieddate") + values (${Segment.paramSegment(unsaved.transactionid)(TransactionhistoryarchiveId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.referenceorderlineid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.transactiondate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text + """.insertReturning(TransactionhistoryarchiveRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: TransactionhistoryarchiveRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + val fs = List( + Some((sql""""transactionid"""", sql"${Segment.paramSegment(unsaved.transactionid)(TransactionhistoryarchiveId.setter)}::int4")), + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4")), + Some((sql""""referenceorderid"""", sql"${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4")), + Some((sql""""transactiontype"""", sql"${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar")), + Some((sql""""quantity"""", sql"${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4")), + Some((sql""""actualcost"""", sql"${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.referenceorderlineid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""referenceorderlineid"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.transactiondate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""transactiondate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.transactionhistoryarchive default values + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.transactionhistoryarchive($names) values ($values) returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text""" + } + q.insertReturning(TransactionhistoryarchiveRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + SelectBuilderSql("production.transactionhistoryarchive", TransactionhistoryarchiveFields, TransactionhistoryarchiveRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistoryarchive""".query(TransactionhistoryarchiveRow.jdbcDecoder).selectStream + } + override def selectById(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Option[TransactionhistoryarchiveRow]] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistoryarchive where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryarchiveId.setter)}""".query(TransactionhistoryarchiveRow.jdbcDecoder).selectOne + } + override def selectByIds(transactionids: Array[TransactionhistoryarchiveId]): ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + sql"""select "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text from production.transactionhistoryarchive where "transactionid" = ANY(${Segment.paramSegment(transactionids)(TransactionhistoryarchiveId.arraySetter)})""".query(TransactionhistoryarchiveRow.jdbcDecoder).selectStream + } + override def update(row: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, Boolean] = { + val transactionid = row.transactionid + sql"""update production.transactionhistoryarchive + set "productid" = ${Segment.paramSegment(row.productid)(Setter.intSetter)}::int4, + "referenceorderid" = ${Segment.paramSegment(row.referenceorderid)(Setter.intSetter)}::int4, + "referenceorderlineid" = ${Segment.paramSegment(row.referenceorderlineid)(Setter.intSetter)}::int4, + "transactiondate" = ${Segment.paramSegment(row.transactiondate)(TypoLocalDateTime.setter)}::timestamp, + "transactiontype" = ${Segment.paramSegment(row.transactiontype)(Setter.stringSetter)}::bpchar, + "quantity" = ${Segment.paramSegment(row.quantity)(Setter.intSetter)}::int4, + "actualcost" = ${Segment.paramSegment(row.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "transactionid" = ${Segment.paramSegment(transactionid)(TransactionhistoryarchiveId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + UpdateBuilder("production.transactionhistoryarchive", TransactionhistoryarchiveFields, TransactionhistoryarchiveRow.jdbcDecoder) + } + override def upsert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryarchiveRow]] = { + sql"""insert into production.transactionhistoryarchive("transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate", "transactiontype", "quantity", "actualcost", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.transactionid)(TransactionhistoryarchiveId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.referenceorderid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.referenceorderlineid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.transactiondate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.transactiontype)(Setter.stringSetter)}::bpchar, + ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.actualcost)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("transactionid") + do update set + "productid" = EXCLUDED."productid", + "referenceorderid" = EXCLUDED."referenceorderid", + "referenceorderlineid" = EXCLUDED."referenceorderlineid", + "transactiondate" = EXCLUDED."transactiondate", + "transactiontype" = EXCLUDED."transactiontype", + "quantity" = EXCLUDED."quantity", + "actualcost" = EXCLUDED."actualcost", + "modifieddate" = EXCLUDED."modifieddate" + returning "transactionid", "productid", "referenceorderid", "referenceorderlineid", "transactiondate"::text, "transactiontype", "quantity", "actualcost", "modifieddate"::text""".insertReturning(TransactionhistoryarchiveRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoMock.scala new file mode 100644 index 0000000000..88c356320c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class TransactionhistoryarchiveRepoMock(toRow: Function1[TransactionhistoryarchiveRowUnsaved, TransactionhistoryarchiveRow], + map: scala.collection.mutable.Map[TransactionhistoryarchiveId, TransactionhistoryarchiveRow] = scala.collection.mutable.Map.empty) extends TransactionhistoryarchiveRepo { + override def delete(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(transactionid).isDefined) + } + override def delete: DeleteBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + DeleteBuilderMock(DeleteParams.empty, TransactionhistoryarchiveFields, map) + } + override def insert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.transactionid)) + sys.error(s"id ${unsaved.transactionid} already exists") + else + map.put(unsaved.transactionid, unsaved) + + unsaved + } + } + override def insert(unsaved: TransactionhistoryarchiveRowUnsaved): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + SelectBuilderMock(TransactionhistoryarchiveFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(transactionid: TransactionhistoryarchiveId): ZIO[ZConnection, Throwable, Option[TransactionhistoryarchiveRow]] = { + ZIO.succeed(map.get(transactionid)) + } + override def selectByIds(transactionids: Array[TransactionhistoryarchiveId]): ZStream[ZConnection, Throwable, TransactionhistoryarchiveRow] = { + ZStream.fromIterable(transactionids.flatMap(map.get)) + } + override def update(row: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.transactionid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.transactionid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow] = { + UpdateBuilderMock(UpdateParams.empty, TransactionhistoryarchiveFields, map) + } + override def upsert(unsaved: TransactionhistoryarchiveRow): ZIO[ZConnection, Throwable, UpdateResult[TransactionhistoryarchiveRow]] = { + ZIO.succeed { + map.put(unsaved.transactionid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRow.scala new file mode 100644 index 0000000000..6d229d44da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRow.scala @@ -0,0 +1,101 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import adventureworks.customtypes.TypoLocalDateTime +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TransactionhistoryarchiveRow( + /** Primary key for TransactionHistoryArchive records. */ + transactionid: TransactionhistoryarchiveId, + /** Product identification number. Foreign key to Product.ProductID. */ + productid: Int, + /** Purchase order, sales order, or work order identification number. */ + referenceorderid: Int, + /** Line number associated with the purchase order, sales order, or work order. */ + referenceorderlineid: Int, + /** Date and time of the transaction. */ + transactiondate: TypoLocalDateTime, + /** W = Work Order, S = Sales Order, P = Purchase Order + Constraint CK_TransactionHistoryArchive_TransactionType affecting columns "transactiontype": ((upper((transactiontype)::text) = ANY (ARRAY['W'::text, 'S'::text, 'P'::text]))) */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Product quantity. */ + quantity: Int, + /** Product cost. */ + actualcost: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object TransactionhistoryarchiveRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TransactionhistoryarchiveRow] = new JdbcDecoder[TransactionhistoryarchiveRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TransactionhistoryarchiveRow) = + columIndex + 8 -> + TransactionhistoryarchiveRow( + transactionid = TransactionhistoryarchiveId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + referenceorderid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + referenceorderlineid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + transactiondate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + transactiontype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + actualcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryarchiveRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(TransactionhistoryarchiveId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(JsonDecoder.int)) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (transactionid.isRight && productid.isRight && referenceorderid.isRight && referenceorderlineid.isRight && transactiondate.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && modifieddate.isRight) + Right(TransactionhistoryarchiveRow(transactionid = transactionid.toOption.get, productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryarchiveRow] = new JsonEncoder[TransactionhistoryarchiveRow] { + override def unsafeEncode(a: TransactionhistoryarchiveRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""transactionid":""") + TransactionhistoryarchiveId.jsonEncoder.unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRowUnsaved.scala new file mode 100644 index 0000000000..a34c151989 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveRowUnsaved.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.transactionhistoryarchive` which has not been persisted yet */ +case class TransactionhistoryarchiveRowUnsaved( + /** Primary key for TransactionHistoryArchive records. */ + transactionid: TransactionhistoryarchiveId, + /** Product identification number. Foreign key to Product.ProductID. */ + productid: Int, + /** Purchase order, sales order, or work order identification number. */ + referenceorderid: Int, + /** W = Work Order, S = Sales Order, P = Purchase Order + Constraint CK_TransactionHistoryArchive_TransactionType affecting columns "transactiontype": ((upper((transactiontype)::text) = ANY (ARRAY['W'::text, 'S'::text, 'P'::text]))) */ + transactiontype: /* bpchar, max 1 chars */ String, + /** Product quantity. */ + quantity: Int, + /** Product cost. */ + actualcost: BigDecimal, + /** Default: 0 + Line number associated with the purchase order, sales order, or work order. */ + referenceorderlineid: Defaulted[Int] = Defaulted.UseDefault, + /** Default: now() + Date and time of the transaction. */ + transactiondate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(referenceorderlineidDefault: => Int, transactiondateDefault: => TypoLocalDateTime, modifieddateDefault: => TypoLocalDateTime): TransactionhistoryarchiveRow = + TransactionhistoryarchiveRow( + transactionid = transactionid, + productid = productid, + referenceorderid = referenceorderid, + transactiontype = transactiontype, + quantity = quantity, + actualcost = actualcost, + referenceorderlineid = referenceorderlineid match { + case Defaulted.UseDefault => referenceorderlineidDefault + case Defaulted.Provided(value) => value + }, + transactiondate = transactiondate match { + case Defaulted.UseDefault => transactiondateDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object TransactionhistoryarchiveRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[TransactionhistoryarchiveRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val transactionid = jsonObj.get("transactionid").toRight("Missing field 'transactionid'").flatMap(_.as(TransactionhistoryarchiveId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val referenceorderid = jsonObj.get("referenceorderid").toRight("Missing field 'referenceorderid'").flatMap(_.as(JsonDecoder.int)) + val transactiontype = jsonObj.get("transactiontype").toRight("Missing field 'transactiontype'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val actualcost = jsonObj.get("actualcost").toRight("Missing field 'actualcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val referenceorderlineid = jsonObj.get("referenceorderlineid").toRight("Missing field 'referenceorderlineid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val transactiondate = jsonObj.get("transactiondate").toRight("Missing field 'transactiondate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (transactionid.isRight && productid.isRight && referenceorderid.isRight && transactiontype.isRight && quantity.isRight && actualcost.isRight && referenceorderlineid.isRight && transactiondate.isRight && modifieddate.isRight) + Right(TransactionhistoryarchiveRowUnsaved(transactionid = transactionid.toOption.get, productid = productid.toOption.get, referenceorderid = referenceorderid.toOption.get, transactiontype = transactiontype.toOption.get, quantity = quantity.toOption.get, actualcost = actualcost.toOption.get, referenceorderlineid = referenceorderlineid.toOption.get, transactiondate = transactiondate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](transactionid, productid, referenceorderid, transactiontype, quantity, actualcost, referenceorderlineid, transactiondate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TransactionhistoryarchiveRowUnsaved] = new JsonEncoder[TransactionhistoryarchiveRowUnsaved] { + override def unsafeEncode(a: TransactionhistoryarchiveRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""transactionid":""") + TransactionhistoryarchiveId.jsonEncoder.unsafeEncode(a.transactionid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""referenceorderid":""") + JsonEncoder.int.unsafeEncode(a.referenceorderid, indent, out) + out.write(",") + out.write(""""transactiontype":""") + JsonEncoder.string.unsafeEncode(a.transactiontype, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""referenceorderlineid":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.referenceorderlineid, indent, out) + out.write(",") + out.write(""""transactiondate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.transactiondate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveStructure.scala new file mode 100644 index 0000000000..48ea814139 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/transactionhistoryarchive/TransactionhistoryarchiveStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package transactionhistoryarchive + +import adventureworks.customtypes.TypoLocalDateTime +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class TransactionhistoryarchiveStructure[Row](val prefix: Option[String], val extract: Row => TransactionhistoryarchiveRow, val merge: (Row, TransactionhistoryarchiveRow) => Row) + extends Relation[TransactionhistoryarchiveFields, TransactionhistoryarchiveRow, Row] + with TransactionhistoryarchiveFields[Row] { outer => + + override val transactionid = new IdField[TransactionhistoryarchiveId, Row](prefix, "transactionid", None, Some("int4"))(x => extract(x).transactionid, (row, value) => merge(row, extract(row).copy(transactionid = value))) + override val productid = new Field[Int, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val referenceorderid = new Field[Int, Row](prefix, "referenceorderid", None, Some("int4"))(x => extract(x).referenceorderid, (row, value) => merge(row, extract(row).copy(referenceorderid = value))) + override val referenceorderlineid = new Field[Int, Row](prefix, "referenceorderlineid", None, Some("int4"))(x => extract(x).referenceorderlineid, (row, value) => merge(row, extract(row).copy(referenceorderlineid = value))) + override val transactiondate = new Field[TypoLocalDateTime, Row](prefix, "transactiondate", Some("text"), Some("timestamp"))(x => extract(x).transactiondate, (row, value) => merge(row, extract(row).copy(transactiondate = value))) + override val transactiontype = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "transactiontype", None, Some("bpchar"))(x => extract(x).transactiontype, (row, value) => merge(row, extract(row).copy(transactiontype = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, Some("int4"))(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val actualcost = new Field[BigDecimal, Row](prefix, "actualcost", None, Some("numeric"))(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](transactionid, productid, referenceorderid, referenceorderlineid, transactiondate, transactiontype, quantity, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TransactionhistoryarchiveRow, merge: (NewRow, TransactionhistoryarchiveRow) => NewRow): TransactionhistoryarchiveStructure[NewRow] = + new TransactionhistoryarchiveStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureFields.scala new file mode 100644 index 0000000000..9f02820d0d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait UnitmeasureFields[Row] { + val unitmeasurecode: IdField[UnitmeasureId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object UnitmeasureFields extends UnitmeasureStructure[UnitmeasureRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureId.scala new file mode 100644 index 0000000000..bc072b4173 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +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.unitmeasure` */ +case class UnitmeasureId(value: /* bpchar, max 3 chars */ String) extends AnyVal +object UnitmeasureId { + implicit lazy val arraySetter: Setter[Array[UnitmeasureId]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[UnitmeasureId, /* bpchar, max 3 chars */ String] = Bijection[UnitmeasureId, /* bpchar, max 3 chars */ String](_.value)(UnitmeasureId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[UnitmeasureId] = JdbcDecoder.stringDecoder.map(UnitmeasureId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[UnitmeasureId] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[UnitmeasureId] = JsonDecoder.string.map(UnitmeasureId.apply) + implicit lazy val jsonEncoder: JsonEncoder[UnitmeasureId] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[UnitmeasureId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[UnitmeasureId] = ParameterMetaData.instance[UnitmeasureId](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[UnitmeasureId] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepo.scala new file mode 100644 index 0000000000..5165ecb012 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UnitmeasureRepo { + def delete(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[UnitmeasureFields, UnitmeasureRow] + def insert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UnitmeasureRow] + def insert(unsaved: UnitmeasureRowUnsaved): ZIO[ZConnection, Throwable, UnitmeasureRow] + def select: SelectBuilder[UnitmeasureFields, UnitmeasureRow] + def selectAll: ZStream[ZConnection, Throwable, UnitmeasureRow] + def selectById(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Option[UnitmeasureRow]] + def selectByIds(unitmeasurecodes: Array[UnitmeasureId]): ZStream[ZConnection, Throwable, UnitmeasureRow] + def update(row: UnitmeasureRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[UnitmeasureFields, UnitmeasureRow] + def upsert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UpdateResult[UnitmeasureRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoImpl.scala new file mode 100644 index 0000000000..f9817949a9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoImpl.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UnitmeasureRepoImpl extends UnitmeasureRepo { + override def delete(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.unitmeasure where "unitmeasurecode" = ${Segment.paramSegment(unitmeasurecode)(UnitmeasureId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[UnitmeasureFields, UnitmeasureRow] = { + DeleteBuilder("production.unitmeasure", UnitmeasureFields) + } + override def insert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UnitmeasureRow] = { + sql"""insert into production.unitmeasure("unitmeasurecode", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "unitmeasurecode", "name", "modifieddate"::text + """.insertReturning(UnitmeasureRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: UnitmeasureRowUnsaved): ZIO[ZConnection, Throwable, UnitmeasureRow] = { + val fs = List( + Some((sql""""unitmeasurecode"""", sql"${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.unitmeasure default values + returning "unitmeasurecode", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.unitmeasure($names) values ($values) returning "unitmeasurecode", "name", "modifieddate"::text""" + } + q.insertReturning(UnitmeasureRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[UnitmeasureFields, UnitmeasureRow] = { + SelectBuilderSql("production.unitmeasure", UnitmeasureFields, UnitmeasureRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UnitmeasureRow] = { + sql"""select "unitmeasurecode", "name", "modifieddate"::text from production.unitmeasure""".query(UnitmeasureRow.jdbcDecoder).selectStream + } + override def selectById(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Option[UnitmeasureRow]] = { + sql"""select "unitmeasurecode", "name", "modifieddate"::text from production.unitmeasure where "unitmeasurecode" = ${Segment.paramSegment(unitmeasurecode)(UnitmeasureId.setter)}""".query(UnitmeasureRow.jdbcDecoder).selectOne + } + override def selectByIds(unitmeasurecodes: Array[UnitmeasureId]): ZStream[ZConnection, Throwable, UnitmeasureRow] = { + sql"""select "unitmeasurecode", "name", "modifieddate"::text from production.unitmeasure where "unitmeasurecode" = ANY(${Segment.paramSegment(unitmeasurecodes)(UnitmeasureId.arraySetter)})""".query(UnitmeasureRow.jdbcDecoder).selectStream + } + override def update(row: UnitmeasureRow): ZIO[ZConnection, Throwable, Boolean] = { + val unitmeasurecode = row.unitmeasurecode + sql"""update production.unitmeasure + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "unitmeasurecode" = ${Segment.paramSegment(unitmeasurecode)(UnitmeasureId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[UnitmeasureFields, UnitmeasureRow] = { + UpdateBuilder("production.unitmeasure", UnitmeasureFields, UnitmeasureRow.jdbcDecoder) + } + override def upsert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UpdateResult[UnitmeasureRow]] = { + sql"""insert into production.unitmeasure("unitmeasurecode", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("unitmeasurecode") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "unitmeasurecode", "name", "modifieddate"::text""".insertReturning(UnitmeasureRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoMock.scala new file mode 100644 index 0000000000..df95e48824 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class UnitmeasureRepoMock(toRow: Function1[UnitmeasureRowUnsaved, UnitmeasureRow], + map: scala.collection.mutable.Map[UnitmeasureId, UnitmeasureRow] = scala.collection.mutable.Map.empty) extends UnitmeasureRepo { + override def delete(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(unitmeasurecode).isDefined) + } + override def delete: DeleteBuilder[UnitmeasureFields, UnitmeasureRow] = { + DeleteBuilderMock(DeleteParams.empty, UnitmeasureFields, map) + } + override def insert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UnitmeasureRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.unitmeasurecode)) + sys.error(s"id ${unsaved.unitmeasurecode} already exists") + else + map.put(unsaved.unitmeasurecode, unsaved) + + unsaved + } + } + override def insert(unsaved: UnitmeasureRowUnsaved): ZIO[ZConnection, Throwable, UnitmeasureRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[UnitmeasureFields, UnitmeasureRow] = { + SelectBuilderMock(UnitmeasureFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, UnitmeasureRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(unitmeasurecode: UnitmeasureId): ZIO[ZConnection, Throwable, Option[UnitmeasureRow]] = { + ZIO.succeed(map.get(unitmeasurecode)) + } + override def selectByIds(unitmeasurecodes: Array[UnitmeasureId]): ZStream[ZConnection, Throwable, UnitmeasureRow] = { + ZStream.fromIterable(unitmeasurecodes.flatMap(map.get)) + } + override def update(row: UnitmeasureRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.unitmeasurecode) match { + case Some(`row`) => false + case Some(_) => + map.put(row.unitmeasurecode, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[UnitmeasureFields, UnitmeasureRow] = { + UpdateBuilderMock(UpdateParams.empty, UnitmeasureFields, map) + } + override def upsert(unsaved: UnitmeasureRow): ZIO[ZConnection, Throwable, UpdateResult[UnitmeasureRow]] = { + ZIO.succeed { + map.put(unsaved.unitmeasurecode, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRow.scala new file mode 100644 index 0000000000..3d65564217 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UnitmeasureRow( + /** Primary key. */ + unitmeasurecode: UnitmeasureId, + /** Unit of measure description. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object UnitmeasureRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UnitmeasureRow] = new JdbcDecoder[UnitmeasureRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UnitmeasureRow) = + columIndex + 2 -> + UnitmeasureRow( + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UnitmeasureRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (unitmeasurecode.isRight && name.isRight && modifieddate.isRight) + Right(UnitmeasureRow(unitmeasurecode = unitmeasurecode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](unitmeasurecode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UnitmeasureRow] = new JsonEncoder[UnitmeasureRow] { + override def unsafeEncode(a: UnitmeasureRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRowUnsaved.scala new file mode 100644 index 0000000000..00fd4887f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureRowUnsaved.scala @@ -0,0 +1,60 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.unitmeasure` which has not been persisted yet */ +case class UnitmeasureRowUnsaved( + /** Primary key. */ + unitmeasurecode: UnitmeasureId, + /** Unit of measure description. */ + name: Name, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): UnitmeasureRow = + UnitmeasureRow( + unitmeasurecode = unitmeasurecode, + name = name, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object UnitmeasureRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[UnitmeasureRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (unitmeasurecode.isRight && name.isRight && modifieddate.isRight) + Right(UnitmeasureRowUnsaved(unitmeasurecode = unitmeasurecode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](unitmeasurecode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UnitmeasureRowUnsaved] = new JsonEncoder[UnitmeasureRowUnsaved] { + override def unsafeEncode(a: UnitmeasureRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureStructure.scala new file mode 100644 index 0000000000..d6a4a84601 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/unitmeasure/UnitmeasureStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package unitmeasure + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class UnitmeasureStructure[Row](val prefix: Option[String], val extract: Row => UnitmeasureRow, val merge: (Row, UnitmeasureRow) => Row) + extends Relation[UnitmeasureFields, UnitmeasureRow, Row] + with UnitmeasureFields[Row] { outer => + + override val unitmeasurecode = new IdField[UnitmeasureId, Row](prefix, "unitmeasurecode", None, Some("bpchar"))(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](unitmeasurecode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UnitmeasureRow, merge: (NewRow, UnitmeasureRow) => NewRow): UnitmeasureStructure[NewRow] = + new UnitmeasureStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVFields.scala new file mode 100644 index 0000000000..91f56cdea4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductanddescription + +import adventureworks.production.culture.CultureId +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field + +trait VproductanddescriptionMVFields[Row] { + val productid: Field[ProductId, Row] + val name: Field[Name, Row] + val productmodel: Field[Name, Row] + val cultureid: Field[CultureId, Row] + val description: Field[/* max 400 chars */ String, Row] +} +object VproductanddescriptionMVFields extends VproductanddescriptionMVStructure[VproductanddescriptionMVRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepo.scala new file mode 100644 index 0000000000..e38ffc2af3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductanddescription + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VproductanddescriptionMVRepo { + def select: SelectBuilder[VproductanddescriptionMVFields, VproductanddescriptionMVRow] + def selectAll: ZStream[ZConnection, Throwable, VproductanddescriptionMVRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepoImpl.scala new file mode 100644 index 0000000000..8022fe03c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductanddescription + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VproductanddescriptionMVRepoImpl extends VproductanddescriptionMVRepo { + override def select: SelectBuilder[VproductanddescriptionMVFields, VproductanddescriptionMVRow] = { + SelectBuilderSql("production.vproductanddescription", VproductanddescriptionMVFields, VproductanddescriptionMVRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VproductanddescriptionMVRow] = { + sql"""select "productid", "name", "productmodel", "cultureid", "description" from production.vproductanddescription""".query(VproductanddescriptionMVRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRow.scala new file mode 100644 index 0000000000..465cdb7590 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductanddescription + +import adventureworks.production.culture.CultureId +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VproductanddescriptionMVRow( + /** Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Points to [[product.ProductRow.name]] */ + name: Name, + /** Points to [[productmodel.ProductmodelRow.name]] */ + productmodel: Name, + /** Points to [[productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow.cultureid]] */ + cultureid: CultureId, + /** Points to [[productdescription.ProductdescriptionRow.description]] */ + description: /* max 400 chars */ String +) + +object VproductanddescriptionMVRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VproductanddescriptionMVRow] = new JdbcDecoder[VproductanddescriptionMVRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VproductanddescriptionMVRow) = + columIndex + 4 -> + VproductanddescriptionMVRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productmodel = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + cultureid = CultureId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VproductanddescriptionMVRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val productmodel = jsonObj.get("productmodel").toRight("Missing field 'productmodel'").flatMap(_.as(Name.jsonDecoder)) + val cultureid = jsonObj.get("cultureid").toRight("Missing field 'cultureid'").flatMap(_.as(CultureId.jsonDecoder)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + if (productid.isRight && name.isRight && productmodel.isRight && cultureid.isRight && description.isRight) + Right(VproductanddescriptionMVRow(productid = productid.toOption.get, name = name.toOption.get, productmodel = productmodel.toOption.get, cultureid = cultureid.toOption.get, description = description.toOption.get)) + else Left(List[Either[String, Any]](productid, name, productmodel, cultureid, description).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VproductanddescriptionMVRow] = new JsonEncoder[VproductanddescriptionMVRow] { + override def unsafeEncode(a: VproductanddescriptionMVRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""productmodel":""") + Name.jsonEncoder.unsafeEncode(a.productmodel, indent, out) + out.write(",") + out.write(""""cultureid":""") + CultureId.jsonEncoder.unsafeEncode(a.cultureid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVStructure.scala new file mode 100644 index 0000000000..e73b8f47cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductanddescription/VproductanddescriptionMVStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductanddescription + +import adventureworks.production.culture.CultureId +import adventureworks.production.product.ProductId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class VproductanddescriptionMVStructure[Row](val prefix: Option[String], val extract: Row => VproductanddescriptionMVRow, val merge: (Row, VproductanddescriptionMVRow) => Row) + extends Relation[VproductanddescriptionMVFields, VproductanddescriptionMVRow, Row] + with VproductanddescriptionMVFields[Row] { outer => + + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val productmodel = new Field[Name, Row](prefix, "productmodel", None, None)(x => extract(x).productmodel, (row, value) => merge(row, extract(row).copy(productmodel = value))) + override val cultureid = new Field[CultureId, Row](prefix, "cultureid", None, None)(x => extract(x).cultureid, (row, value) => merge(row, extract(row).copy(cultureid = value))) + override val description = new Field[/* max 400 chars */ String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, name, productmodel, cultureid, description) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VproductanddescriptionMVRow, merge: (NewRow, VproductanddescriptionMVRow) => NewRow): VproductanddescriptionMVStructure[NewRow] = + new VproductanddescriptionMVStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewFields.scala new file mode 100644 index 0000000000..a1ee8c8769 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewFields.scala @@ -0,0 +1,45 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelcatalogdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VproductmodelcatalogdescriptionViewFields[Row] { + val productmodelid: Field[ProductmodelId, Row] + val name: Field[Name, Row] + val Summary: OptField[String, Row] + val manufacturer: OptField[String, Row] + val copyright: OptField[/* max 30 chars */ String, Row] + val producturl: OptField[/* max 256 chars */ String, Row] + val warrantyperiod: OptField[/* max 256 chars */ String, Row] + val warrantydescription: OptField[/* max 256 chars */ String, Row] + val noofyears: OptField[/* max 256 chars */ String, Row] + val maintenancedescription: OptField[/* max 256 chars */ String, Row] + val wheel: OptField[/* max 256 chars */ String, Row] + val saddle: OptField[/* max 256 chars */ String, Row] + val pedal: OptField[/* max 256 chars */ String, Row] + val bikeframe: OptField[String, Row] + val crankset: OptField[/* max 256 chars */ String, Row] + val pictureangle: OptField[/* max 256 chars */ String, Row] + val picturesize: OptField[/* max 256 chars */ String, Row] + val productphotoid: OptField[/* max 256 chars */ String, Row] + val material: OptField[/* max 256 chars */ String, Row] + val color: OptField[/* max 256 chars */ String, Row] + val productline: OptField[/* max 256 chars */ String, Row] + val style: OptField[/* max 256 chars */ String, Row] + val riderexperience: OptField[/* max 1024 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VproductmodelcatalogdescriptionViewFields extends VproductmodelcatalogdescriptionViewStructure[VproductmodelcatalogdescriptionViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepo.scala new file mode 100644 index 0000000000..2245b0ad87 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelcatalogdescription + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VproductmodelcatalogdescriptionViewRepo { + def select: SelectBuilder[VproductmodelcatalogdescriptionViewFields, VproductmodelcatalogdescriptionViewRow] + def selectAll: ZStream[ZConnection, Throwable, VproductmodelcatalogdescriptionViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepoImpl.scala new file mode 100644 index 0000000000..c7aa90c240 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelcatalogdescription + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VproductmodelcatalogdescriptionViewRepoImpl extends VproductmodelcatalogdescriptionViewRepo { + override def select: SelectBuilder[VproductmodelcatalogdescriptionViewFields, VproductmodelcatalogdescriptionViewRow] = { + SelectBuilderSql("production.vproductmodelcatalogdescription", VproductmodelcatalogdescriptionViewFields, VproductmodelcatalogdescriptionViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VproductmodelcatalogdescriptionViewRow] = { + sql"""select "productmodelid", "name", "Summary", "manufacturer", "copyright", "producturl", "warrantyperiod", "warrantydescription", "noofyears", "maintenancedescription", "wheel", "saddle", "pedal", "bikeframe", "crankset", "pictureangle", "picturesize", "productphotoid", "material", "color", "productline", "style", "riderexperience", "rowguid", "modifieddate"::text from production.vproductmodelcatalogdescription""".query(VproductmodelcatalogdescriptionViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRow.scala new file mode 100644 index 0000000000..59e883f357 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewRow.scala @@ -0,0 +1,195 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelcatalogdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VproductmodelcatalogdescriptionViewRow( + /** Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Points to [[productmodel.ProductmodelRow.name]] */ + name: Name, + Summary: /* nullability unknown */ Option[String], + manufacturer: /* nullability unknown */ Option[String], + copyright: /* nullability unknown */ Option[/* max 30 chars */ String], + producturl: /* nullability unknown */ Option[/* max 256 chars */ String], + warrantyperiod: /* nullability unknown */ Option[/* max 256 chars */ String], + warrantydescription: /* nullability unknown */ Option[/* max 256 chars */ String], + noofyears: /* nullability unknown */ Option[/* max 256 chars */ String], + maintenancedescription: /* nullability unknown */ Option[/* max 256 chars */ String], + wheel: /* nullability unknown */ Option[/* max 256 chars */ String], + saddle: /* nullability unknown */ Option[/* max 256 chars */ String], + pedal: /* nullability unknown */ Option[/* max 256 chars */ String], + bikeframe: /* nullability unknown */ Option[String], + crankset: /* nullability unknown */ Option[/* max 256 chars */ String], + pictureangle: /* nullability unknown */ Option[/* max 256 chars */ String], + picturesize: /* nullability unknown */ Option[/* max 256 chars */ String], + productphotoid: /* nullability unknown */ Option[/* max 256 chars */ String], + material: /* nullability unknown */ Option[/* max 256 chars */ String], + color: /* nullability unknown */ Option[/* max 256 chars */ String], + productline: /* nullability unknown */ Option[/* max 256 chars */ String], + style: /* nullability unknown */ Option[/* max 256 chars */ String], + riderexperience: /* nullability unknown */ Option[/* max 1024 chars */ String], + /** Points to [[productmodel.ProductmodelRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[productmodel.ProductmodelRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object VproductmodelcatalogdescriptionViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VproductmodelcatalogdescriptionViewRow] = new JdbcDecoder[VproductmodelcatalogdescriptionViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VproductmodelcatalogdescriptionViewRow) = + columIndex + 24 -> + VproductmodelcatalogdescriptionViewRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + Summary = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + manufacturer = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + copyright = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + producturl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + warrantyperiod = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + warrantydescription = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + noofyears = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + maintenancedescription = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + wheel = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + saddle = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 11, rs)._2, + pedal = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + bikeframe = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 13, rs)._2, + crankset = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 14, rs)._2, + pictureangle = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 15, rs)._2, + picturesize = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + productphotoid = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + material = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + color = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 19, rs)._2, + productline = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 20, rs)._2, + style = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 21, rs)._2, + riderexperience = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 23, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 24, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VproductmodelcatalogdescriptionViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val Summary = jsonObj.get("Summary").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val manufacturer = jsonObj.get("manufacturer").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val copyright = jsonObj.get("copyright").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val producturl = jsonObj.get("producturl").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val warrantyperiod = jsonObj.get("warrantyperiod").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val warrantydescription = jsonObj.get("warrantydescription").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val noofyears = jsonObj.get("noofyears").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val maintenancedescription = jsonObj.get("maintenancedescription").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val wheel = jsonObj.get("wheel").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val saddle = jsonObj.get("saddle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val pedal = jsonObj.get("pedal").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val bikeframe = jsonObj.get("bikeframe").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val crankset = jsonObj.get("crankset").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val pictureangle = jsonObj.get("pictureangle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val picturesize = jsonObj.get("picturesize").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productphotoid = jsonObj.get("productphotoid").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val material = jsonObj.get("material").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val color = jsonObj.get("color").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val productline = jsonObj.get("productline").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val style = jsonObj.get("style").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val riderexperience = jsonObj.get("riderexperience").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && name.isRight && Summary.isRight && manufacturer.isRight && copyright.isRight && producturl.isRight && warrantyperiod.isRight && warrantydescription.isRight && noofyears.isRight && maintenancedescription.isRight && wheel.isRight && saddle.isRight && pedal.isRight && bikeframe.isRight && crankset.isRight && pictureangle.isRight && picturesize.isRight && productphotoid.isRight && material.isRight && color.isRight && productline.isRight && style.isRight && riderexperience.isRight && rowguid.isRight && modifieddate.isRight) + Right(VproductmodelcatalogdescriptionViewRow(productmodelid = productmodelid.toOption.get, name = name.toOption.get, Summary = Summary.toOption.get, manufacturer = manufacturer.toOption.get, copyright = copyright.toOption.get, producturl = producturl.toOption.get, warrantyperiod = warrantyperiod.toOption.get, warrantydescription = warrantydescription.toOption.get, noofyears = noofyears.toOption.get, maintenancedescription = maintenancedescription.toOption.get, wheel = wheel.toOption.get, saddle = saddle.toOption.get, pedal = pedal.toOption.get, bikeframe = bikeframe.toOption.get, crankset = crankset.toOption.get, pictureangle = pictureangle.toOption.get, picturesize = picturesize.toOption.get, productphotoid = productphotoid.toOption.get, material = material.toOption.get, color = color.toOption.get, productline = productline.toOption.get, style = style.toOption.get, riderexperience = riderexperience.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, name, Summary, manufacturer, copyright, producturl, warrantyperiod, warrantydescription, noofyears, maintenancedescription, wheel, saddle, pedal, bikeframe, crankset, pictureangle, picturesize, productphotoid, material, color, productline, style, riderexperience, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VproductmodelcatalogdescriptionViewRow] = new JsonEncoder[VproductmodelcatalogdescriptionViewRow] { + override def unsafeEncode(a: VproductmodelcatalogdescriptionViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""Summary":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Summary, indent, out) + out.write(",") + out.write(""""manufacturer":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.manufacturer, indent, out) + out.write(",") + out.write(""""copyright":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.copyright, indent, out) + out.write(",") + out.write(""""producturl":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.producturl, indent, out) + out.write(",") + out.write(""""warrantyperiod":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.warrantyperiod, indent, out) + out.write(",") + out.write(""""warrantydescription":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.warrantydescription, indent, out) + out.write(",") + out.write(""""noofyears":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.noofyears, indent, out) + out.write(",") + out.write(""""maintenancedescription":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.maintenancedescription, indent, out) + out.write(",") + out.write(""""wheel":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.wheel, indent, out) + out.write(",") + out.write(""""saddle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.saddle, indent, out) + out.write(",") + out.write(""""pedal":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.pedal, indent, out) + out.write(",") + out.write(""""bikeframe":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.bikeframe, indent, out) + out.write(",") + out.write(""""crankset":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.crankset, indent, out) + out.write(",") + out.write(""""pictureangle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.pictureangle, indent, out) + out.write(",") + out.write(""""picturesize":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.picturesize, indent, out) + out.write(",") + out.write(""""productphotoid":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.productphotoid, indent, out) + out.write(",") + out.write(""""material":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.material, indent, out) + out.write(",") + out.write(""""color":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.color, indent, out) + out.write(",") + out.write(""""productline":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.productline, indent, out) + out.write(",") + out.write(""""style":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.style, indent, out) + out.write(",") + out.write(""""riderexperience":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.riderexperience, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewStructure.scala new file mode 100644 index 0000000000..71298da4a1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelcatalogdescription/VproductmodelcatalogdescriptionViewStructure.scala @@ -0,0 +1,54 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelcatalogdescription + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VproductmodelcatalogdescriptionViewStructure[Row](val prefix: Option[String], val extract: Row => VproductmodelcatalogdescriptionViewRow, val merge: (Row, VproductmodelcatalogdescriptionViewRow) => Row) + extends Relation[VproductmodelcatalogdescriptionViewFields, VproductmodelcatalogdescriptionViewRow, Row] + with VproductmodelcatalogdescriptionViewFields[Row] { outer => + + override val productmodelid = new Field[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val Summary = new OptField[String, Row](prefix, "Summary", None, None)(x => extract(x).Summary, (row, value) => merge(row, extract(row).copy(Summary = value))) + override val manufacturer = new OptField[String, Row](prefix, "manufacturer", None, None)(x => extract(x).manufacturer, (row, value) => merge(row, extract(row).copy(manufacturer = value))) + override val copyright = new OptField[/* max 30 chars */ String, Row](prefix, "copyright", None, None)(x => extract(x).copyright, (row, value) => merge(row, extract(row).copy(copyright = value))) + override val producturl = new OptField[/* max 256 chars */ String, Row](prefix, "producturl", None, None)(x => extract(x).producturl, (row, value) => merge(row, extract(row).copy(producturl = value))) + override val warrantyperiod = new OptField[/* max 256 chars */ String, Row](prefix, "warrantyperiod", None, None)(x => extract(x).warrantyperiod, (row, value) => merge(row, extract(row).copy(warrantyperiod = value))) + override val warrantydescription = new OptField[/* max 256 chars */ String, Row](prefix, "warrantydescription", None, None)(x => extract(x).warrantydescription, (row, value) => merge(row, extract(row).copy(warrantydescription = value))) + override val noofyears = new OptField[/* max 256 chars */ String, Row](prefix, "noofyears", None, None)(x => extract(x).noofyears, (row, value) => merge(row, extract(row).copy(noofyears = value))) + override val maintenancedescription = new OptField[/* max 256 chars */ String, Row](prefix, "maintenancedescription", None, None)(x => extract(x).maintenancedescription, (row, value) => merge(row, extract(row).copy(maintenancedescription = value))) + override val wheel = new OptField[/* max 256 chars */ String, Row](prefix, "wheel", None, None)(x => extract(x).wheel, (row, value) => merge(row, extract(row).copy(wheel = value))) + override val saddle = new OptField[/* max 256 chars */ String, Row](prefix, "saddle", None, None)(x => extract(x).saddle, (row, value) => merge(row, extract(row).copy(saddle = value))) + override val pedal = new OptField[/* max 256 chars */ String, Row](prefix, "pedal", None, None)(x => extract(x).pedal, (row, value) => merge(row, extract(row).copy(pedal = value))) + override val bikeframe = new OptField[String, Row](prefix, "bikeframe", None, None)(x => extract(x).bikeframe, (row, value) => merge(row, extract(row).copy(bikeframe = value))) + override val crankset = new OptField[/* max 256 chars */ String, Row](prefix, "crankset", None, None)(x => extract(x).crankset, (row, value) => merge(row, extract(row).copy(crankset = value))) + override val pictureangle = new OptField[/* max 256 chars */ String, Row](prefix, "pictureangle", None, None)(x => extract(x).pictureangle, (row, value) => merge(row, extract(row).copy(pictureangle = value))) + override val picturesize = new OptField[/* max 256 chars */ String, Row](prefix, "picturesize", None, None)(x => extract(x).picturesize, (row, value) => merge(row, extract(row).copy(picturesize = value))) + override val productphotoid = new OptField[/* max 256 chars */ String, Row](prefix, "productphotoid", None, None)(x => extract(x).productphotoid, (row, value) => merge(row, extract(row).copy(productphotoid = value))) + override val material = new OptField[/* max 256 chars */ String, Row](prefix, "material", None, None)(x => extract(x).material, (row, value) => merge(row, extract(row).copy(material = value))) + override val color = new OptField[/* max 256 chars */ String, Row](prefix, "color", None, None)(x => extract(x).color, (row, value) => merge(row, extract(row).copy(color = value))) + override val productline = new OptField[/* max 256 chars */ String, Row](prefix, "productline", None, None)(x => extract(x).productline, (row, value) => merge(row, extract(row).copy(productline = value))) + override val style = new OptField[/* max 256 chars */ String, Row](prefix, "style", None, None)(x => extract(x).style, (row, value) => merge(row, extract(row).copy(style = value))) + override val riderexperience = new OptField[/* max 1024 chars */ String, Row](prefix, "riderexperience", None, None)(x => extract(x).riderexperience, (row, value) => merge(row, extract(row).copy(riderexperience = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, name, Summary, manufacturer, copyright, producturl, warrantyperiod, warrantydescription, noofyears, maintenancedescription, wheel, saddle, pedal, bikeframe, crankset, pictureangle, picturesize, productphotoid, material, color, productline, style, riderexperience, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VproductmodelcatalogdescriptionViewRow, merge: (NewRow, VproductmodelcatalogdescriptionViewRow) => NewRow): VproductmodelcatalogdescriptionViewStructure[NewRow] = + new VproductmodelcatalogdescriptionViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewFields.scala new file mode 100644 index 0000000000..5355b83c42 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelinstructions + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VproductmodelinstructionsViewFields[Row] { + val productmodelid: Field[ProductmodelId, Row] + val name: Field[Name, Row] + val instructions: OptField[String, Row] + val LocationID: OptField[Int, Row] + val SetupHours: OptField[BigDecimal, Row] + val MachineHours: OptField[BigDecimal, Row] + val LaborHours: OptField[BigDecimal, Row] + val LotSize: OptField[Int, Row] + val Step: OptField[/* max 1024 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VproductmodelinstructionsViewFields extends VproductmodelinstructionsViewStructure[VproductmodelinstructionsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepo.scala new file mode 100644 index 0000000000..ba0f9834b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelinstructions + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VproductmodelinstructionsViewRepo { + def select: SelectBuilder[VproductmodelinstructionsViewFields, VproductmodelinstructionsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VproductmodelinstructionsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepoImpl.scala new file mode 100644 index 0000000000..5245bc1f2e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelinstructions + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VproductmodelinstructionsViewRepoImpl extends VproductmodelinstructionsViewRepo { + override def select: SelectBuilder[VproductmodelinstructionsViewFields, VproductmodelinstructionsViewRow] = { + SelectBuilderSql("production.vproductmodelinstructions", VproductmodelinstructionsViewFields, VproductmodelinstructionsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VproductmodelinstructionsViewRow] = { + sql"""select "productmodelid", "name", "instructions", "LocationID", "SetupHours", "MachineHours", "LaborHours", "LotSize", "Step", "rowguid", "modifieddate"::text from production.vproductmodelinstructions""".query(VproductmodelinstructionsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRow.scala new file mode 100644 index 0000000000..2f57888506 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewRow.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelinstructions + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VproductmodelinstructionsViewRow( + /** Points to [[productmodel.ProductmodelRow.productmodelid]] */ + productmodelid: ProductmodelId, + /** Points to [[productmodel.ProductmodelRow.name]] */ + name: Name, + instructions: /* nullability unknown */ Option[String], + LocationID: /* nullability unknown */ Option[Int], + SetupHours: /* nullability unknown */ Option[BigDecimal], + MachineHours: /* nullability unknown */ Option[BigDecimal], + LaborHours: /* nullability unknown */ Option[BigDecimal], + LotSize: /* nullability unknown */ Option[Int], + Step: /* nullability unknown */ Option[/* max 1024 chars */ String], + /** Points to [[productmodel.ProductmodelRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[productmodel.ProductmodelRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object VproductmodelinstructionsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VproductmodelinstructionsViewRow] = new JdbcDecoder[VproductmodelinstructionsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VproductmodelinstructionsViewRow) = + columIndex + 10 -> + VproductmodelinstructionsViewRow( + productmodelid = ProductmodelId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + instructions = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + LocationID = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 3, rs)._2, + SetupHours = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 4, rs)._2, + MachineHours = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 5, rs)._2, + LaborHours = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 6, rs)._2, + LotSize = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + Step = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VproductmodelinstructionsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productmodelid = jsonObj.get("productmodelid").toRight("Missing field 'productmodelid'").flatMap(_.as(ProductmodelId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val instructions = jsonObj.get("instructions").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val LocationID = jsonObj.get("LocationID").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val SetupHours = jsonObj.get("SetupHours").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val MachineHours = jsonObj.get("MachineHours").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val LaborHours = jsonObj.get("LaborHours").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val LotSize = jsonObj.get("LotSize").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val Step = jsonObj.get("Step").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productmodelid.isRight && name.isRight && instructions.isRight && LocationID.isRight && SetupHours.isRight && MachineHours.isRight && LaborHours.isRight && LotSize.isRight && Step.isRight && rowguid.isRight && modifieddate.isRight) + Right(VproductmodelinstructionsViewRow(productmodelid = productmodelid.toOption.get, name = name.toOption.get, instructions = instructions.toOption.get, LocationID = LocationID.toOption.get, SetupHours = SetupHours.toOption.get, MachineHours = MachineHours.toOption.get, LaborHours = LaborHours.toOption.get, LotSize = LotSize.toOption.get, Step = Step.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productmodelid, name, instructions, LocationID, SetupHours, MachineHours, LaborHours, LotSize, Step, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VproductmodelinstructionsViewRow] = new JsonEncoder[VproductmodelinstructionsViewRow] { + override def unsafeEncode(a: VproductmodelinstructionsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productmodelid":""") + ProductmodelId.jsonEncoder.unsafeEncode(a.productmodelid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""instructions":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.instructions, indent, out) + out.write(",") + out.write(""""LocationID":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.LocationID, indent, out) + out.write(",") + out.write(""""SetupHours":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.SetupHours, indent, out) + out.write(",") + out.write(""""MachineHours":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.MachineHours, indent, out) + out.write(",") + out.write(""""LaborHours":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.LaborHours, indent, out) + out.write(",") + out.write(""""LotSize":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.LotSize, indent, out) + out.write(",") + out.write(""""Step":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Step, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewStructure.scala new file mode 100644 index 0000000000..8a44e88098 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/vproductmodelinstructions/VproductmodelinstructionsViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package vproductmodelinstructions + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VproductmodelinstructionsViewStructure[Row](val prefix: Option[String], val extract: Row => VproductmodelinstructionsViewRow, val merge: (Row, VproductmodelinstructionsViewRow) => Row) + extends Relation[VproductmodelinstructionsViewFields, VproductmodelinstructionsViewRow, Row] + with VproductmodelinstructionsViewFields[Row] { outer => + + override val productmodelid = new Field[ProductmodelId, Row](prefix, "productmodelid", None, None)(x => extract(x).productmodelid, (row, value) => merge(row, extract(row).copy(productmodelid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val instructions = new OptField[String, Row](prefix, "instructions", None, None)(x => extract(x).instructions, (row, value) => merge(row, extract(row).copy(instructions = value))) + override val LocationID = new OptField[Int, Row](prefix, "LocationID", None, None)(x => extract(x).LocationID, (row, value) => merge(row, extract(row).copy(LocationID = value))) + override val SetupHours = new OptField[BigDecimal, Row](prefix, "SetupHours", None, None)(x => extract(x).SetupHours, (row, value) => merge(row, extract(row).copy(SetupHours = value))) + override val MachineHours = new OptField[BigDecimal, Row](prefix, "MachineHours", None, None)(x => extract(x).MachineHours, (row, value) => merge(row, extract(row).copy(MachineHours = value))) + override val LaborHours = new OptField[BigDecimal, Row](prefix, "LaborHours", None, None)(x => extract(x).LaborHours, (row, value) => merge(row, extract(row).copy(LaborHours = value))) + override val LotSize = new OptField[Int, Row](prefix, "LotSize", None, None)(x => extract(x).LotSize, (row, value) => merge(row, extract(row).copy(LotSize = value))) + override val Step = new OptField[/* max 1024 chars */ String, Row](prefix, "Step", None, None)(x => extract(x).Step, (row, value) => merge(row, extract(row).copy(Step = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productmodelid, name, instructions, LocationID, SetupHours, MachineHours, LaborHours, LotSize, Step, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VproductmodelinstructionsViewRow, merge: (NewRow, VproductmodelinstructionsViewRow) => NewRow): VproductmodelinstructionsViewStructure[NewRow] = + new VproductmodelinstructionsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderFields.scala new file mode 100644 index 0000000000..add847ee57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait WorkorderFields[Row] { + val workorderid: IdField[WorkorderId, Row] + val productid: Field[ProductId, Row] + val orderqty: Field[Int, Row] + val scrappedqty: Field[TypoShort, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val duedate: Field[TypoLocalDateTime, Row] + val scrapreasonid: OptField[ScrapreasonId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object WorkorderFields extends WorkorderStructure[WorkorderRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderId.scala new file mode 100644 index 0000000000..5b9c4297dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +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.workorder` */ +case class WorkorderId(value: Int) extends AnyVal +object WorkorderId { + implicit lazy val arraySetter: Setter[Array[WorkorderId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[WorkorderId, Int] = Bijection[WorkorderId, Int](_.value)(WorkorderId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[WorkorderId] = JdbcDecoder.intDecoder.map(WorkorderId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[WorkorderId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[WorkorderId] = JsonDecoder.int.map(WorkorderId.apply) + implicit lazy val jsonEncoder: JsonEncoder[WorkorderId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[WorkorderId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[WorkorderId] = ParameterMetaData.instance[WorkorderId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[WorkorderId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepo.scala new file mode 100644 index 0000000000..086ddc52df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait WorkorderRepo { + def delete(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[WorkorderFields, WorkorderRow] + def insert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, WorkorderRow] + def insert(unsaved: WorkorderRowUnsaved): ZIO[ZConnection, Throwable, WorkorderRow] + def select: SelectBuilder[WorkorderFields, WorkorderRow] + def selectAll: ZStream[ZConnection, Throwable, WorkorderRow] + def selectById(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Option[WorkorderRow]] + def selectByIds(workorderids: Array[WorkorderId]): ZStream[ZConnection, Throwable, WorkorderRow] + def update(row: WorkorderRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[WorkorderFields, WorkorderRow] + def upsert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoImpl.scala new file mode 100644 index 0000000000..244d7511fb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoImpl.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object WorkorderRepoImpl extends WorkorderRepo { + override def delete(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.workorder where "workorderid" = ${Segment.paramSegment(workorderid)(WorkorderId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[WorkorderFields, WorkorderRow] = { + DeleteBuilder("production.workorder", WorkorderFields) + } + override def insert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, WorkorderRow] = { + sql"""insert into production.workorder("workorderid", "productid", "orderqty", "scrappedqty", "startdate", "enddate", "duedate", "scrapreasonid", "modifieddate") + values (${Segment.paramSegment(unsaved.workorderid)(WorkorderId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.orderqty)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.scrappedqty)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.scrapreasonid)(Setter.optionParamSetter(ScrapreasonId.setter))}::int2, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text + """.insertReturning(WorkorderRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: WorkorderRowUnsaved): ZIO[ZConnection, Throwable, WorkorderRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""orderqty"""", sql"${Segment.paramSegment(unsaved.orderqty)(Setter.intSetter)}::int4")), + Some((sql""""scrappedqty"""", sql"${Segment.paramSegment(unsaved.scrappedqty)(TypoShort.setter)}::int2")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""duedate"""", sql"${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""scrapreasonid"""", sql"${Segment.paramSegment(unsaved.scrapreasonid)(Setter.optionParamSetter(ScrapreasonId.setter))}::int2")), + unsaved.workorderid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""workorderid"""", sql"${Segment.paramSegment(value: WorkorderId)(WorkorderId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.workorder default values + returning "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.workorder($names) values ($values) returning "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text""" + } + q.insertReturning(WorkorderRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[WorkorderFields, WorkorderRow] = { + SelectBuilderSql("production.workorder", WorkorderFields, WorkorderRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, WorkorderRow] = { + sql"""select "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text from production.workorder""".query(WorkorderRow.jdbcDecoder).selectStream + } + override def selectById(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Option[WorkorderRow]] = { + sql"""select "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text from production.workorder where "workorderid" = ${Segment.paramSegment(workorderid)(WorkorderId.setter)}""".query(WorkorderRow.jdbcDecoder).selectOne + } + override def selectByIds(workorderids: Array[WorkorderId]): ZStream[ZConnection, Throwable, WorkorderRow] = { + sql"""select "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text from production.workorder where "workorderid" = ANY(${Segment.paramSegment(workorderids)(WorkorderId.arraySetter)})""".query(WorkorderRow.jdbcDecoder).selectStream + } + override def update(row: WorkorderRow): ZIO[ZConnection, Throwable, Boolean] = { + val workorderid = row.workorderid + sql"""update production.workorder + set "productid" = ${Segment.paramSegment(row.productid)(ProductId.setter)}::int4, + "orderqty" = ${Segment.paramSegment(row.orderqty)(Setter.intSetter)}::int4, + "scrappedqty" = ${Segment.paramSegment(row.scrappedqty)(TypoShort.setter)}::int2, + "startdate" = ${Segment.paramSegment(row.startdate)(TypoLocalDateTime.setter)}::timestamp, + "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "duedate" = ${Segment.paramSegment(row.duedate)(TypoLocalDateTime.setter)}::timestamp, + "scrapreasonid" = ${Segment.paramSegment(row.scrapreasonid)(Setter.optionParamSetter(ScrapreasonId.setter))}::int2, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "workorderid" = ${Segment.paramSegment(workorderid)(WorkorderId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[WorkorderFields, WorkorderRow] = { + UpdateBuilder("production.workorder", WorkorderFields, WorkorderRow.jdbcDecoder) + } + override def upsert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderRow]] = { + sql"""insert into production.workorder("workorderid", "productid", "orderqty", "scrappedqty", "startdate", "enddate", "duedate", "scrapreasonid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.workorderid)(WorkorderId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.orderqty)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.scrappedqty)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.scrapreasonid)(Setter.optionParamSetter(ScrapreasonId.setter))}::int2, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("workorderid") + do update set + "productid" = EXCLUDED."productid", + "orderqty" = EXCLUDED."orderqty", + "scrappedqty" = EXCLUDED."scrappedqty", + "startdate" = EXCLUDED."startdate", + "enddate" = EXCLUDED."enddate", + "duedate" = EXCLUDED."duedate", + "scrapreasonid" = EXCLUDED."scrapreasonid", + "modifieddate" = EXCLUDED."modifieddate" + returning "workorderid", "productid", "orderqty", "scrappedqty", "startdate"::text, "enddate"::text, "duedate"::text, "scrapreasonid", "modifieddate"::text""".insertReturning(WorkorderRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoMock.scala new file mode 100644 index 0000000000..dea31e0247 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class WorkorderRepoMock(toRow: Function1[WorkorderRowUnsaved, WorkorderRow], + map: scala.collection.mutable.Map[WorkorderId, WorkorderRow] = scala.collection.mutable.Map.empty) extends WorkorderRepo { + override def delete(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(workorderid).isDefined) + } + override def delete: DeleteBuilder[WorkorderFields, WorkorderRow] = { + DeleteBuilderMock(DeleteParams.empty, WorkorderFields, map) + } + override def insert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, WorkorderRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.workorderid)) + sys.error(s"id ${unsaved.workorderid} already exists") + else + map.put(unsaved.workorderid, unsaved) + + unsaved + } + } + override def insert(unsaved: WorkorderRowUnsaved): ZIO[ZConnection, Throwable, WorkorderRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[WorkorderFields, WorkorderRow] = { + SelectBuilderMock(WorkorderFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, WorkorderRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(workorderid: WorkorderId): ZIO[ZConnection, Throwable, Option[WorkorderRow]] = { + ZIO.succeed(map.get(workorderid)) + } + override def selectByIds(workorderids: Array[WorkorderId]): ZStream[ZConnection, Throwable, WorkorderRow] = { + ZStream.fromIterable(workorderids.flatMap(map.get)) + } + override def update(row: WorkorderRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.workorderid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.workorderid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[WorkorderFields, WorkorderRow] = { + UpdateBuilderMock(UpdateParams.empty, WorkorderFields, map) + } + override def upsert(unsaved: WorkorderRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderRow]] = { + ZIO.succeed { + map.put(unsaved.workorderid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRow.scala new file mode 100644 index 0000000000..396a06a8ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class WorkorderRow( + /** Primary key for WorkOrder records. */ + workorderid: WorkorderId, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product quantity to build. + Constraint CK_WorkOrder_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: Int, + /** Quantity that failed inspection. + Constraint CK_WorkOrder_ScrappedQty affecting columns "scrappedqty": ((scrappedqty >= 0)) */ + scrappedqty: TypoShort, + /** Work order start date. + Constraint CK_WorkOrder_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Work order end date. + Constraint CK_WorkOrder_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Work order due date. */ + duedate: TypoLocalDateTime, + /** Reason for inspection failure. + Points to [[scrapreason.ScrapreasonRow.scrapreasonid]] */ + scrapreasonid: Option[ScrapreasonId], + modifieddate: TypoLocalDateTime +) + +object WorkorderRow { + implicit lazy val jdbcDecoder: JdbcDecoder[WorkorderRow] = new JdbcDecoder[WorkorderRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, WorkorderRow) = + columIndex + 8 -> + WorkorderRow( + workorderid = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + orderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + scrappedqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + scrapreasonid = JdbcDecoder.optionDecoder(ScrapreasonId.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[WorkorderRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(JsonDecoder.int)) + val scrappedqty = jsonObj.get("scrappedqty").toRight("Missing field 'scrappedqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scrapreasonid = jsonObj.get("scrapreasonid").fold[Either[String, Option[ScrapreasonId]]](Right(None))(_.as(JsonDecoder.option(ScrapreasonId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (workorderid.isRight && productid.isRight && orderqty.isRight && scrappedqty.isRight && startdate.isRight && enddate.isRight && duedate.isRight && scrapreasonid.isRight && modifieddate.isRight) + Right(WorkorderRow(workorderid = workorderid.toOption.get, productid = productid.toOption.get, orderqty = orderqty.toOption.get, scrappedqty = scrappedqty.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, duedate = duedate.toOption.get, scrapreasonid = scrapreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](workorderid, productid, orderqty, scrappedqty, startdate, enddate, duedate, scrapreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WorkorderRow] = new JsonEncoder[WorkorderRow] { + override def unsafeEncode(a: WorkorderRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""orderqty":""") + JsonEncoder.int.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""scrappedqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.scrappedqty, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""scrapreasonid":""") + JsonEncoder.option(ScrapreasonId.jsonEncoder).unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRowUnsaved.scala new file mode 100644 index 0000000000..758cefd264 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderRowUnsaved.scala @@ -0,0 +1,114 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.workorder` which has not been persisted yet */ +case class WorkorderRowUnsaved( + /** Product identification number. Foreign key to Product.ProductID. + Points to [[product.ProductRow.productid]] */ + productid: ProductId, + /** Product quantity to build. + Constraint CK_WorkOrder_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: Int, + /** Quantity that failed inspection. + Constraint CK_WorkOrder_ScrappedQty affecting columns "scrappedqty": ((scrappedqty >= 0)) */ + scrappedqty: TypoShort, + /** Work order start date. + Constraint CK_WorkOrder_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Work order end date. + Constraint CK_WorkOrder_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Work order due date. */ + duedate: TypoLocalDateTime, + /** Reason for inspection failure. + Points to [[scrapreason.ScrapreasonRow.scrapreasonid]] */ + scrapreasonid: Option[ScrapreasonId], + /** Default: nextval('production.workorder_workorderid_seq'::regclass) + Primary key for WorkOrder records. */ + workorderid: Defaulted[WorkorderId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(workorderidDefault: => WorkorderId, modifieddateDefault: => TypoLocalDateTime): WorkorderRow = + WorkorderRow( + productid = productid, + orderqty = orderqty, + scrappedqty = scrappedqty, + startdate = startdate, + enddate = enddate, + duedate = duedate, + scrapreasonid = scrapreasonid, + workorderid = workorderid match { + case Defaulted.UseDefault => workorderidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object WorkorderRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[WorkorderRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(JsonDecoder.int)) + val scrappedqty = jsonObj.get("scrappedqty").toRight("Missing field 'scrappedqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scrapreasonid = jsonObj.get("scrapreasonid").fold[Either[String, Option[ScrapreasonId]]](Right(None))(_.as(JsonDecoder.option(ScrapreasonId.jsonDecoder))) + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(Defaulted.jsonDecoder(WorkorderId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && orderqty.isRight && scrappedqty.isRight && startdate.isRight && enddate.isRight && duedate.isRight && scrapreasonid.isRight && workorderid.isRight && modifieddate.isRight) + Right(WorkorderRowUnsaved(productid = productid.toOption.get, orderqty = orderqty.toOption.get, scrappedqty = scrappedqty.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, duedate = duedate.toOption.get, scrapreasonid = scrapreasonid.toOption.get, workorderid = workorderid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, orderqty, scrappedqty, startdate, enddate, duedate, scrapreasonid, workorderid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WorkorderRowUnsaved] = new JsonEncoder[WorkorderRowUnsaved] { + override def unsafeEncode(a: WorkorderRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""orderqty":""") + JsonEncoder.int.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""scrappedqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.scrappedqty, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""scrapreasonid":""") + JsonEncoder.option(ScrapreasonId.jsonEncoder).unsafeEncode(a.scrapreasonid, indent, out) + out.write(",") + out.write(""""workorderid":""") + Defaulted.jsonEncoder(WorkorderId.jsonEncoder).unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderStructure.scala new file mode 100644 index 0000000000..0ec9c52e4c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorder/WorkorderStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorder + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.production.scrapreason.ScrapreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class WorkorderStructure[Row](val prefix: Option[String], val extract: Row => WorkorderRow, val merge: (Row, WorkorderRow) => Row) + extends Relation[WorkorderFields, WorkorderRow, Row] + with WorkorderFields[Row] { outer => + + override val workorderid = new IdField[WorkorderId, Row](prefix, "workorderid", None, Some("int4"))(x => extract(x).workorderid, (row, value) => merge(row, extract(row).copy(workorderid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val orderqty = new Field[Int, Row](prefix, "orderqty", None, Some("int4"))(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val scrappedqty = new Field[TypoShort, Row](prefix, "scrappedqty", None, Some("int2"))(x => extract(x).scrappedqty, (row, value) => merge(row, extract(row).copy(scrappedqty = 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), Some("timestamp"))(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val scrapreasonid = new OptField[ScrapreasonId, Row](prefix, "scrapreasonid", None, Some("int2"))(x => extract(x).scrapreasonid, (row, value) => merge(row, extract(row).copy(scrapreasonid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](workorderid, productid, orderqty, scrappedqty, startdate, enddate, duedate, scrapreasonid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => WorkorderRow, merge: (NewRow, WorkorderRow) => NewRow): WorkorderStructure[NewRow] = + new WorkorderStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingFields.scala new file mode 100644 index 0000000000..65f604d366 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait WorkorderroutingFields[Row] { + val workorderid: IdField[WorkorderId, Row] + val productid: IdField[Int, Row] + val operationsequence: IdField[TypoShort, Row] + val locationid: Field[LocationId, Row] + val scheduledstartdate: Field[TypoLocalDateTime, Row] + val scheduledenddate: Field[TypoLocalDateTime, Row] + val actualstartdate: OptField[TypoLocalDateTime, Row] + val actualenddate: OptField[TypoLocalDateTime, Row] + val actualresourcehrs: OptField[BigDecimal, Row] + val plannedcost: Field[BigDecimal, Row] + val actualcost: OptField[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object WorkorderroutingFields extends WorkorderroutingStructure[WorkorderroutingRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingId.scala new file mode 100644 index 0000000000..e6816dfeca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingId.scala @@ -0,0 +1,43 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.TypoShort +import adventureworks.production.workorder.WorkorderId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `production.workorderrouting` */ +case class WorkorderroutingId(workorderid: WorkorderId, productid: Int, operationsequence: TypoShort) +object WorkorderroutingId { + implicit lazy val jsonDecoder: JsonDecoder[WorkorderroutingId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val operationsequence = jsonObj.get("operationsequence").toRight("Missing field 'operationsequence'").flatMap(_.as(TypoShort.jsonDecoder)) + if (workorderid.isRight && productid.isRight && operationsequence.isRight) + Right(WorkorderroutingId(workorderid = workorderid.toOption.get, productid = productid.toOption.get, operationsequence = operationsequence.toOption.get)) + else Left(List[Either[String, Any]](workorderid, productid, operationsequence).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WorkorderroutingId] = new JsonEncoder[WorkorderroutingId] { + override def unsafeEncode(a: WorkorderroutingId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""operationsequence":""") + TypoShort.jsonEncoder.unsafeEncode(a.operationsequence, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoShort]): Ordering[WorkorderroutingId] = Ordering.by(x => (x.workorderid, x.productid, x.operationsequence)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepo.scala new file mode 100644 index 0000000000..a69b569380 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait WorkorderroutingRepo { + def delete(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[WorkorderroutingFields, WorkorderroutingRow] + def insert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, WorkorderroutingRow] + def insert(unsaved: WorkorderroutingRowUnsaved): ZIO[ZConnection, Throwable, WorkorderroutingRow] + def select: SelectBuilder[WorkorderroutingFields, WorkorderroutingRow] + def selectAll: ZStream[ZConnection, Throwable, WorkorderroutingRow] + def selectById(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Option[WorkorderroutingRow]] + def update(row: WorkorderroutingRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[WorkorderroutingFields, WorkorderroutingRow] + def upsert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderroutingRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoImpl.scala new file mode 100644 index 0000000000..b832d85d34 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoImpl.scala @@ -0,0 +1,127 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object WorkorderroutingRepoImpl extends WorkorderroutingRepo { + override def delete(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from production.workorderrouting where "workorderid" = ${Segment.paramSegment(compositeId.workorderid)(WorkorderId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(Setter.intSetter)} AND "operationsequence" = ${Segment.paramSegment(compositeId.operationsequence)(TypoShort.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + DeleteBuilder("production.workorderrouting", WorkorderroutingFields) + } + override def insert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, WorkorderroutingRow] = { + sql"""insert into production.workorderrouting("workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate", "scheduledenddate", "actualstartdate", "actualenddate", "actualresourcehrs", "plannedcost", "actualcost", "modifieddate") + values (${Segment.paramSegment(unsaved.workorderid)(WorkorderId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.operationsequence)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2, ${Segment.paramSegment(unsaved.scheduledstartdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.scheduledenddate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.actualstartdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.actualenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.actualresourcehrs)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.plannedcost)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.actualcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text + """.insertReturning(WorkorderroutingRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: WorkorderroutingRowUnsaved): ZIO[ZConnection, Throwable, WorkorderroutingRow] = { + val fs = List( + Some((sql""""workorderid"""", sql"${Segment.paramSegment(unsaved.workorderid)(WorkorderId.setter)}::int4")), + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4")), + Some((sql""""operationsequence"""", sql"${Segment.paramSegment(unsaved.operationsequence)(TypoShort.setter)}::int2")), + Some((sql""""locationid"""", sql"${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2")), + Some((sql""""scheduledstartdate"""", sql"${Segment.paramSegment(unsaved.scheduledstartdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""scheduledenddate"""", sql"${Segment.paramSegment(unsaved.scheduledenddate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""actualstartdate"""", sql"${Segment.paramSegment(unsaved.actualstartdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""actualenddate"""", sql"${Segment.paramSegment(unsaved.actualenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""actualresourcehrs"""", sql"${Segment.paramSegment(unsaved.actualresourcehrs)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + Some((sql""""plannedcost"""", sql"${Segment.paramSegment(unsaved.plannedcost)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""actualcost"""", sql"${Segment.paramSegment(unsaved.actualcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into production.workorderrouting default values + returning "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into production.workorderrouting($names) values ($values) returning "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text""" + } + q.insertReturning(WorkorderroutingRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + SelectBuilderSql("production.workorderrouting", WorkorderroutingFields, WorkorderroutingRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, WorkorderroutingRow] = { + sql"""select "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text from production.workorderrouting""".query(WorkorderroutingRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Option[WorkorderroutingRow]] = { + sql"""select "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text from production.workorderrouting where "workorderid" = ${Segment.paramSegment(compositeId.workorderid)(WorkorderId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(Setter.intSetter)} AND "operationsequence" = ${Segment.paramSegment(compositeId.operationsequence)(TypoShort.setter)}""".query(WorkorderroutingRow.jdbcDecoder).selectOne + } + override def update(row: WorkorderroutingRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update production.workorderrouting + set "locationid" = ${Segment.paramSegment(row.locationid)(LocationId.setter)}::int2, + "scheduledstartdate" = ${Segment.paramSegment(row.scheduledstartdate)(TypoLocalDateTime.setter)}::timestamp, + "scheduledenddate" = ${Segment.paramSegment(row.scheduledenddate)(TypoLocalDateTime.setter)}::timestamp, + "actualstartdate" = ${Segment.paramSegment(row.actualstartdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "actualenddate" = ${Segment.paramSegment(row.actualenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "actualresourcehrs" = ${Segment.paramSegment(row.actualresourcehrs)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "plannedcost" = ${Segment.paramSegment(row.plannedcost)(Setter.bigDecimalScalaSetter)}::numeric, + "actualcost" = ${Segment.paramSegment(row.actualcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "workorderid" = ${Segment.paramSegment(compositeId.workorderid)(WorkorderId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(Setter.intSetter)} AND "operationsequence" = ${Segment.paramSegment(compositeId.operationsequence)(TypoShort.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + UpdateBuilder("production.workorderrouting", WorkorderroutingFields, WorkorderroutingRow.jdbcDecoder) + } + override def upsert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderroutingRow]] = { + sql"""insert into production.workorderrouting("workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate", "scheduledenddate", "actualstartdate", "actualenddate", "actualresourcehrs", "plannedcost", "actualcost", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.workorderid)(WorkorderId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.operationsequence)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.locationid)(LocationId.setter)}::int2, + ${Segment.paramSegment(unsaved.scheduledstartdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.scheduledenddate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.actualstartdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.actualenddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.actualresourcehrs)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.plannedcost)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.actualcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("workorderid", "productid", "operationsequence") + do update set + "locationid" = EXCLUDED."locationid", + "scheduledstartdate" = EXCLUDED."scheduledstartdate", + "scheduledenddate" = EXCLUDED."scheduledenddate", + "actualstartdate" = EXCLUDED."actualstartdate", + "actualenddate" = EXCLUDED."actualenddate", + "actualresourcehrs" = EXCLUDED."actualresourcehrs", + "plannedcost" = EXCLUDED."plannedcost", + "actualcost" = EXCLUDED."actualcost", + "modifieddate" = EXCLUDED."modifieddate" + returning "workorderid", "productid", "operationsequence", "locationid", "scheduledstartdate"::text, "scheduledenddate"::text, "actualstartdate"::text, "actualenddate"::text, "actualresourcehrs", "plannedcost", "actualcost", "modifieddate"::text""".insertReturning(WorkorderroutingRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoMock.scala new file mode 100644 index 0000000000..d0e8a3f4dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class WorkorderroutingRepoMock(toRow: Function1[WorkorderroutingRowUnsaved, WorkorderroutingRow], + map: scala.collection.mutable.Map[WorkorderroutingId, WorkorderroutingRow] = scala.collection.mutable.Map.empty) extends WorkorderroutingRepo { + override def delete(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + DeleteBuilderMock(DeleteParams.empty, WorkorderroutingFields, map) + } + override def insert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, WorkorderroutingRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: WorkorderroutingRowUnsaved): ZIO[ZConnection, Throwable, WorkorderroutingRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + SelectBuilderMock(WorkorderroutingFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, WorkorderroutingRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: WorkorderroutingId): ZIO[ZConnection, Throwable, Option[WorkorderroutingRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: WorkorderroutingRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[WorkorderroutingFields, WorkorderroutingRow] = { + UpdateBuilderMock(UpdateParams.empty, WorkorderroutingFields, map) + } + override def upsert(unsaved: WorkorderroutingRow): ZIO[ZConnection, Throwable, UpdateResult[WorkorderroutingRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRow.scala new file mode 100644 index 0000000000..8ccf8ad9b7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRow.scala @@ -0,0 +1,135 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class WorkorderroutingRow( + /** Primary key. Foreign key to WorkOrder.WorkOrderID. + Points to [[workorder.WorkorderRow.workorderid]] */ + workorderid: WorkorderId, + /** Primary key. Foreign key to Product.ProductID. */ + productid: Int, + /** Primary key. Indicates the manufacturing process sequence. */ + operationsequence: TypoShort, + /** Manufacturing location where the part is processed. Foreign key to Location.LocationID. + Points to [[location.LocationRow.locationid]] */ + locationid: LocationId, + /** Planned manufacturing start date. + Constraint CK_WorkOrderRouting_ScheduledEndDate affecting columns "scheduledenddate", "scheduledstartdate": ((scheduledenddate >= scheduledstartdate)) */ + scheduledstartdate: TypoLocalDateTime, + /** Planned manufacturing end date. + Constraint CK_WorkOrderRouting_ScheduledEndDate affecting columns "scheduledenddate", "scheduledstartdate": ((scheduledenddate >= scheduledstartdate)) */ + scheduledenddate: TypoLocalDateTime, + /** Actual start date. + Constraint CK_WorkOrderRouting_ActualEndDate affecting columns "actualenddate", "actualstartdate": (((actualenddate >= actualstartdate) OR (actualenddate IS NULL) OR (actualstartdate IS NULL))) */ + actualstartdate: Option[TypoLocalDateTime], + /** Actual end date. + Constraint CK_WorkOrderRouting_ActualEndDate affecting columns "actualenddate", "actualstartdate": (((actualenddate >= actualstartdate) OR (actualenddate IS NULL) OR (actualstartdate IS NULL))) */ + actualenddate: Option[TypoLocalDateTime], + /** Number of manufacturing hours used. + Constraint CK_WorkOrderRouting_ActualResourceHrs affecting columns "actualresourcehrs": ((actualresourcehrs >= 0.0000)) */ + actualresourcehrs: Option[BigDecimal], + /** Estimated manufacturing cost. + Constraint CK_WorkOrderRouting_PlannedCost affecting columns "plannedcost": ((plannedcost > 0.00)) */ + plannedcost: BigDecimal, + /** Actual manufacturing cost. + Constraint CK_WorkOrderRouting_ActualCost affecting columns "actualcost": ((actualcost > 0.00)) */ + actualcost: Option[BigDecimal], + modifieddate: TypoLocalDateTime +){ + val compositeId: WorkorderroutingId = WorkorderroutingId(workorderid, productid, operationsequence) + } + +object WorkorderroutingRow { + implicit lazy val jdbcDecoder: JdbcDecoder[WorkorderroutingRow] = new JdbcDecoder[WorkorderroutingRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, WorkorderroutingRow) = + columIndex + 11 -> + WorkorderroutingRow( + workorderid = WorkorderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + operationsequence = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + locationid = LocationId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + scheduledstartdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + scheduledenddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + actualstartdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + actualenddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + actualresourcehrs = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 8, rs)._2, + plannedcost = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 9, rs)._2, + actualcost = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[WorkorderroutingRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val operationsequence = jsonObj.get("operationsequence").toRight("Missing field 'operationsequence'").flatMap(_.as(TypoShort.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val scheduledstartdate = jsonObj.get("scheduledstartdate").toRight("Missing field 'scheduledstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scheduledenddate = jsonObj.get("scheduledenddate").toRight("Missing field 'scheduledenddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val actualstartdate = jsonObj.get("actualstartdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualenddate = jsonObj.get("actualenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualresourcehrs = jsonObj.get("actualresourcehrs").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val plannedcost = jsonObj.get("plannedcost").toRight("Missing field 'plannedcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val actualcost = jsonObj.get("actualcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (workorderid.isRight && productid.isRight && operationsequence.isRight && locationid.isRight && scheduledstartdate.isRight && scheduledenddate.isRight && actualstartdate.isRight && actualenddate.isRight && actualresourcehrs.isRight && plannedcost.isRight && actualcost.isRight && modifieddate.isRight) + Right(WorkorderroutingRow(workorderid = workorderid.toOption.get, productid = productid.toOption.get, operationsequence = operationsequence.toOption.get, locationid = locationid.toOption.get, scheduledstartdate = scheduledstartdate.toOption.get, scheduledenddate = scheduledenddate.toOption.get, actualstartdate = actualstartdate.toOption.get, actualenddate = actualenddate.toOption.get, actualresourcehrs = actualresourcehrs.toOption.get, plannedcost = plannedcost.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](workorderid, productid, operationsequence, locationid, scheduledstartdate, scheduledenddate, actualstartdate, actualenddate, actualresourcehrs, plannedcost, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WorkorderroutingRow] = new JsonEncoder[WorkorderroutingRow] { + override def unsafeEncode(a: WorkorderroutingRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""operationsequence":""") + TypoShort.jsonEncoder.unsafeEncode(a.operationsequence, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""scheduledstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledstartdate, indent, out) + out.write(",") + out.write(""""scheduledenddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledenddate, indent, out) + out.write(",") + out.write(""""actualstartdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualstartdate, indent, out) + out.write(",") + out.write(""""actualenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualenddate, indent, out) + out.write(",") + out.write(""""actualresourcehrs":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualresourcehrs, indent, out) + out.write(",") + out.write(""""plannedcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.plannedcost, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRowUnsaved.scala new file mode 100644 index 0000000000..bdf8359fc9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingRowUnsaved.scala @@ -0,0 +1,134 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `production.workorderrouting` which has not been persisted yet */ +case class WorkorderroutingRowUnsaved( + /** Primary key. Foreign key to WorkOrder.WorkOrderID. + Points to [[workorder.WorkorderRow.workorderid]] */ + workorderid: WorkorderId, + /** Primary key. Foreign key to Product.ProductID. */ + productid: Int, + /** Primary key. Indicates the manufacturing process sequence. */ + operationsequence: TypoShort, + /** Manufacturing location where the part is processed. Foreign key to Location.LocationID. + Points to [[location.LocationRow.locationid]] */ + locationid: LocationId, + /** Planned manufacturing start date. + Constraint CK_WorkOrderRouting_ScheduledEndDate affecting columns "scheduledenddate", "scheduledstartdate": ((scheduledenddate >= scheduledstartdate)) */ + scheduledstartdate: TypoLocalDateTime, + /** Planned manufacturing end date. + Constraint CK_WorkOrderRouting_ScheduledEndDate affecting columns "scheduledenddate", "scheduledstartdate": ((scheduledenddate >= scheduledstartdate)) */ + scheduledenddate: TypoLocalDateTime, + /** Actual start date. + Constraint CK_WorkOrderRouting_ActualEndDate affecting columns "actualenddate", "actualstartdate": (((actualenddate >= actualstartdate) OR (actualenddate IS NULL) OR (actualstartdate IS NULL))) */ + actualstartdate: Option[TypoLocalDateTime], + /** Actual end date. + Constraint CK_WorkOrderRouting_ActualEndDate affecting columns "actualenddate", "actualstartdate": (((actualenddate >= actualstartdate) OR (actualenddate IS NULL) OR (actualstartdate IS NULL))) */ + actualenddate: Option[TypoLocalDateTime], + /** Number of manufacturing hours used. + Constraint CK_WorkOrderRouting_ActualResourceHrs affecting columns "actualresourcehrs": ((actualresourcehrs >= 0.0000)) */ + actualresourcehrs: Option[BigDecimal], + /** Estimated manufacturing cost. + Constraint CK_WorkOrderRouting_PlannedCost affecting columns "plannedcost": ((plannedcost > 0.00)) */ + plannedcost: BigDecimal, + /** Actual manufacturing cost. + Constraint CK_WorkOrderRouting_ActualCost affecting columns "actualcost": ((actualcost > 0.00)) */ + actualcost: Option[BigDecimal], + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): WorkorderroutingRow = + WorkorderroutingRow( + workorderid = workorderid, + productid = productid, + operationsequence = operationsequence, + locationid = locationid, + scheduledstartdate = scheduledstartdate, + scheduledenddate = scheduledenddate, + actualstartdate = actualstartdate, + actualenddate = actualenddate, + actualresourcehrs = actualresourcehrs, + plannedcost = plannedcost, + actualcost = actualcost, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object WorkorderroutingRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[WorkorderroutingRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val workorderid = jsonObj.get("workorderid").toRight("Missing field 'workorderid'").flatMap(_.as(WorkorderId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(JsonDecoder.int)) + val operationsequence = jsonObj.get("operationsequence").toRight("Missing field 'operationsequence'").flatMap(_.as(TypoShort.jsonDecoder)) + val locationid = jsonObj.get("locationid").toRight("Missing field 'locationid'").flatMap(_.as(LocationId.jsonDecoder)) + val scheduledstartdate = jsonObj.get("scheduledstartdate").toRight("Missing field 'scheduledstartdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val scheduledenddate = jsonObj.get("scheduledenddate").toRight("Missing field 'scheduledenddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val actualstartdate = jsonObj.get("actualstartdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualenddate = jsonObj.get("actualenddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val actualresourcehrs = jsonObj.get("actualresourcehrs").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val plannedcost = jsonObj.get("plannedcost").toRight("Missing field 'plannedcost'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val actualcost = jsonObj.get("actualcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (workorderid.isRight && productid.isRight && operationsequence.isRight && locationid.isRight && scheduledstartdate.isRight && scheduledenddate.isRight && actualstartdate.isRight && actualenddate.isRight && actualresourcehrs.isRight && plannedcost.isRight && actualcost.isRight && modifieddate.isRight) + Right(WorkorderroutingRowUnsaved(workorderid = workorderid.toOption.get, productid = productid.toOption.get, operationsequence = operationsequence.toOption.get, locationid = locationid.toOption.get, scheduledstartdate = scheduledstartdate.toOption.get, scheduledenddate = scheduledenddate.toOption.get, actualstartdate = actualstartdate.toOption.get, actualenddate = actualenddate.toOption.get, actualresourcehrs = actualresourcehrs.toOption.get, plannedcost = plannedcost.toOption.get, actualcost = actualcost.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](workorderid, productid, operationsequence, locationid, scheduledstartdate, scheduledenddate, actualstartdate, actualenddate, actualresourcehrs, plannedcost, actualcost, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[WorkorderroutingRowUnsaved] = new JsonEncoder[WorkorderroutingRowUnsaved] { + override def unsafeEncode(a: WorkorderroutingRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""workorderid":""") + WorkorderId.jsonEncoder.unsafeEncode(a.workorderid, indent, out) + out.write(",") + out.write(""""productid":""") + JsonEncoder.int.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""operationsequence":""") + TypoShort.jsonEncoder.unsafeEncode(a.operationsequence, indent, out) + out.write(",") + out.write(""""locationid":""") + LocationId.jsonEncoder.unsafeEncode(a.locationid, indent, out) + out.write(",") + out.write(""""scheduledstartdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledstartdate, indent, out) + out.write(",") + out.write(""""scheduledenddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.scheduledenddate, indent, out) + out.write(",") + out.write(""""actualstartdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualstartdate, indent, out) + out.write(",") + out.write(""""actualenddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.actualenddate, indent, out) + out.write(",") + out.write(""""actualresourcehrs":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualresourcehrs, indent, out) + out.write(",") + out.write(""""plannedcost":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.plannedcost, indent, out) + out.write(",") + out.write(""""actualcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.actualcost, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingStructure.scala new file mode 100644 index 0000000000..7329ce8cd9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/production/workorderrouting/WorkorderroutingStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package production +package workorderrouting + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.location.LocationId +import adventureworks.production.workorder.WorkorderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class WorkorderroutingStructure[Row](val prefix: Option[String], val extract: Row => WorkorderroutingRow, val merge: (Row, WorkorderroutingRow) => Row) + extends Relation[WorkorderroutingFields, WorkorderroutingRow, Row] + with WorkorderroutingFields[Row] { outer => + + override val workorderid = new IdField[WorkorderId, Row](prefix, "workorderid", None, Some("int4"))(x => extract(x).workorderid, (row, value) => merge(row, extract(row).copy(workorderid = value))) + override val productid = new IdField[Int, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val operationsequence = new IdField[TypoShort, Row](prefix, "operationsequence", None, Some("int2"))(x => extract(x).operationsequence, (row, value) => merge(row, extract(row).copy(operationsequence = value))) + override val locationid = new Field[LocationId, Row](prefix, "locationid", None, Some("int2"))(x => extract(x).locationid, (row, value) => merge(row, extract(row).copy(locationid = value))) + override val scheduledstartdate = new Field[TypoLocalDateTime, Row](prefix, "scheduledstartdate", Some("text"), Some("timestamp"))(x => extract(x).scheduledstartdate, (row, value) => merge(row, extract(row).copy(scheduledstartdate = value))) + override val scheduledenddate = new Field[TypoLocalDateTime, Row](prefix, "scheduledenddate", Some("text"), Some("timestamp"))(x => extract(x).scheduledenddate, (row, value) => merge(row, extract(row).copy(scheduledenddate = value))) + override val actualstartdate = new OptField[TypoLocalDateTime, Row](prefix, "actualstartdate", Some("text"), Some("timestamp"))(x => extract(x).actualstartdate, (row, value) => merge(row, extract(row).copy(actualstartdate = value))) + override val actualenddate = new OptField[TypoLocalDateTime, Row](prefix, "actualenddate", Some("text"), Some("timestamp"))(x => extract(x).actualenddate, (row, value) => merge(row, extract(row).copy(actualenddate = value))) + override val actualresourcehrs = new OptField[BigDecimal, Row](prefix, "actualresourcehrs", None, Some("numeric"))(x => extract(x).actualresourcehrs, (row, value) => merge(row, extract(row).copy(actualresourcehrs = value))) + override val plannedcost = new Field[BigDecimal, Row](prefix, "plannedcost", None, Some("numeric"))(x => extract(x).plannedcost, (row, value) => merge(row, extract(row).copy(plannedcost = value))) + override val actualcost = new OptField[BigDecimal, Row](prefix, "actualcost", None, Some("numeric"))(x => extract(x).actualcost, (row, value) => merge(row, extract(row).copy(actualcost = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](workorderid, productid, operationsequence, locationid, scheduledstartdate, scheduledenddate, actualstartdate, actualenddate, actualresourcehrs, plannedcost, actualcost, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => WorkorderroutingRow, merge: (NewRow, WorkorderroutingRow) => NewRow): WorkorderroutingStructure[NewRow] = + new WorkorderroutingStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewFields.scala new file mode 100644 index 0000000000..5ab9028beb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import typo.dsl.SqlExpr.Field + +trait PodViewFields[Row] { + val id: Field[Int, Row] + val purchaseorderid: Field[PurchaseorderheaderId, Row] + val purchaseorderdetailid: Field[Int, Row] + val duedate: Field[TypoLocalDateTime, Row] + val orderqty: Field[TypoShort, Row] + val productid: Field[ProductId, Row] + val unitprice: Field[BigDecimal, Row] + val receivedqty: Field[BigDecimal, Row] + val rejectedqty: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PodViewFields extends PodViewStructure[PodViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepo.scala new file mode 100644 index 0000000000..69290c52cc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pod + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PodViewRepo { + def select: SelectBuilder[PodViewFields, PodViewRow] + def selectAll: ZStream[ZConnection, Throwable, PodViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepoImpl.scala new file mode 100644 index 0000000000..339ff3cdf4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pod + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PodViewRepoImpl extends PodViewRepo { + override def select: SelectBuilder[PodViewFields, PodViewRow] = { + SelectBuilderSql("pu.pod", PodViewFields, PodViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PodViewRow] = { + sql"""select "id", "purchaseorderid", "purchaseorderdetailid", "duedate"::text, "orderqty", "productid", "unitprice", "receivedqty", "rejectedqty", "modifieddate"::text from pu.pod""".query(PodViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRow.scala new file mode 100644 index 0000000000..66eeda7776 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewRow.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PodViewRow( + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.purchaseorderdetailid]] */ + id: Int, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.purchaseorderid]] */ + purchaseorderid: PurchaseorderheaderId, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.purchaseorderdetailid]] */ + purchaseorderdetailid: Int, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.duedate]] */ + duedate: TypoLocalDateTime, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.orderqty]] */ + orderqty: TypoShort, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.productid]] */ + productid: ProductId, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.unitprice]] */ + unitprice: BigDecimal, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.receivedqty]] */ + receivedqty: BigDecimal, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.rejectedqty]] */ + rejectedqty: BigDecimal, + /** Points to [[purchasing.purchaseorderdetail.PurchaseorderdetailRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PodViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PodViewRow] = new JdbcDecoder[PodViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PodViewRow) = + columIndex + 9 -> + PodViewRow( + id = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 0, rs)._2, + purchaseorderid = PurchaseorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + purchaseorderdetailid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + orderqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + unitprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + receivedqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + rejectedqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PodViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(JsonDecoder.int)) + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val purchaseorderdetailid = jsonObj.get("purchaseorderdetailid").toRight("Missing field 'purchaseorderdetailid'").flatMap(_.as(JsonDecoder.int)) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val receivedqty = jsonObj.get("receivedqty").toRight("Missing field 'receivedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rejectedqty = jsonObj.get("rejectedqty").toRight("Missing field 'rejectedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && purchaseorderid.isRight && purchaseorderdetailid.isRight && duedate.isRight && orderqty.isRight && productid.isRight && unitprice.isRight && receivedqty.isRight && rejectedqty.isRight && modifieddate.isRight) + Right(PodViewRow(id = id.toOption.get, purchaseorderid = purchaseorderid.toOption.get, purchaseorderdetailid = purchaseorderdetailid.toOption.get, duedate = duedate.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, unitprice = unitprice.toOption.get, receivedqty = receivedqty.toOption.get, rejectedqty = rejectedqty.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, purchaseorderid, purchaseorderdetailid, duedate, orderqty, productid, unitprice, receivedqty, rejectedqty, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PodViewRow] = new JsonEncoder[PodViewRow] { + override def unsafeEncode(a: PodViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + JsonEncoder.int.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""purchaseorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.purchaseorderdetailid, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""receivedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.receivedqty, indent, out) + out.write(",") + out.write(""""rejectedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rejectedqty, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewStructure.scala new file mode 100644 index 0000000000..15d841aa3a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pod/PodViewStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PodViewStructure[Row](val prefix: Option[String], val extract: Row => PodViewRow, val merge: (Row, PodViewRow) => Row) + extends Relation[PodViewFields, PodViewRow, Row] + with PodViewFields[Row] { outer => + + 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 purchaseorderid = new Field[PurchaseorderheaderId, Row](prefix, "purchaseorderid", None, None)(x => extract(x).purchaseorderid, (row, value) => merge(row, extract(row).copy(purchaseorderid = value))) + override val purchaseorderdetailid = new Field[Int, Row](prefix, "purchaseorderdetailid", None, None)(x => extract(x).purchaseorderdetailid, (row, value) => merge(row, extract(row).copy(purchaseorderdetailid = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), None)(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val orderqty = new Field[TypoShort, Row](prefix, "orderqty", None, None)(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val unitprice = new Field[BigDecimal, Row](prefix, "unitprice", None, None)(x => extract(x).unitprice, (row, value) => merge(row, extract(row).copy(unitprice = value))) + override val receivedqty = new Field[BigDecimal, Row](prefix, "receivedqty", None, None)(x => extract(x).receivedqty, (row, value) => merge(row, extract(row).copy(receivedqty = value))) + override val rejectedqty = new Field[BigDecimal, Row](prefix, "rejectedqty", None, None)(x => extract(x).rejectedqty, (row, value) => merge(row, extract(row).copy(rejectedqty = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, purchaseorderid, purchaseorderdetailid, duedate, orderqty, productid, unitprice, receivedqty, rejectedqty, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PodViewRow, merge: (NewRow, PodViewRow) => NewRow): PodViewStructure[NewRow] = + new PodViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewFields.scala new file mode 100644 index 0000000000..a2734562de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewFields.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package poh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PohViewFields[Row] { + val id: Field[PurchaseorderheaderId, Row] + val purchaseorderid: Field[PurchaseorderheaderId, Row] + val revisionnumber: Field[TypoShort, Row] + val status: Field[TypoShort, Row] + val employeeid: Field[BusinessentityId, Row] + val vendorid: Field[BusinessentityId, Row] + val shipmethodid: Field[ShipmethodId, Row] + val orderdate: Field[TypoLocalDateTime, Row] + val shipdate: OptField[TypoLocalDateTime, Row] + val subtotal: Field[BigDecimal, Row] + val taxamt: Field[BigDecimal, Row] + val freight: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PohViewFields extends PohViewStructure[PohViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepo.scala new file mode 100644 index 0000000000..6f86ed8af7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package poh + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PohViewRepo { + def select: SelectBuilder[PohViewFields, PohViewRow] + def selectAll: ZStream[ZConnection, Throwable, PohViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepoImpl.scala new file mode 100644 index 0000000000..7407af3c3f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package poh + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PohViewRepoImpl extends PohViewRepo { + override def select: SelectBuilder[PohViewFields, PohViewRow] = { + SelectBuilderSql("pu.poh", PohViewFields, PohViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PohViewRow] = { + sql"""select "id", "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text from pu.poh""".query(PohViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRow.scala new file mode 100644 index 0000000000..29edb2e1fd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewRow.scala @@ -0,0 +1,133 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package poh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import adventureworks.purchasing.shipmethod.ShipmethodId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PohViewRow( + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.purchaseorderid]] */ + id: PurchaseorderheaderId, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.purchaseorderid]] */ + purchaseorderid: PurchaseorderheaderId, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.revisionnumber]] */ + revisionnumber: TypoShort, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.status]] */ + status: TypoShort, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.employeeid]] */ + employeeid: BusinessentityId, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.vendorid]] */ + vendorid: BusinessentityId, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.orderdate]] */ + orderdate: TypoLocalDateTime, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.shipdate]] */ + shipdate: Option[TypoLocalDateTime], + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.subtotal]] */ + subtotal: BigDecimal, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.taxamt]] */ + taxamt: BigDecimal, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.freight]] */ + freight: BigDecimal, + /** Points to [[purchasing.purchaseorderheader.PurchaseorderheaderRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PohViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PohViewRow] = new JdbcDecoder[PohViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PohViewRow) = + columIndex + 12 -> + PohViewRow( + id = PurchaseorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + purchaseorderid = PurchaseorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + revisionnumber = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + employeeid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + vendorid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + orderdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + shipdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + subtotal = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 9, rs)._2, + taxamt = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 10, rs)._2, + freight = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 11, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PohViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(TypoShort.jsonDecoder)) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val employeeid = jsonObj.get("employeeid").toRight("Missing field 'employeeid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val vendorid = jsonObj.get("vendorid").toRight("Missing field 'vendorid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && purchaseorderid.isRight && revisionnumber.isRight && status.isRight && employeeid.isRight && vendorid.isRight && shipmethodid.isRight && orderdate.isRight && shipdate.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && modifieddate.isRight) + Right(PohViewRow(id = id.toOption.get, purchaseorderid = purchaseorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, status = status.toOption.get, employeeid = employeeid.toOption.get, vendorid = vendorid.toOption.get, shipmethodid = shipmethodid.toOption.get, orderdate = orderdate.toOption.get, shipdate = shipdate.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, purchaseorderid, revisionnumber, status, employeeid, vendorid, shipmethodid, orderdate, shipdate, subtotal, taxamt, freight, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PohViewRow] = new JsonEncoder[PohViewRow] { + override def unsafeEncode(a: PohViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + TypoShort.jsonEncoder.unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""employeeid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.employeeid, indent, out) + out.write(",") + out.write(""""vendorid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.vendorid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""orderdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""subtotal":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewStructure.scala new file mode 100644 index 0000000000..8051ee9753 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/poh/PohViewStructure.scala @@ -0,0 +1,43 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package poh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PohViewStructure[Row](val prefix: Option[String], val extract: Row => PohViewRow, val merge: (Row, PohViewRow) => Row) + extends Relation[PohViewFields, PohViewRow, Row] + with PohViewFields[Row] { outer => + + override val id = new Field[PurchaseorderheaderId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val purchaseorderid = new Field[PurchaseorderheaderId, Row](prefix, "purchaseorderid", None, None)(x => extract(x).purchaseorderid, (row, value) => merge(row, extract(row).copy(purchaseorderid = value))) + override val revisionnumber = new Field[TypoShort, Row](prefix, "revisionnumber", None, None)(x => extract(x).revisionnumber, (row, value) => merge(row, extract(row).copy(revisionnumber = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, None)(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val employeeid = new Field[BusinessentityId, Row](prefix, "employeeid", None, None)(x => extract(x).employeeid, (row, value) => merge(row, extract(row).copy(employeeid = value))) + override val vendorid = new Field[BusinessentityId, Row](prefix, "vendorid", None, None)(x => extract(x).vendorid, (row, value) => merge(row, extract(row).copy(vendorid = value))) + override val shipmethodid = new Field[ShipmethodId, Row](prefix, "shipmethodid", None, None)(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val orderdate = new Field[TypoLocalDateTime, Row](prefix, "orderdate", Some("text"), None)(x => extract(x).orderdate, (row, value) => merge(row, extract(row).copy(orderdate = value))) + override val shipdate = new OptField[TypoLocalDateTime, Row](prefix, "shipdate", Some("text"), None)(x => extract(x).shipdate, (row, value) => merge(row, extract(row).copy(shipdate = value))) + override val subtotal = new Field[BigDecimal, Row](prefix, "subtotal", None, None)(x => extract(x).subtotal, (row, value) => merge(row, extract(row).copy(subtotal = value))) + override val taxamt = new Field[BigDecimal, Row](prefix, "taxamt", None, None)(x => extract(x).taxamt, (row, value) => merge(row, extract(row).copy(taxamt = value))) + override val freight = new Field[BigDecimal, Row](prefix, "freight", None, None)(x => extract(x).freight, (row, value) => merge(row, extract(row).copy(freight = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, purchaseorderid, revisionnumber, status, employeeid, vendorid, shipmethodid, orderdate, shipdate, subtotal, taxamt, freight, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PohViewRow, merge: (NewRow, PohViewRow) => NewRow): PohViewStructure[NewRow] = + new PohViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewFields.scala new file mode 100644 index 0000000000..a84f485b9b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pv + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait PvViewFields[Row] { + val id: Field[ProductId, Row] + val productid: Field[ProductId, Row] + val businessentityid: Field[BusinessentityId, Row] + val averageleadtime: Field[Int, Row] + val standardprice: Field[BigDecimal, Row] + val lastreceiptcost: OptField[BigDecimal, Row] + val lastreceiptdate: OptField[TypoLocalDateTime, Row] + val minorderqty: Field[Int, Row] + val maxorderqty: Field[Int, Row] + val onorderqty: OptField[Int, Row] + val unitmeasurecode: Field[UnitmeasureId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PvViewFields extends PvViewStructure[PvViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepo.scala new file mode 100644 index 0000000000..e7d06358a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pv + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PvViewRepo { + def select: SelectBuilder[PvViewFields, PvViewRow] + def selectAll: ZStream[ZConnection, Throwable, PvViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepoImpl.scala new file mode 100644 index 0000000000..7fa1f9dfca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pv + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PvViewRepoImpl extends PvViewRepo { + override def select: SelectBuilder[PvViewFields, PvViewRow] = { + SelectBuilderSql("pu.pv", PvViewFields, PvViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PvViewRow] = { + sql"""select "id", "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text from pu.pv""".query(PvViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRow.scala new file mode 100644 index 0000000000..605f40f85b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewRow.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pv + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PvViewRow( + /** Points to [[purchasing.productvendor.ProductvendorRow.productid]] */ + id: ProductId, + /** Points to [[purchasing.productvendor.ProductvendorRow.productid]] */ + productid: ProductId, + /** Points to [[purchasing.productvendor.ProductvendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[purchasing.productvendor.ProductvendorRow.averageleadtime]] */ + averageleadtime: Int, + /** Points to [[purchasing.productvendor.ProductvendorRow.standardprice]] */ + standardprice: BigDecimal, + /** Points to [[purchasing.productvendor.ProductvendorRow.lastreceiptcost]] */ + lastreceiptcost: Option[BigDecimal], + /** Points to [[purchasing.productvendor.ProductvendorRow.lastreceiptdate]] */ + lastreceiptdate: Option[TypoLocalDateTime], + /** Points to [[purchasing.productvendor.ProductvendorRow.minorderqty]] */ + minorderqty: Int, + /** Points to [[purchasing.productvendor.ProductvendorRow.maxorderqty]] */ + maxorderqty: Int, + /** Points to [[purchasing.productvendor.ProductvendorRow.onorderqty]] */ + onorderqty: Option[Int], + /** Points to [[purchasing.productvendor.ProductvendorRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Points to [[purchasing.productvendor.ProductvendorRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PvViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PvViewRow] = new JdbcDecoder[PvViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PvViewRow) = + columIndex + 11 -> + PvViewRow( + id = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + averageleadtime = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + standardprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + lastreceiptcost = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 5, rs)._2, + lastreceiptdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + minorderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + maxorderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 8, rs)._2, + onorderqty = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PvViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ProductId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val averageleadtime = jsonObj.get("averageleadtime").toRight("Missing field 'averageleadtime'").flatMap(_.as(JsonDecoder.int)) + val standardprice = jsonObj.get("standardprice").toRight("Missing field 'standardprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val lastreceiptcost = jsonObj.get("lastreceiptcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val lastreceiptdate = jsonObj.get("lastreceiptdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val minorderqty = jsonObj.get("minorderqty").toRight("Missing field 'minorderqty'").flatMap(_.as(JsonDecoder.int)) + val maxorderqty = jsonObj.get("maxorderqty").toRight("Missing field 'maxorderqty'").flatMap(_.as(JsonDecoder.int)) + val onorderqty = jsonObj.get("onorderqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && productid.isRight && businessentityid.isRight && averageleadtime.isRight && standardprice.isRight && lastreceiptcost.isRight && lastreceiptdate.isRight && minorderqty.isRight && maxorderqty.isRight && onorderqty.isRight && unitmeasurecode.isRight && modifieddate.isRight) + Right(PvViewRow(id = id.toOption.get, productid = productid.toOption.get, businessentityid = businessentityid.toOption.get, averageleadtime = averageleadtime.toOption.get, standardprice = standardprice.toOption.get, lastreceiptcost = lastreceiptcost.toOption.get, lastreceiptdate = lastreceiptdate.toOption.get, minorderqty = minorderqty.toOption.get, maxorderqty = maxorderqty.toOption.get, onorderqty = onorderqty.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, productid, businessentityid, averageleadtime, standardprice, lastreceiptcost, lastreceiptdate, minorderqty, maxorderqty, onorderqty, unitmeasurecode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PvViewRow] = new JsonEncoder[PvViewRow] { + override def unsafeEncode(a: PvViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ProductId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""averageleadtime":""") + JsonEncoder.int.unsafeEncode(a.averageleadtime, indent, out) + out.write(",") + out.write(""""standardprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardprice, indent, out) + out.write(",") + out.write(""""lastreceiptcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.lastreceiptcost, indent, out) + out.write(",") + out.write(""""lastreceiptdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.lastreceiptdate, indent, out) + out.write(",") + out.write(""""minorderqty":""") + JsonEncoder.int.unsafeEncode(a.minorderqty, indent, out) + out.write(",") + out.write(""""maxorderqty":""") + JsonEncoder.int.unsafeEncode(a.maxorderqty, indent, out) + out.write(",") + out.write(""""onorderqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.onorderqty, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewStructure.scala new file mode 100644 index 0000000000..5fbdabf88c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/pv/PvViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package pv + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PvViewStructure[Row](val prefix: Option[String], val extract: Row => PvViewRow, val merge: (Row, PvViewRow) => Row) + extends Relation[PvViewFields, PvViewRow, Row] + with PvViewFields[Row] { outer => + + override val id = new Field[ProductId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val averageleadtime = new Field[Int, Row](prefix, "averageleadtime", None, None)(x => extract(x).averageleadtime, (row, value) => merge(row, extract(row).copy(averageleadtime = value))) + override val standardprice = new Field[BigDecimal, Row](prefix, "standardprice", None, None)(x => extract(x).standardprice, (row, value) => merge(row, extract(row).copy(standardprice = value))) + override val lastreceiptcost = new OptField[BigDecimal, Row](prefix, "lastreceiptcost", None, None)(x => extract(x).lastreceiptcost, (row, value) => merge(row, extract(row).copy(lastreceiptcost = value))) + override val lastreceiptdate = new OptField[TypoLocalDateTime, Row](prefix, "lastreceiptdate", Some("text"), None)(x => extract(x).lastreceiptdate, (row, value) => merge(row, extract(row).copy(lastreceiptdate = value))) + override val minorderqty = new Field[Int, Row](prefix, "minorderqty", None, None)(x => extract(x).minorderqty, (row, value) => merge(row, extract(row).copy(minorderqty = value))) + override val maxorderqty = new Field[Int, Row](prefix, "maxorderqty", None, None)(x => extract(x).maxorderqty, (row, value) => merge(row, extract(row).copy(maxorderqty = value))) + override val onorderqty = new OptField[Int, Row](prefix, "onorderqty", None, None)(x => extract(x).onorderqty, (row, value) => merge(row, extract(row).copy(onorderqty = value))) + override val unitmeasurecode = new Field[UnitmeasureId, Row](prefix, "unitmeasurecode", None, None)(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, productid, businessentityid, averageleadtime, standardprice, lastreceiptcost, lastreceiptdate, minorderqty, maxorderqty, onorderqty, unitmeasurecode, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PvViewRow, merge: (NewRow, PvViewRow) => NewRow): PvViewStructure[NewRow] = + new PvViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewFields.scala new file mode 100644 index 0000000000..50bdb92690 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package sm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field + +trait SmViewFields[Row] { + val id: Field[ShipmethodId, Row] + val shipmethodid: Field[ShipmethodId, Row] + val name: Field[Name, Row] + val shipbase: Field[BigDecimal, Row] + val shiprate: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SmViewFields extends SmViewStructure[SmViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepo.scala new file mode 100644 index 0000000000..51d93703d6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package sm + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SmViewRepo { + def select: SelectBuilder[SmViewFields, SmViewRow] + def selectAll: ZStream[ZConnection, Throwable, SmViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepoImpl.scala new file mode 100644 index 0000000000..cb09f0244b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package sm + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SmViewRepoImpl extends SmViewRepo { + override def select: SelectBuilder[SmViewFields, SmViewRow] = { + SelectBuilderSql("pu.sm", SmViewFields, SmViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SmViewRow] = { + sql"""select "id", "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text from pu.sm""".query(SmViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRow.scala new file mode 100644 index 0000000000..4695b99a80 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewRow.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package sm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import adventureworks.purchasing.shipmethod.ShipmethodId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SmViewRow( + /** Points to [[purchasing.shipmethod.ShipmethodRow.shipmethodid]] */ + id: ShipmethodId, + /** Points to [[purchasing.shipmethod.ShipmethodRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Points to [[purchasing.shipmethod.ShipmethodRow.name]] */ + name: Name, + /** Points to [[purchasing.shipmethod.ShipmethodRow.shipbase]] */ + shipbase: BigDecimal, + /** Points to [[purchasing.shipmethod.ShipmethodRow.shiprate]] */ + shiprate: BigDecimal, + /** Points to [[purchasing.shipmethod.ShipmethodRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[purchasing.shipmethod.ShipmethodRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SmViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SmViewRow] = new JdbcDecoder[SmViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SmViewRow) = + columIndex + 6 -> + SmViewRow( + id = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + shipbase = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + shiprate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SmViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val shipbase = jsonObj.get("shipbase").toRight("Missing field 'shipbase'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val shiprate = jsonObj.get("shiprate").toRight("Missing field 'shiprate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && shipmethodid.isRight && name.isRight && shipbase.isRight && shiprate.isRight && rowguid.isRight && modifieddate.isRight) + Right(SmViewRow(id = id.toOption.get, shipmethodid = shipmethodid.toOption.get, name = name.toOption.get, shipbase = shipbase.toOption.get, shiprate = shiprate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, shipmethodid, name, shipbase, shiprate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SmViewRow] = new JsonEncoder[SmViewRow] { + override def unsafeEncode(a: SmViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""shipbase":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.shipbase, indent, out) + out.write(",") + out.write(""""shiprate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.shiprate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewStructure.scala new file mode 100644 index 0000000000..0af2eb84b3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/sm/SmViewStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package sm + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SmViewStructure[Row](val prefix: Option[String], val extract: Row => SmViewRow, val merge: (Row, SmViewRow) => Row) + extends Relation[SmViewFields, SmViewRow, Row] + with SmViewFields[Row] { outer => + + override val id = new Field[ShipmethodId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val shipmethodid = new Field[ShipmethodId, Row](prefix, "shipmethodid", None, None)(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val shipbase = new Field[BigDecimal, Row](prefix, "shipbase", None, None)(x => extract(x).shipbase, (row, value) => merge(row, extract(row).copy(shipbase = value))) + override val shiprate = new Field[BigDecimal, Row](prefix, "shiprate", None, None)(x => extract(x).shiprate, (row, value) => merge(row, extract(row).copy(shiprate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, shipmethodid, name, shipbase, shiprate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SmViewRow, merge: (NewRow, SmViewRow) => NewRow): SmViewStructure[NewRow] = + new SmViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewFields.scala new file mode 100644 index 0000000000..f871aa41b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package v + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val accountnumber: Field[AccountNumber, Row] + val name: Field[Name, Row] + val creditrating: Field[TypoShort, Row] + val preferredvendorstatus: Field[Flag, Row] + val activeflag: Field[Flag, Row] + val purchasingwebserviceurl: OptField[/* max 1024 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VViewFields extends VViewStructure[VViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepo.scala new file mode 100644 index 0000000000..a89cd1338a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package v + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VViewRepo { + def select: SelectBuilder[VViewFields, VViewRow] + def selectAll: ZStream[ZConnection, Throwable, VViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepoImpl.scala new file mode 100644 index 0000000000..9ad5bda7d9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package v + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VViewRepoImpl extends VViewRepo { + override def select: SelectBuilder[VViewFields, VViewRow] = { + SelectBuilderSql("pu.v", VViewFields, VViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VViewRow] = { + sql"""select "id", "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text from pu.v""".query(VViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRow.scala new file mode 100644 index 0000000000..bc77562d56 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewRow.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package v + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VViewRow( + /** Points to [[purchasing.vendor.VendorRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[purchasing.vendor.VendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[purchasing.vendor.VendorRow.accountnumber]] */ + accountnumber: AccountNumber, + /** Points to [[purchasing.vendor.VendorRow.name]] */ + name: Name, + /** Points to [[purchasing.vendor.VendorRow.creditrating]] */ + creditrating: TypoShort, + /** Points to [[purchasing.vendor.VendorRow.preferredvendorstatus]] */ + preferredvendorstatus: Flag, + /** Points to [[purchasing.vendor.VendorRow.activeflag]] */ + activeflag: Flag, + /** Points to [[purchasing.vendor.VendorRow.purchasingwebserviceurl]] */ + purchasingwebserviceurl: Option[/* max 1024 chars */ String], + /** Points to [[purchasing.vendor.VendorRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object VViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VViewRow] = new JdbcDecoder[VViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VViewRow) = + columIndex + 8 -> + VViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + accountnumber = AccountNumber.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + creditrating = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + preferredvendorstatus = Flag.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + activeflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + purchasingwebserviceurl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val accountnumber = jsonObj.get("accountnumber").toRight("Missing field 'accountnumber'").flatMap(_.as(AccountNumber.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val creditrating = jsonObj.get("creditrating").toRight("Missing field 'creditrating'").flatMap(_.as(TypoShort.jsonDecoder)) + val preferredvendorstatus = jsonObj.get("preferredvendorstatus").toRight("Missing field 'preferredvendorstatus'").flatMap(_.as(Flag.jsonDecoder)) + val activeflag = jsonObj.get("activeflag").toRight("Missing field 'activeflag'").flatMap(_.as(Flag.jsonDecoder)) + val purchasingwebserviceurl = jsonObj.get("purchasingwebserviceurl").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && accountnumber.isRight && name.isRight && creditrating.isRight && preferredvendorstatus.isRight && activeflag.isRight && purchasingwebserviceurl.isRight && modifieddate.isRight) + Right(VViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, accountnumber = accountnumber.toOption.get, name = name.toOption.get, creditrating = creditrating.toOption.get, preferredvendorstatus = preferredvendorstatus.toOption.get, activeflag = activeflag.toOption.get, purchasingwebserviceurl = purchasingwebserviceurl.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, accountnumber, name, creditrating, preferredvendorstatus, activeflag, purchasingwebserviceurl, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VViewRow] = new JsonEncoder[VViewRow] { + override def unsafeEncode(a: VViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""accountnumber":""") + AccountNumber.jsonEncoder.unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""creditrating":""") + TypoShort.jsonEncoder.unsafeEncode(a.creditrating, indent, out) + out.write(",") + out.write(""""preferredvendorstatus":""") + Flag.jsonEncoder.unsafeEncode(a.preferredvendorstatus, indent, out) + out.write(",") + out.write(""""activeflag":""") + Flag.jsonEncoder.unsafeEncode(a.activeflag, indent, out) + out.write(",") + out.write(""""purchasingwebserviceurl":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.purchasingwebserviceurl, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewStructure.scala new file mode 100644 index 0000000000..5177f6ecf7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/pu/v/VViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package pu +package v + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VViewStructure[Row](val prefix: Option[String], val extract: Row => VViewRow, val merge: (Row, VViewRow) => Row) + extends Relation[VViewFields, VViewRow, Row] + with VViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val accountnumber = new Field[AccountNumber, Row](prefix, "accountnumber", None, None)(x => extract(x).accountnumber, (row, value) => merge(row, extract(row).copy(accountnumber = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val creditrating = new Field[TypoShort, Row](prefix, "creditrating", None, None)(x => extract(x).creditrating, (row, value) => merge(row, extract(row).copy(creditrating = value))) + override val preferredvendorstatus = new Field[Flag, Row](prefix, "preferredvendorstatus", None, None)(x => extract(x).preferredvendorstatus, (row, value) => merge(row, extract(row).copy(preferredvendorstatus = value))) + override val activeflag = new Field[Flag, Row](prefix, "activeflag", None, None)(x => extract(x).activeflag, (row, value) => merge(row, extract(row).copy(activeflag = value))) + override val purchasingwebserviceurl = new OptField[/* max 1024 chars */ String, Row](prefix, "purchasingwebserviceurl", None, None)(x => extract(x).purchasingwebserviceurl, (row, value) => merge(row, extract(row).copy(purchasingwebserviceurl = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, accountnumber, name, creditrating, preferredvendorstatus, activeflag, purchasingwebserviceurl, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VViewRow, merge: (NewRow, VViewRow) => NewRow): VViewStructure[NewRow] = + new VViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/AccountNumber.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/AccountNumber.scala new file mode 100644 index 0000000000..a04362d082 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/AccountNumber.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.AccountNumber` + * No constraint + */ +case class AccountNumber(value: String) extends AnyVal +object AccountNumber { + implicit lazy val arraySetter: Setter[Array[AccountNumber]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[AccountNumber, String] = Bijection[AccountNumber, String](_.value)(AccountNumber.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[AccountNumber] = JdbcDecoder.stringDecoder.map(AccountNumber.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[AccountNumber] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[AccountNumber] = JsonDecoder.string.map(AccountNumber.apply) + implicit lazy val jsonEncoder: JsonEncoder[AccountNumber] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[AccountNumber] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[AccountNumber] = ParameterMetaData.instance[AccountNumber](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[AccountNumber] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Flag.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Flag.scala new file mode 100644 index 0000000000..02bc80b413 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Flag.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.Flag` + * No constraint + */ +case class Flag(value: Boolean) extends AnyVal +object Flag { + implicit lazy val arraySetter: Setter[Array[Flag]] = adventureworks.BooleanArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[Flag, Boolean] = Bijection[Flag, Boolean](_.value)(Flag.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[Flag] = JdbcDecoder.booleanDecoder.map(Flag.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[Flag] = JdbcEncoder.booleanEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Flag] = JsonDecoder.boolean.map(Flag.apply) + implicit lazy val jsonEncoder: JsonEncoder[Flag] = JsonEncoder.boolean.contramap(_.value) + implicit lazy val ordering: Ordering[Flag] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Flag] = ParameterMetaData.instance[Flag](ParameterMetaData.BooleanParameterMetaData.sqlType, ParameterMetaData.BooleanParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Flag] = Setter.booleanSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Mydomain.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Mydomain.scala new file mode 100644 index 0000000000..2b9b54a7ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Mydomain.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.mydomain` + * No constraint + */ +case class Mydomain(value: String) extends AnyVal +object Mydomain { + implicit lazy val arraySetter: Setter[Array[Mydomain]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[Mydomain, String] = Bijection[Mydomain, String](_.value)(Mydomain.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[Mydomain] = JdbcDecoder.stringDecoder.map(Mydomain.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[Mydomain] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Mydomain] = JsonDecoder.string.map(Mydomain.apply) + implicit lazy val jsonEncoder: JsonEncoder[Mydomain] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Mydomain] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Mydomain] = ParameterMetaData.instance[Mydomain](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Mydomain] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Myenum.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Myenum.scala new file mode 100644 index 0000000000..62d2ddb8cd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Myenum.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +import java.sql.ResultSet +import typo.dsl.ParameterMetaData +import zio.jdbc.JdbcDecoder +import zio.jdbc.JdbcDecoderError +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment.Setter +import zio.json.JsonDecoder +import zio.json.JsonEncoder + +/** Enum `public.myenum` + * - a + * - b + * - c + */ +sealed abstract class Myenum(val value: String) + +object Myenum { + def apply(str: String): Either[String, Myenum] = + ByName.get(str).toRight(s"'$str' does not match any of the following legal values: $Names") + def force(str: String): Myenum = + apply(str) match { + case Left(msg) => sys.error(msg) + case Right(value) => value + } + case object a extends Myenum("a") + case object b extends Myenum("b") + case object c extends Myenum("c") + val All: List[Myenum] = List(a, b, c) + val Names: String = All.map(_.value).mkString(", ") + val ByName: Map[String, Myenum] = All.map(x => (x.value, x)).toMap + + implicit lazy val arrayJdbcDecoder: JdbcDecoder[Array[Myenum]] = adventureworks.StringArrayDecoder.map(a => if (a == null) null else a.map(force)) + implicit lazy val arrayJdbcEncoder: JdbcEncoder[Array[Myenum]] = JdbcEncoder.singleParamEncoder(arraySetter) + implicit lazy val arraySetter: Setter[Array[Myenum]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val jdbcDecoder: JdbcDecoder[Myenum] = JdbcDecoder.stringDecoder.flatMap { s => + new JdbcDecoder[Myenum] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, Myenum) = { + def error(msg: String): JdbcDecoderError = + JdbcDecoderError( + message = s"Error decoding Myenum from ResultSet", + cause = new RuntimeException(msg), + metadata = rs.getMetaData, + row = rs.getRow + ) + + Myenum.apply(s).fold(e => throw error(e), (columIndex, _)) + } + } + } + implicit lazy val jdbcEncoder: JdbcEncoder[Myenum] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Myenum] = JsonDecoder.string.mapOrFail(Myenum.apply) + implicit lazy val jsonEncoder: JsonEncoder[Myenum] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Myenum] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Myenum] = ParameterMetaData.instance[Myenum](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Myenum] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Name.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Name.scala new file mode 100644 index 0000000000..9fb6994f37 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Name.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.Name` + * No constraint + */ +case class Name(value: String) extends AnyVal +object Name { + implicit lazy val arraySetter: Setter[Array[Name]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[Name, String] = Bijection[Name, String](_.value)(Name.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[Name] = JdbcDecoder.stringDecoder.map(Name.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[Name] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Name] = JsonDecoder.string.map(Name.apply) + implicit lazy val jsonEncoder: JsonEncoder[Name] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Name] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Name] = ParameterMetaData.instance[Name](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Name] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/NameStyle.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/NameStyle.scala new file mode 100644 index 0000000000..95996d7b1c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/NameStyle.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.NameStyle` + * No constraint + */ +case class NameStyle(value: Boolean) extends AnyVal +object NameStyle { + implicit lazy val arraySetter: Setter[Array[NameStyle]] = adventureworks.BooleanArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[NameStyle, Boolean] = Bijection[NameStyle, Boolean](_.value)(NameStyle.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[NameStyle] = JdbcDecoder.booleanDecoder.map(NameStyle.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[NameStyle] = JdbcEncoder.booleanEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[NameStyle] = JsonDecoder.boolean.map(NameStyle.apply) + implicit lazy val jsonEncoder: JsonEncoder[NameStyle] = JsonEncoder.boolean.contramap(_.value) + implicit lazy val ordering: Ordering[NameStyle] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[NameStyle] = ParameterMetaData.instance[NameStyle](ParameterMetaData.BooleanParameterMetaData.sqlType, ParameterMetaData.BooleanParameterMetaData.jdbcType) + implicit lazy val setter: Setter[NameStyle] = Setter.booleanSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/OrderNumber.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/OrderNumber.scala new file mode 100644 index 0000000000..6699dde5bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/OrderNumber.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.OrderNumber` + * No constraint + */ +case class OrderNumber(value: String) extends AnyVal +object OrderNumber { + implicit lazy val arraySetter: Setter[Array[OrderNumber]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[OrderNumber, String] = Bijection[OrderNumber, String](_.value)(OrderNumber.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[OrderNumber] = JdbcDecoder.stringDecoder.map(OrderNumber.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[OrderNumber] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[OrderNumber] = JsonDecoder.string.map(OrderNumber.apply) + implicit lazy val jsonEncoder: JsonEncoder[OrderNumber] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[OrderNumber] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[OrderNumber] = ParameterMetaData.instance[OrderNumber](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[OrderNumber] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Phone.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Phone.scala new file mode 100644 index 0000000000..e700e838f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/Phone.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public + +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 + +/** Domain `public.Phone` + * No constraint + */ +case class Phone(value: String) extends AnyVal +object Phone { + implicit lazy val arraySetter: Setter[Array[Phone]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[Phone, String] = Bijection[Phone, String](_.value)(Phone.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[Phone] = JdbcDecoder.stringDecoder.map(Phone.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[Phone] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[Phone] = JsonDecoder.string.map(Phone.apply) + implicit lazy val jsonEncoder: JsonEncoder[Phone] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[Phone] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[Phone] = ParameterMetaData.instance[Phone](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[Phone] = Setter.stringSetter.contramap(_.value) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestFields.scala new file mode 100644 index 0000000000..16e50c3232 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestFields.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtest + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.SqlExpr.Field + +trait PgtestFields[Row] { + val bool: Field[Boolean, Row] + val box: Field[TypoBox, Row] + val bpchar: Field[/* bpchar, max 3 chars */ String, Row] + val bytea: Field[TypoBytea, Row] + val char: Field[/* bpchar, max 1 chars */ String, Row] + val circle: Field[TypoCircle, Row] + val date: Field[TypoLocalDate, Row] + val float4: Field[Float, Row] + val float8: Field[Double, Row] + val hstore: Field[TypoHStore, Row] + val inet: Field[TypoInet, Row] + val int2: Field[TypoShort, Row] + val int2vector: Field[TypoInt2Vector, Row] + val int4: Field[Int, Row] + val int8: Field[Long, Row] + val interval: Field[TypoInterval, Row] + val json: Field[TypoJson, Row] + val jsonb: Field[TypoJsonb, Row] + val line: Field[TypoLine, Row] + val lseg: Field[TypoLineSegment, Row] + val money: Field[TypoMoney, Row] + val mydomain: Field[Mydomain, Row] + val myenum: Field[Myenum, Row] + val name: Field[String, Row] + val numeric: Field[BigDecimal, Row] + val path: Field[TypoPath, Row] + val point: Field[TypoPoint, Row] + val polygon: Field[TypoPolygon, Row] + val text: Field[String, Row] + val time: Field[TypoLocalTime, Row] + val timestamp: Field[TypoLocalDateTime, Row] + val timestampz: Field[TypoInstant, Row] + val timez: Field[TypoOffsetTime, Row] + val uuid: Field[TypoUUID, Row] + val varchar: Field[String, Row] + val vector: Field[TypoVector, Row] + val xml: Field[TypoXml, Row] + val boxes: Field[Array[TypoBox], Row] + val bpchares: Field[Array[/* bpchar */ String], Row] + val chares: Field[Array[/* bpchar */ String], Row] + val circlees: Field[Array[TypoCircle], Row] + val datees: Field[Array[TypoLocalDate], Row] + val float4es: Field[Array[Float], Row] + val float8es: Field[Array[Double], Row] + val inetes: Field[Array[TypoInet], Row] + val int2es: Field[Array[TypoShort], Row] + val int2vectores: Field[Array[TypoInt2Vector], Row] + val int4es: Field[Array[Int], Row] + val int8es: Field[Array[Long], Row] + val intervales: Field[Array[TypoInterval], Row] + val jsones: Field[Array[TypoJson], Row] + val jsonbes: Field[Array[TypoJsonb], Row] + val linees: Field[Array[TypoLine], Row] + val lseges: Field[Array[TypoLineSegment], Row] + val moneyes: Field[Array[TypoMoney], Row] + val myenumes: Field[Array[Myenum], Row] + val namees: Field[Array[String], Row] + val numerices: Field[Array[BigDecimal], Row] + val pathes: Field[Array[TypoPath], Row] + val pointes: Field[Array[TypoPoint], Row] + val polygones: Field[Array[TypoPolygon], Row] + val textes: Field[Array[String], Row] + val timees: Field[Array[TypoLocalTime], Row] + val timestampes: Field[Array[TypoLocalDateTime], Row] + val timestampzes: Field[Array[TypoInstant], Row] + val timezes: Field[Array[TypoOffsetTime], Row] + val uuides: Field[Array[TypoUUID], Row] + val varchares: Field[Array[String], Row] + val xmles: Field[Array[TypoXml], Row] +} +object PgtestFields extends PgtestStructure[PgtestRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepo.scala new file mode 100644 index 0000000000..d7d362f3c8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtest + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgtestRepo { + def delete: DeleteBuilder[PgtestFields, PgtestRow] + def insert(unsaved: PgtestRow): ZIO[ZConnection, Throwable, PgtestRow] + def select: SelectBuilder[PgtestFields, PgtestRow] + def selectAll: ZStream[ZConnection, Throwable, PgtestRow] + def update: UpdateBuilder[PgtestFields, PgtestRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepoImpl.scala new file mode 100644 index 0000000000..9d5203afe8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtest + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgtestRepoImpl extends PgtestRepo { + override def delete: DeleteBuilder[PgtestFields, PgtestRow] = { + DeleteBuilder("public.pgtest", PgtestFields) + } + override def insert(unsaved: PgtestRow): ZIO[ZConnection, Throwable, PgtestRow] = { + sql"""insert into public.pgtest("bool", "box", "bpchar", "bytea", "char", "circle", "date", "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money", "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time", "timestamp", "timestampz", "timez", "uuid", "varchar", "vector", "xml", "boxes", "bpchares", "chares", "circlees", "datees", "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes", "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees", "timestampes", "timestampzes", "timezes", "uuides", "varchares", "xmles") + values (${Segment.paramSegment(unsaved.bool)(Setter.booleanSetter)}, ${Segment.paramSegment(unsaved.box)(TypoBox.setter)}::box, ${Segment.paramSegment(unsaved.bpchar)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.bytea)(TypoBytea.setter)}::bytea, ${Segment.paramSegment(unsaved.char)(Setter.stringSetter)}::bpchar, ${Segment.paramSegment(unsaved.circle)(TypoCircle.setter)}::circle, ${Segment.paramSegment(unsaved.date)(TypoLocalDate.setter)}::date, ${Segment.paramSegment(unsaved.float4)(Setter.floatSetter)}::float4, ${Segment.paramSegment(unsaved.float8)(Setter.doubleSetter)}::float8, ${Segment.paramSegment(unsaved.hstore)(TypoHStore.setter)}::hstore, ${Segment.paramSegment(unsaved.inet)(TypoInet.setter)}::inet, ${Segment.paramSegment(unsaved.int2)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.int2vector)(TypoInt2Vector.setter)}::int2vector, ${Segment.paramSegment(unsaved.int4)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.int8)(Setter.longSetter)}::int8, ${Segment.paramSegment(unsaved.interval)(TypoInterval.setter)}::interval, ${Segment.paramSegment(unsaved.json)(TypoJson.setter)}::json, ${Segment.paramSegment(unsaved.jsonb)(TypoJsonb.setter)}::jsonb, ${Segment.paramSegment(unsaved.line)(TypoLine.setter)}::line, ${Segment.paramSegment(unsaved.lseg)(TypoLineSegment.setter)}::lseg, ${Segment.paramSegment(unsaved.money)(TypoMoney.setter)}::money, ${Segment.paramSegment(unsaved.mydomain)(Mydomain.setter)}::text, ${Segment.paramSegment(unsaved.myenum)(Myenum.setter)}::public.myenum, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}::name, ${Segment.paramSegment(unsaved.numeric)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.path)(TypoPath.setter)}::path, ${Segment.paramSegment(unsaved.point)(TypoPoint.setter)}::point, ${Segment.paramSegment(unsaved.polygon)(TypoPolygon.setter)}::polygon, ${Segment.paramSegment(unsaved.text)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.time)(TypoLocalTime.setter)}::time, ${Segment.paramSegment(unsaved.timestamp)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.timestampz)(TypoInstant.setter)}::timestamptz, ${Segment.paramSegment(unsaved.timez)(TypoOffsetTime.setter)}::timetz, ${Segment.paramSegment(unsaved.uuid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.varchar)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.vector)(TypoVector.setter)}::vector, ${Segment.paramSegment(unsaved.xml)(TypoXml.setter)}::xml, ${Segment.paramSegment(unsaved.boxes)(TypoBox.arraySetter)}::_box, ${Segment.paramSegment(unsaved.bpchares)(adventureworks.StringArraySetter)}::_bpchar, ${Segment.paramSegment(unsaved.chares)(adventureworks.StringArraySetter)}::_bpchar, ${Segment.paramSegment(unsaved.circlees)(TypoCircle.arraySetter)}::_circle, ${Segment.paramSegment(unsaved.datees)(TypoLocalDate.arraySetter)}::_date, ${Segment.paramSegment(unsaved.float4es)(adventureworks.FloatArraySetter)}::_float4, ${Segment.paramSegment(unsaved.float8es)(adventureworks.DoubleArraySetter)}::_float8, ${Segment.paramSegment(unsaved.inetes)(TypoInet.arraySetter)}::_inet, ${Segment.paramSegment(unsaved.int2es)(TypoShort.arraySetter)}::_int2, ${Segment.paramSegment(unsaved.int2vectores)(TypoInt2Vector.arraySetter)}::_int2vector, ${Segment.paramSegment(unsaved.int4es)(adventureworks.IntArraySetter)}::_int4, ${Segment.paramSegment(unsaved.int8es)(adventureworks.LongArraySetter)}::_int8, ${Segment.paramSegment(unsaved.intervales)(TypoInterval.arraySetter)}::_interval, ${Segment.paramSegment(unsaved.jsones)(TypoJson.arraySetter)}::_json, ${Segment.paramSegment(unsaved.jsonbes)(TypoJsonb.arraySetter)}::_jsonb, ${Segment.paramSegment(unsaved.linees)(TypoLine.arraySetter)}::_line, ${Segment.paramSegment(unsaved.lseges)(TypoLineSegment.arraySetter)}::_lseg, ${Segment.paramSegment(unsaved.moneyes)(TypoMoney.arraySetter)}::_money, ${Segment.paramSegment(unsaved.myenumes)(Myenum.arraySetter)}::_myenum, ${Segment.paramSegment(unsaved.namees)(adventureworks.StringArraySetter)}::_name, ${Segment.paramSegment(unsaved.numerices)(adventureworks.ScalaBigDecimalArraySetter)}::_numeric, ${Segment.paramSegment(unsaved.pathes)(TypoPath.arraySetter)}::_path, ${Segment.paramSegment(unsaved.pointes)(TypoPoint.arraySetter)}::_point, ${Segment.paramSegment(unsaved.polygones)(TypoPolygon.arraySetter)}::_polygon, ${Segment.paramSegment(unsaved.textes)(adventureworks.StringArraySetter)}::_text, ${Segment.paramSegment(unsaved.timees)(TypoLocalTime.arraySetter)}::_time, ${Segment.paramSegment(unsaved.timestampes)(TypoLocalDateTime.arraySetter)}::_timestamp, ${Segment.paramSegment(unsaved.timestampzes)(TypoInstant.arraySetter)}::_timestamptz, ${Segment.paramSegment(unsaved.timezes)(TypoOffsetTime.arraySetter)}::_timetz, ${Segment.paramSegment(unsaved.uuides)(TypoUUID.arraySetter)}::_uuid, ${Segment.paramSegment(unsaved.varchares)(adventureworks.StringArraySetter)}::_varchar, ${Segment.paramSegment(unsaved.xmles)(TypoXml.arraySetter)}::_xml) + returning "bool", "box", "bpchar", "bytea", "char", "circle", "date"::text, "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money"::numeric, "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time"::text, "timestamp"::text, "timestampz"::text, "timez"::text, "uuid", "varchar", "vector"::float4[], "xml", "boxes", "bpchares", "chares", "circlees", "datees"::text[], "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes"::numeric[], "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees"::text[], "timestampes"::text[], "timestampzes"::text[], "timezes"::text[], "uuides", "varchares", "xmles" + """.insertReturning(PgtestRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgtestFields, PgtestRow] = { + SelectBuilderSql("public.pgtest", PgtestFields, PgtestRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgtestRow] = { + sql"""select "bool", "box", "bpchar", "bytea", "char", "circle", "date"::text, "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money"::numeric, "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time"::text, "timestamp"::text, "timestampz"::text, "timez"::text, "uuid", "varchar", "vector"::float4[], "xml", "boxes", "bpchares", "chares", "circlees", "datees"::text[], "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes"::numeric[], "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees"::text[], "timestampes"::text[], "timestampzes"::text[], "timezes"::text[], "uuides", "varchares", "xmles" from public.pgtest""".query(PgtestRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[PgtestFields, PgtestRow] = { + UpdateBuilder("public.pgtest", PgtestFields, PgtestRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRow.scala new file mode 100644 index 0000000000..7fd0a2f947 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestRow.scala @@ -0,0 +1,477 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtest + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgtestRow( + bool: Boolean, + box: TypoBox, + bpchar: /* bpchar, max 3 chars */ String, + bytea: TypoBytea, + char: /* bpchar, max 1 chars */ String, + circle: TypoCircle, + date: TypoLocalDate, + float4: Float, + float8: Double, + hstore: TypoHStore, + inet: TypoInet, + int2: TypoShort, + int2vector: TypoInt2Vector, + int4: Int, + int8: Long, + interval: TypoInterval, + json: TypoJson, + jsonb: TypoJsonb, + line: TypoLine, + lseg: TypoLineSegment, + money: TypoMoney, + mydomain: Mydomain, + myenum: Myenum, + name: String, + numeric: BigDecimal, + path: TypoPath, + point: TypoPoint, + polygon: TypoPolygon, + text: String, + time: TypoLocalTime, + timestamp: TypoLocalDateTime, + timestampz: TypoInstant, + timez: TypoOffsetTime, + uuid: TypoUUID, + varchar: String, + vector: TypoVector, + xml: TypoXml, + boxes: Array[TypoBox], + bpchares: Array[/* bpchar */ String], + chares: Array[/* bpchar */ String], + circlees: Array[TypoCircle], + datees: Array[TypoLocalDate], + float4es: Array[Float], + float8es: Array[Double], + inetes: Array[TypoInet], + int2es: Array[TypoShort], + int2vectores: Array[TypoInt2Vector], + int4es: Array[Int], + int8es: Array[Long], + intervales: Array[TypoInterval], + jsones: Array[TypoJson], + jsonbes: Array[TypoJsonb], + linees: Array[TypoLine], + lseges: Array[TypoLineSegment], + moneyes: Array[TypoMoney], + myenumes: Array[Myenum], + namees: Array[String], + numerices: Array[BigDecimal], + pathes: Array[TypoPath], + pointes: Array[TypoPoint], + polygones: Array[TypoPolygon], + textes: Array[String], + timees: Array[TypoLocalTime], + timestampes: Array[TypoLocalDateTime], + timestampzes: Array[TypoInstant], + timezes: Array[TypoOffsetTime], + uuides: Array[TypoUUID], + varchares: Array[String], + xmles: Array[TypoXml] +) + +object PgtestRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgtestRow] = new JdbcDecoder[PgtestRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgtestRow) = + columIndex + 68 -> + PgtestRow( + bool = JdbcDecoder.booleanDecoder.unsafeDecode(columIndex + 0, rs)._2, + box = TypoBox.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + bpchar = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + bytea = TypoBytea.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + char = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + circle = TypoCircle.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + date = TypoLocalDate.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + float4 = JdbcDecoder.floatDecoder.unsafeDecode(columIndex + 7, rs)._2, + float8 = JdbcDecoder.doubleDecoder.unsafeDecode(columIndex + 8, rs)._2, + hstore = TypoHStore.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + inet = TypoInet.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + int2 = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2, + int2vector = TypoInt2Vector.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + int4 = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 13, rs)._2, + int8 = JdbcDecoder.longDecoder.unsafeDecode(columIndex + 14, rs)._2, + interval = TypoInterval.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + json = TypoJson.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + jsonb = TypoJsonb.jdbcDecoder.unsafeDecode(columIndex + 17, rs)._2, + line = TypoLine.jdbcDecoder.unsafeDecode(columIndex + 18, rs)._2, + lseg = TypoLineSegment.jdbcDecoder.unsafeDecode(columIndex + 19, rs)._2, + money = TypoMoney.jdbcDecoder.unsafeDecode(columIndex + 20, rs)._2, + mydomain = Mydomain.jdbcDecoder.unsafeDecode(columIndex + 21, rs)._2, + myenum = Myenum.jdbcDecoder.unsafeDecode(columIndex + 22, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 23, rs)._2, + numeric = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 24, rs)._2, + path = TypoPath.jdbcDecoder.unsafeDecode(columIndex + 25, rs)._2, + point = TypoPoint.jdbcDecoder.unsafeDecode(columIndex + 26, rs)._2, + polygon = TypoPolygon.jdbcDecoder.unsafeDecode(columIndex + 27, rs)._2, + text = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 28, rs)._2, + time = TypoLocalTime.jdbcDecoder.unsafeDecode(columIndex + 29, rs)._2, + timestamp = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 30, rs)._2, + timestampz = TypoInstant.jdbcDecoder.unsafeDecode(columIndex + 31, rs)._2, + timez = TypoOffsetTime.jdbcDecoder.unsafeDecode(columIndex + 32, rs)._2, + uuid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 33, rs)._2, + varchar = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 34, rs)._2, + vector = TypoVector.jdbcDecoder.unsafeDecode(columIndex + 35, rs)._2, + xml = TypoXml.jdbcDecoder.unsafeDecode(columIndex + 36, rs)._2, + boxes = JdbcDecoder[Array[TypoBox]].unsafeDecode(columIndex + 37, rs)._2, + bpchares = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 38, rs)._2, + chares = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 39, rs)._2, + circlees = JdbcDecoder[Array[TypoCircle]].unsafeDecode(columIndex + 40, rs)._2, + datees = JdbcDecoder[Array[TypoLocalDate]].unsafeDecode(columIndex + 41, rs)._2, + float4es = adventureworks.FloatArrayDecoder.unsafeDecode(columIndex + 42, rs)._2, + float8es = adventureworks.DoubleArrayDecoder.unsafeDecode(columIndex + 43, rs)._2, + inetes = JdbcDecoder[Array[TypoInet]].unsafeDecode(columIndex + 44, rs)._2, + int2es = JdbcDecoder[Array[TypoShort]].unsafeDecode(columIndex + 45, rs)._2, + int2vectores = JdbcDecoder[Array[TypoInt2Vector]].unsafeDecode(columIndex + 46, rs)._2, + int4es = adventureworks.IntArrayDecoder.unsafeDecode(columIndex + 47, rs)._2, + int8es = adventureworks.LongArrayDecoder.unsafeDecode(columIndex + 48, rs)._2, + intervales = JdbcDecoder[Array[TypoInterval]].unsafeDecode(columIndex + 49, rs)._2, + jsones = JdbcDecoder[Array[TypoJson]].unsafeDecode(columIndex + 50, rs)._2, + jsonbes = JdbcDecoder[Array[TypoJsonb]].unsafeDecode(columIndex + 51, rs)._2, + linees = JdbcDecoder[Array[TypoLine]].unsafeDecode(columIndex + 52, rs)._2, + lseges = JdbcDecoder[Array[TypoLineSegment]].unsafeDecode(columIndex + 53, rs)._2, + moneyes = JdbcDecoder[Array[TypoMoney]].unsafeDecode(columIndex + 54, rs)._2, + myenumes = JdbcDecoder[Array[Myenum]].unsafeDecode(columIndex + 55, rs)._2, + namees = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 56, rs)._2, + numerices = adventureworks.ScalaBigDecimalArrayDecoder.unsafeDecode(columIndex + 57, rs)._2, + pathes = JdbcDecoder[Array[TypoPath]].unsafeDecode(columIndex + 58, rs)._2, + pointes = JdbcDecoder[Array[TypoPoint]].unsafeDecode(columIndex + 59, rs)._2, + polygones = JdbcDecoder[Array[TypoPolygon]].unsafeDecode(columIndex + 60, rs)._2, + textes = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 61, rs)._2, + timees = JdbcDecoder[Array[TypoLocalTime]].unsafeDecode(columIndex + 62, rs)._2, + timestampes = JdbcDecoder[Array[TypoLocalDateTime]].unsafeDecode(columIndex + 63, rs)._2, + timestampzes = JdbcDecoder[Array[TypoInstant]].unsafeDecode(columIndex + 64, rs)._2, + timezes = JdbcDecoder[Array[TypoOffsetTime]].unsafeDecode(columIndex + 65, rs)._2, + uuides = JdbcDecoder[Array[TypoUUID]].unsafeDecode(columIndex + 66, rs)._2, + varchares = adventureworks.StringArrayDecoder.unsafeDecode(columIndex + 67, rs)._2, + xmles = JdbcDecoder[Array[TypoXml]].unsafeDecode(columIndex + 68, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgtestRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val bool = jsonObj.get("bool").toRight("Missing field 'bool'").flatMap(_.as(JsonDecoder.boolean)) + val box = jsonObj.get("box").toRight("Missing field 'box'").flatMap(_.as(TypoBox.jsonDecoder)) + val bpchar = jsonObj.get("bpchar").toRight("Missing field 'bpchar'").flatMap(_.as(JsonDecoder.string)) + val bytea = jsonObj.get("bytea").toRight("Missing field 'bytea'").flatMap(_.as(TypoBytea.jsonDecoder)) + val char = jsonObj.get("char").toRight("Missing field 'char'").flatMap(_.as(JsonDecoder.string)) + val circle = jsonObj.get("circle").toRight("Missing field 'circle'").flatMap(_.as(TypoCircle.jsonDecoder)) + val date = jsonObj.get("date").toRight("Missing field 'date'").flatMap(_.as(TypoLocalDate.jsonDecoder)) + val float4 = jsonObj.get("float4").toRight("Missing field 'float4'").flatMap(_.as(JsonDecoder.float)) + val float8 = jsonObj.get("float8").toRight("Missing field 'float8'").flatMap(_.as(JsonDecoder.double)) + val hstore = jsonObj.get("hstore").toRight("Missing field 'hstore'").flatMap(_.as(TypoHStore.jsonDecoder)) + val inet = jsonObj.get("inet").toRight("Missing field 'inet'").flatMap(_.as(TypoInet.jsonDecoder)) + val int2 = jsonObj.get("int2").toRight("Missing field 'int2'").flatMap(_.as(TypoShort.jsonDecoder)) + val int2vector = jsonObj.get("int2vector").toRight("Missing field 'int2vector'").flatMap(_.as(TypoInt2Vector.jsonDecoder)) + val int4 = jsonObj.get("int4").toRight("Missing field 'int4'").flatMap(_.as(JsonDecoder.int)) + val int8 = jsonObj.get("int8").toRight("Missing field 'int8'").flatMap(_.as(JsonDecoder.long)) + val interval = jsonObj.get("interval").toRight("Missing field 'interval'").flatMap(_.as(TypoInterval.jsonDecoder)) + val json = jsonObj.get("json").toRight("Missing field 'json'").flatMap(_.as(TypoJson.jsonDecoder)) + val jsonb = jsonObj.get("jsonb").toRight("Missing field 'jsonb'").flatMap(_.as(TypoJsonb.jsonDecoder)) + val line = jsonObj.get("line").toRight("Missing field 'line'").flatMap(_.as(TypoLine.jsonDecoder)) + val lseg = jsonObj.get("lseg").toRight("Missing field 'lseg'").flatMap(_.as(TypoLineSegment.jsonDecoder)) + val money = jsonObj.get("money").toRight("Missing field 'money'").flatMap(_.as(TypoMoney.jsonDecoder)) + val mydomain = jsonObj.get("mydomain").toRight("Missing field 'mydomain'").flatMap(_.as(Mydomain.jsonDecoder)) + val myenum = jsonObj.get("myenum").toRight("Missing field 'myenum'").flatMap(_.as(Myenum.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val numeric = jsonObj.get("numeric").toRight("Missing field 'numeric'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val path = jsonObj.get("path").toRight("Missing field 'path'").flatMap(_.as(TypoPath.jsonDecoder)) + val point = jsonObj.get("point").toRight("Missing field 'point'").flatMap(_.as(TypoPoint.jsonDecoder)) + val polygon = jsonObj.get("polygon").toRight("Missing field 'polygon'").flatMap(_.as(TypoPolygon.jsonDecoder)) + val text = jsonObj.get("text").toRight("Missing field 'text'").flatMap(_.as(JsonDecoder.string)) + val time = jsonObj.get("time").toRight("Missing field 'time'").flatMap(_.as(TypoLocalTime.jsonDecoder)) + val timestamp = jsonObj.get("timestamp").toRight("Missing field 'timestamp'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val timestampz = jsonObj.get("timestampz").toRight("Missing field 'timestampz'").flatMap(_.as(TypoInstant.jsonDecoder)) + val timez = jsonObj.get("timez").toRight("Missing field 'timez'").flatMap(_.as(TypoOffsetTime.jsonDecoder)) + val uuid = jsonObj.get("uuid").toRight("Missing field 'uuid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val varchar = jsonObj.get("varchar").toRight("Missing field 'varchar'").flatMap(_.as(JsonDecoder.string)) + val vector = jsonObj.get("vector").toRight("Missing field 'vector'").flatMap(_.as(TypoVector.jsonDecoder)) + val xml = jsonObj.get("xml").toRight("Missing field 'xml'").flatMap(_.as(TypoXml.jsonDecoder)) + val boxes = jsonObj.get("boxes").toRight("Missing field 'boxes'").flatMap(_.as(JsonDecoder.array[TypoBox](TypoBox.jsonDecoder, implicitly))) + val bpchares = jsonObj.get("bpchares").toRight("Missing field 'bpchares'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val chares = jsonObj.get("chares").toRight("Missing field 'chares'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val circlees = jsonObj.get("circlees").toRight("Missing field 'circlees'").flatMap(_.as(JsonDecoder.array[TypoCircle](TypoCircle.jsonDecoder, implicitly))) + val datees = jsonObj.get("datees").toRight("Missing field 'datees'").flatMap(_.as(JsonDecoder.array[TypoLocalDate](TypoLocalDate.jsonDecoder, implicitly))) + val float4es = jsonObj.get("float4es").toRight("Missing field 'float4es'").flatMap(_.as(JsonDecoder.array[Float](JsonDecoder.float, implicitly))) + val float8es = jsonObj.get("float8es").toRight("Missing field 'float8es'").flatMap(_.as(JsonDecoder.array[Double](JsonDecoder.double, implicitly))) + val inetes = jsonObj.get("inetes").toRight("Missing field 'inetes'").flatMap(_.as(JsonDecoder.array[TypoInet](TypoInet.jsonDecoder, implicitly))) + val int2es = jsonObj.get("int2es").toRight("Missing field 'int2es'").flatMap(_.as(JsonDecoder.array[TypoShort](TypoShort.jsonDecoder, implicitly))) + val int2vectores = jsonObj.get("int2vectores").toRight("Missing field 'int2vectores'").flatMap(_.as(JsonDecoder.array[TypoInt2Vector](TypoInt2Vector.jsonDecoder, implicitly))) + val int4es = jsonObj.get("int4es").toRight("Missing field 'int4es'").flatMap(_.as(JsonDecoder.array[Int](JsonDecoder.int, implicitly))) + val int8es = jsonObj.get("int8es").toRight("Missing field 'int8es'").flatMap(_.as(JsonDecoder.array[Long](JsonDecoder.long, implicitly))) + val intervales = jsonObj.get("intervales").toRight("Missing field 'intervales'").flatMap(_.as(JsonDecoder.array[TypoInterval](TypoInterval.jsonDecoder, implicitly))) + val jsones = jsonObj.get("jsones").toRight("Missing field 'jsones'").flatMap(_.as(JsonDecoder.array[TypoJson](TypoJson.jsonDecoder, implicitly))) + val jsonbes = jsonObj.get("jsonbes").toRight("Missing field 'jsonbes'").flatMap(_.as(JsonDecoder.array[TypoJsonb](TypoJsonb.jsonDecoder, implicitly))) + val linees = jsonObj.get("linees").toRight("Missing field 'linees'").flatMap(_.as(JsonDecoder.array[TypoLine](TypoLine.jsonDecoder, implicitly))) + val lseges = jsonObj.get("lseges").toRight("Missing field 'lseges'").flatMap(_.as(JsonDecoder.array[TypoLineSegment](TypoLineSegment.jsonDecoder, implicitly))) + val moneyes = jsonObj.get("moneyes").toRight("Missing field 'moneyes'").flatMap(_.as(JsonDecoder.array[TypoMoney](TypoMoney.jsonDecoder, implicitly))) + val myenumes = jsonObj.get("myenumes").toRight("Missing field 'myenumes'").flatMap(_.as(JsonDecoder.array[Myenum](Myenum.jsonDecoder, implicitly))) + val namees = jsonObj.get("namees").toRight("Missing field 'namees'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val numerices = jsonObj.get("numerices").toRight("Missing field 'numerices'").flatMap(_.as(JsonDecoder.array[BigDecimal](JsonDecoder.scalaBigDecimal, implicitly))) + val pathes = jsonObj.get("pathes").toRight("Missing field 'pathes'").flatMap(_.as(JsonDecoder.array[TypoPath](TypoPath.jsonDecoder, implicitly))) + val pointes = jsonObj.get("pointes").toRight("Missing field 'pointes'").flatMap(_.as(JsonDecoder.array[TypoPoint](TypoPoint.jsonDecoder, implicitly))) + val polygones = jsonObj.get("polygones").toRight("Missing field 'polygones'").flatMap(_.as(JsonDecoder.array[TypoPolygon](TypoPolygon.jsonDecoder, implicitly))) + val textes = jsonObj.get("textes").toRight("Missing field 'textes'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val timees = jsonObj.get("timees").toRight("Missing field 'timees'").flatMap(_.as(JsonDecoder.array[TypoLocalTime](TypoLocalTime.jsonDecoder, implicitly))) + val timestampes = jsonObj.get("timestampes").toRight("Missing field 'timestampes'").flatMap(_.as(JsonDecoder.array[TypoLocalDateTime](TypoLocalDateTime.jsonDecoder, implicitly))) + val timestampzes = jsonObj.get("timestampzes").toRight("Missing field 'timestampzes'").flatMap(_.as(JsonDecoder.array[TypoInstant](TypoInstant.jsonDecoder, implicitly))) + val timezes = jsonObj.get("timezes").toRight("Missing field 'timezes'").flatMap(_.as(JsonDecoder.array[TypoOffsetTime](TypoOffsetTime.jsonDecoder, implicitly))) + val uuides = jsonObj.get("uuides").toRight("Missing field 'uuides'").flatMap(_.as(JsonDecoder.array[TypoUUID](TypoUUID.jsonDecoder, implicitly))) + val varchares = jsonObj.get("varchares").toRight("Missing field 'varchares'").flatMap(_.as(JsonDecoder.array[String](JsonDecoder.string, implicitly))) + val xmles = jsonObj.get("xmles").toRight("Missing field 'xmles'").flatMap(_.as(JsonDecoder.array[TypoXml](TypoXml.jsonDecoder, implicitly))) + if (bool.isRight && box.isRight && bpchar.isRight && bytea.isRight && char.isRight && circle.isRight && date.isRight && float4.isRight && float8.isRight && hstore.isRight && inet.isRight && int2.isRight && int2vector.isRight && int4.isRight && int8.isRight && interval.isRight && json.isRight && jsonb.isRight && line.isRight && lseg.isRight && money.isRight && mydomain.isRight && myenum.isRight && name.isRight && numeric.isRight && path.isRight && point.isRight && polygon.isRight && text.isRight && time.isRight && timestamp.isRight && timestampz.isRight && timez.isRight && uuid.isRight && varchar.isRight && vector.isRight && xml.isRight && boxes.isRight && bpchares.isRight && chares.isRight && circlees.isRight && datees.isRight && float4es.isRight && float8es.isRight && inetes.isRight && int2es.isRight && int2vectores.isRight && int4es.isRight && int8es.isRight && intervales.isRight && jsones.isRight && jsonbes.isRight && linees.isRight && lseges.isRight && moneyes.isRight && myenumes.isRight && namees.isRight && numerices.isRight && pathes.isRight && pointes.isRight && polygones.isRight && textes.isRight && timees.isRight && timestampes.isRight && timestampzes.isRight && timezes.isRight && uuides.isRight && varchares.isRight && xmles.isRight) + Right(PgtestRow(bool = bool.toOption.get, box = box.toOption.get, bpchar = bpchar.toOption.get, bytea = bytea.toOption.get, char = char.toOption.get, circle = circle.toOption.get, date = date.toOption.get, float4 = float4.toOption.get, float8 = float8.toOption.get, hstore = hstore.toOption.get, inet = inet.toOption.get, int2 = int2.toOption.get, int2vector = int2vector.toOption.get, int4 = int4.toOption.get, int8 = int8.toOption.get, interval = interval.toOption.get, json = json.toOption.get, jsonb = jsonb.toOption.get, line = line.toOption.get, lseg = lseg.toOption.get, money = money.toOption.get, mydomain = mydomain.toOption.get, myenum = myenum.toOption.get, name = name.toOption.get, numeric = numeric.toOption.get, path = path.toOption.get, point = point.toOption.get, polygon = polygon.toOption.get, text = text.toOption.get, time = time.toOption.get, timestamp = timestamp.toOption.get, timestampz = timestampz.toOption.get, timez = timez.toOption.get, uuid = uuid.toOption.get, varchar = varchar.toOption.get, vector = vector.toOption.get, xml = xml.toOption.get, boxes = boxes.toOption.get, bpchares = bpchares.toOption.get, chares = chares.toOption.get, circlees = circlees.toOption.get, datees = datees.toOption.get, float4es = float4es.toOption.get, float8es = float8es.toOption.get, inetes = inetes.toOption.get, int2es = int2es.toOption.get, int2vectores = int2vectores.toOption.get, int4es = int4es.toOption.get, int8es = int8es.toOption.get, intervales = intervales.toOption.get, jsones = jsones.toOption.get, jsonbes = jsonbes.toOption.get, linees = linees.toOption.get, lseges = lseges.toOption.get, moneyes = moneyes.toOption.get, myenumes = myenumes.toOption.get, namees = namees.toOption.get, numerices = numerices.toOption.get, pathes = pathes.toOption.get, pointes = pointes.toOption.get, polygones = polygones.toOption.get, textes = textes.toOption.get, timees = timees.toOption.get, timestampes = timestampes.toOption.get, timestampzes = timestampzes.toOption.get, timezes = timezes.toOption.get, uuides = uuides.toOption.get, varchares = varchares.toOption.get, xmles = xmles.toOption.get)) + else Left(List[Either[String, Any]](bool, box, bpchar, bytea, char, circle, date, float4, float8, hstore, inet, int2, int2vector, int4, int8, interval, json, jsonb, line, lseg, money, mydomain, myenum, name, numeric, path, point, polygon, text, time, timestamp, timestampz, timez, uuid, varchar, vector, xml, boxes, bpchares, chares, circlees, datees, float4es, float8es, inetes, int2es, int2vectores, int4es, int8es, intervales, jsones, jsonbes, linees, lseges, moneyes, myenumes, namees, numerices, pathes, pointes, polygones, textes, timees, timestampes, timestampzes, timezes, uuides, varchares, xmles).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgtestRow] = new JsonEncoder[PgtestRow] { + override def unsafeEncode(a: PgtestRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""bool":""") + JsonEncoder.boolean.unsafeEncode(a.bool, indent, out) + out.write(",") + out.write(""""box":""") + TypoBox.jsonEncoder.unsafeEncode(a.box, indent, out) + out.write(",") + out.write(""""bpchar":""") + JsonEncoder.string.unsafeEncode(a.bpchar, indent, out) + out.write(",") + out.write(""""bytea":""") + TypoBytea.jsonEncoder.unsafeEncode(a.bytea, indent, out) + out.write(",") + out.write(""""char":""") + JsonEncoder.string.unsafeEncode(a.char, indent, out) + out.write(",") + out.write(""""circle":""") + TypoCircle.jsonEncoder.unsafeEncode(a.circle, indent, out) + out.write(",") + out.write(""""date":""") + TypoLocalDate.jsonEncoder.unsafeEncode(a.date, indent, out) + out.write(",") + out.write(""""float4":""") + JsonEncoder.float.unsafeEncode(a.float4, indent, out) + out.write(",") + out.write(""""float8":""") + JsonEncoder.double.unsafeEncode(a.float8, indent, out) + out.write(",") + out.write(""""hstore":""") + TypoHStore.jsonEncoder.unsafeEncode(a.hstore, indent, out) + out.write(",") + out.write(""""inet":""") + TypoInet.jsonEncoder.unsafeEncode(a.inet, indent, out) + out.write(",") + out.write(""""int2":""") + TypoShort.jsonEncoder.unsafeEncode(a.int2, indent, out) + out.write(",") + out.write(""""int2vector":""") + TypoInt2Vector.jsonEncoder.unsafeEncode(a.int2vector, indent, out) + out.write(",") + out.write(""""int4":""") + JsonEncoder.int.unsafeEncode(a.int4, indent, out) + out.write(",") + out.write(""""int8":""") + JsonEncoder.long.unsafeEncode(a.int8, indent, out) + out.write(",") + out.write(""""interval":""") + TypoInterval.jsonEncoder.unsafeEncode(a.interval, indent, out) + out.write(",") + out.write(""""json":""") + TypoJson.jsonEncoder.unsafeEncode(a.json, indent, out) + out.write(",") + out.write(""""jsonb":""") + TypoJsonb.jsonEncoder.unsafeEncode(a.jsonb, indent, out) + out.write(",") + out.write(""""line":""") + TypoLine.jsonEncoder.unsafeEncode(a.line, indent, out) + out.write(",") + out.write(""""lseg":""") + TypoLineSegment.jsonEncoder.unsafeEncode(a.lseg, indent, out) + out.write(",") + out.write(""""money":""") + TypoMoney.jsonEncoder.unsafeEncode(a.money, indent, out) + out.write(",") + out.write(""""mydomain":""") + Mydomain.jsonEncoder.unsafeEncode(a.mydomain, indent, out) + out.write(",") + out.write(""""myenum":""") + Myenum.jsonEncoder.unsafeEncode(a.myenum, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""numeric":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.numeric, indent, out) + out.write(",") + out.write(""""path":""") + TypoPath.jsonEncoder.unsafeEncode(a.path, indent, out) + out.write(",") + out.write(""""point":""") + TypoPoint.jsonEncoder.unsafeEncode(a.point, indent, out) + out.write(",") + out.write(""""polygon":""") + TypoPolygon.jsonEncoder.unsafeEncode(a.polygon, indent, out) + out.write(",") + out.write(""""text":""") + JsonEncoder.string.unsafeEncode(a.text, indent, out) + out.write(",") + out.write(""""time":""") + TypoLocalTime.jsonEncoder.unsafeEncode(a.time, indent, out) + out.write(",") + out.write(""""timestamp":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.timestamp, indent, out) + out.write(",") + out.write(""""timestampz":""") + TypoInstant.jsonEncoder.unsafeEncode(a.timestampz, indent, out) + out.write(",") + out.write(""""timez":""") + TypoOffsetTime.jsonEncoder.unsafeEncode(a.timez, indent, out) + out.write(",") + out.write(""""uuid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.uuid, indent, out) + out.write(",") + out.write(""""varchar":""") + JsonEncoder.string.unsafeEncode(a.varchar, indent, out) + out.write(",") + out.write(""""vector":""") + TypoVector.jsonEncoder.unsafeEncode(a.vector, indent, out) + out.write(",") + out.write(""""xml":""") + TypoXml.jsonEncoder.unsafeEncode(a.xml, indent, out) + out.write(",") + out.write(""""boxes":""") + JsonEncoder.array[TypoBox](TypoBox.jsonEncoder, implicitly).unsafeEncode(a.boxes, indent, out) + out.write(",") + out.write(""""bpchares":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.bpchares, indent, out) + out.write(",") + out.write(""""chares":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.chares, indent, out) + out.write(",") + out.write(""""circlees":""") + JsonEncoder.array[TypoCircle](TypoCircle.jsonEncoder, implicitly).unsafeEncode(a.circlees, indent, out) + out.write(",") + out.write(""""datees":""") + JsonEncoder.array[TypoLocalDate](TypoLocalDate.jsonEncoder, implicitly).unsafeEncode(a.datees, indent, out) + out.write(",") + out.write(""""float4es":""") + JsonEncoder.array[Float](JsonEncoder.float, implicitly).unsafeEncode(a.float4es, indent, out) + out.write(",") + out.write(""""float8es":""") + JsonEncoder.array[Double](JsonEncoder.double, implicitly).unsafeEncode(a.float8es, indent, out) + out.write(",") + out.write(""""inetes":""") + JsonEncoder.array[TypoInet](TypoInet.jsonEncoder, implicitly).unsafeEncode(a.inetes, indent, out) + out.write(",") + out.write(""""int2es":""") + JsonEncoder.array[TypoShort](TypoShort.jsonEncoder, implicitly).unsafeEncode(a.int2es, indent, out) + out.write(",") + out.write(""""int2vectores":""") + JsonEncoder.array[TypoInt2Vector](TypoInt2Vector.jsonEncoder, implicitly).unsafeEncode(a.int2vectores, indent, out) + out.write(",") + out.write(""""int4es":""") + JsonEncoder.array[Int](JsonEncoder.int, implicitly).unsafeEncode(a.int4es, indent, out) + out.write(",") + out.write(""""int8es":""") + JsonEncoder.array[Long](JsonEncoder.long, implicitly).unsafeEncode(a.int8es, indent, out) + out.write(",") + out.write(""""intervales":""") + JsonEncoder.array[TypoInterval](TypoInterval.jsonEncoder, implicitly).unsafeEncode(a.intervales, indent, out) + out.write(",") + out.write(""""jsones":""") + JsonEncoder.array[TypoJson](TypoJson.jsonEncoder, implicitly).unsafeEncode(a.jsones, indent, out) + out.write(",") + out.write(""""jsonbes":""") + JsonEncoder.array[TypoJsonb](TypoJsonb.jsonEncoder, implicitly).unsafeEncode(a.jsonbes, indent, out) + out.write(",") + out.write(""""linees":""") + JsonEncoder.array[TypoLine](TypoLine.jsonEncoder, implicitly).unsafeEncode(a.linees, indent, out) + out.write(",") + out.write(""""lseges":""") + JsonEncoder.array[TypoLineSegment](TypoLineSegment.jsonEncoder, implicitly).unsafeEncode(a.lseges, indent, out) + out.write(",") + out.write(""""moneyes":""") + JsonEncoder.array[TypoMoney](TypoMoney.jsonEncoder, implicitly).unsafeEncode(a.moneyes, indent, out) + out.write(",") + out.write(""""myenumes":""") + JsonEncoder.array[Myenum](Myenum.jsonEncoder, implicitly).unsafeEncode(a.myenumes, indent, out) + out.write(",") + out.write(""""namees":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.namees, indent, out) + out.write(",") + out.write(""""numerices":""") + JsonEncoder.array[BigDecimal](JsonEncoder.scalaBigDecimal, implicitly).unsafeEncode(a.numerices, indent, out) + out.write(",") + out.write(""""pathes":""") + JsonEncoder.array[TypoPath](TypoPath.jsonEncoder, implicitly).unsafeEncode(a.pathes, indent, out) + out.write(",") + out.write(""""pointes":""") + JsonEncoder.array[TypoPoint](TypoPoint.jsonEncoder, implicitly).unsafeEncode(a.pointes, indent, out) + out.write(",") + out.write(""""polygones":""") + JsonEncoder.array[TypoPolygon](TypoPolygon.jsonEncoder, implicitly).unsafeEncode(a.polygones, indent, out) + out.write(",") + out.write(""""textes":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.textes, indent, out) + out.write(",") + out.write(""""timees":""") + JsonEncoder.array[TypoLocalTime](TypoLocalTime.jsonEncoder, implicitly).unsafeEncode(a.timees, indent, out) + out.write(",") + out.write(""""timestampes":""") + JsonEncoder.array[TypoLocalDateTime](TypoLocalDateTime.jsonEncoder, implicitly).unsafeEncode(a.timestampes, indent, out) + out.write(",") + out.write(""""timestampzes":""") + JsonEncoder.array[TypoInstant](TypoInstant.jsonEncoder, implicitly).unsafeEncode(a.timestampzes, indent, out) + out.write(",") + out.write(""""timezes":""") + JsonEncoder.array[TypoOffsetTime](TypoOffsetTime.jsonEncoder, implicitly).unsafeEncode(a.timezes, indent, out) + out.write(",") + out.write(""""uuides":""") + JsonEncoder.array[TypoUUID](TypoUUID.jsonEncoder, implicitly).unsafeEncode(a.uuides, indent, out) + out.write(",") + out.write(""""varchares":""") + JsonEncoder.array[String](JsonEncoder.string, implicitly).unsafeEncode(a.varchares, indent, out) + out.write(",") + out.write(""""xmles":""") + JsonEncoder.array[TypoXml](TypoXml.jsonEncoder, implicitly).unsafeEncode(a.xmles, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestStructure.scala new file mode 100644 index 0000000000..fc9276d7c9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtest/PgtestStructure.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtest + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PgtestStructure[Row](val prefix: Option[String], val extract: Row => PgtestRow, val merge: (Row, PgtestRow) => Row) + extends Relation[PgtestFields, PgtestRow, Row] + with PgtestFields[Row] { outer => + + override val bool = new Field[Boolean, Row](prefix, "bool", None, None)(x => extract(x).bool, (row, value) => merge(row, extract(row).copy(bool = value))) + override val box = new Field[TypoBox, Row](prefix, "box", None, Some("box"))(x => extract(x).box, (row, value) => merge(row, extract(row).copy(box = value))) + override val bpchar = new Field[/* bpchar, max 3 chars */ String, Row](prefix, "bpchar", None, Some("bpchar"))(x => extract(x).bpchar, (row, value) => merge(row, extract(row).copy(bpchar = value))) + override val bytea = new Field[TypoBytea, Row](prefix, "bytea", None, Some("bytea"))(x => extract(x).bytea, (row, value) => merge(row, extract(row).copy(bytea = value))) + override val char = new Field[/* bpchar, max 1 chars */ String, Row](prefix, "char", None, Some("bpchar"))(x => extract(x).char, (row, value) => merge(row, extract(row).copy(char = value))) + override val circle = new Field[TypoCircle, Row](prefix, "circle", None, Some("circle"))(x => extract(x).circle, (row, value) => merge(row, extract(row).copy(circle = value))) + override val date = new Field[TypoLocalDate, Row](prefix, "date", Some("text"), Some("date"))(x => extract(x).date, (row, value) => merge(row, extract(row).copy(date = value))) + override val float4 = new Field[Float, Row](prefix, "float4", None, Some("float4"))(x => extract(x).float4, (row, value) => merge(row, extract(row).copy(float4 = value))) + override val float8 = new Field[Double, Row](prefix, "float8", None, Some("float8"))(x => extract(x).float8, (row, value) => merge(row, extract(row).copy(float8 = value))) + override val hstore = new Field[TypoHStore, Row](prefix, "hstore", None, Some("hstore"))(x => extract(x).hstore, (row, value) => merge(row, extract(row).copy(hstore = value))) + override val inet = new Field[TypoInet, Row](prefix, "inet", None, Some("inet"))(x => extract(x).inet, (row, value) => merge(row, extract(row).copy(inet = value))) + override val int2 = new Field[TypoShort, Row](prefix, "int2", None, Some("int2"))(x => extract(x).int2, (row, value) => merge(row, extract(row).copy(int2 = value))) + override val int2vector = new Field[TypoInt2Vector, Row](prefix, "int2vector", None, Some("int2vector"))(x => extract(x).int2vector, (row, value) => merge(row, extract(row).copy(int2vector = value))) + override val int4 = new Field[Int, Row](prefix, "int4", None, Some("int4"))(x => extract(x).int4, (row, value) => merge(row, extract(row).copy(int4 = value))) + override val int8 = new Field[Long, Row](prefix, "int8", None, Some("int8"))(x => extract(x).int8, (row, value) => merge(row, extract(row).copy(int8 = value))) + override val interval = new Field[TypoInterval, Row](prefix, "interval", None, Some("interval"))(x => extract(x).interval, (row, value) => merge(row, extract(row).copy(interval = value))) + override val json = new Field[TypoJson, Row](prefix, "json", None, Some("json"))(x => extract(x).json, (row, value) => merge(row, extract(row).copy(json = value))) + override val jsonb = new Field[TypoJsonb, Row](prefix, "jsonb", None, Some("jsonb"))(x => extract(x).jsonb, (row, value) => merge(row, extract(row).copy(jsonb = value))) + override val line = new Field[TypoLine, Row](prefix, "line", None, Some("line"))(x => extract(x).line, (row, value) => merge(row, extract(row).copy(line = value))) + override val lseg = new Field[TypoLineSegment, Row](prefix, "lseg", None, Some("lseg"))(x => extract(x).lseg, (row, value) => merge(row, extract(row).copy(lseg = value))) + override val money = new Field[TypoMoney, Row](prefix, "money", Some("numeric"), Some("money"))(x => extract(x).money, (row, value) => merge(row, extract(row).copy(money = value))) + override val mydomain = new Field[Mydomain, Row](prefix, "mydomain", None, Some("text"))(x => extract(x).mydomain, (row, value) => merge(row, extract(row).copy(mydomain = value))) + override val myenum = new Field[Myenum, Row](prefix, "myenum", None, Some("public.myenum"))(x => extract(x).myenum, (row, value) => merge(row, extract(row).copy(myenum = value))) + override val name = new Field[String, Row](prefix, "name", None, Some("name"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val numeric = new Field[BigDecimal, Row](prefix, "numeric", None, Some("numeric"))(x => extract(x).numeric, (row, value) => merge(row, extract(row).copy(numeric = value))) + override val path = new Field[TypoPath, Row](prefix, "path", None, Some("path"))(x => extract(x).path, (row, value) => merge(row, extract(row).copy(path = value))) + override val point = new Field[TypoPoint, Row](prefix, "point", None, Some("point"))(x => extract(x).point, (row, value) => merge(row, extract(row).copy(point = value))) + override val polygon = new Field[TypoPolygon, Row](prefix, "polygon", None, Some("polygon"))(x => extract(x).polygon, (row, value) => merge(row, extract(row).copy(polygon = value))) + override val text = new Field[String, Row](prefix, "text", None, None)(x => extract(x).text, (row, value) => merge(row, extract(row).copy(text = value))) + override val time = new Field[TypoLocalTime, Row](prefix, "time", Some("text"), Some("time"))(x => extract(x).time, (row, value) => merge(row, extract(row).copy(time = value))) + override val timestamp = new Field[TypoLocalDateTime, Row](prefix, "timestamp", Some("text"), Some("timestamp"))(x => extract(x).timestamp, (row, value) => merge(row, extract(row).copy(timestamp = value))) + override val timestampz = new Field[TypoInstant, Row](prefix, "timestampz", Some("text"), Some("timestamptz"))(x => extract(x).timestampz, (row, value) => merge(row, extract(row).copy(timestampz = value))) + override val timez = new Field[TypoOffsetTime, Row](prefix, "timez", Some("text"), Some("timetz"))(x => extract(x).timez, (row, value) => merge(row, extract(row).copy(timez = value))) + override val uuid = new Field[TypoUUID, Row](prefix, "uuid", None, Some("uuid"))(x => extract(x).uuid, (row, value) => merge(row, extract(row).copy(uuid = value))) + override val varchar = new Field[String, Row](prefix, "varchar", None, None)(x => extract(x).varchar, (row, value) => merge(row, extract(row).copy(varchar = value))) + override val vector = new Field[TypoVector, Row](prefix, "vector", Some("float4[]"), Some("vector"))(x => extract(x).vector, (row, value) => merge(row, extract(row).copy(vector = value))) + override val xml = new Field[TypoXml, Row](prefix, "xml", None, Some("xml"))(x => extract(x).xml, (row, value) => merge(row, extract(row).copy(xml = value))) + override val boxes = new Field[Array[TypoBox], Row](prefix, "boxes", None, Some("_box"))(x => extract(x).boxes, (row, value) => merge(row, extract(row).copy(boxes = value))) + override val bpchares = new Field[Array[/* bpchar */ String], Row](prefix, "bpchares", None, Some("_bpchar"))(x => extract(x).bpchares, (row, value) => merge(row, extract(row).copy(bpchares = value))) + override val chares = new Field[Array[/* bpchar */ String], Row](prefix, "chares", None, Some("_bpchar"))(x => extract(x).chares, (row, value) => merge(row, extract(row).copy(chares = value))) + override val circlees = new Field[Array[TypoCircle], Row](prefix, "circlees", None, Some("_circle"))(x => extract(x).circlees, (row, value) => merge(row, extract(row).copy(circlees = value))) + override val datees = new Field[Array[TypoLocalDate], Row](prefix, "datees", Some("text[]"), Some("_date"))(x => extract(x).datees, (row, value) => merge(row, extract(row).copy(datees = value))) + override val float4es = new Field[Array[Float], Row](prefix, "float4es", None, Some("_float4"))(x => extract(x).float4es, (row, value) => merge(row, extract(row).copy(float4es = value))) + override val float8es = new Field[Array[Double], Row](prefix, "float8es", None, Some("_float8"))(x => extract(x).float8es, (row, value) => merge(row, extract(row).copy(float8es = value))) + override val inetes = new Field[Array[TypoInet], Row](prefix, "inetes", None, Some("_inet"))(x => extract(x).inetes, (row, value) => merge(row, extract(row).copy(inetes = value))) + override val int2es = new Field[Array[TypoShort], Row](prefix, "int2es", None, Some("_int2"))(x => extract(x).int2es, (row, value) => merge(row, extract(row).copy(int2es = value))) + override val int2vectores = new Field[Array[TypoInt2Vector], Row](prefix, "int2vectores", None, Some("_int2vector"))(x => extract(x).int2vectores, (row, value) => merge(row, extract(row).copy(int2vectores = value))) + override val int4es = new Field[Array[Int], Row](prefix, "int4es", None, Some("_int4"))(x => extract(x).int4es, (row, value) => merge(row, extract(row).copy(int4es = value))) + override val int8es = new Field[Array[Long], Row](prefix, "int8es", None, Some("_int8"))(x => extract(x).int8es, (row, value) => merge(row, extract(row).copy(int8es = value))) + override val intervales = new Field[Array[TypoInterval], Row](prefix, "intervales", None, Some("_interval"))(x => extract(x).intervales, (row, value) => merge(row, extract(row).copy(intervales = value))) + override val jsones = new Field[Array[TypoJson], Row](prefix, "jsones", None, Some("_json"))(x => extract(x).jsones, (row, value) => merge(row, extract(row).copy(jsones = value))) + override val jsonbes = new Field[Array[TypoJsonb], Row](prefix, "jsonbes", None, Some("_jsonb"))(x => extract(x).jsonbes, (row, value) => merge(row, extract(row).copy(jsonbes = value))) + override val linees = new Field[Array[TypoLine], Row](prefix, "linees", None, Some("_line"))(x => extract(x).linees, (row, value) => merge(row, extract(row).copy(linees = value))) + override val lseges = new Field[Array[TypoLineSegment], Row](prefix, "lseges", None, Some("_lseg"))(x => extract(x).lseges, (row, value) => merge(row, extract(row).copy(lseges = value))) + override val moneyes = new Field[Array[TypoMoney], Row](prefix, "moneyes", Some("numeric[]"), Some("_money"))(x => extract(x).moneyes, (row, value) => merge(row, extract(row).copy(moneyes = value))) + override val myenumes = new Field[Array[Myenum], Row](prefix, "myenumes", None, Some("_myenum"))(x => extract(x).myenumes, (row, value) => merge(row, extract(row).copy(myenumes = value))) + override val namees = new Field[Array[String], Row](prefix, "namees", None, Some("_name"))(x => extract(x).namees, (row, value) => merge(row, extract(row).copy(namees = value))) + override val numerices = new Field[Array[BigDecimal], Row](prefix, "numerices", None, Some("_numeric"))(x => extract(x).numerices, (row, value) => merge(row, extract(row).copy(numerices = value))) + override val pathes = new Field[Array[TypoPath], Row](prefix, "pathes", None, Some("_path"))(x => extract(x).pathes, (row, value) => merge(row, extract(row).copy(pathes = value))) + override val pointes = new Field[Array[TypoPoint], Row](prefix, "pointes", None, Some("_point"))(x => extract(x).pointes, (row, value) => merge(row, extract(row).copy(pointes = value))) + override val polygones = new Field[Array[TypoPolygon], Row](prefix, "polygones", None, Some("_polygon"))(x => extract(x).polygones, (row, value) => merge(row, extract(row).copy(polygones = value))) + override val textes = new Field[Array[String], Row](prefix, "textes", None, Some("_text"))(x => extract(x).textes, (row, value) => merge(row, extract(row).copy(textes = value))) + override val timees = new Field[Array[TypoLocalTime], Row](prefix, "timees", Some("text[]"), Some("_time"))(x => extract(x).timees, (row, value) => merge(row, extract(row).copy(timees = value))) + override val timestampes = new Field[Array[TypoLocalDateTime], Row](prefix, "timestampes", Some("text[]"), Some("_timestamp"))(x => extract(x).timestampes, (row, value) => merge(row, extract(row).copy(timestampes = value))) + override val timestampzes = new Field[Array[TypoInstant], Row](prefix, "timestampzes", Some("text[]"), Some("_timestamptz"))(x => extract(x).timestampzes, (row, value) => merge(row, extract(row).copy(timestampzes = value))) + override val timezes = new Field[Array[TypoOffsetTime], Row](prefix, "timezes", Some("text[]"), Some("_timetz"))(x => extract(x).timezes, (row, value) => merge(row, extract(row).copy(timezes = value))) + override val uuides = new Field[Array[TypoUUID], Row](prefix, "uuides", None, Some("_uuid"))(x => extract(x).uuides, (row, value) => merge(row, extract(row).copy(uuides = value))) + override val varchares = new Field[Array[String], Row](prefix, "varchares", None, Some("_varchar"))(x => extract(x).varchares, (row, value) => merge(row, extract(row).copy(varchares = value))) + override val xmles = new Field[Array[TypoXml], Row](prefix, "xmles", None, Some("_xml"))(x => extract(x).xmles, (row, value) => merge(row, extract(row).copy(xmles = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](bool, box, bpchar, bytea, char, circle, date, float4, float8, hstore, inet, int2, int2vector, int4, int8, interval, json, jsonb, line, lseg, money, mydomain, myenum, name, numeric, path, point, polygon, text, time, timestamp, timestampz, timez, uuid, varchar, vector, xml, boxes, bpchares, chares, circlees, datees, float4es, float8es, inetes, int2es, int2vectores, int4es, int8es, intervales, jsones, jsonbes, linees, lseges, moneyes, myenumes, namees, numerices, pathes, pointes, polygones, textes, timees, timestampes, timestampzes, timezes, uuides, varchares, xmles) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgtestRow, merge: (NewRow, PgtestRow) => NewRow): PgtestStructure[NewRow] = + new PgtestStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullFields.scala new file mode 100644 index 0000000000..74ebafbc89 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullFields.scala @@ -0,0 +1,110 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtestnull + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.SqlExpr.OptField + +trait PgtestnullFields[Row] { + val bool: OptField[Boolean, Row] + val box: OptField[TypoBox, Row] + val bpchar: OptField[/* bpchar, max 3 chars */ String, Row] + val bytea: OptField[TypoBytea, Row] + val char: OptField[/* bpchar, max 1 chars */ String, Row] + val circle: OptField[TypoCircle, Row] + val date: OptField[TypoLocalDate, Row] + val float4: OptField[Float, Row] + val float8: OptField[Double, Row] + val hstore: OptField[TypoHStore, Row] + val inet: OptField[TypoInet, Row] + val int2: OptField[TypoShort, Row] + val int2vector: OptField[TypoInt2Vector, Row] + val int4: OptField[Int, Row] + val int8: OptField[Long, Row] + val interval: OptField[TypoInterval, Row] + val json: OptField[TypoJson, Row] + val jsonb: OptField[TypoJsonb, Row] + val line: OptField[TypoLine, Row] + val lseg: OptField[TypoLineSegment, Row] + val money: OptField[TypoMoney, Row] + val mydomain: OptField[Mydomain, Row] + val myenum: OptField[Myenum, Row] + val name: OptField[String, Row] + val numeric: OptField[BigDecimal, Row] + val path: OptField[TypoPath, Row] + val point: OptField[TypoPoint, Row] + val polygon: OptField[TypoPolygon, Row] + val text: OptField[String, Row] + val time: OptField[TypoLocalTime, Row] + val timestamp: OptField[TypoLocalDateTime, Row] + val timestampz: OptField[TypoInstant, Row] + val timez: OptField[TypoOffsetTime, Row] + val uuid: OptField[TypoUUID, Row] + val varchar: OptField[String, Row] + val vector: OptField[TypoVector, Row] + val xml: OptField[TypoXml, Row] + val boxes: OptField[Array[TypoBox], Row] + val bpchares: OptField[Array[/* bpchar */ String], Row] + val chares: OptField[Array[/* bpchar */ String], Row] + val circlees: OptField[Array[TypoCircle], Row] + val datees: OptField[Array[TypoLocalDate], Row] + val float4es: OptField[Array[Float], Row] + val float8es: OptField[Array[Double], Row] + val inetes: OptField[Array[TypoInet], Row] + val int2es: OptField[Array[TypoShort], Row] + val int2vectores: OptField[Array[TypoInt2Vector], Row] + val int4es: OptField[Array[Int], Row] + val int8es: OptField[Array[Long], Row] + val intervales: OptField[Array[TypoInterval], Row] + val jsones: OptField[Array[TypoJson], Row] + val jsonbes: OptField[Array[TypoJsonb], Row] + val linees: OptField[Array[TypoLine], Row] + val lseges: OptField[Array[TypoLineSegment], Row] + val moneyes: OptField[Array[TypoMoney], Row] + val myenumes: OptField[Array[Myenum], Row] + val namees: OptField[Array[String], Row] + val numerices: OptField[Array[BigDecimal], Row] + val pathes: OptField[Array[TypoPath], Row] + val pointes: OptField[Array[TypoPoint], Row] + val polygones: OptField[Array[TypoPolygon], Row] + val textes: OptField[Array[String], Row] + val timees: OptField[Array[TypoLocalTime], Row] + val timestampes: OptField[Array[TypoLocalDateTime], Row] + val timestampzes: OptField[Array[TypoInstant], Row] + val timezes: OptField[Array[TypoOffsetTime], Row] + val uuides: OptField[Array[TypoUUID], Row] + val varchares: OptField[Array[String], Row] + val xmles: OptField[Array[TypoXml], Row] +} +object PgtestnullFields extends PgtestnullStructure[PgtestnullRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepo.scala new file mode 100644 index 0000000000..82a0288e99 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepo.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtestnull + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PgtestnullRepo { + def delete: DeleteBuilder[PgtestnullFields, PgtestnullRow] + def insert(unsaved: PgtestnullRow): ZIO[ZConnection, Throwable, PgtestnullRow] + def select: SelectBuilder[PgtestnullFields, PgtestnullRow] + def selectAll: ZStream[ZConnection, Throwable, PgtestnullRow] + def update: UpdateBuilder[PgtestnullFields, PgtestnullRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepoImpl.scala new file mode 100644 index 0000000000..0f26aa1e54 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRepoImpl.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtestnull + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PgtestnullRepoImpl extends PgtestnullRepo { + override def delete: DeleteBuilder[PgtestnullFields, PgtestnullRow] = { + DeleteBuilder("public.pgtestnull", PgtestnullFields) + } + override def insert(unsaved: PgtestnullRow): ZIO[ZConnection, Throwable, PgtestnullRow] = { + sql"""insert into public.pgtestnull("bool", "box", "bpchar", "bytea", "char", "circle", "date", "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money", "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time", "timestamp", "timestampz", "timez", "uuid", "varchar", "vector", "xml", "boxes", "bpchares", "chares", "circlees", "datees", "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes", "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees", "timestampes", "timestampzes", "timezes", "uuides", "varchares", "xmles") + values (${Segment.paramSegment(unsaved.bool)(Setter.optionParamSetter(Setter.booleanSetter))}, ${Segment.paramSegment(unsaved.box)(Setter.optionParamSetter(TypoBox.setter))}::box, ${Segment.paramSegment(unsaved.bpchar)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, ${Segment.paramSegment(unsaved.bytea)(Setter.optionParamSetter(TypoBytea.setter))}::bytea, ${Segment.paramSegment(unsaved.char)(Setter.optionParamSetter(Setter.stringSetter))}::bpchar, ${Segment.paramSegment(unsaved.circle)(Setter.optionParamSetter(TypoCircle.setter))}::circle, ${Segment.paramSegment(unsaved.date)(Setter.optionParamSetter(TypoLocalDate.setter))}::date, ${Segment.paramSegment(unsaved.float4)(Setter.optionParamSetter(Setter.floatSetter))}::float4, ${Segment.paramSegment(unsaved.float8)(Setter.optionParamSetter(Setter.doubleSetter))}::float8, ${Segment.paramSegment(unsaved.hstore)(Setter.optionParamSetter(TypoHStore.setter))}::hstore, ${Segment.paramSegment(unsaved.inet)(Setter.optionParamSetter(TypoInet.setter))}::inet, ${Segment.paramSegment(unsaved.int2)(Setter.optionParamSetter(TypoShort.setter))}::int2, ${Segment.paramSegment(unsaved.int2vector)(Setter.optionParamSetter(TypoInt2Vector.setter))}::int2vector, ${Segment.paramSegment(unsaved.int4)(Setter.optionParamSetter(Setter.intSetter))}::int4, ${Segment.paramSegment(unsaved.int8)(Setter.optionParamSetter(Setter.longSetter))}::int8, ${Segment.paramSegment(unsaved.interval)(Setter.optionParamSetter(TypoInterval.setter))}::interval, ${Segment.paramSegment(unsaved.json)(Setter.optionParamSetter(TypoJson.setter))}::json, ${Segment.paramSegment(unsaved.jsonb)(Setter.optionParamSetter(TypoJsonb.setter))}::jsonb, ${Segment.paramSegment(unsaved.line)(Setter.optionParamSetter(TypoLine.setter))}::line, ${Segment.paramSegment(unsaved.lseg)(Setter.optionParamSetter(TypoLineSegment.setter))}::lseg, ${Segment.paramSegment(unsaved.money)(Setter.optionParamSetter(TypoMoney.setter))}::money, ${Segment.paramSegment(unsaved.mydomain)(Setter.optionParamSetter(Mydomain.setter))}::text, ${Segment.paramSegment(unsaved.myenum)(Setter.optionParamSetter(Myenum.setter))}::public.myenum, ${Segment.paramSegment(unsaved.name)(Setter.optionParamSetter(Setter.stringSetter))}::name, ${Segment.paramSegment(unsaved.numeric)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.path)(Setter.optionParamSetter(TypoPath.setter))}::path, ${Segment.paramSegment(unsaved.point)(Setter.optionParamSetter(TypoPoint.setter))}::point, ${Segment.paramSegment(unsaved.polygon)(Setter.optionParamSetter(TypoPolygon.setter))}::polygon, ${Segment.paramSegment(unsaved.text)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.time)(Setter.optionParamSetter(TypoLocalTime.setter))}::time, ${Segment.paramSegment(unsaved.timestamp)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.timestampz)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz, ${Segment.paramSegment(unsaved.timez)(Setter.optionParamSetter(TypoOffsetTime.setter))}::timetz, ${Segment.paramSegment(unsaved.uuid)(Setter.optionParamSetter(TypoUUID.setter))}::uuid, ${Segment.paramSegment(unsaved.varchar)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.vector)(Setter.optionParamSetter(TypoVector.setter))}::vector, ${Segment.paramSegment(unsaved.xml)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.boxes)(Setter.optionParamSetter(TypoBox.arraySetter))}::_box, ${Segment.paramSegment(unsaved.bpchares)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_bpchar, ${Segment.paramSegment(unsaved.chares)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_bpchar, ${Segment.paramSegment(unsaved.circlees)(Setter.optionParamSetter(TypoCircle.arraySetter))}::_circle, ${Segment.paramSegment(unsaved.datees)(Setter.optionParamSetter(TypoLocalDate.arraySetter))}::_date, ${Segment.paramSegment(unsaved.float4es)(Setter.optionParamSetter(adventureworks.FloatArraySetter))}::_float4, ${Segment.paramSegment(unsaved.float8es)(Setter.optionParamSetter(adventureworks.DoubleArraySetter))}::_float8, ${Segment.paramSegment(unsaved.inetes)(Setter.optionParamSetter(TypoInet.arraySetter))}::_inet, ${Segment.paramSegment(unsaved.int2es)(Setter.optionParamSetter(TypoShort.arraySetter))}::_int2, ${Segment.paramSegment(unsaved.int2vectores)(Setter.optionParamSetter(TypoInt2Vector.arraySetter))}::_int2vector, ${Segment.paramSegment(unsaved.int4es)(Setter.optionParamSetter(adventureworks.IntArraySetter))}::_int4, ${Segment.paramSegment(unsaved.int8es)(Setter.optionParamSetter(adventureworks.LongArraySetter))}::_int8, ${Segment.paramSegment(unsaved.intervales)(Setter.optionParamSetter(TypoInterval.arraySetter))}::_interval, ${Segment.paramSegment(unsaved.jsones)(Setter.optionParamSetter(TypoJson.arraySetter))}::_json, ${Segment.paramSegment(unsaved.jsonbes)(Setter.optionParamSetter(TypoJsonb.arraySetter))}::_jsonb, ${Segment.paramSegment(unsaved.linees)(Setter.optionParamSetter(TypoLine.arraySetter))}::_line, ${Segment.paramSegment(unsaved.lseges)(Setter.optionParamSetter(TypoLineSegment.arraySetter))}::_lseg, ${Segment.paramSegment(unsaved.moneyes)(Setter.optionParamSetter(TypoMoney.arraySetter))}::_money, ${Segment.paramSegment(unsaved.myenumes)(Setter.optionParamSetter(Myenum.arraySetter))}::_myenum, ${Segment.paramSegment(unsaved.namees)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_name, ${Segment.paramSegment(unsaved.numerices)(Setter.optionParamSetter(adventureworks.ScalaBigDecimalArraySetter))}::_numeric, ${Segment.paramSegment(unsaved.pathes)(Setter.optionParamSetter(TypoPath.arraySetter))}::_path, ${Segment.paramSegment(unsaved.pointes)(Setter.optionParamSetter(TypoPoint.arraySetter))}::_point, ${Segment.paramSegment(unsaved.polygones)(Setter.optionParamSetter(TypoPolygon.arraySetter))}::_polygon, ${Segment.paramSegment(unsaved.textes)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_text, ${Segment.paramSegment(unsaved.timees)(Setter.optionParamSetter(TypoLocalTime.arraySetter))}::_time, ${Segment.paramSegment(unsaved.timestampes)(Setter.optionParamSetter(TypoLocalDateTime.arraySetter))}::_timestamp, ${Segment.paramSegment(unsaved.timestampzes)(Setter.optionParamSetter(TypoInstant.arraySetter))}::_timestamptz, ${Segment.paramSegment(unsaved.timezes)(Setter.optionParamSetter(TypoOffsetTime.arraySetter))}::_timetz, ${Segment.paramSegment(unsaved.uuides)(Setter.optionParamSetter(TypoUUID.arraySetter))}::_uuid, ${Segment.paramSegment(unsaved.varchares)(Setter.optionParamSetter(adventureworks.StringArraySetter))}::_varchar, ${Segment.paramSegment(unsaved.xmles)(Setter.optionParamSetter(TypoXml.arraySetter))}::_xml) + returning "bool", "box", "bpchar", "bytea", "char", "circle", "date"::text, "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money"::numeric, "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time"::text, "timestamp"::text, "timestampz"::text, "timez"::text, "uuid", "varchar", "vector"::float4[], "xml", "boxes", "bpchares", "chares", "circlees", "datees"::text[], "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes"::numeric[], "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees"::text[], "timestampes"::text[], "timestampzes"::text[], "timezes"::text[], "uuides", "varchares", "xmles" + """.insertReturning(PgtestnullRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def select: SelectBuilder[PgtestnullFields, PgtestnullRow] = { + SelectBuilderSql("public.pgtestnull", PgtestnullFields, PgtestnullRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PgtestnullRow] = { + sql"""select "bool", "box", "bpchar", "bytea", "char", "circle", "date"::text, "float4", "float8", "hstore", "inet", "int2", "int2vector", "int4", "int8", "interval", "json", "jsonb", "line", "lseg", "money"::numeric, "mydomain", "myenum", "name", "numeric", "path", "point", "polygon", "text", "time"::text, "timestamp"::text, "timestampz"::text, "timez"::text, "uuid", "varchar", "vector"::float4[], "xml", "boxes", "bpchares", "chares", "circlees", "datees"::text[], "float4es", "float8es", "inetes", "int2es", "int2vectores", "int4es", "int8es", "intervales", "jsones", "jsonbes", "linees", "lseges", "moneyes"::numeric[], "myenumes", "namees", "numerices", "pathes", "pointes", "polygones", "textes", "timees"::text[], "timestampes"::text[], "timestampzes"::text[], "timezes"::text[], "uuides", "varchares", "xmles" from public.pgtestnull""".query(PgtestnullRow.jdbcDecoder).selectStream + } + override def update: UpdateBuilder[PgtestnullFields, PgtestnullRow] = { + UpdateBuilder("public.pgtestnull", PgtestnullFields, PgtestnullRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRow.scala new file mode 100644 index 0000000000..b10a7cb35e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullRow.scala @@ -0,0 +1,477 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtestnull + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PgtestnullRow( + bool: Option[Boolean], + box: Option[TypoBox], + bpchar: Option[/* bpchar, max 3 chars */ String], + bytea: Option[TypoBytea], + char: Option[/* bpchar, max 1 chars */ String], + circle: Option[TypoCircle], + date: Option[TypoLocalDate], + float4: Option[Float], + float8: Option[Double], + hstore: Option[TypoHStore], + inet: Option[TypoInet], + int2: Option[TypoShort], + int2vector: Option[TypoInt2Vector], + int4: Option[Int], + int8: Option[Long], + interval: Option[TypoInterval], + json: Option[TypoJson], + jsonb: Option[TypoJsonb], + line: Option[TypoLine], + lseg: Option[TypoLineSegment], + money: Option[TypoMoney], + mydomain: Option[Mydomain], + myenum: Option[Myenum], + name: Option[String], + numeric: Option[BigDecimal], + path: Option[TypoPath], + point: Option[TypoPoint], + polygon: Option[TypoPolygon], + text: Option[String], + time: Option[TypoLocalTime], + timestamp: Option[TypoLocalDateTime], + timestampz: Option[TypoInstant], + timez: Option[TypoOffsetTime], + uuid: Option[TypoUUID], + varchar: Option[String], + vector: Option[TypoVector], + xml: Option[TypoXml], + boxes: Option[Array[TypoBox]], + bpchares: Option[Array[/* bpchar */ String]], + chares: Option[Array[/* bpchar */ String]], + circlees: Option[Array[TypoCircle]], + datees: Option[Array[TypoLocalDate]], + float4es: Option[Array[Float]], + float8es: Option[Array[Double]], + inetes: Option[Array[TypoInet]], + int2es: Option[Array[TypoShort]], + int2vectores: Option[Array[TypoInt2Vector]], + int4es: Option[Array[Int]], + int8es: Option[Array[Long]], + intervales: Option[Array[TypoInterval]], + jsones: Option[Array[TypoJson]], + jsonbes: Option[Array[TypoJsonb]], + linees: Option[Array[TypoLine]], + lseges: Option[Array[TypoLineSegment]], + moneyes: Option[Array[TypoMoney]], + myenumes: Option[Array[Myenum]], + namees: Option[Array[String]], + numerices: Option[Array[BigDecimal]], + pathes: Option[Array[TypoPath]], + pointes: Option[Array[TypoPoint]], + polygones: Option[Array[TypoPolygon]], + textes: Option[Array[String]], + timees: Option[Array[TypoLocalTime]], + timestampes: Option[Array[TypoLocalDateTime]], + timestampzes: Option[Array[TypoInstant]], + timezes: Option[Array[TypoOffsetTime]], + uuides: Option[Array[TypoUUID]], + varchares: Option[Array[String]], + xmles: Option[Array[TypoXml]] +) + +object PgtestnullRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PgtestnullRow] = new JdbcDecoder[PgtestnullRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PgtestnullRow) = + columIndex + 68 -> + PgtestnullRow( + bool = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 0, rs)._2, + box = JdbcDecoder.optionDecoder(TypoBox.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + bpchar = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + bytea = JdbcDecoder.optionDecoder(TypoBytea.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + char = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + circle = JdbcDecoder.optionDecoder(TypoCircle.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + date = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + float4 = JdbcDecoder.optionDecoder(JdbcDecoder.floatDecoder).unsafeDecode(columIndex + 7, rs)._2, + float8 = JdbcDecoder.optionDecoder(JdbcDecoder.doubleDecoder).unsafeDecode(columIndex + 8, rs)._2, + hstore = JdbcDecoder.optionDecoder(TypoHStore.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + inet = JdbcDecoder.optionDecoder(TypoInet.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + int2 = JdbcDecoder.optionDecoder(TypoShort.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + int2vector = JdbcDecoder.optionDecoder(TypoInt2Vector.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + int4 = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 13, rs)._2, + int8 = JdbcDecoder.optionDecoder(JdbcDecoder.longDecoder).unsafeDecode(columIndex + 14, rs)._2, + interval = JdbcDecoder.optionDecoder(TypoInterval.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + json = JdbcDecoder.optionDecoder(TypoJson.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + jsonb = JdbcDecoder.optionDecoder(TypoJsonb.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + line = JdbcDecoder.optionDecoder(TypoLine.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + lseg = JdbcDecoder.optionDecoder(TypoLineSegment.jdbcDecoder).unsafeDecode(columIndex + 19, rs)._2, + money = JdbcDecoder.optionDecoder(TypoMoney.jdbcDecoder).unsafeDecode(columIndex + 20, rs)._2, + mydomain = JdbcDecoder.optionDecoder(Mydomain.jdbcDecoder).unsafeDecode(columIndex + 21, rs)._2, + myenum = JdbcDecoder.optionDecoder(Myenum.jdbcDecoder).unsafeDecode(columIndex + 22, rs)._2, + name = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + numeric = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 24, rs)._2, + path = JdbcDecoder.optionDecoder(TypoPath.jdbcDecoder).unsafeDecode(columIndex + 25, rs)._2, + point = JdbcDecoder.optionDecoder(TypoPoint.jdbcDecoder).unsafeDecode(columIndex + 26, rs)._2, + polygon = JdbcDecoder.optionDecoder(TypoPolygon.jdbcDecoder).unsafeDecode(columIndex + 27, rs)._2, + text = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 28, rs)._2, + time = JdbcDecoder.optionDecoder(TypoLocalTime.jdbcDecoder).unsafeDecode(columIndex + 29, rs)._2, + timestamp = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 30, rs)._2, + timestampz = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 31, rs)._2, + timez = JdbcDecoder.optionDecoder(TypoOffsetTime.jdbcDecoder).unsafeDecode(columIndex + 32, rs)._2, + uuid = JdbcDecoder.optionDecoder(TypoUUID.jdbcDecoder).unsafeDecode(columIndex + 33, rs)._2, + varchar = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 34, rs)._2, + vector = JdbcDecoder.optionDecoder(TypoVector.jdbcDecoder).unsafeDecode(columIndex + 35, rs)._2, + xml = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 36, rs)._2, + boxes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoBox]]).unsafeDecode(columIndex + 37, rs)._2, + bpchares = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 38, rs)._2, + chares = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 39, rs)._2, + circlees = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoCircle]]).unsafeDecode(columIndex + 40, rs)._2, + datees = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoLocalDate]]).unsafeDecode(columIndex + 41, rs)._2, + float4es = JdbcDecoder.optionDecoder(adventureworks.FloatArrayDecoder).unsafeDecode(columIndex + 42, rs)._2, + float8es = JdbcDecoder.optionDecoder(adventureworks.DoubleArrayDecoder).unsafeDecode(columIndex + 43, rs)._2, + inetes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoInet]]).unsafeDecode(columIndex + 44, rs)._2, + int2es = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoShort]]).unsafeDecode(columIndex + 45, rs)._2, + int2vectores = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoInt2Vector]]).unsafeDecode(columIndex + 46, rs)._2, + int4es = JdbcDecoder.optionDecoder(adventureworks.IntArrayDecoder).unsafeDecode(columIndex + 47, rs)._2, + int8es = JdbcDecoder.optionDecoder(adventureworks.LongArrayDecoder).unsafeDecode(columIndex + 48, rs)._2, + intervales = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoInterval]]).unsafeDecode(columIndex + 49, rs)._2, + jsones = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoJson]]).unsafeDecode(columIndex + 50, rs)._2, + jsonbes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoJsonb]]).unsafeDecode(columIndex + 51, rs)._2, + linees = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoLine]]).unsafeDecode(columIndex + 52, rs)._2, + lseges = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoLineSegment]]).unsafeDecode(columIndex + 53, rs)._2, + moneyes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoMoney]]).unsafeDecode(columIndex + 54, rs)._2, + myenumes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[Myenum]]).unsafeDecode(columIndex + 55, rs)._2, + namees = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 56, rs)._2, + numerices = JdbcDecoder.optionDecoder(adventureworks.ScalaBigDecimalArrayDecoder).unsafeDecode(columIndex + 57, rs)._2, + pathes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoPath]]).unsafeDecode(columIndex + 58, rs)._2, + pointes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoPoint]]).unsafeDecode(columIndex + 59, rs)._2, + polygones = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoPolygon]]).unsafeDecode(columIndex + 60, rs)._2, + textes = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 61, rs)._2, + timees = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoLocalTime]]).unsafeDecode(columIndex + 62, rs)._2, + timestampes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoLocalDateTime]]).unsafeDecode(columIndex + 63, rs)._2, + timestampzes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoInstant]]).unsafeDecode(columIndex + 64, rs)._2, + timezes = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoOffsetTime]]).unsafeDecode(columIndex + 65, rs)._2, + uuides = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoUUID]]).unsafeDecode(columIndex + 66, rs)._2, + varchares = JdbcDecoder.optionDecoder(adventureworks.StringArrayDecoder).unsafeDecode(columIndex + 67, rs)._2, + xmles = JdbcDecoder.optionDecoder(JdbcDecoder[Array[TypoXml]]).unsafeDecode(columIndex + 68, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PgtestnullRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val bool = jsonObj.get("bool").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val box = jsonObj.get("box").fold[Either[String, Option[TypoBox]]](Right(None))(_.as(JsonDecoder.option(TypoBox.jsonDecoder))) + val bpchar = jsonObj.get("bpchar").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val bytea = jsonObj.get("bytea").fold[Either[String, Option[TypoBytea]]](Right(None))(_.as(JsonDecoder.option(TypoBytea.jsonDecoder))) + val char = jsonObj.get("char").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val circle = jsonObj.get("circle").fold[Either[String, Option[TypoCircle]]](Right(None))(_.as(JsonDecoder.option(TypoCircle.jsonDecoder))) + val date = jsonObj.get("date").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val float4 = jsonObj.get("float4").fold[Either[String, Option[Float]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.float))) + val float8 = jsonObj.get("float8").fold[Either[String, Option[Double]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.double))) + val hstore = jsonObj.get("hstore").fold[Either[String, Option[TypoHStore]]](Right(None))(_.as(JsonDecoder.option(TypoHStore.jsonDecoder))) + val inet = jsonObj.get("inet").fold[Either[String, Option[TypoInet]]](Right(None))(_.as(JsonDecoder.option(TypoInet.jsonDecoder))) + val int2 = jsonObj.get("int2").fold[Either[String, Option[TypoShort]]](Right(None))(_.as(JsonDecoder.option(TypoShort.jsonDecoder))) + val int2vector = jsonObj.get("int2vector").fold[Either[String, Option[TypoInt2Vector]]](Right(None))(_.as(JsonDecoder.option(TypoInt2Vector.jsonDecoder))) + val int4 = jsonObj.get("int4").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val int8 = jsonObj.get("int8").fold[Either[String, Option[Long]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.long))) + val interval = jsonObj.get("interval").fold[Either[String, Option[TypoInterval]]](Right(None))(_.as(JsonDecoder.option(TypoInterval.jsonDecoder))) + val json = jsonObj.get("json").fold[Either[String, Option[TypoJson]]](Right(None))(_.as(JsonDecoder.option(TypoJson.jsonDecoder))) + val jsonb = jsonObj.get("jsonb").fold[Either[String, Option[TypoJsonb]]](Right(None))(_.as(JsonDecoder.option(TypoJsonb.jsonDecoder))) + val line = jsonObj.get("line").fold[Either[String, Option[TypoLine]]](Right(None))(_.as(JsonDecoder.option(TypoLine.jsonDecoder))) + val lseg = jsonObj.get("lseg").fold[Either[String, Option[TypoLineSegment]]](Right(None))(_.as(JsonDecoder.option(TypoLineSegment.jsonDecoder))) + val money = jsonObj.get("money").fold[Either[String, Option[TypoMoney]]](Right(None))(_.as(JsonDecoder.option(TypoMoney.jsonDecoder))) + val mydomain = jsonObj.get("mydomain").fold[Either[String, Option[Mydomain]]](Right(None))(_.as(JsonDecoder.option(Mydomain.jsonDecoder))) + val myenum = jsonObj.get("myenum").fold[Either[String, Option[Myenum]]](Right(None))(_.as(JsonDecoder.option(Myenum.jsonDecoder))) + val name = jsonObj.get("name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val numeric = jsonObj.get("numeric").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val path = jsonObj.get("path").fold[Either[String, Option[TypoPath]]](Right(None))(_.as(JsonDecoder.option(TypoPath.jsonDecoder))) + val point = jsonObj.get("point").fold[Either[String, Option[TypoPoint]]](Right(None))(_.as(JsonDecoder.option(TypoPoint.jsonDecoder))) + val polygon = jsonObj.get("polygon").fold[Either[String, Option[TypoPolygon]]](Right(None))(_.as(JsonDecoder.option(TypoPolygon.jsonDecoder))) + val text = jsonObj.get("text").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val time = jsonObj.get("time").fold[Either[String, Option[TypoLocalTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalTime.jsonDecoder))) + val timestamp = jsonObj.get("timestamp").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val timestampz = jsonObj.get("timestampz").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val timez = jsonObj.get("timez").fold[Either[String, Option[TypoOffsetTime]]](Right(None))(_.as(JsonDecoder.option(TypoOffsetTime.jsonDecoder))) + val uuid = jsonObj.get("uuid").fold[Either[String, Option[TypoUUID]]](Right(None))(_.as(JsonDecoder.option(TypoUUID.jsonDecoder))) + val varchar = jsonObj.get("varchar").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val vector = jsonObj.get("vector").fold[Either[String, Option[TypoVector]]](Right(None))(_.as(JsonDecoder.option(TypoVector.jsonDecoder))) + val xml = jsonObj.get("xml").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val boxes = jsonObj.get("boxes").fold[Either[String, Option[Array[TypoBox]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoBox](TypoBox.jsonDecoder, implicitly)))) + val bpchares = jsonObj.get("bpchares").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val chares = jsonObj.get("chares").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val circlees = jsonObj.get("circlees").fold[Either[String, Option[Array[TypoCircle]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoCircle](TypoCircle.jsonDecoder, implicitly)))) + val datees = jsonObj.get("datees").fold[Either[String, Option[Array[TypoLocalDate]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoLocalDate](TypoLocalDate.jsonDecoder, implicitly)))) + val float4es = jsonObj.get("float4es").fold[Either[String, Option[Array[Float]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Float](JsonDecoder.float, implicitly)))) + val float8es = jsonObj.get("float8es").fold[Either[String, Option[Array[Double]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Double](JsonDecoder.double, implicitly)))) + val inetes = jsonObj.get("inetes").fold[Either[String, Option[Array[TypoInet]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoInet](TypoInet.jsonDecoder, implicitly)))) + val int2es = jsonObj.get("int2es").fold[Either[String, Option[Array[TypoShort]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoShort](TypoShort.jsonDecoder, implicitly)))) + val int2vectores = jsonObj.get("int2vectores").fold[Either[String, Option[Array[TypoInt2Vector]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoInt2Vector](TypoInt2Vector.jsonDecoder, implicitly)))) + val int4es = jsonObj.get("int4es").fold[Either[String, Option[Array[Int]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Int](JsonDecoder.int, implicitly)))) + val int8es = jsonObj.get("int8es").fold[Either[String, Option[Array[Long]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Long](JsonDecoder.long, implicitly)))) + val intervales = jsonObj.get("intervales").fold[Either[String, Option[Array[TypoInterval]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoInterval](TypoInterval.jsonDecoder, implicitly)))) + val jsones = jsonObj.get("jsones").fold[Either[String, Option[Array[TypoJson]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoJson](TypoJson.jsonDecoder, implicitly)))) + val jsonbes = jsonObj.get("jsonbes").fold[Either[String, Option[Array[TypoJsonb]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoJsonb](TypoJsonb.jsonDecoder, implicitly)))) + val linees = jsonObj.get("linees").fold[Either[String, Option[Array[TypoLine]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoLine](TypoLine.jsonDecoder, implicitly)))) + val lseges = jsonObj.get("lseges").fold[Either[String, Option[Array[TypoLineSegment]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoLineSegment](TypoLineSegment.jsonDecoder, implicitly)))) + val moneyes = jsonObj.get("moneyes").fold[Either[String, Option[Array[TypoMoney]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoMoney](TypoMoney.jsonDecoder, implicitly)))) + val myenumes = jsonObj.get("myenumes").fold[Either[String, Option[Array[Myenum]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[Myenum](Myenum.jsonDecoder, implicitly)))) + val namees = jsonObj.get("namees").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val numerices = jsonObj.get("numerices").fold[Either[String, Option[Array[BigDecimal]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[BigDecimal](JsonDecoder.scalaBigDecimal, implicitly)))) + val pathes = jsonObj.get("pathes").fold[Either[String, Option[Array[TypoPath]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoPath](TypoPath.jsonDecoder, implicitly)))) + val pointes = jsonObj.get("pointes").fold[Either[String, Option[Array[TypoPoint]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoPoint](TypoPoint.jsonDecoder, implicitly)))) + val polygones = jsonObj.get("polygones").fold[Either[String, Option[Array[TypoPolygon]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoPolygon](TypoPolygon.jsonDecoder, implicitly)))) + val textes = jsonObj.get("textes").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val timees = jsonObj.get("timees").fold[Either[String, Option[Array[TypoLocalTime]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoLocalTime](TypoLocalTime.jsonDecoder, implicitly)))) + val timestampes = jsonObj.get("timestampes").fold[Either[String, Option[Array[TypoLocalDateTime]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoLocalDateTime](TypoLocalDateTime.jsonDecoder, implicitly)))) + val timestampzes = jsonObj.get("timestampzes").fold[Either[String, Option[Array[TypoInstant]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoInstant](TypoInstant.jsonDecoder, implicitly)))) + val timezes = jsonObj.get("timezes").fold[Either[String, Option[Array[TypoOffsetTime]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoOffsetTime](TypoOffsetTime.jsonDecoder, implicitly)))) + val uuides = jsonObj.get("uuides").fold[Either[String, Option[Array[TypoUUID]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoUUID](TypoUUID.jsonDecoder, implicitly)))) + val varchares = jsonObj.get("varchares").fold[Either[String, Option[Array[String]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[String](JsonDecoder.string, implicitly)))) + val xmles = jsonObj.get("xmles").fold[Either[String, Option[Array[TypoXml]]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.array[TypoXml](TypoXml.jsonDecoder, implicitly)))) + if (bool.isRight && box.isRight && bpchar.isRight && bytea.isRight && char.isRight && circle.isRight && date.isRight && float4.isRight && float8.isRight && hstore.isRight && inet.isRight && int2.isRight && int2vector.isRight && int4.isRight && int8.isRight && interval.isRight && json.isRight && jsonb.isRight && line.isRight && lseg.isRight && money.isRight && mydomain.isRight && myenum.isRight && name.isRight && numeric.isRight && path.isRight && point.isRight && polygon.isRight && text.isRight && time.isRight && timestamp.isRight && timestampz.isRight && timez.isRight && uuid.isRight && varchar.isRight && vector.isRight && xml.isRight && boxes.isRight && bpchares.isRight && chares.isRight && circlees.isRight && datees.isRight && float4es.isRight && float8es.isRight && inetes.isRight && int2es.isRight && int2vectores.isRight && int4es.isRight && int8es.isRight && intervales.isRight && jsones.isRight && jsonbes.isRight && linees.isRight && lseges.isRight && moneyes.isRight && myenumes.isRight && namees.isRight && numerices.isRight && pathes.isRight && pointes.isRight && polygones.isRight && textes.isRight && timees.isRight && timestampes.isRight && timestampzes.isRight && timezes.isRight && uuides.isRight && varchares.isRight && xmles.isRight) + Right(PgtestnullRow(bool = bool.toOption.get, box = box.toOption.get, bpchar = bpchar.toOption.get, bytea = bytea.toOption.get, char = char.toOption.get, circle = circle.toOption.get, date = date.toOption.get, float4 = float4.toOption.get, float8 = float8.toOption.get, hstore = hstore.toOption.get, inet = inet.toOption.get, int2 = int2.toOption.get, int2vector = int2vector.toOption.get, int4 = int4.toOption.get, int8 = int8.toOption.get, interval = interval.toOption.get, json = json.toOption.get, jsonb = jsonb.toOption.get, line = line.toOption.get, lseg = lseg.toOption.get, money = money.toOption.get, mydomain = mydomain.toOption.get, myenum = myenum.toOption.get, name = name.toOption.get, numeric = numeric.toOption.get, path = path.toOption.get, point = point.toOption.get, polygon = polygon.toOption.get, text = text.toOption.get, time = time.toOption.get, timestamp = timestamp.toOption.get, timestampz = timestampz.toOption.get, timez = timez.toOption.get, uuid = uuid.toOption.get, varchar = varchar.toOption.get, vector = vector.toOption.get, xml = xml.toOption.get, boxes = boxes.toOption.get, bpchares = bpchares.toOption.get, chares = chares.toOption.get, circlees = circlees.toOption.get, datees = datees.toOption.get, float4es = float4es.toOption.get, float8es = float8es.toOption.get, inetes = inetes.toOption.get, int2es = int2es.toOption.get, int2vectores = int2vectores.toOption.get, int4es = int4es.toOption.get, int8es = int8es.toOption.get, intervales = intervales.toOption.get, jsones = jsones.toOption.get, jsonbes = jsonbes.toOption.get, linees = linees.toOption.get, lseges = lseges.toOption.get, moneyes = moneyes.toOption.get, myenumes = myenumes.toOption.get, namees = namees.toOption.get, numerices = numerices.toOption.get, pathes = pathes.toOption.get, pointes = pointes.toOption.get, polygones = polygones.toOption.get, textes = textes.toOption.get, timees = timees.toOption.get, timestampes = timestampes.toOption.get, timestampzes = timestampzes.toOption.get, timezes = timezes.toOption.get, uuides = uuides.toOption.get, varchares = varchares.toOption.get, xmles = xmles.toOption.get)) + else Left(List[Either[String, Any]](bool, box, bpchar, bytea, char, circle, date, float4, float8, hstore, inet, int2, int2vector, int4, int8, interval, json, jsonb, line, lseg, money, mydomain, myenum, name, numeric, path, point, polygon, text, time, timestamp, timestampz, timez, uuid, varchar, vector, xml, boxes, bpchares, chares, circlees, datees, float4es, float8es, inetes, int2es, int2vectores, int4es, int8es, intervales, jsones, jsonbes, linees, lseges, moneyes, myenumes, namees, numerices, pathes, pointes, polygones, textes, timees, timestampes, timestampzes, timezes, uuides, varchares, xmles).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PgtestnullRow] = new JsonEncoder[PgtestnullRow] { + override def unsafeEncode(a: PgtestnullRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""bool":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.bool, indent, out) + out.write(",") + out.write(""""box":""") + JsonEncoder.option(TypoBox.jsonEncoder).unsafeEncode(a.box, indent, out) + out.write(",") + out.write(""""bpchar":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.bpchar, indent, out) + out.write(",") + out.write(""""bytea":""") + JsonEncoder.option(TypoBytea.jsonEncoder).unsafeEncode(a.bytea, indent, out) + out.write(",") + out.write(""""char":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.char, indent, out) + out.write(",") + out.write(""""circle":""") + JsonEncoder.option(TypoCircle.jsonEncoder).unsafeEncode(a.circle, indent, out) + out.write(",") + out.write(""""date":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.date, indent, out) + out.write(",") + out.write(""""float4":""") + JsonEncoder.option(JsonEncoder.float).unsafeEncode(a.float4, indent, out) + out.write(",") + out.write(""""float8":""") + JsonEncoder.option(JsonEncoder.double).unsafeEncode(a.float8, indent, out) + out.write(",") + out.write(""""hstore":""") + JsonEncoder.option(TypoHStore.jsonEncoder).unsafeEncode(a.hstore, indent, out) + out.write(",") + out.write(""""inet":""") + JsonEncoder.option(TypoInet.jsonEncoder).unsafeEncode(a.inet, indent, out) + out.write(",") + out.write(""""int2":""") + JsonEncoder.option(TypoShort.jsonEncoder).unsafeEncode(a.int2, indent, out) + out.write(",") + out.write(""""int2vector":""") + JsonEncoder.option(TypoInt2Vector.jsonEncoder).unsafeEncode(a.int2vector, indent, out) + out.write(",") + out.write(""""int4":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.int4, indent, out) + out.write(",") + out.write(""""int8":""") + JsonEncoder.option(JsonEncoder.long).unsafeEncode(a.int8, indent, out) + out.write(",") + out.write(""""interval":""") + JsonEncoder.option(TypoInterval.jsonEncoder).unsafeEncode(a.interval, indent, out) + out.write(",") + out.write(""""json":""") + JsonEncoder.option(TypoJson.jsonEncoder).unsafeEncode(a.json, indent, out) + out.write(",") + out.write(""""jsonb":""") + JsonEncoder.option(TypoJsonb.jsonEncoder).unsafeEncode(a.jsonb, indent, out) + out.write(",") + out.write(""""line":""") + JsonEncoder.option(TypoLine.jsonEncoder).unsafeEncode(a.line, indent, out) + out.write(",") + out.write(""""lseg":""") + JsonEncoder.option(TypoLineSegment.jsonEncoder).unsafeEncode(a.lseg, indent, out) + out.write(",") + out.write(""""money":""") + JsonEncoder.option(TypoMoney.jsonEncoder).unsafeEncode(a.money, indent, out) + out.write(",") + out.write(""""mydomain":""") + JsonEncoder.option(Mydomain.jsonEncoder).unsafeEncode(a.mydomain, indent, out) + out.write(",") + out.write(""""myenum":""") + JsonEncoder.option(Myenum.jsonEncoder).unsafeEncode(a.myenum, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""numeric":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.numeric, indent, out) + out.write(",") + out.write(""""path":""") + JsonEncoder.option(TypoPath.jsonEncoder).unsafeEncode(a.path, indent, out) + out.write(",") + out.write(""""point":""") + JsonEncoder.option(TypoPoint.jsonEncoder).unsafeEncode(a.point, indent, out) + out.write(",") + out.write(""""polygon":""") + JsonEncoder.option(TypoPolygon.jsonEncoder).unsafeEncode(a.polygon, indent, out) + out.write(",") + out.write(""""text":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.text, indent, out) + out.write(",") + out.write(""""time":""") + JsonEncoder.option(TypoLocalTime.jsonEncoder).unsafeEncode(a.time, indent, out) + out.write(",") + out.write(""""timestamp":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.timestamp, indent, out) + out.write(",") + out.write(""""timestampz":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.timestampz, indent, out) + out.write(",") + out.write(""""timez":""") + JsonEncoder.option(TypoOffsetTime.jsonEncoder).unsafeEncode(a.timez, indent, out) + out.write(",") + out.write(""""uuid":""") + JsonEncoder.option(TypoUUID.jsonEncoder).unsafeEncode(a.uuid, indent, out) + out.write(",") + out.write(""""varchar":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.varchar, indent, out) + out.write(",") + out.write(""""vector":""") + JsonEncoder.option(TypoVector.jsonEncoder).unsafeEncode(a.vector, indent, out) + out.write(",") + out.write(""""xml":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.xml, indent, out) + out.write(",") + out.write(""""boxes":""") + JsonEncoder.option(JsonEncoder.array[TypoBox](TypoBox.jsonEncoder, implicitly)).unsafeEncode(a.boxes, indent, out) + out.write(",") + out.write(""""bpchares":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.bpchares, indent, out) + out.write(",") + out.write(""""chares":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.chares, indent, out) + out.write(",") + out.write(""""circlees":""") + JsonEncoder.option(JsonEncoder.array[TypoCircle](TypoCircle.jsonEncoder, implicitly)).unsafeEncode(a.circlees, indent, out) + out.write(",") + out.write(""""datees":""") + JsonEncoder.option(JsonEncoder.array[TypoLocalDate](TypoLocalDate.jsonEncoder, implicitly)).unsafeEncode(a.datees, indent, out) + out.write(",") + out.write(""""float4es":""") + JsonEncoder.option(JsonEncoder.array[Float](JsonEncoder.float, implicitly)).unsafeEncode(a.float4es, indent, out) + out.write(",") + out.write(""""float8es":""") + JsonEncoder.option(JsonEncoder.array[Double](JsonEncoder.double, implicitly)).unsafeEncode(a.float8es, indent, out) + out.write(",") + out.write(""""inetes":""") + JsonEncoder.option(JsonEncoder.array[TypoInet](TypoInet.jsonEncoder, implicitly)).unsafeEncode(a.inetes, indent, out) + out.write(",") + out.write(""""int2es":""") + JsonEncoder.option(JsonEncoder.array[TypoShort](TypoShort.jsonEncoder, implicitly)).unsafeEncode(a.int2es, indent, out) + out.write(",") + out.write(""""int2vectores":""") + JsonEncoder.option(JsonEncoder.array[TypoInt2Vector](TypoInt2Vector.jsonEncoder, implicitly)).unsafeEncode(a.int2vectores, indent, out) + out.write(",") + out.write(""""int4es":""") + JsonEncoder.option(JsonEncoder.array[Int](JsonEncoder.int, implicitly)).unsafeEncode(a.int4es, indent, out) + out.write(",") + out.write(""""int8es":""") + JsonEncoder.option(JsonEncoder.array[Long](JsonEncoder.long, implicitly)).unsafeEncode(a.int8es, indent, out) + out.write(",") + out.write(""""intervales":""") + JsonEncoder.option(JsonEncoder.array[TypoInterval](TypoInterval.jsonEncoder, implicitly)).unsafeEncode(a.intervales, indent, out) + out.write(",") + out.write(""""jsones":""") + JsonEncoder.option(JsonEncoder.array[TypoJson](TypoJson.jsonEncoder, implicitly)).unsafeEncode(a.jsones, indent, out) + out.write(",") + out.write(""""jsonbes":""") + JsonEncoder.option(JsonEncoder.array[TypoJsonb](TypoJsonb.jsonEncoder, implicitly)).unsafeEncode(a.jsonbes, indent, out) + out.write(",") + out.write(""""linees":""") + JsonEncoder.option(JsonEncoder.array[TypoLine](TypoLine.jsonEncoder, implicitly)).unsafeEncode(a.linees, indent, out) + out.write(",") + out.write(""""lseges":""") + JsonEncoder.option(JsonEncoder.array[TypoLineSegment](TypoLineSegment.jsonEncoder, implicitly)).unsafeEncode(a.lseges, indent, out) + out.write(",") + out.write(""""moneyes":""") + JsonEncoder.option(JsonEncoder.array[TypoMoney](TypoMoney.jsonEncoder, implicitly)).unsafeEncode(a.moneyes, indent, out) + out.write(",") + out.write(""""myenumes":""") + JsonEncoder.option(JsonEncoder.array[Myenum](Myenum.jsonEncoder, implicitly)).unsafeEncode(a.myenumes, indent, out) + out.write(",") + out.write(""""namees":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.namees, indent, out) + out.write(",") + out.write(""""numerices":""") + JsonEncoder.option(JsonEncoder.array[BigDecimal](JsonEncoder.scalaBigDecimal, implicitly)).unsafeEncode(a.numerices, indent, out) + out.write(",") + out.write(""""pathes":""") + JsonEncoder.option(JsonEncoder.array[TypoPath](TypoPath.jsonEncoder, implicitly)).unsafeEncode(a.pathes, indent, out) + out.write(",") + out.write(""""pointes":""") + JsonEncoder.option(JsonEncoder.array[TypoPoint](TypoPoint.jsonEncoder, implicitly)).unsafeEncode(a.pointes, indent, out) + out.write(",") + out.write(""""polygones":""") + JsonEncoder.option(JsonEncoder.array[TypoPolygon](TypoPolygon.jsonEncoder, implicitly)).unsafeEncode(a.polygones, indent, out) + out.write(",") + out.write(""""textes":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.textes, indent, out) + out.write(",") + out.write(""""timees":""") + JsonEncoder.option(JsonEncoder.array[TypoLocalTime](TypoLocalTime.jsonEncoder, implicitly)).unsafeEncode(a.timees, indent, out) + out.write(",") + out.write(""""timestampes":""") + JsonEncoder.option(JsonEncoder.array[TypoLocalDateTime](TypoLocalDateTime.jsonEncoder, implicitly)).unsafeEncode(a.timestampes, indent, out) + out.write(",") + out.write(""""timestampzes":""") + JsonEncoder.option(JsonEncoder.array[TypoInstant](TypoInstant.jsonEncoder, implicitly)).unsafeEncode(a.timestampzes, indent, out) + out.write(",") + out.write(""""timezes":""") + JsonEncoder.option(JsonEncoder.array[TypoOffsetTime](TypoOffsetTime.jsonEncoder, implicitly)).unsafeEncode(a.timezes, indent, out) + out.write(",") + out.write(""""uuides":""") + JsonEncoder.option(JsonEncoder.array[TypoUUID](TypoUUID.jsonEncoder, implicitly)).unsafeEncode(a.uuides, indent, out) + out.write(",") + out.write(""""varchares":""") + JsonEncoder.option(JsonEncoder.array[String](JsonEncoder.string, implicitly)).unsafeEncode(a.varchares, indent, out) + out.write(",") + out.write(""""xmles":""") + JsonEncoder.option(JsonEncoder.array[TypoXml](TypoXml.jsonEncoder, implicitly)).unsafeEncode(a.xmles, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullStructure.scala new file mode 100644 index 0000000000..a5e6a04b14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/pgtestnull/PgtestnullStructure.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package pgtestnull + +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXml +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PgtestnullStructure[Row](val prefix: Option[String], val extract: Row => PgtestnullRow, val merge: (Row, PgtestnullRow) => Row) + extends Relation[PgtestnullFields, PgtestnullRow, Row] + with PgtestnullFields[Row] { outer => + + override val bool = new OptField[Boolean, Row](prefix, "bool", None, None)(x => extract(x).bool, (row, value) => merge(row, extract(row).copy(bool = value))) + override val box = new OptField[TypoBox, Row](prefix, "box", None, Some("box"))(x => extract(x).box, (row, value) => merge(row, extract(row).copy(box = value))) + override val bpchar = new OptField[/* bpchar, max 3 chars */ String, Row](prefix, "bpchar", None, Some("bpchar"))(x => extract(x).bpchar, (row, value) => merge(row, extract(row).copy(bpchar = value))) + override val bytea = new OptField[TypoBytea, Row](prefix, "bytea", None, Some("bytea"))(x => extract(x).bytea, (row, value) => merge(row, extract(row).copy(bytea = value))) + override val char = new OptField[/* bpchar, max 1 chars */ String, Row](prefix, "char", None, Some("bpchar"))(x => extract(x).char, (row, value) => merge(row, extract(row).copy(char = value))) + override val circle = new OptField[TypoCircle, Row](prefix, "circle", None, Some("circle"))(x => extract(x).circle, (row, value) => merge(row, extract(row).copy(circle = value))) + override val date = new OptField[TypoLocalDate, Row](prefix, "date", Some("text"), Some("date"))(x => extract(x).date, (row, value) => merge(row, extract(row).copy(date = value))) + override val float4 = new OptField[Float, Row](prefix, "float4", None, Some("float4"))(x => extract(x).float4, (row, value) => merge(row, extract(row).copy(float4 = value))) + override val float8 = new OptField[Double, Row](prefix, "float8", None, Some("float8"))(x => extract(x).float8, (row, value) => merge(row, extract(row).copy(float8 = value))) + override val hstore = new OptField[TypoHStore, Row](prefix, "hstore", None, Some("hstore"))(x => extract(x).hstore, (row, value) => merge(row, extract(row).copy(hstore = value))) + override val inet = new OptField[TypoInet, Row](prefix, "inet", None, Some("inet"))(x => extract(x).inet, (row, value) => merge(row, extract(row).copy(inet = value))) + override val int2 = new OptField[TypoShort, Row](prefix, "int2", None, Some("int2"))(x => extract(x).int2, (row, value) => merge(row, extract(row).copy(int2 = value))) + override val int2vector = new OptField[TypoInt2Vector, Row](prefix, "int2vector", None, Some("int2vector"))(x => extract(x).int2vector, (row, value) => merge(row, extract(row).copy(int2vector = value))) + override val int4 = new OptField[Int, Row](prefix, "int4", None, Some("int4"))(x => extract(x).int4, (row, value) => merge(row, extract(row).copy(int4 = value))) + override val int8 = new OptField[Long, Row](prefix, "int8", None, Some("int8"))(x => extract(x).int8, (row, value) => merge(row, extract(row).copy(int8 = value))) + override val interval = new OptField[TypoInterval, Row](prefix, "interval", None, Some("interval"))(x => extract(x).interval, (row, value) => merge(row, extract(row).copy(interval = value))) + override val json = new OptField[TypoJson, Row](prefix, "json", None, Some("json"))(x => extract(x).json, (row, value) => merge(row, extract(row).copy(json = value))) + override val jsonb = new OptField[TypoJsonb, Row](prefix, "jsonb", None, Some("jsonb"))(x => extract(x).jsonb, (row, value) => merge(row, extract(row).copy(jsonb = value))) + override val line = new OptField[TypoLine, Row](prefix, "line", None, Some("line"))(x => extract(x).line, (row, value) => merge(row, extract(row).copy(line = value))) + override val lseg = new OptField[TypoLineSegment, Row](prefix, "lseg", None, Some("lseg"))(x => extract(x).lseg, (row, value) => merge(row, extract(row).copy(lseg = value))) + override val money = new OptField[TypoMoney, Row](prefix, "money", Some("numeric"), Some("money"))(x => extract(x).money, (row, value) => merge(row, extract(row).copy(money = value))) + override val mydomain = new OptField[Mydomain, Row](prefix, "mydomain", None, Some("text"))(x => extract(x).mydomain, (row, value) => merge(row, extract(row).copy(mydomain = value))) + override val myenum = new OptField[Myenum, Row](prefix, "myenum", None, Some("public.myenum"))(x => extract(x).myenum, (row, value) => merge(row, extract(row).copy(myenum = value))) + override val name = new OptField[String, Row](prefix, "name", None, Some("name"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val numeric = new OptField[BigDecimal, Row](prefix, "numeric", None, Some("numeric"))(x => extract(x).numeric, (row, value) => merge(row, extract(row).copy(numeric = value))) + override val path = new OptField[TypoPath, Row](prefix, "path", None, Some("path"))(x => extract(x).path, (row, value) => merge(row, extract(row).copy(path = value))) + override val point = new OptField[TypoPoint, Row](prefix, "point", None, Some("point"))(x => extract(x).point, (row, value) => merge(row, extract(row).copy(point = value))) + override val polygon = new OptField[TypoPolygon, Row](prefix, "polygon", None, Some("polygon"))(x => extract(x).polygon, (row, value) => merge(row, extract(row).copy(polygon = value))) + override val text = new OptField[String, Row](prefix, "text", None, None)(x => extract(x).text, (row, value) => merge(row, extract(row).copy(text = value))) + override val time = new OptField[TypoLocalTime, Row](prefix, "time", Some("text"), Some("time"))(x => extract(x).time, (row, value) => merge(row, extract(row).copy(time = value))) + override val timestamp = new OptField[TypoLocalDateTime, Row](prefix, "timestamp", Some("text"), Some("timestamp"))(x => extract(x).timestamp, (row, value) => merge(row, extract(row).copy(timestamp = value))) + override val timestampz = new OptField[TypoInstant, Row](prefix, "timestampz", Some("text"), Some("timestamptz"))(x => extract(x).timestampz, (row, value) => merge(row, extract(row).copy(timestampz = value))) + override val timez = new OptField[TypoOffsetTime, Row](prefix, "timez", Some("text"), Some("timetz"))(x => extract(x).timez, (row, value) => merge(row, extract(row).copy(timez = value))) + override val uuid = new OptField[TypoUUID, Row](prefix, "uuid", None, Some("uuid"))(x => extract(x).uuid, (row, value) => merge(row, extract(row).copy(uuid = value))) + override val varchar = new OptField[String, Row](prefix, "varchar", None, None)(x => extract(x).varchar, (row, value) => merge(row, extract(row).copy(varchar = value))) + override val vector = new OptField[TypoVector, Row](prefix, "vector", Some("float4[]"), Some("vector"))(x => extract(x).vector, (row, value) => merge(row, extract(row).copy(vector = value))) + override val xml = new OptField[TypoXml, Row](prefix, "xml", None, Some("xml"))(x => extract(x).xml, (row, value) => merge(row, extract(row).copy(xml = value))) + override val boxes = new OptField[Array[TypoBox], Row](prefix, "boxes", None, Some("_box"))(x => extract(x).boxes, (row, value) => merge(row, extract(row).copy(boxes = value))) + override val bpchares = new OptField[Array[/* bpchar */ String], Row](prefix, "bpchares", None, Some("_bpchar"))(x => extract(x).bpchares, (row, value) => merge(row, extract(row).copy(bpchares = value))) + override val chares = new OptField[Array[/* bpchar */ String], Row](prefix, "chares", None, Some("_bpchar"))(x => extract(x).chares, (row, value) => merge(row, extract(row).copy(chares = value))) + override val circlees = new OptField[Array[TypoCircle], Row](prefix, "circlees", None, Some("_circle"))(x => extract(x).circlees, (row, value) => merge(row, extract(row).copy(circlees = value))) + override val datees = new OptField[Array[TypoLocalDate], Row](prefix, "datees", Some("text[]"), Some("_date"))(x => extract(x).datees, (row, value) => merge(row, extract(row).copy(datees = value))) + override val float4es = new OptField[Array[Float], Row](prefix, "float4es", None, Some("_float4"))(x => extract(x).float4es, (row, value) => merge(row, extract(row).copy(float4es = value))) + override val float8es = new OptField[Array[Double], Row](prefix, "float8es", None, Some("_float8"))(x => extract(x).float8es, (row, value) => merge(row, extract(row).copy(float8es = value))) + override val inetes = new OptField[Array[TypoInet], Row](prefix, "inetes", None, Some("_inet"))(x => extract(x).inetes, (row, value) => merge(row, extract(row).copy(inetes = value))) + override val int2es = new OptField[Array[TypoShort], Row](prefix, "int2es", None, Some("_int2"))(x => extract(x).int2es, (row, value) => merge(row, extract(row).copy(int2es = value))) + override val int2vectores = new OptField[Array[TypoInt2Vector], Row](prefix, "int2vectores", None, Some("_int2vector"))(x => extract(x).int2vectores, (row, value) => merge(row, extract(row).copy(int2vectores = value))) + override val int4es = new OptField[Array[Int], Row](prefix, "int4es", None, Some("_int4"))(x => extract(x).int4es, (row, value) => merge(row, extract(row).copy(int4es = value))) + override val int8es = new OptField[Array[Long], Row](prefix, "int8es", None, Some("_int8"))(x => extract(x).int8es, (row, value) => merge(row, extract(row).copy(int8es = value))) + override val intervales = new OptField[Array[TypoInterval], Row](prefix, "intervales", None, Some("_interval"))(x => extract(x).intervales, (row, value) => merge(row, extract(row).copy(intervales = value))) + override val jsones = new OptField[Array[TypoJson], Row](prefix, "jsones", None, Some("_json"))(x => extract(x).jsones, (row, value) => merge(row, extract(row).copy(jsones = value))) + override val jsonbes = new OptField[Array[TypoJsonb], Row](prefix, "jsonbes", None, Some("_jsonb"))(x => extract(x).jsonbes, (row, value) => merge(row, extract(row).copy(jsonbes = value))) + override val linees = new OptField[Array[TypoLine], Row](prefix, "linees", None, Some("_line"))(x => extract(x).linees, (row, value) => merge(row, extract(row).copy(linees = value))) + override val lseges = new OptField[Array[TypoLineSegment], Row](prefix, "lseges", None, Some("_lseg"))(x => extract(x).lseges, (row, value) => merge(row, extract(row).copy(lseges = value))) + override val moneyes = new OptField[Array[TypoMoney], Row](prefix, "moneyes", Some("numeric[]"), Some("_money"))(x => extract(x).moneyes, (row, value) => merge(row, extract(row).copy(moneyes = value))) + override val myenumes = new OptField[Array[Myenum], Row](prefix, "myenumes", None, Some("_myenum"))(x => extract(x).myenumes, (row, value) => merge(row, extract(row).copy(myenumes = value))) + override val namees = new OptField[Array[String], Row](prefix, "namees", None, Some("_name"))(x => extract(x).namees, (row, value) => merge(row, extract(row).copy(namees = value))) + override val numerices = new OptField[Array[BigDecimal], Row](prefix, "numerices", None, Some("_numeric"))(x => extract(x).numerices, (row, value) => merge(row, extract(row).copy(numerices = value))) + override val pathes = new OptField[Array[TypoPath], Row](prefix, "pathes", None, Some("_path"))(x => extract(x).pathes, (row, value) => merge(row, extract(row).copy(pathes = value))) + override val pointes = new OptField[Array[TypoPoint], Row](prefix, "pointes", None, Some("_point"))(x => extract(x).pointes, (row, value) => merge(row, extract(row).copy(pointes = value))) + override val polygones = new OptField[Array[TypoPolygon], Row](prefix, "polygones", None, Some("_polygon"))(x => extract(x).polygones, (row, value) => merge(row, extract(row).copy(polygones = value))) + override val textes = new OptField[Array[String], Row](prefix, "textes", None, Some("_text"))(x => extract(x).textes, (row, value) => merge(row, extract(row).copy(textes = value))) + override val timees = new OptField[Array[TypoLocalTime], Row](prefix, "timees", Some("text[]"), Some("_time"))(x => extract(x).timees, (row, value) => merge(row, extract(row).copy(timees = value))) + override val timestampes = new OptField[Array[TypoLocalDateTime], Row](prefix, "timestampes", Some("text[]"), Some("_timestamp"))(x => extract(x).timestampes, (row, value) => merge(row, extract(row).copy(timestampes = value))) + override val timestampzes = new OptField[Array[TypoInstant], Row](prefix, "timestampzes", Some("text[]"), Some("_timestamptz"))(x => extract(x).timestampzes, (row, value) => merge(row, extract(row).copy(timestampzes = value))) + override val timezes = new OptField[Array[TypoOffsetTime], Row](prefix, "timezes", Some("text[]"), Some("_timetz"))(x => extract(x).timezes, (row, value) => merge(row, extract(row).copy(timezes = value))) + override val uuides = new OptField[Array[TypoUUID], Row](prefix, "uuides", None, Some("_uuid"))(x => extract(x).uuides, (row, value) => merge(row, extract(row).copy(uuides = value))) + override val varchares = new OptField[Array[String], Row](prefix, "varchares", None, Some("_varchar"))(x => extract(x).varchares, (row, value) => merge(row, extract(row).copy(varchares = value))) + override val xmles = new OptField[Array[TypoXml], Row](prefix, "xmles", None, Some("_xml"))(x => extract(x).xmles, (row, value) => merge(row, extract(row).copy(xmles = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](bool, box, bpchar, bytea, char, circle, date, float4, float8, hstore, inet, int2, int2vector, int4, int8, interval, json, jsonb, line, lseg, money, mydomain, myenum, name, numeric, path, point, polygon, text, time, timestamp, timestampz, timez, uuid, varchar, vector, xml, boxes, bpchares, chares, circlees, datees, float4es, float8es, inetes, int2es, int2vectores, int4es, int8es, intervales, jsones, jsonbes, linees, lseges, moneyes, myenumes, namees, numerices, pathes, pointes, polygones, textes, timees, timestampes, timestampzes, timezes, uuides, varchares, xmles) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PgtestnullRow, merge: (NewRow, PgtestnullRow) => NewRow): PgtestnullStructure[NewRow] = + new PgtestnullStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersFields.scala new file mode 100644 index 0000000000..13061aa062 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersFields.scala @@ -0,0 +1,26 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoUnknownCitext +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait UsersFields[Row] { + val userId: IdField[UsersId, Row] + val name: Field[String, Row] + val lastName: OptField[String, Row] + val email: Field[TypoUnknownCitext, Row] + val password: Field[String, Row] + val createdAt: Field[TypoInstant, Row] + val verifiedOn: OptField[TypoInstant, Row] +} +object UsersFields extends UsersStructure[UsersRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersId.scala new file mode 100644 index 0000000000..0bb0c19db6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersId.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoUUID +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 `public.users` */ +case class UsersId(value: TypoUUID) extends AnyVal +object UsersId { + implicit lazy val arraySetter: Setter[Array[UsersId]] = TypoUUID.arraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[UsersId, TypoUUID] = Bijection[UsersId, TypoUUID](_.value)(UsersId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[UsersId] = TypoUUID.jdbcDecoder.map(UsersId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[UsersId] = TypoUUID.jdbcEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[UsersId] = TypoUUID.jsonDecoder.map(UsersId.apply) + implicit lazy val jsonEncoder: JsonEncoder[UsersId] = TypoUUID.jsonEncoder.contramap(_.value) + implicit def ordering(implicit O0: Ordering[TypoUUID]): Ordering[UsersId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[UsersId] = ParameterMetaData.instance[UsersId](TypoUUID.parameterMetadata.sqlType, TypoUUID.parameterMetadata.jdbcType) + implicit lazy val setter: Setter[UsersId] = TypoUUID.setter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepo.scala new file mode 100644 index 0000000000..d6f91d9f20 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepo.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoUnknownCitext +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UsersRepo { + def delete(userId: UsersId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[UsersFields, UsersRow] + def insert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UsersRow] + def insert(unsaved: UsersRowUnsaved): ZIO[ZConnection, Throwable, UsersRow] + def select: SelectBuilder[UsersFields, UsersRow] + def selectAll: ZStream[ZConnection, Throwable, UsersRow] + def selectById(userId: UsersId): ZIO[ZConnection, Throwable, Option[UsersRow]] + def selectByIds(userIds: Array[UsersId]): ZStream[ZConnection, Throwable, UsersRow] + def selectByUnique(email: TypoUnknownCitext): ZIO[ZConnection, Throwable, Option[UsersRow]] + def update(row: UsersRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[UsersFields, UsersRow] + def upsert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UpdateResult[UsersRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoImpl.scala new file mode 100644 index 0000000000..2cae44a3bc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoImpl.scala @@ -0,0 +1,118 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoUnknownCitext +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UsersRepoImpl extends UsersRepo { + override def delete(userId: UsersId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from public.users where "user_id" = ${Segment.paramSegment(userId)(UsersId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[UsersFields, UsersRow] = { + DeleteBuilder("public.users", UsersFields) + } + override def insert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UsersRow] = { + sql"""insert into public.users("user_id", "name", "last_name", "email", "password", "created_at", "verified_on") + values (${Segment.paramSegment(unsaved.userId)(UsersId.setter)}::uuid, ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.lastName)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.email)(TypoUnknownCitext.setter)}::citext, ${Segment.paramSegment(unsaved.password)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.createdAt)(TypoInstant.setter)}::timestamptz, ${Segment.paramSegment(unsaved.verifiedOn)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz) + returning "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text + """.insertReturning(UsersRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: UsersRowUnsaved): ZIO[ZConnection, Throwable, UsersRow] = { + val fs = List( + Some((sql""""user_id"""", sql"${Segment.paramSegment(unsaved.userId)(UsersId.setter)}::uuid")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}")), + Some((sql""""last_name"""", sql"${Segment.paramSegment(unsaved.lastName)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""email"""", sql"${Segment.paramSegment(unsaved.email)(TypoUnknownCitext.setter)}::citext")), + Some((sql""""password"""", sql"${Segment.paramSegment(unsaved.password)(Setter.stringSetter)}")), + Some((sql""""verified_on"""", sql"${Segment.paramSegment(unsaved.verifiedOn)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz")), + unsaved.createdAt match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""created_at"""", sql"${Segment.paramSegment(value: TypoInstant)(TypoInstant.setter)}::timestamptz")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into public.users default values + returning "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into public.users($names) values ($values) returning "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text""" + } + q.insertReturning(UsersRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[UsersFields, UsersRow] = { + SelectBuilderSql("public.users", UsersFields, UsersRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, UsersRow] = { + sql"""select "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text from public.users""".query(UsersRow.jdbcDecoder).selectStream + } + override def selectById(userId: UsersId): ZIO[ZConnection, Throwable, Option[UsersRow]] = { + sql"""select "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text from public.users where "user_id" = ${Segment.paramSegment(userId)(UsersId.setter)}""".query(UsersRow.jdbcDecoder).selectOne + } + override def selectByIds(userIds: Array[UsersId]): ZStream[ZConnection, Throwable, UsersRow] = { + sql"""select "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text from public.users where "user_id" = ANY(${Segment.paramSegment(userIds)(UsersId.arraySetter)})""".query(UsersRow.jdbcDecoder).selectStream + } + override def selectByUnique(email: TypoUnknownCitext): ZIO[ZConnection, Throwable, Option[UsersRow]] = { + sql"""select "email"::text + from public.users + where "email" = ${Segment.paramSegment(email)(TypoUnknownCitext.setter)} + """.query(UsersRow.jdbcDecoder).selectOne + } + override def update(row: UsersRow): ZIO[ZConnection, Throwable, Boolean] = { + val userId = row.userId + sql"""update public.users + set "name" = ${Segment.paramSegment(row.name)(Setter.stringSetter)}, + "last_name" = ${Segment.paramSegment(row.lastName)(Setter.optionParamSetter(Setter.stringSetter))}, + "email" = ${Segment.paramSegment(row.email)(TypoUnknownCitext.setter)}::citext, + "password" = ${Segment.paramSegment(row.password)(Setter.stringSetter)}, + "created_at" = ${Segment.paramSegment(row.createdAt)(TypoInstant.setter)}::timestamptz, + "verified_on" = ${Segment.paramSegment(row.verifiedOn)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz + where "user_id" = ${Segment.paramSegment(userId)(UsersId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[UsersFields, UsersRow] = { + UpdateBuilder("public.users", UsersFields, UsersRow.jdbcDecoder) + } + override def upsert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UpdateResult[UsersRow]] = { + sql"""insert into public.users("user_id", "name", "last_name", "email", "password", "created_at", "verified_on") + values ( + ${Segment.paramSegment(unsaved.userId)(UsersId.setter)}::uuid, + ${Segment.paramSegment(unsaved.name)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.lastName)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.email)(TypoUnknownCitext.setter)}::citext, + ${Segment.paramSegment(unsaved.password)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.createdAt)(TypoInstant.setter)}::timestamptz, + ${Segment.paramSegment(unsaved.verifiedOn)(Setter.optionParamSetter(TypoInstant.setter))}::timestamptz + ) + on conflict ("user_id") + do update set + "name" = EXCLUDED."name", + "last_name" = EXCLUDED."last_name", + "email" = EXCLUDED."email", + "password" = EXCLUDED."password", + "created_at" = EXCLUDED."created_at", + "verified_on" = EXCLUDED."verified_on" + returning "user_id", "name", "last_name", "email"::text, "password", "created_at"::text, "verified_on"::text""".insertReturning(UsersRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoMock.scala new file mode 100644 index 0000000000..b10f771cb3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRepoMock.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoUnknownCitext +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class UsersRepoMock(toRow: Function1[UsersRowUnsaved, UsersRow], + map: scala.collection.mutable.Map[UsersId, UsersRow] = scala.collection.mutable.Map.empty) extends UsersRepo { + override def delete(userId: UsersId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(userId).isDefined) + } + override def delete: DeleteBuilder[UsersFields, UsersRow] = { + DeleteBuilderMock(DeleteParams.empty, UsersFields, map) + } + override def insert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UsersRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.userId)) + sys.error(s"id ${unsaved.userId} already exists") + else + map.put(unsaved.userId, unsaved) + + unsaved + } + } + override def insert(unsaved: UsersRowUnsaved): ZIO[ZConnection, Throwable, UsersRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[UsersFields, UsersRow] = { + SelectBuilderMock(UsersFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, UsersRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(userId: UsersId): ZIO[ZConnection, Throwable, Option[UsersRow]] = { + ZIO.succeed(map.get(userId)) + } + override def selectByIds(userIds: Array[UsersId]): ZStream[ZConnection, Throwable, UsersRow] = { + ZStream.fromIterable(userIds.flatMap(map.get)) + } + override def selectByUnique(email: TypoUnknownCitext): ZIO[ZConnection, Throwable, Option[UsersRow]] = { + ZIO.succeed(map.values.find(v => email == v.email)) + } + override def update(row: UsersRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.userId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.userId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[UsersFields, UsersRow] = { + UpdateBuilderMock(UpdateParams.empty, UsersFields, map) + } + override def upsert(unsaved: UsersRow): ZIO[ZConnection, Throwable, UpdateResult[UsersRow]] = { + ZIO.succeed { + map.put(unsaved.userId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRow.scala new file mode 100644 index 0000000000..a3a16801db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoUnknownCitext +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UsersRow( + userId: UsersId, + name: String, + lastName: Option[String], + email: TypoUnknownCitext, + password: String, + createdAt: TypoInstant, + verifiedOn: Option[TypoInstant] +) + +object UsersRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UsersRow] = new JdbcDecoder[UsersRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UsersRow) = + columIndex + 6 -> + UsersRow( + userId = UsersId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + lastName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + email = TypoUnknownCitext.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + password = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + createdAt = TypoInstant.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + verifiedOn = JdbcDecoder.optionDecoder(TypoInstant.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UsersRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val userId = jsonObj.get("user_id").toRight("Missing field 'user_id'").flatMap(_.as(UsersId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val lastName = jsonObj.get("last_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(TypoUnknownCitext.jsonDecoder)) + val password = jsonObj.get("password").toRight("Missing field 'password'").flatMap(_.as(JsonDecoder.string)) + val createdAt = jsonObj.get("created_at").toRight("Missing field 'created_at'").flatMap(_.as(TypoInstant.jsonDecoder)) + val verifiedOn = jsonObj.get("verified_on").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + if (userId.isRight && name.isRight && lastName.isRight && email.isRight && password.isRight && createdAt.isRight && verifiedOn.isRight) + Right(UsersRow(userId = userId.toOption.get, name = name.toOption.get, lastName = lastName.toOption.get, email = email.toOption.get, password = password.toOption.get, createdAt = createdAt.toOption.get, verifiedOn = verifiedOn.toOption.get)) + else Left(List[Either[String, Any]](userId, name, lastName, email, password, createdAt, verifiedOn).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UsersRow] = new JsonEncoder[UsersRow] { + override def unsafeEncode(a: UsersRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""user_id":""") + UsersId.jsonEncoder.unsafeEncode(a.userId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""last_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.lastName, indent, out) + out.write(",") + out.write(""""email":""") + TypoUnknownCitext.jsonEncoder.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""password":""") + JsonEncoder.string.unsafeEncode(a.password, indent, out) + out.write(",") + out.write(""""created_at":""") + TypoInstant.jsonEncoder.unsafeEncode(a.createdAt, indent, out) + out.write(",") + out.write(""""verified_on":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.verifiedOn, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRowUnsaved.scala new file mode 100644 index 0000000000..d712ee0d7d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersRowUnsaved.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoUnknownCitext +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `public.users` which has not been persisted yet */ +case class UsersRowUnsaved( + userId: UsersId, + name: String, + lastName: Option[String], + email: TypoUnknownCitext, + password: String, + verifiedOn: Option[TypoInstant], + /** Default: now() */ + createdAt: Defaulted[TypoInstant] = Defaulted.UseDefault +) { + def toRow(createdAtDefault: => TypoInstant): UsersRow = + UsersRow( + userId = userId, + name = name, + lastName = lastName, + email = email, + password = password, + verifiedOn = verifiedOn, + createdAt = createdAt match { + case Defaulted.UseDefault => createdAtDefault + case Defaulted.Provided(value) => value + } + ) +} +object UsersRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[UsersRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val userId = jsonObj.get("user_id").toRight("Missing field 'user_id'").flatMap(_.as(UsersId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(JsonDecoder.string)) + val lastName = jsonObj.get("last_name").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val email = jsonObj.get("email").toRight("Missing field 'email'").flatMap(_.as(TypoUnknownCitext.jsonDecoder)) + val password = jsonObj.get("password").toRight("Missing field 'password'").flatMap(_.as(JsonDecoder.string)) + val verifiedOn = jsonObj.get("verified_on").fold[Either[String, Option[TypoInstant]]](Right(None))(_.as(JsonDecoder.option(TypoInstant.jsonDecoder))) + val createdAt = jsonObj.get("created_at").toRight("Missing field 'created_at'").flatMap(_.as(Defaulted.jsonDecoder(TypoInstant.jsonDecoder))) + if (userId.isRight && name.isRight && lastName.isRight && email.isRight && password.isRight && verifiedOn.isRight && createdAt.isRight) + Right(UsersRowUnsaved(userId = userId.toOption.get, name = name.toOption.get, lastName = lastName.toOption.get, email = email.toOption.get, password = password.toOption.get, verifiedOn = verifiedOn.toOption.get, createdAt = createdAt.toOption.get)) + else Left(List[Either[String, Any]](userId, name, lastName, email, password, verifiedOn, createdAt).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UsersRowUnsaved] = new JsonEncoder[UsersRowUnsaved] { + override def unsafeEncode(a: UsersRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""user_id":""") + UsersId.jsonEncoder.unsafeEncode(a.userId, indent, out) + out.write(",") + out.write(""""name":""") + JsonEncoder.string.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""last_name":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.lastName, indent, out) + out.write(",") + out.write(""""email":""") + TypoUnknownCitext.jsonEncoder.unsafeEncode(a.email, indent, out) + out.write(",") + out.write(""""password":""") + JsonEncoder.string.unsafeEncode(a.password, indent, out) + out.write(",") + out.write(""""verified_on":""") + JsonEncoder.option(TypoInstant.jsonEncoder).unsafeEncode(a.verifiedOn, indent, out) + out.write(",") + out.write(""""created_at":""") + Defaulted.jsonEncoder(TypoInstant.jsonEncoder).unsafeEncode(a.createdAt, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersStructure.scala new file mode 100644 index 0000000000..df2145cd74 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/public/users/UsersStructure.scala @@ -0,0 +1,35 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package public +package users + +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoUnknownCitext +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class UsersStructure[Row](val prefix: Option[String], val extract: Row => UsersRow, val merge: (Row, UsersRow) => Row) + extends Relation[UsersFields, UsersRow, Row] + with UsersFields[Row] { outer => + + override val userId = new IdField[UsersId, Row](prefix, "user_id", None, Some("uuid"))(x => extract(x).userId, (row, value) => merge(row, extract(row).copy(userId = value))) + override val name = new Field[String, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val lastName = new OptField[String, Row](prefix, "last_name", None, None)(x => extract(x).lastName, (row, value) => merge(row, extract(row).copy(lastName = value))) + override val email = new Field[TypoUnknownCitext, Row](prefix, "email", Some("text"), Some("citext"))(x => extract(x).email, (row, value) => merge(row, extract(row).copy(email = value))) + override val password = new Field[String, Row](prefix, "password", None, None)(x => extract(x).password, (row, value) => merge(row, extract(row).copy(password = value))) + override val createdAt = new Field[TypoInstant, Row](prefix, "created_at", Some("text"), Some("timestamptz"))(x => extract(x).createdAt, (row, value) => merge(row, extract(row).copy(createdAt = value))) + override val verifiedOn = new OptField[TypoInstant, Row](prefix, "verified_on", Some("text"), Some("timestamptz"))(x => extract(x).verifiedOn, (row, value) => merge(row, extract(row).copy(verifiedOn = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](userId, name, lastName, email, password, createdAt, verifiedOn) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => UsersRow, merge: (NewRow, UsersRow) => NewRow): UsersStructure[NewRow] = + new UsersStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorFields.scala new file mode 100644 index 0000000000..abc2ebb2ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait ProductvendorFields[Row] { + val productid: IdField[ProductId, Row] + val businessentityid: IdField[BusinessentityId, Row] + val averageleadtime: Field[Int, Row] + val standardprice: Field[BigDecimal, Row] + val lastreceiptcost: OptField[BigDecimal, Row] + val lastreceiptdate: OptField[TypoLocalDateTime, Row] + val minorderqty: Field[Int, Row] + val maxorderqty: Field[Int, Row] + val onorderqty: OptField[Int, Row] + val unitmeasurecode: Field[UnitmeasureId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ProductvendorFields extends ProductvendorStructure[ProductvendorRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorId.scala new file mode 100644 index 0000000000..b1fd88a9df --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `purchasing.productvendor` */ +case class ProductvendorId(productid: ProductId, businessentityid: BusinessentityId) +object ProductvendorId { + implicit lazy val jsonDecoder: JsonDecoder[ProductvendorId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + if (productid.isRight && businessentityid.isRight) + Right(ProductvendorId(productid = productid.toOption.get, businessentityid = businessentityid.toOption.get)) + else Left(List[Either[String, Any]](productid, businessentityid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductvendorId] = new JsonEncoder[ProductvendorId] { + override def unsafeEncode(a: ProductvendorId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[ProductvendorId] = Ordering.by(x => (x.productid, x.businessentityid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepo.scala new file mode 100644 index 0000000000..1bdcf91477 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ProductvendorRepo { + def delete(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ProductvendorFields, ProductvendorRow] + def insert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, ProductvendorRow] + def insert(unsaved: ProductvendorRowUnsaved): ZIO[ZConnection, Throwable, ProductvendorRow] + def select: SelectBuilder[ProductvendorFields, ProductvendorRow] + def selectAll: ZStream[ZConnection, Throwable, ProductvendorRow] + def selectById(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Option[ProductvendorRow]] + def update(row: ProductvendorRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ProductvendorFields, ProductvendorRow] + def upsert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, UpdateResult[ProductvendorRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoImpl.scala new file mode 100644 index 0000000000..69e4d9ac8a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoImpl.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ProductvendorRepoImpl extends ProductvendorRepo { + override def delete(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from purchasing.productvendor where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ProductvendorFields, ProductvendorRow] = { + DeleteBuilder("purchasing.productvendor", ProductvendorFields) + } + override def insert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, ProductvendorRow] = { + sql"""insert into purchasing.productvendor("productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate", "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate") + values (${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.averageleadtime)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.standardprice)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.lastreceiptcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.lastreceiptdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.minorderqty)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.maxorderqty)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.onorderqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, ${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text + """.insertReturning(ProductvendorRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ProductvendorRowUnsaved): ZIO[ZConnection, Throwable, ProductvendorRow] = { + val fs = List( + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""averageleadtime"""", sql"${Segment.paramSegment(unsaved.averageleadtime)(Setter.intSetter)}::int4")), + Some((sql""""standardprice"""", sql"${Segment.paramSegment(unsaved.standardprice)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""lastreceiptcost"""", sql"${Segment.paramSegment(unsaved.lastreceiptcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + Some((sql""""lastreceiptdate"""", sql"${Segment.paramSegment(unsaved.lastreceiptdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""minorderqty"""", sql"${Segment.paramSegment(unsaved.minorderqty)(Setter.intSetter)}::int4")), + Some((sql""""maxorderqty"""", sql"${Segment.paramSegment(unsaved.maxorderqty)(Setter.intSetter)}::int4")), + Some((sql""""onorderqty"""", sql"${Segment.paramSegment(unsaved.onorderqty)(Setter.optionParamSetter(Setter.intSetter))}::int4")), + Some((sql""""unitmeasurecode"""", sql"${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into purchasing.productvendor default values + returning "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into purchasing.productvendor($names) values ($values) returning "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text""" + } + q.insertReturning(ProductvendorRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ProductvendorFields, ProductvendorRow] = { + SelectBuilderSql("purchasing.productvendor", ProductvendorFields, ProductvendorRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductvendorRow] = { + sql"""select "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text from purchasing.productvendor""".query(ProductvendorRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Option[ProductvendorRow]] = { + sql"""select "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text from purchasing.productvendor where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)}""".query(ProductvendorRow.jdbcDecoder).selectOne + } + override def update(row: ProductvendorRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update purchasing.productvendor + set "averageleadtime" = ${Segment.paramSegment(row.averageleadtime)(Setter.intSetter)}::int4, + "standardprice" = ${Segment.paramSegment(row.standardprice)(Setter.bigDecimalScalaSetter)}::numeric, + "lastreceiptcost" = ${Segment.paramSegment(row.lastreceiptcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "lastreceiptdate" = ${Segment.paramSegment(row.lastreceiptdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "minorderqty" = ${Segment.paramSegment(row.minorderqty)(Setter.intSetter)}::int4, + "maxorderqty" = ${Segment.paramSegment(row.maxorderqty)(Setter.intSetter)}::int4, + "onorderqty" = ${Segment.paramSegment(row.onorderqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, + "unitmeasurecode" = ${Segment.paramSegment(row.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)} AND "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ProductvendorFields, ProductvendorRow] = { + UpdateBuilder("purchasing.productvendor", ProductvendorFields, ProductvendorRow.jdbcDecoder) + } + override def upsert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, UpdateResult[ProductvendorRow]] = { + sql"""insert into purchasing.productvendor("productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate", "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.averageleadtime)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.standardprice)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.lastreceiptcost)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.lastreceiptdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.minorderqty)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.maxorderqty)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.onorderqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, + ${Segment.paramSegment(unsaved.unitmeasurecode)(UnitmeasureId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("productid", "businessentityid") + do update set + "averageleadtime" = EXCLUDED."averageleadtime", + "standardprice" = EXCLUDED."standardprice", + "lastreceiptcost" = EXCLUDED."lastreceiptcost", + "lastreceiptdate" = EXCLUDED."lastreceiptdate", + "minorderqty" = EXCLUDED."minorderqty", + "maxorderqty" = EXCLUDED."maxorderqty", + "onorderqty" = EXCLUDED."onorderqty", + "unitmeasurecode" = EXCLUDED."unitmeasurecode", + "modifieddate" = EXCLUDED."modifieddate" + returning "productid", "businessentityid", "averageleadtime", "standardprice", "lastreceiptcost", "lastreceiptdate"::text, "minorderqty", "maxorderqty", "onorderqty", "unitmeasurecode", "modifieddate"::text""".insertReturning(ProductvendorRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoMock.scala new file mode 100644 index 0000000000..b5ac4a9d6b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ProductvendorRepoMock(toRow: Function1[ProductvendorRowUnsaved, ProductvendorRow], + map: scala.collection.mutable.Map[ProductvendorId, ProductvendorRow] = scala.collection.mutable.Map.empty) extends ProductvendorRepo { + override def delete(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[ProductvendorFields, ProductvendorRow] = { + DeleteBuilderMock(DeleteParams.empty, ProductvendorFields, map) + } + override def insert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, ProductvendorRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: ProductvendorRowUnsaved): ZIO[ZConnection, Throwable, ProductvendorRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ProductvendorFields, ProductvendorRow] = { + SelectBuilderMock(ProductvendorFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ProductvendorRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: ProductvendorId): ZIO[ZConnection, Throwable, Option[ProductvendorRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: ProductvendorRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ProductvendorFields, ProductvendorRow] = { + UpdateBuilderMock(UpdateParams.empty, ProductvendorFields, map) + } + override def upsert(unsaved: ProductvendorRow): ZIO[ZConnection, Throwable, UpdateResult[ProductvendorRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRow.scala new file mode 100644 index 0000000000..b0311edaac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRow.scala @@ -0,0 +1,128 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ProductvendorRow( + /** Primary key. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Primary key. Foreign key to Vendor.BusinessEntityID. + Points to [[vendor.VendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** The average span of time (in days) between placing an order with the vendor and receiving the purchased product. + Constraint CK_ProductVendor_AverageLeadTime affecting columns "averageleadtime": ((averageleadtime >= 1)) */ + averageleadtime: Int, + /** The vendor's usual selling price. + Constraint CK_ProductVendor_StandardPrice affecting columns "standardprice": ((standardprice > 0.00)) */ + standardprice: BigDecimal, + /** The selling price when last purchased. + Constraint CK_ProductVendor_LastReceiptCost affecting columns "lastreceiptcost": ((lastreceiptcost > 0.00)) */ + lastreceiptcost: Option[BigDecimal], + /** Date the product was last received by the vendor. */ + lastreceiptdate: Option[TypoLocalDateTime], + /** The maximum quantity that should be ordered. + Constraint CK_ProductVendor_MinOrderQty affecting columns "minorderqty": ((minorderqty >= 1)) */ + minorderqty: Int, + /** The minimum quantity that should be ordered. + Constraint CK_ProductVendor_MaxOrderQty affecting columns "maxorderqty": ((maxorderqty >= 1)) */ + maxorderqty: Int, + /** The quantity currently on order. + Constraint CK_ProductVendor_OnOrderQty affecting columns "onorderqty": ((onorderqty >= 0)) */ + onorderqty: Option[Int], + /** The product's unit of measure. + Points to [[production.unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + modifieddate: TypoLocalDateTime +){ + val compositeId: ProductvendorId = ProductvendorId(productid, businessentityid) + } + +object ProductvendorRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ProductvendorRow] = new JdbcDecoder[ProductvendorRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ProductvendorRow) = + columIndex + 10 -> + ProductvendorRow( + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + averageleadtime = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + standardprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + lastreceiptcost = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 4, rs)._2, + lastreceiptdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + minorderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 6, rs)._2, + maxorderqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + onorderqty = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + unitmeasurecode = UnitmeasureId.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ProductvendorRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val averageleadtime = jsonObj.get("averageleadtime").toRight("Missing field 'averageleadtime'").flatMap(_.as(JsonDecoder.int)) + val standardprice = jsonObj.get("standardprice").toRight("Missing field 'standardprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val lastreceiptcost = jsonObj.get("lastreceiptcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val lastreceiptdate = jsonObj.get("lastreceiptdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val minorderqty = jsonObj.get("minorderqty").toRight("Missing field 'minorderqty'").flatMap(_.as(JsonDecoder.int)) + val maxorderqty = jsonObj.get("maxorderqty").toRight("Missing field 'maxorderqty'").flatMap(_.as(JsonDecoder.int)) + val onorderqty = jsonObj.get("onorderqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (productid.isRight && businessentityid.isRight && averageleadtime.isRight && standardprice.isRight && lastreceiptcost.isRight && lastreceiptdate.isRight && minorderqty.isRight && maxorderqty.isRight && onorderqty.isRight && unitmeasurecode.isRight && modifieddate.isRight) + Right(ProductvendorRow(productid = productid.toOption.get, businessentityid = businessentityid.toOption.get, averageleadtime = averageleadtime.toOption.get, standardprice = standardprice.toOption.get, lastreceiptcost = lastreceiptcost.toOption.get, lastreceiptdate = lastreceiptdate.toOption.get, minorderqty = minorderqty.toOption.get, maxorderqty = maxorderqty.toOption.get, onorderqty = onorderqty.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, businessentityid, averageleadtime, standardprice, lastreceiptcost, lastreceiptdate, minorderqty, maxorderqty, onorderqty, unitmeasurecode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductvendorRow] = new JsonEncoder[ProductvendorRow] { + override def unsafeEncode(a: ProductvendorRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""averageleadtime":""") + JsonEncoder.int.unsafeEncode(a.averageleadtime, indent, out) + out.write(",") + out.write(""""standardprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardprice, indent, out) + out.write(",") + out.write(""""lastreceiptcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.lastreceiptcost, indent, out) + out.write(",") + out.write(""""lastreceiptdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.lastreceiptdate, indent, out) + out.write(",") + out.write(""""minorderqty":""") + JsonEncoder.int.unsafeEncode(a.minorderqty, indent, out) + out.write(",") + out.write(""""maxorderqty":""") + JsonEncoder.int.unsafeEncode(a.maxorderqty, indent, out) + out.write(",") + out.write(""""onorderqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.onorderqty, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRowUnsaved.scala new file mode 100644 index 0000000000..3bd1038734 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorRowUnsaved.scala @@ -0,0 +1,127 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `purchasing.productvendor` which has not been persisted yet */ +case class ProductvendorRowUnsaved( + /** Primary key. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Primary key. Foreign key to Vendor.BusinessEntityID. + Points to [[vendor.VendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** The average span of time (in days) between placing an order with the vendor and receiving the purchased product. + Constraint CK_ProductVendor_AverageLeadTime affecting columns "averageleadtime": ((averageleadtime >= 1)) */ + averageleadtime: Int, + /** The vendor's usual selling price. + Constraint CK_ProductVendor_StandardPrice affecting columns "standardprice": ((standardprice > 0.00)) */ + standardprice: BigDecimal, + /** The selling price when last purchased. + Constraint CK_ProductVendor_LastReceiptCost affecting columns "lastreceiptcost": ((lastreceiptcost > 0.00)) */ + lastreceiptcost: Option[BigDecimal], + /** Date the product was last received by the vendor. */ + lastreceiptdate: Option[TypoLocalDateTime], + /** The maximum quantity that should be ordered. + Constraint CK_ProductVendor_MinOrderQty affecting columns "minorderqty": ((minorderqty >= 1)) */ + minorderqty: Int, + /** The minimum quantity that should be ordered. + Constraint CK_ProductVendor_MaxOrderQty affecting columns "maxorderqty": ((maxorderqty >= 1)) */ + maxorderqty: Int, + /** The quantity currently on order. + Constraint CK_ProductVendor_OnOrderQty affecting columns "onorderqty": ((onorderqty >= 0)) */ + onorderqty: Option[Int], + /** The product's unit of measure. + Points to [[production.unitmeasure.UnitmeasureRow.unitmeasurecode]] */ + unitmeasurecode: UnitmeasureId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): ProductvendorRow = + ProductvendorRow( + productid = productid, + businessentityid = businessentityid, + averageleadtime = averageleadtime, + standardprice = standardprice, + lastreceiptcost = lastreceiptcost, + lastreceiptdate = lastreceiptdate, + minorderqty = minorderqty, + maxorderqty = maxorderqty, + onorderqty = onorderqty, + unitmeasurecode = unitmeasurecode, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ProductvendorRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ProductvendorRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val averageleadtime = jsonObj.get("averageleadtime").toRight("Missing field 'averageleadtime'").flatMap(_.as(JsonDecoder.int)) + val standardprice = jsonObj.get("standardprice").toRight("Missing field 'standardprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val lastreceiptcost = jsonObj.get("lastreceiptcost").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val lastreceiptdate = jsonObj.get("lastreceiptdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val minorderqty = jsonObj.get("minorderqty").toRight("Missing field 'minorderqty'").flatMap(_.as(JsonDecoder.int)) + val maxorderqty = jsonObj.get("maxorderqty").toRight("Missing field 'maxorderqty'").flatMap(_.as(JsonDecoder.int)) + val onorderqty = jsonObj.get("onorderqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val unitmeasurecode = jsonObj.get("unitmeasurecode").toRight("Missing field 'unitmeasurecode'").flatMap(_.as(UnitmeasureId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (productid.isRight && businessentityid.isRight && averageleadtime.isRight && standardprice.isRight && lastreceiptcost.isRight && lastreceiptdate.isRight && minorderqty.isRight && maxorderqty.isRight && onorderqty.isRight && unitmeasurecode.isRight && modifieddate.isRight) + Right(ProductvendorRowUnsaved(productid = productid.toOption.get, businessentityid = businessentityid.toOption.get, averageleadtime = averageleadtime.toOption.get, standardprice = standardprice.toOption.get, lastreceiptcost = lastreceiptcost.toOption.get, lastreceiptdate = lastreceiptdate.toOption.get, minorderqty = minorderqty.toOption.get, maxorderqty = maxorderqty.toOption.get, onorderqty = onorderqty.toOption.get, unitmeasurecode = unitmeasurecode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](productid, businessentityid, averageleadtime, standardprice, lastreceiptcost, lastreceiptdate, minorderqty, maxorderqty, onorderqty, unitmeasurecode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ProductvendorRowUnsaved] = new JsonEncoder[ProductvendorRowUnsaved] { + override def unsafeEncode(a: ProductvendorRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""averageleadtime":""") + JsonEncoder.int.unsafeEncode(a.averageleadtime, indent, out) + out.write(",") + out.write(""""standardprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.standardprice, indent, out) + out.write(",") + out.write(""""lastreceiptcost":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.lastreceiptcost, indent, out) + out.write(",") + out.write(""""lastreceiptdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.lastreceiptdate, indent, out) + out.write(",") + out.write(""""minorderqty":""") + JsonEncoder.int.unsafeEncode(a.minorderqty, indent, out) + out.write(",") + out.write(""""maxorderqty":""") + JsonEncoder.int.unsafeEncode(a.maxorderqty, indent, out) + out.write(",") + out.write(""""onorderqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.onorderqty, indent, out) + out.write(",") + out.write(""""unitmeasurecode":""") + UnitmeasureId.jsonEncoder.unsafeEncode(a.unitmeasurecode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorStructure.scala new file mode 100644 index 0000000000..2499959af1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/productvendor/ProductvendorStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package productvendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.production.product.ProductId +import adventureworks.production.unitmeasure.UnitmeasureId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class ProductvendorStructure[Row](val prefix: Option[String], val extract: Row => ProductvendorRow, val merge: (Row, ProductvendorRow) => Row) + extends Relation[ProductvendorFields, ProductvendorRow, Row] + with ProductvendorFields[Row] { outer => + + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val averageleadtime = new Field[Int, Row](prefix, "averageleadtime", None, Some("int4"))(x => extract(x).averageleadtime, (row, value) => merge(row, extract(row).copy(averageleadtime = value))) + override val standardprice = new Field[BigDecimal, Row](prefix, "standardprice", None, Some("numeric"))(x => extract(x).standardprice, (row, value) => merge(row, extract(row).copy(standardprice = value))) + override val lastreceiptcost = new OptField[BigDecimal, Row](prefix, "lastreceiptcost", None, Some("numeric"))(x => extract(x).lastreceiptcost, (row, value) => merge(row, extract(row).copy(lastreceiptcost = value))) + override val lastreceiptdate = new OptField[TypoLocalDateTime, Row](prefix, "lastreceiptdate", Some("text"), Some("timestamp"))(x => extract(x).lastreceiptdate, (row, value) => merge(row, extract(row).copy(lastreceiptdate = value))) + override val minorderqty = new Field[Int, Row](prefix, "minorderqty", None, Some("int4"))(x => extract(x).minorderqty, (row, value) => merge(row, extract(row).copy(minorderqty = value))) + override val maxorderqty = new Field[Int, Row](prefix, "maxorderqty", None, Some("int4"))(x => extract(x).maxorderqty, (row, value) => merge(row, extract(row).copy(maxorderqty = value))) + override val onorderqty = new OptField[Int, Row](prefix, "onorderqty", None, Some("int4"))(x => extract(x).onorderqty, (row, value) => merge(row, extract(row).copy(onorderqty = value))) + override val unitmeasurecode = new Field[UnitmeasureId, Row](prefix, "unitmeasurecode", None, Some("bpchar"))(x => extract(x).unitmeasurecode, (row, value) => merge(row, extract(row).copy(unitmeasurecode = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](productid, businessentityid, averageleadtime, standardprice, lastreceiptcost, lastreceiptdate, minorderqty, maxorderqty, onorderqty, unitmeasurecode, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ProductvendorRow, merge: (NewRow, ProductvendorRow) => NewRow): ProductvendorStructure[NewRow] = + new ProductvendorStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailFields.scala new file mode 100644 index 0000000000..b66e95a16d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PurchaseorderdetailFields[Row] { + val purchaseorderid: IdField[PurchaseorderheaderId, Row] + val purchaseorderdetailid: IdField[Int, Row] + val duedate: Field[TypoLocalDateTime, Row] + val orderqty: Field[TypoShort, Row] + val productid: Field[ProductId, Row] + val unitprice: Field[BigDecimal, Row] + val receivedqty: Field[BigDecimal, Row] + val rejectedqty: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PurchaseorderdetailFields extends PurchaseorderdetailStructure[PurchaseorderdetailRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailId.scala new file mode 100644 index 0000000000..fecfca583c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailId.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `purchasing.purchaseorderdetail` */ +case class PurchaseorderdetailId(purchaseorderid: PurchaseorderheaderId, purchaseorderdetailid: Int) +object PurchaseorderdetailId { + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderdetailId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val purchaseorderdetailid = jsonObj.get("purchaseorderdetailid").toRight("Missing field 'purchaseorderdetailid'").flatMap(_.as(JsonDecoder.int)) + if (purchaseorderid.isRight && purchaseorderdetailid.isRight) + Right(PurchaseorderdetailId(purchaseorderid = purchaseorderid.toOption.get, purchaseorderdetailid = purchaseorderdetailid.toOption.get)) + else Left(List[Either[String, Any]](purchaseorderid, purchaseorderdetailid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderdetailId] = new JsonEncoder[PurchaseorderdetailId] { + override def unsafeEncode(a: PurchaseorderdetailId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""purchaseorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.purchaseorderdetailid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PurchaseorderdetailId] = Ordering.by(x => (x.purchaseorderid, x.purchaseorderdetailid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepo.scala new file mode 100644 index 0000000000..e8489b5957 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepo.scala @@ -0,0 +1,19 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import typo.dsl.SelectBuilder +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PurchaseorderdetailRepo { + def select: SelectBuilder[PurchaseorderdetailFields, PurchaseorderdetailRow] + def selectAll: ZStream[ZConnection, Throwable, PurchaseorderdetailRow] + def selectById(compositeId: PurchaseorderdetailId): ZIO[ZConnection, Throwable, Option[PurchaseorderdetailRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoImpl.scala new file mode 100644 index 0000000000..22f08f6438 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoImpl.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PurchaseorderdetailRepoImpl extends PurchaseorderdetailRepo { + override def select: SelectBuilder[PurchaseorderdetailFields, PurchaseorderdetailRow] = { + SelectBuilderSql("purchasing.purchaseorderdetail", PurchaseorderdetailFields, PurchaseorderdetailRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PurchaseorderdetailRow] = { + sql"""select "purchaseorderid", "purchaseorderdetailid", "duedate"::text, "orderqty", "productid", "unitprice", "receivedqty", "rejectedqty", "modifieddate"::text from purchasing.purchaseorderdetail""".query(PurchaseorderdetailRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PurchaseorderdetailId): ZIO[ZConnection, Throwable, Option[PurchaseorderdetailRow]] = { + sql"""select "purchaseorderid", "purchaseorderdetailid", "duedate"::text, "orderqty", "productid", "unitprice", "receivedqty", "rejectedqty", "modifieddate"::text from purchasing.purchaseorderdetail where "purchaseorderid" = ${Segment.paramSegment(compositeId.purchaseorderid)(PurchaseorderheaderId.setter)} AND "purchaseorderdetailid" = ${Segment.paramSegment(compositeId.purchaseorderdetailid)(Setter.intSetter)}""".query(PurchaseorderdetailRow.jdbcDecoder).selectOne + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoMock.scala new file mode 100644 index 0000000000..063b12d220 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRepoMock.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PurchaseorderdetailRepoMock(map: scala.collection.mutable.Map[PurchaseorderdetailId, PurchaseorderdetailRow] = scala.collection.mutable.Map.empty) extends PurchaseorderdetailRepo { + override def select: SelectBuilder[PurchaseorderdetailFields, PurchaseorderdetailRow] = { + SelectBuilderMock(PurchaseorderdetailFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PurchaseorderdetailRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PurchaseorderdetailId): ZIO[ZConnection, Throwable, Option[PurchaseorderdetailRow]] = { + ZIO.succeed(map.get(compositeId)) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRow.scala new file mode 100644 index 0000000000..ce93edb68a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRow.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PurchaseorderdetailRow( + /** Primary key. Foreign key to PurchaseOrderHeader.PurchaseOrderID. + Points to [[purchaseorderheader.PurchaseorderheaderRow.purchaseorderid]] */ + purchaseorderid: PurchaseorderheaderId, + /** Primary key. One line number per purchased product. */ + purchaseorderdetailid: Int, + /** Date the product is expected to be received. */ + duedate: TypoLocalDateTime, + /** Quantity ordered. + Constraint CK_PurchaseOrderDetail_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: TypoShort, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Vendor's selling price of a single product. + Constraint CK_PurchaseOrderDetail_UnitPrice affecting columns "unitprice": ((unitprice >= 0.00)) */ + unitprice: BigDecimal, + /** Quantity actually received from the vendor. + Constraint CK_PurchaseOrderDetail_ReceivedQty affecting columns "receivedqty": ((receivedqty >= 0.00)) */ + receivedqty: BigDecimal, + /** Quantity rejected during inspection. + Constraint CK_PurchaseOrderDetail_RejectedQty affecting columns "rejectedqty": ((rejectedqty >= 0.00)) */ + rejectedqty: BigDecimal, + modifieddate: TypoLocalDateTime +){ + val compositeId: PurchaseorderdetailId = PurchaseorderdetailId(purchaseorderid, purchaseorderdetailid) + } + +object PurchaseorderdetailRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PurchaseorderdetailRow] = new JdbcDecoder[PurchaseorderdetailRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PurchaseorderdetailRow) = + columIndex + 8 -> + PurchaseorderdetailRow( + purchaseorderid = PurchaseorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + purchaseorderdetailid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + orderqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + unitprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + receivedqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + rejectedqty = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderdetailRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val purchaseorderdetailid = jsonObj.get("purchaseorderdetailid").toRight("Missing field 'purchaseorderdetailid'").flatMap(_.as(JsonDecoder.int)) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val receivedqty = jsonObj.get("receivedqty").toRight("Missing field 'receivedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rejectedqty = jsonObj.get("rejectedqty").toRight("Missing field 'rejectedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (purchaseorderid.isRight && purchaseorderdetailid.isRight && duedate.isRight && orderqty.isRight && productid.isRight && unitprice.isRight && receivedqty.isRight && rejectedqty.isRight && modifieddate.isRight) + Right(PurchaseorderdetailRow(purchaseorderid = purchaseorderid.toOption.get, purchaseorderdetailid = purchaseorderdetailid.toOption.get, duedate = duedate.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, unitprice = unitprice.toOption.get, receivedqty = receivedqty.toOption.get, rejectedqty = rejectedqty.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](purchaseorderid, purchaseorderdetailid, duedate, orderqty, productid, unitprice, receivedqty, rejectedqty, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderdetailRow] = new JsonEncoder[PurchaseorderdetailRow] { + override def unsafeEncode(a: PurchaseorderdetailRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""purchaseorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.purchaseorderdetailid, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""receivedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.receivedqty, indent, out) + out.write(",") + out.write(""""rejectedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rejectedqty, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRowUnsaved.scala new file mode 100644 index 0000000000..19244f7545 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailRowUnsaved.scala @@ -0,0 +1,114 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `purchasing.purchaseorderdetail` which has not been persisted yet */ +case class PurchaseorderdetailRowUnsaved( + /** Primary key. Foreign key to PurchaseOrderHeader.PurchaseOrderID. + Points to [[purchaseorderheader.PurchaseorderheaderRow.purchaseorderid]] */ + purchaseorderid: PurchaseorderheaderId, + /** Date the product is expected to be received. */ + duedate: TypoLocalDateTime, + /** Quantity ordered. + Constraint CK_PurchaseOrderDetail_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: TypoShort, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Vendor's selling price of a single product. + Constraint CK_PurchaseOrderDetail_UnitPrice affecting columns "unitprice": ((unitprice >= 0.00)) */ + unitprice: BigDecimal, + /** Quantity actually received from the vendor. + Constraint CK_PurchaseOrderDetail_ReceivedQty affecting columns "receivedqty": ((receivedqty >= 0.00)) */ + receivedqty: BigDecimal, + /** Quantity rejected during inspection. + Constraint CK_PurchaseOrderDetail_RejectedQty affecting columns "rejectedqty": ((rejectedqty >= 0.00)) */ + rejectedqty: BigDecimal, + /** Default: nextval('purchasing.purchaseorderdetail_purchaseorderdetailid_seq'::regclass) + Primary key. One line number per purchased product. */ + purchaseorderdetailid: Defaulted[Int] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(purchaseorderdetailidDefault: => Int, modifieddateDefault: => TypoLocalDateTime): PurchaseorderdetailRow = + PurchaseorderdetailRow( + purchaseorderid = purchaseorderid, + duedate = duedate, + orderqty = orderqty, + productid = productid, + unitprice = unitprice, + receivedqty = receivedqty, + rejectedqty = rejectedqty, + purchaseorderdetailid = purchaseorderdetailid match { + case Defaulted.UseDefault => purchaseorderdetailidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PurchaseorderdetailRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderdetailRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val receivedqty = jsonObj.get("receivedqty").toRight("Missing field 'receivedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rejectedqty = jsonObj.get("rejectedqty").toRight("Missing field 'rejectedqty'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val purchaseorderdetailid = jsonObj.get("purchaseorderdetailid").toRight("Missing field 'purchaseorderdetailid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (purchaseorderid.isRight && duedate.isRight && orderqty.isRight && productid.isRight && unitprice.isRight && receivedqty.isRight && rejectedqty.isRight && purchaseorderdetailid.isRight && modifieddate.isRight) + Right(PurchaseorderdetailRowUnsaved(purchaseorderid = purchaseorderid.toOption.get, duedate = duedate.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, unitprice = unitprice.toOption.get, receivedqty = receivedqty.toOption.get, rejectedqty = rejectedqty.toOption.get, purchaseorderdetailid = purchaseorderdetailid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](purchaseorderid, duedate, orderqty, productid, unitprice, receivedqty, rejectedqty, purchaseorderdetailid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderdetailRowUnsaved] = new JsonEncoder[PurchaseorderdetailRowUnsaved] { + override def unsafeEncode(a: PurchaseorderdetailRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""receivedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.receivedqty, indent, out) + out.write(",") + out.write(""""rejectedqty":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.rejectedqty, indent, out) + out.write(",") + out.write(""""purchaseorderdetailid":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.purchaseorderdetailid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailStructure.scala new file mode 100644 index 0000000000..2d1db47893 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderdetail/PurchaseorderdetailStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.production.product.ProductId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PurchaseorderdetailStructure[Row](val prefix: Option[String], val extract: Row => PurchaseorderdetailRow, val merge: (Row, PurchaseorderdetailRow) => Row) + extends Relation[PurchaseorderdetailFields, PurchaseorderdetailRow, Row] + with PurchaseorderdetailFields[Row] { outer => + + override val purchaseorderid = new IdField[PurchaseorderheaderId, Row](prefix, "purchaseorderid", None, Some("int4"))(x => extract(x).purchaseorderid, (row, value) => merge(row, extract(row).copy(purchaseorderid = value))) + override val purchaseorderdetailid = new IdField[Int, Row](prefix, "purchaseorderdetailid", None, Some("int4"))(x => extract(x).purchaseorderdetailid, (row, value) => merge(row, extract(row).copy(purchaseorderdetailid = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), Some("timestamp"))(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val orderqty = new Field[TypoShort, Row](prefix, "orderqty", None, Some("int2"))(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val unitprice = new Field[BigDecimal, Row](prefix, "unitprice", None, Some("numeric"))(x => extract(x).unitprice, (row, value) => merge(row, extract(row).copy(unitprice = value))) + override val receivedqty = new Field[BigDecimal, Row](prefix, "receivedqty", None, Some("numeric"))(x => extract(x).receivedqty, (row, value) => merge(row, extract(row).copy(receivedqty = value))) + override val rejectedqty = new Field[BigDecimal, Row](prefix, "rejectedqty", None, Some("numeric"))(x => extract(x).rejectedqty, (row, value) => merge(row, extract(row).copy(rejectedqty = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](purchaseorderid, purchaseorderdetailid, duedate, orderqty, productid, unitprice, receivedqty, rejectedqty, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PurchaseorderdetailRow, merge: (NewRow, PurchaseorderdetailRow) => NewRow): PurchaseorderdetailStructure[NewRow] = + new PurchaseorderdetailStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderFields.scala new file mode 100644 index 0000000000..3289fd3a0c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait PurchaseorderheaderFields[Row] { + val purchaseorderid: IdField[PurchaseorderheaderId, Row] + val revisionnumber: Field[TypoShort, Row] + val status: Field[TypoShort, Row] + val employeeid: Field[BusinessentityId, Row] + val vendorid: Field[BusinessentityId, Row] + val shipmethodid: Field[ShipmethodId, Row] + val orderdate: Field[TypoLocalDateTime, Row] + val shipdate: OptField[TypoLocalDateTime, Row] + val subtotal: Field[BigDecimal, Row] + val taxamt: Field[BigDecimal, Row] + val freight: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PurchaseorderheaderFields extends PurchaseorderheaderStructure[PurchaseorderheaderRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderId.scala new file mode 100644 index 0000000000..73d1348198 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +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 `purchasing.purchaseorderheader` */ +case class PurchaseorderheaderId(value: Int) extends AnyVal +object PurchaseorderheaderId { + implicit lazy val arraySetter: Setter[Array[PurchaseorderheaderId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[PurchaseorderheaderId, Int] = Bijection[PurchaseorderheaderId, Int](_.value)(PurchaseorderheaderId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[PurchaseorderheaderId] = JdbcDecoder.intDecoder.map(PurchaseorderheaderId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[PurchaseorderheaderId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderheaderId] = JsonDecoder.int.map(PurchaseorderheaderId.apply) + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderheaderId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[PurchaseorderheaderId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[PurchaseorderheaderId] = ParameterMetaData.instance[PurchaseorderheaderId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[PurchaseorderheaderId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepo.scala new file mode 100644 index 0000000000..0b2db3065c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PurchaseorderheaderRepo { + def delete(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] + def insert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] + def insert(unsaved: PurchaseorderheaderRowUnsaved): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] + def select: SelectBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] + def selectAll: ZStream[ZConnection, Throwable, PurchaseorderheaderRow] + def selectById(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Option[PurchaseorderheaderRow]] + def selectByIds(purchaseorderids: Array[PurchaseorderheaderId]): ZStream[ZConnection, Throwable, PurchaseorderheaderRow] + def update(row: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] + def upsert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[PurchaseorderheaderRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoImpl.scala new file mode 100644 index 0000000000..8d6b8f78b0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoImpl.scala @@ -0,0 +1,155 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PurchaseorderheaderRepoImpl extends PurchaseorderheaderRepo { + override def delete(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from purchasing.purchaseorderheader where "purchaseorderid" = ${Segment.paramSegment(purchaseorderid)(PurchaseorderheaderId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + DeleteBuilder("purchasing.purchaseorderheader", PurchaseorderheaderFields) + } + override def insert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] = { + sql"""insert into purchasing.purchaseorderheader("purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate", "shipdate", "subtotal", "taxamt", "freight", "modifieddate") + values (${Segment.paramSegment(unsaved.purchaseorderid)(PurchaseorderheaderId.setter)}::int4, ${Segment.paramSegment(unsaved.revisionnumber)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.employeeid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.vendorid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, ${Segment.paramSegment(unsaved.orderdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.freight)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text + """.insertReturning(PurchaseorderheaderRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PurchaseorderheaderRowUnsaved): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] = { + val fs = List( + Some((sql""""employeeid"""", sql"${Segment.paramSegment(unsaved.employeeid)(BusinessentityId.setter)}::int4")), + Some((sql""""vendorid"""", sql"${Segment.paramSegment(unsaved.vendorid)(BusinessentityId.setter)}::int4")), + Some((sql""""shipmethodid"""", sql"${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4")), + Some((sql""""shipdate"""", sql"${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + unsaved.purchaseorderid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""purchaseorderid"""", sql"${Segment.paramSegment(value: PurchaseorderheaderId)(PurchaseorderheaderId.setter)}::int4")) + }, + unsaved.revisionnumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""revisionnumber"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.status match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""status"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.orderdate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""orderdate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.subtotal match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""subtotal"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.taxamt match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""taxamt"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.freight match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""freight"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into purchasing.purchaseorderheader default values + returning "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into purchasing.purchaseorderheader($names) values ($values) returning "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text""" + } + q.insertReturning(PurchaseorderheaderRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + SelectBuilderSql("purchasing.purchaseorderheader", PurchaseorderheaderFields, PurchaseorderheaderRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PurchaseorderheaderRow] = { + sql"""select "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text from purchasing.purchaseorderheader""".query(PurchaseorderheaderRow.jdbcDecoder).selectStream + } + override def selectById(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Option[PurchaseorderheaderRow]] = { + sql"""select "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text from purchasing.purchaseorderheader where "purchaseorderid" = ${Segment.paramSegment(purchaseorderid)(PurchaseorderheaderId.setter)}""".query(PurchaseorderheaderRow.jdbcDecoder).selectOne + } + override def selectByIds(purchaseorderids: Array[PurchaseorderheaderId]): ZStream[ZConnection, Throwable, PurchaseorderheaderRow] = { + sql"""select "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text from purchasing.purchaseorderheader where "purchaseorderid" = ANY(${Segment.paramSegment(purchaseorderids)(PurchaseorderheaderId.arraySetter)})""".query(PurchaseorderheaderRow.jdbcDecoder).selectStream + } + override def update(row: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, Boolean] = { + val purchaseorderid = row.purchaseorderid + sql"""update purchasing.purchaseorderheader + set "revisionnumber" = ${Segment.paramSegment(row.revisionnumber)(TypoShort.setter)}::int2, + "status" = ${Segment.paramSegment(row.status)(TypoShort.setter)}::int2, + "employeeid" = ${Segment.paramSegment(row.employeeid)(BusinessentityId.setter)}::int4, + "vendorid" = ${Segment.paramSegment(row.vendorid)(BusinessentityId.setter)}::int4, + "shipmethodid" = ${Segment.paramSegment(row.shipmethodid)(ShipmethodId.setter)}::int4, + "orderdate" = ${Segment.paramSegment(row.orderdate)(TypoLocalDateTime.setter)}::timestamp, + "shipdate" = ${Segment.paramSegment(row.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "subtotal" = ${Segment.paramSegment(row.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, + "taxamt" = ${Segment.paramSegment(row.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, + "freight" = ${Segment.paramSegment(row.freight)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "purchaseorderid" = ${Segment.paramSegment(purchaseorderid)(PurchaseorderheaderId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + UpdateBuilder("purchasing.purchaseorderheader", PurchaseorderheaderFields, PurchaseorderheaderRow.jdbcDecoder) + } + override def upsert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[PurchaseorderheaderRow]] = { + sql"""insert into purchasing.purchaseorderheader("purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate", "shipdate", "subtotal", "taxamt", "freight", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.purchaseorderid)(PurchaseorderheaderId.setter)}::int4, + ${Segment.paramSegment(unsaved.revisionnumber)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.employeeid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.vendorid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, + ${Segment.paramSegment(unsaved.orderdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.freight)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("purchaseorderid") + do update set + "revisionnumber" = EXCLUDED."revisionnumber", + "status" = EXCLUDED."status", + "employeeid" = EXCLUDED."employeeid", + "vendorid" = EXCLUDED."vendorid", + "shipmethodid" = EXCLUDED."shipmethodid", + "orderdate" = EXCLUDED."orderdate", + "shipdate" = EXCLUDED."shipdate", + "subtotal" = EXCLUDED."subtotal", + "taxamt" = EXCLUDED."taxamt", + "freight" = EXCLUDED."freight", + "modifieddate" = EXCLUDED."modifieddate" + returning "purchaseorderid", "revisionnumber", "status", "employeeid", "vendorid", "shipmethodid", "orderdate"::text, "shipdate"::text, "subtotal", "taxamt", "freight", "modifieddate"::text""".insertReturning(PurchaseorderheaderRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoMock.scala new file mode 100644 index 0000000000..e2a7a7e3d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PurchaseorderheaderRepoMock(toRow: Function1[PurchaseorderheaderRowUnsaved, PurchaseorderheaderRow], + map: scala.collection.mutable.Map[PurchaseorderheaderId, PurchaseorderheaderRow] = scala.collection.mutable.Map.empty) extends PurchaseorderheaderRepo { + override def delete(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(purchaseorderid).isDefined) + } + override def delete: DeleteBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + DeleteBuilderMock(DeleteParams.empty, PurchaseorderheaderFields, map) + } + override def insert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.purchaseorderid)) + sys.error(s"id ${unsaved.purchaseorderid} already exists") + else + map.put(unsaved.purchaseorderid, unsaved) + + unsaved + } + } + override def insert(unsaved: PurchaseorderheaderRowUnsaved): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + SelectBuilderMock(PurchaseorderheaderFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PurchaseorderheaderRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(purchaseorderid: PurchaseorderheaderId): ZIO[ZConnection, Throwable, Option[PurchaseorderheaderRow]] = { + ZIO.succeed(map.get(purchaseorderid)) + } + override def selectByIds(purchaseorderids: Array[PurchaseorderheaderId]): ZStream[ZConnection, Throwable, PurchaseorderheaderRow] = { + ZStream.fromIterable(purchaseorderids.flatMap(map.get)) + } + override def update(row: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.purchaseorderid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.purchaseorderid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PurchaseorderheaderFields, PurchaseorderheaderRow] = { + UpdateBuilderMock(UpdateParams.empty, PurchaseorderheaderFields, map) + } + override def upsert(unsaved: PurchaseorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[PurchaseorderheaderRow]] = { + ZIO.succeed { + map.put(unsaved.purchaseorderid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRow.scala new file mode 100644 index 0000000000..e07cc0f2bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRow.scala @@ -0,0 +1,133 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.shipmethod.ShipmethodId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PurchaseorderheaderRow( + /** Primary key. */ + purchaseorderid: PurchaseorderheaderId, + /** Incremental number to track changes to the purchase order over time. */ + revisionnumber: TypoShort, + /** Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete + Constraint CK_PurchaseOrderHeader_Status affecting columns "status": (((status >= 1) AND (status <= 4))) */ + status: TypoShort, + /** Employee who created the purchase order. Foreign key to Employee.BusinessEntityID. + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + employeeid: BusinessentityId, + /** Vendor with whom the purchase order is placed. Foreign key to Vendor.BusinessEntityID. + Points to [[vendor.VendorRow.businessentityid]] */ + vendorid: BusinessentityId, + /** Shipping method. Foreign key to ShipMethod.ShipMethodID. + Points to [[shipmethod.ShipmethodRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Purchase order creation date. + Constraint CK_PurchaseOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + orderdate: TypoLocalDateTime, + /** Estimated shipment date from the vendor. + Constraint CK_PurchaseOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + shipdate: Option[TypoLocalDateTime], + /** Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. + Constraint CK_PurchaseOrderHeader_SubTotal affecting columns "subtotal": ((subtotal >= 0.00)) */ + subtotal: BigDecimal, + /** Tax amount. + Constraint CK_PurchaseOrderHeader_TaxAmt affecting columns "taxamt": ((taxamt >= 0.00)) */ + taxamt: BigDecimal, + /** Shipping cost. + Constraint CK_PurchaseOrderHeader_Freight affecting columns "freight": ((freight >= 0.00)) */ + freight: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object PurchaseorderheaderRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PurchaseorderheaderRow] = new JdbcDecoder[PurchaseorderheaderRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PurchaseorderheaderRow) = + columIndex + 11 -> + PurchaseorderheaderRow( + purchaseorderid = PurchaseorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + revisionnumber = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + employeeid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + vendorid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + orderdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + shipdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + subtotal = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + taxamt = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 9, rs)._2, + freight = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderheaderRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(PurchaseorderheaderId.jsonDecoder)) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(TypoShort.jsonDecoder)) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val employeeid = jsonObj.get("employeeid").toRight("Missing field 'employeeid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val vendorid = jsonObj.get("vendorid").toRight("Missing field 'vendorid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (purchaseorderid.isRight && revisionnumber.isRight && status.isRight && employeeid.isRight && vendorid.isRight && shipmethodid.isRight && orderdate.isRight && shipdate.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && modifieddate.isRight) + Right(PurchaseorderheaderRow(purchaseorderid = purchaseorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, status = status.toOption.get, employeeid = employeeid.toOption.get, vendorid = vendorid.toOption.get, shipmethodid = shipmethodid.toOption.get, orderdate = orderdate.toOption.get, shipdate = shipdate.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](purchaseorderid, revisionnumber, status, employeeid, vendorid, shipmethodid, orderdate, shipdate, subtotal, taxamt, freight, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderheaderRow] = new JsonEncoder[PurchaseorderheaderRow] { + override def unsafeEncode(a: PurchaseorderheaderRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""purchaseorderid":""") + PurchaseorderheaderId.jsonEncoder.unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + TypoShort.jsonEncoder.unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""employeeid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.employeeid, indent, out) + out.write(",") + out.write(""""vendorid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.vendorid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""orderdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""subtotal":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRowUnsaved.scala new file mode 100644 index 0000000000..73a82e1861 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderRowUnsaved.scala @@ -0,0 +1,162 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.shipmethod.ShipmethodId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `purchasing.purchaseorderheader` which has not been persisted yet */ +case class PurchaseorderheaderRowUnsaved( + /** Employee who created the purchase order. Foreign key to Employee.BusinessEntityID. + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + employeeid: BusinessentityId, + /** Vendor with whom the purchase order is placed. Foreign key to Vendor.BusinessEntityID. + Points to [[vendor.VendorRow.businessentityid]] */ + vendorid: BusinessentityId, + /** Shipping method. Foreign key to ShipMethod.ShipMethodID. + Points to [[shipmethod.ShipmethodRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Estimated shipment date from the vendor. + Constraint CK_PurchaseOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + shipdate: Option[TypoLocalDateTime], + /** Default: nextval('purchasing.purchaseorderheader_purchaseorderid_seq'::regclass) + Primary key. */ + purchaseorderid: Defaulted[PurchaseorderheaderId] = Defaulted.UseDefault, + /** Default: 0 + Incremental number to track changes to the purchase order over time. */ + revisionnumber: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: 1 + Order current status. 1 = Pending; 2 = Approved; 3 = Rejected; 4 = Complete + Constraint CK_PurchaseOrderHeader_Status affecting columns "status": (((status >= 1) AND (status <= 4))) */ + status: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: now() + Purchase order creation date. + Constraint CK_PurchaseOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + orderdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: 0.00 + Purchase order subtotal. Computed as SUM(PurchaseOrderDetail.LineTotal)for the appropriate PurchaseOrderID. + Constraint CK_PurchaseOrderHeader_SubTotal affecting columns "subtotal": ((subtotal >= 0.00)) */ + subtotal: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Tax amount. + Constraint CK_PurchaseOrderHeader_TaxAmt affecting columns "taxamt": ((taxamt >= 0.00)) */ + taxamt: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Shipping cost. + Constraint CK_PurchaseOrderHeader_Freight affecting columns "freight": ((freight >= 0.00)) */ + freight: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(purchaseorderidDefault: => PurchaseorderheaderId, revisionnumberDefault: => TypoShort, statusDefault: => TypoShort, orderdateDefault: => TypoLocalDateTime, subtotalDefault: => BigDecimal, taxamtDefault: => BigDecimal, freightDefault: => BigDecimal, modifieddateDefault: => TypoLocalDateTime): PurchaseorderheaderRow = + PurchaseorderheaderRow( + employeeid = employeeid, + vendorid = vendorid, + shipmethodid = shipmethodid, + shipdate = shipdate, + purchaseorderid = purchaseorderid match { + case Defaulted.UseDefault => purchaseorderidDefault + case Defaulted.Provided(value) => value + }, + revisionnumber = revisionnumber match { + case Defaulted.UseDefault => revisionnumberDefault + case Defaulted.Provided(value) => value + }, + status = status match { + case Defaulted.UseDefault => statusDefault + case Defaulted.Provided(value) => value + }, + orderdate = orderdate match { + case Defaulted.UseDefault => orderdateDefault + case Defaulted.Provided(value) => value + }, + subtotal = subtotal match { + case Defaulted.UseDefault => subtotalDefault + case Defaulted.Provided(value) => value + }, + taxamt = taxamt match { + case Defaulted.UseDefault => taxamtDefault + case Defaulted.Provided(value) => value + }, + freight = freight match { + case Defaulted.UseDefault => freightDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PurchaseorderheaderRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PurchaseorderheaderRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val employeeid = jsonObj.get("employeeid").toRight("Missing field 'employeeid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val vendorid = jsonObj.get("vendorid").toRight("Missing field 'vendorid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val purchaseorderid = jsonObj.get("purchaseorderid").toRight("Missing field 'purchaseorderid'").flatMap(_.as(Defaulted.jsonDecoder(PurchaseorderheaderId.jsonDecoder))) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (employeeid.isRight && vendorid.isRight && shipmethodid.isRight && shipdate.isRight && purchaseorderid.isRight && revisionnumber.isRight && status.isRight && orderdate.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && modifieddate.isRight) + Right(PurchaseorderheaderRowUnsaved(employeeid = employeeid.toOption.get, vendorid = vendorid.toOption.get, shipmethodid = shipmethodid.toOption.get, shipdate = shipdate.toOption.get, purchaseorderid = purchaseorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, status = status.toOption.get, orderdate = orderdate.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](employeeid, vendorid, shipmethodid, shipdate, purchaseorderid, revisionnumber, status, orderdate, subtotal, taxamt, freight, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PurchaseorderheaderRowUnsaved] = new JsonEncoder[PurchaseorderheaderRowUnsaved] { + override def unsafeEncode(a: PurchaseorderheaderRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""employeeid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.employeeid, indent, out) + out.write(",") + out.write(""""vendorid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.vendorid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""purchaseorderid":""") + Defaulted.jsonEncoder(PurchaseorderheaderId.jsonEncoder).unsafeEncode(a.purchaseorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""status":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""orderdate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""subtotal":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderStructure.scala new file mode 100644 index 0000000000..e35523c02d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/purchaseorderheader/PurchaseorderheaderStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package purchaseorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.purchasing.shipmethod.ShipmethodId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class PurchaseorderheaderStructure[Row](val prefix: Option[String], val extract: Row => PurchaseorderheaderRow, val merge: (Row, PurchaseorderheaderRow) => Row) + extends Relation[PurchaseorderheaderFields, PurchaseorderheaderRow, Row] + with PurchaseorderheaderFields[Row] { outer => + + override val purchaseorderid = new IdField[PurchaseorderheaderId, Row](prefix, "purchaseorderid", None, Some("int4"))(x => extract(x).purchaseorderid, (row, value) => merge(row, extract(row).copy(purchaseorderid = value))) + override val revisionnumber = new Field[TypoShort, Row](prefix, "revisionnumber", None, Some("int2"))(x => extract(x).revisionnumber, (row, value) => merge(row, extract(row).copy(revisionnumber = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, Some("int2"))(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val employeeid = new Field[BusinessentityId, Row](prefix, "employeeid", None, Some("int4"))(x => extract(x).employeeid, (row, value) => merge(row, extract(row).copy(employeeid = value))) + override val vendorid = new Field[BusinessentityId, Row](prefix, "vendorid", None, Some("int4"))(x => extract(x).vendorid, (row, value) => merge(row, extract(row).copy(vendorid = value))) + override val shipmethodid = new Field[ShipmethodId, Row](prefix, "shipmethodid", None, Some("int4"))(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val orderdate = new Field[TypoLocalDateTime, Row](prefix, "orderdate", Some("text"), Some("timestamp"))(x => extract(x).orderdate, (row, value) => merge(row, extract(row).copy(orderdate = value))) + override val shipdate = new OptField[TypoLocalDateTime, Row](prefix, "shipdate", Some("text"), Some("timestamp"))(x => extract(x).shipdate, (row, value) => merge(row, extract(row).copy(shipdate = value))) + override val subtotal = new Field[BigDecimal, Row](prefix, "subtotal", None, Some("numeric"))(x => extract(x).subtotal, (row, value) => merge(row, extract(row).copy(subtotal = value))) + override val taxamt = new Field[BigDecimal, Row](prefix, "taxamt", None, Some("numeric"))(x => extract(x).taxamt, (row, value) => merge(row, extract(row).copy(taxamt = value))) + override val freight = new Field[BigDecimal, Row](prefix, "freight", None, Some("numeric"))(x => extract(x).freight, (row, value) => merge(row, extract(row).copy(freight = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](purchaseorderid, revisionnumber, status, employeeid, vendorid, shipmethodid, orderdate, shipdate, subtotal, taxamt, freight, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PurchaseorderheaderRow, merge: (NewRow, PurchaseorderheaderRow) => NewRow): PurchaseorderheaderStructure[NewRow] = + new PurchaseorderheaderStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodFields.scala new file mode 100644 index 0000000000..5d1d6be534 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ShipmethodFields[Row] { + val shipmethodid: IdField[ShipmethodId, Row] + val name: Field[Name, Row] + val shipbase: Field[BigDecimal, Row] + val shiprate: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ShipmethodFields extends ShipmethodStructure[ShipmethodRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodId.scala new file mode 100644 index 0000000000..2d3afc5254 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +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 `purchasing.shipmethod` */ +case class ShipmethodId(value: Int) extends AnyVal +object ShipmethodId { + implicit lazy val arraySetter: Setter[Array[ShipmethodId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ShipmethodId, Int] = Bijection[ShipmethodId, Int](_.value)(ShipmethodId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ShipmethodId] = JdbcDecoder.intDecoder.map(ShipmethodId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ShipmethodId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ShipmethodId] = JsonDecoder.int.map(ShipmethodId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ShipmethodId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ShipmethodId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ShipmethodId] = ParameterMetaData.instance[ShipmethodId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ShipmethodId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepo.scala new file mode 100644 index 0000000000..c420a63bdc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ShipmethodRepo { + def delete(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ShipmethodFields, ShipmethodRow] + def insert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, ShipmethodRow] + def insert(unsaved: ShipmethodRowUnsaved): ZIO[ZConnection, Throwable, ShipmethodRow] + def select: SelectBuilder[ShipmethodFields, ShipmethodRow] + def selectAll: ZStream[ZConnection, Throwable, ShipmethodRow] + def selectById(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Option[ShipmethodRow]] + def selectByIds(shipmethodids: Array[ShipmethodId]): ZStream[ZConnection, Throwable, ShipmethodRow] + def update(row: ShipmethodRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ShipmethodFields, ShipmethodRow] + def upsert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, UpdateResult[ShipmethodRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoImpl.scala new file mode 100644 index 0000000000..f51609ac3e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoImpl.scala @@ -0,0 +1,121 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ShipmethodRepoImpl extends ShipmethodRepo { + override def delete(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from purchasing.shipmethod where "shipmethodid" = ${Segment.paramSegment(shipmethodid)(ShipmethodId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ShipmethodFields, ShipmethodRow] = { + DeleteBuilder("purchasing.shipmethod", ShipmethodFields) + } + override def insert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, ShipmethodRow] = { + sql"""insert into purchasing.shipmethod("shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.shipbase)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.shiprate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text + """.insertReturning(ShipmethodRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ShipmethodRowUnsaved): ZIO[ZConnection, Throwable, ShipmethodRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.shipmethodid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""shipmethodid"""", sql"${Segment.paramSegment(value: ShipmethodId)(ShipmethodId.setter)}::int4")) + }, + unsaved.shipbase match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""shipbase"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.shiprate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""shiprate"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into purchasing.shipmethod default values + returning "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into purchasing.shipmethod($names) values ($values) returning "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text""" + } + q.insertReturning(ShipmethodRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ShipmethodFields, ShipmethodRow] = { + SelectBuilderSql("purchasing.shipmethod", ShipmethodFields, ShipmethodRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ShipmethodRow] = { + sql"""select "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text from purchasing.shipmethod""".query(ShipmethodRow.jdbcDecoder).selectStream + } + override def selectById(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Option[ShipmethodRow]] = { + sql"""select "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text from purchasing.shipmethod where "shipmethodid" = ${Segment.paramSegment(shipmethodid)(ShipmethodId.setter)}""".query(ShipmethodRow.jdbcDecoder).selectOne + } + override def selectByIds(shipmethodids: Array[ShipmethodId]): ZStream[ZConnection, Throwable, ShipmethodRow] = { + sql"""select "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text from purchasing.shipmethod where "shipmethodid" = ANY(${Segment.paramSegment(shipmethodids)(ShipmethodId.arraySetter)})""".query(ShipmethodRow.jdbcDecoder).selectStream + } + override def update(row: ShipmethodRow): ZIO[ZConnection, Throwable, Boolean] = { + val shipmethodid = row.shipmethodid + sql"""update purchasing.shipmethod + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "shipbase" = ${Segment.paramSegment(row.shipbase)(Setter.bigDecimalScalaSetter)}::numeric, + "shiprate" = ${Segment.paramSegment(row.shiprate)(Setter.bigDecimalScalaSetter)}::numeric, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "shipmethodid" = ${Segment.paramSegment(shipmethodid)(ShipmethodId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ShipmethodFields, ShipmethodRow] = { + UpdateBuilder("purchasing.shipmethod", ShipmethodFields, ShipmethodRow.jdbcDecoder) + } + override def upsert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, UpdateResult[ShipmethodRow]] = { + sql"""insert into purchasing.shipmethod("shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.shipbase)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.shiprate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("shipmethodid") + do update set + "name" = EXCLUDED."name", + "shipbase" = EXCLUDED."shipbase", + "shiprate" = EXCLUDED."shiprate", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "shipmethodid", "name", "shipbase", "shiprate", "rowguid", "modifieddate"::text""".insertReturning(ShipmethodRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoMock.scala new file mode 100644 index 0000000000..3510dccd40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ShipmethodRepoMock(toRow: Function1[ShipmethodRowUnsaved, ShipmethodRow], + map: scala.collection.mutable.Map[ShipmethodId, ShipmethodRow] = scala.collection.mutable.Map.empty) extends ShipmethodRepo { + override def delete(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(shipmethodid).isDefined) + } + override def delete: DeleteBuilder[ShipmethodFields, ShipmethodRow] = { + DeleteBuilderMock(DeleteParams.empty, ShipmethodFields, map) + } + override def insert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, ShipmethodRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.shipmethodid)) + sys.error(s"id ${unsaved.shipmethodid} already exists") + else + map.put(unsaved.shipmethodid, unsaved) + + unsaved + } + } + override def insert(unsaved: ShipmethodRowUnsaved): ZIO[ZConnection, Throwable, ShipmethodRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ShipmethodFields, ShipmethodRow] = { + SelectBuilderMock(ShipmethodFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ShipmethodRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(shipmethodid: ShipmethodId): ZIO[ZConnection, Throwable, Option[ShipmethodRow]] = { + ZIO.succeed(map.get(shipmethodid)) + } + override def selectByIds(shipmethodids: Array[ShipmethodId]): ZStream[ZConnection, Throwable, ShipmethodRow] = { + ZStream.fromIterable(shipmethodids.flatMap(map.get)) + } + override def update(row: ShipmethodRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.shipmethodid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.shipmethodid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ShipmethodFields, ShipmethodRow] = { + UpdateBuilderMock(UpdateParams.empty, ShipmethodFields, map) + } + override def upsert(unsaved: ShipmethodRow): ZIO[ZConnection, Throwable, UpdateResult[ShipmethodRow]] = { + ZIO.succeed { + map.put(unsaved.shipmethodid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRow.scala new file mode 100644 index 0000000000..5b3a84448e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ShipmethodRow( + /** Primary key for ShipMethod records. */ + shipmethodid: ShipmethodId, + /** Shipping company name. */ + name: Name, + /** Minimum shipping charge. + Constraint CK_ShipMethod_ShipBase affecting columns "shipbase": ((shipbase > 0.00)) */ + shipbase: BigDecimal, + /** Shipping charge per pound. + Constraint CK_ShipMethod_ShipRate affecting columns "shiprate": ((shiprate > 0.00)) */ + shiprate: BigDecimal, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object ShipmethodRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ShipmethodRow] = new JdbcDecoder[ShipmethodRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ShipmethodRow) = + columIndex + 5 -> + ShipmethodRow( + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + shipbase = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 2, rs)._2, + shiprate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ShipmethodRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val shipbase = jsonObj.get("shipbase").toRight("Missing field 'shipbase'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val shiprate = jsonObj.get("shiprate").toRight("Missing field 'shiprate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (shipmethodid.isRight && name.isRight && shipbase.isRight && shiprate.isRight && rowguid.isRight && modifieddate.isRight) + Right(ShipmethodRow(shipmethodid = shipmethodid.toOption.get, name = name.toOption.get, shipbase = shipbase.toOption.get, shiprate = shiprate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](shipmethodid, name, shipbase, shiprate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShipmethodRow] = new JsonEncoder[ShipmethodRow] { + override def unsafeEncode(a: ShipmethodRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""shipbase":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.shipbase, indent, out) + out.write(",") + out.write(""""shiprate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.shiprate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRowUnsaved.scala new file mode 100644 index 0000000000..951bbb44b8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodRowUnsaved.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `purchasing.shipmethod` which has not been persisted yet */ +case class ShipmethodRowUnsaved( + /** Shipping company name. */ + name: Name, + /** Default: nextval('purchasing.shipmethod_shipmethodid_seq'::regclass) + Primary key for ShipMethod records. */ + shipmethodid: Defaulted[ShipmethodId] = Defaulted.UseDefault, + /** Default: 0.00 + Minimum shipping charge. + Constraint CK_ShipMethod_ShipBase affecting columns "shipbase": ((shipbase > 0.00)) */ + shipbase: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Shipping charge per pound. + Constraint CK_ShipMethod_ShipRate affecting columns "shiprate": ((shiprate > 0.00)) */ + shiprate: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(shipmethodidDefault: => ShipmethodId, shipbaseDefault: => BigDecimal, shiprateDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): ShipmethodRow = + ShipmethodRow( + name = name, + shipmethodid = shipmethodid match { + case Defaulted.UseDefault => shipmethodidDefault + case Defaulted.Provided(value) => value + }, + shipbase = shipbase match { + case Defaulted.UseDefault => shipbaseDefault + case Defaulted.Provided(value) => value + }, + shiprate = shiprate match { + case Defaulted.UseDefault => shiprateDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ShipmethodRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ShipmethodRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(Defaulted.jsonDecoder(ShipmethodId.jsonDecoder))) + val shipbase = jsonObj.get("shipbase").toRight("Missing field 'shipbase'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val shiprate = jsonObj.get("shiprate").toRight("Missing field 'shiprate'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && shipmethodid.isRight && shipbase.isRight && shiprate.isRight && rowguid.isRight && modifieddate.isRight) + Right(ShipmethodRowUnsaved(name = name.toOption.get, shipmethodid = shipmethodid.toOption.get, shipbase = shipbase.toOption.get, shiprate = shiprate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, shipmethodid, shipbase, shiprate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShipmethodRowUnsaved] = new JsonEncoder[ShipmethodRowUnsaved] { + override def unsafeEncode(a: ShipmethodRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + Defaulted.jsonEncoder(ShipmethodId.jsonEncoder).unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""shipbase":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.shipbase, indent, out) + out.write(",") + out.write(""""shiprate":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.shiprate, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodStructure.scala new file mode 100644 index 0000000000..90cfaab1ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/shipmethod/ShipmethodStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package shipmethod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ShipmethodStructure[Row](val prefix: Option[String], val extract: Row => ShipmethodRow, val merge: (Row, ShipmethodRow) => Row) + extends Relation[ShipmethodFields, ShipmethodRow, Row] + with ShipmethodFields[Row] { outer => + + override val shipmethodid = new IdField[ShipmethodId, Row](prefix, "shipmethodid", None, Some("int4"))(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val shipbase = new Field[BigDecimal, Row](prefix, "shipbase", None, Some("numeric"))(x => extract(x).shipbase, (row, value) => merge(row, extract(row).copy(shipbase = value))) + override val shiprate = new Field[BigDecimal, Row](prefix, "shiprate", None, Some("numeric"))(x => extract(x).shiprate, (row, value) => merge(row, extract(row).copy(shiprate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](shipmethodid, name, shipbase, shiprate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ShipmethodRow, merge: (NewRow, ShipmethodRow) => NewRow): ShipmethodStructure[NewRow] = + new ShipmethodStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorFields.scala new file mode 100644 index 0000000000..4e5bed797b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait VendorFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val accountnumber: Field[AccountNumber, Row] + val name: Field[Name, Row] + val creditrating: Field[TypoShort, Row] + val preferredvendorstatus: Field[Flag, Row] + val activeflag: Field[Flag, Row] + val purchasingwebserviceurl: OptField[/* max 1024 chars */ String, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object VendorFields extends VendorStructure[VendorRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepo.scala new file mode 100644 index 0000000000..9b460e7f63 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VendorRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[VendorFields, VendorRow] + def insert(unsaved: VendorRow): ZIO[ZConnection, Throwable, VendorRow] + def insert(unsaved: VendorRowUnsaved): ZIO[ZConnection, Throwable, VendorRow] + def select: SelectBuilder[VendorFields, VendorRow] + def selectAll: ZStream[ZConnection, Throwable, VendorRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[VendorRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, VendorRow] + def update(row: VendorRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[VendorFields, VendorRow] + def upsert(unsaved: VendorRow): ZIO[ZConnection, Throwable, UpdateResult[VendorRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoImpl.scala new file mode 100644 index 0000000000..bb4d92121e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoImpl.scala @@ -0,0 +1,126 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VendorRepoImpl extends VendorRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from purchasing.vendor where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[VendorFields, VendorRow] = { + DeleteBuilder("purchasing.vendor", VendorFields) + } + override def insert(unsaved: VendorRow): ZIO[ZConnection, Throwable, VendorRow] = { + sql"""insert into purchasing.vendor("businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.accountnumber)(AccountNumber.setter)}::varchar, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.creditrating)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.preferredvendorstatus)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.activeflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.purchasingwebserviceurl)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text + """.insertReturning(VendorRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: VendorRowUnsaved): ZIO[ZConnection, Throwable, VendorRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""accountnumber"""", sql"${Segment.paramSegment(unsaved.accountnumber)(AccountNumber.setter)}::varchar")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""creditrating"""", sql"${Segment.paramSegment(unsaved.creditrating)(TypoShort.setter)}::int2")), + Some((sql""""purchasingwebserviceurl"""", sql"${Segment.paramSegment(unsaved.purchasingwebserviceurl)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.preferredvendorstatus match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""preferredvendorstatus"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.activeflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""activeflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into purchasing.vendor default values + returning "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into purchasing.vendor($names) values ($values) returning "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text""" + } + q.insertReturning(VendorRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[VendorFields, VendorRow] = { + SelectBuilderSql("purchasing.vendor", VendorFields, VendorRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VendorRow] = { + sql"""select "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text from purchasing.vendor""".query(VendorRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[VendorRow]] = { + sql"""select "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text from purchasing.vendor where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(VendorRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, VendorRow] = { + sql"""select "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text from purchasing.vendor where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(VendorRow.jdbcDecoder).selectStream + } + override def update(row: VendorRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update purchasing.vendor + set "accountnumber" = ${Segment.paramSegment(row.accountnumber)(AccountNumber.setter)}::varchar, + "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "creditrating" = ${Segment.paramSegment(row.creditrating)(TypoShort.setter)}::int2, + "preferredvendorstatus" = ${Segment.paramSegment(row.preferredvendorstatus)(Flag.setter)}::bool, + "activeflag" = ${Segment.paramSegment(row.activeflag)(Flag.setter)}::bool, + "purchasingwebserviceurl" = ${Segment.paramSegment(row.purchasingwebserviceurl)(Setter.optionParamSetter(Setter.stringSetter))}, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[VendorFields, VendorRow] = { + UpdateBuilder("purchasing.vendor", VendorFields, VendorRow.jdbcDecoder) + } + override def upsert(unsaved: VendorRow): ZIO[ZConnection, Throwable, UpdateResult[VendorRow]] = { + sql"""insert into purchasing.vendor("businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.accountnumber)(AccountNumber.setter)}::varchar, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.creditrating)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.preferredvendorstatus)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.activeflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.purchasingwebserviceurl)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "accountnumber" = EXCLUDED."accountnumber", + "name" = EXCLUDED."name", + "creditrating" = EXCLUDED."creditrating", + "preferredvendorstatus" = EXCLUDED."preferredvendorstatus", + "activeflag" = EXCLUDED."activeflag", + "purchasingwebserviceurl" = EXCLUDED."purchasingwebserviceurl", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "accountnumber", "name", "creditrating", "preferredvendorstatus", "activeflag", "purchasingwebserviceurl", "modifieddate"::text""".insertReturning(VendorRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoMock.scala new file mode 100644 index 0000000000..b1b0cbfea1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class VendorRepoMock(toRow: Function1[VendorRowUnsaved, VendorRow], + map: scala.collection.mutable.Map[BusinessentityId, VendorRow] = scala.collection.mutable.Map.empty) extends VendorRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[VendorFields, VendorRow] = { + DeleteBuilderMock(DeleteParams.empty, VendorFields, map) + } + override def insert(unsaved: VendorRow): ZIO[ZConnection, Throwable, VendorRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: VendorRowUnsaved): ZIO[ZConnection, Throwable, VendorRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[VendorFields, VendorRow] = { + SelectBuilderMock(VendorFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, VendorRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[VendorRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, VendorRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: VendorRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[VendorFields, VendorRow] = { + UpdateBuilderMock(UpdateParams.empty, VendorFields, map) + } + override def upsert(unsaved: VendorRow): ZIO[ZConnection, Throwable, UpdateResult[VendorRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRow.scala new file mode 100644 index 0000000000..1b6245a04f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRow.scala @@ -0,0 +1,100 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VendorRow( + /** Primary key for Vendor records. Foreign key to BusinessEntity.BusinessEntityID + Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Vendor account (identification) number. */ + accountnumber: AccountNumber, + /** Company name. */ + name: Name, + /** 1 = Superior, 2 = Excellent, 3 = Above average, 4 = Average, 5 = Below average + Constraint CK_Vendor_CreditRating affecting columns "creditrating": (((creditrating >= 1) AND (creditrating <= 5))) */ + creditrating: TypoShort, + /** 0 = Do not use if another vendor is available. 1 = Preferred over other vendors supplying the same product. */ + preferredvendorstatus: Flag, + /** 0 = Vendor no longer used. 1 = Vendor is actively used. */ + activeflag: Flag, + /** Vendor URL. */ + purchasingwebserviceurl: Option[/* max 1024 chars */ String], + modifieddate: TypoLocalDateTime +) + +object VendorRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VendorRow] = new JdbcDecoder[VendorRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VendorRow) = + columIndex + 7 -> + VendorRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + accountnumber = AccountNumber.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + creditrating = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + preferredvendorstatus = Flag.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + activeflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + purchasingwebserviceurl = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VendorRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val accountnumber = jsonObj.get("accountnumber").toRight("Missing field 'accountnumber'").flatMap(_.as(AccountNumber.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val creditrating = jsonObj.get("creditrating").toRight("Missing field 'creditrating'").flatMap(_.as(TypoShort.jsonDecoder)) + val preferredvendorstatus = jsonObj.get("preferredvendorstatus").toRight("Missing field 'preferredvendorstatus'").flatMap(_.as(Flag.jsonDecoder)) + val activeflag = jsonObj.get("activeflag").toRight("Missing field 'activeflag'").flatMap(_.as(Flag.jsonDecoder)) + val purchasingwebserviceurl = jsonObj.get("purchasingwebserviceurl").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && accountnumber.isRight && name.isRight && creditrating.isRight && preferredvendorstatus.isRight && activeflag.isRight && purchasingwebserviceurl.isRight && modifieddate.isRight) + Right(VendorRow(businessentityid = businessentityid.toOption.get, accountnumber = accountnumber.toOption.get, name = name.toOption.get, creditrating = creditrating.toOption.get, preferredvendorstatus = preferredvendorstatus.toOption.get, activeflag = activeflag.toOption.get, purchasingwebserviceurl = purchasingwebserviceurl.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, accountnumber, name, creditrating, preferredvendorstatus, activeflag, purchasingwebserviceurl, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VendorRow] = new JsonEncoder[VendorRow] { + override def unsafeEncode(a: VendorRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""accountnumber":""") + AccountNumber.jsonEncoder.unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""creditrating":""") + TypoShort.jsonEncoder.unsafeEncode(a.creditrating, indent, out) + out.write(",") + out.write(""""preferredvendorstatus":""") + Flag.jsonEncoder.unsafeEncode(a.preferredvendorstatus, indent, out) + out.write(",") + out.write(""""activeflag":""") + Flag.jsonEncoder.unsafeEncode(a.activeflag, indent, out) + out.write(",") + out.write(""""purchasingwebserviceurl":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.purchasingwebserviceurl, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRowUnsaved.scala new file mode 100644 index 0000000000..d0f34289ca --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorRowUnsaved.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `purchasing.vendor` which has not been persisted yet */ +case class VendorRowUnsaved( + /** Primary key for Vendor records. Foreign key to BusinessEntity.BusinessEntityID + Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Vendor account (identification) number. */ + accountnumber: AccountNumber, + /** Company name. */ + name: Name, + /** 1 = Superior, 2 = Excellent, 3 = Above average, 4 = Average, 5 = Below average + Constraint CK_Vendor_CreditRating affecting columns "creditrating": (((creditrating >= 1) AND (creditrating <= 5))) */ + creditrating: TypoShort, + /** Vendor URL. */ + purchasingwebserviceurl: Option[/* max 1024 chars */ String], + /** Default: true + 0 = Do not use if another vendor is available. 1 = Preferred over other vendors supplying the same product. */ + preferredvendorstatus: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: true + 0 = Vendor no longer used. 1 = Vendor is actively used. */ + activeflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(preferredvendorstatusDefault: => Flag, activeflagDefault: => Flag, modifieddateDefault: => TypoLocalDateTime): VendorRow = + VendorRow( + businessentityid = businessentityid, + accountnumber = accountnumber, + name = name, + creditrating = creditrating, + purchasingwebserviceurl = purchasingwebserviceurl, + preferredvendorstatus = preferredvendorstatus match { + case Defaulted.UseDefault => preferredvendorstatusDefault + case Defaulted.Provided(value) => value + }, + activeflag = activeflag match { + case Defaulted.UseDefault => activeflagDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object VendorRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[VendorRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val accountnumber = jsonObj.get("accountnumber").toRight("Missing field 'accountnumber'").flatMap(_.as(AccountNumber.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val creditrating = jsonObj.get("creditrating").toRight("Missing field 'creditrating'").flatMap(_.as(TypoShort.jsonDecoder)) + val purchasingwebserviceurl = jsonObj.get("purchasingwebserviceurl").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val preferredvendorstatus = jsonObj.get("preferredvendorstatus").toRight("Missing field 'preferredvendorstatus'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val activeflag = jsonObj.get("activeflag").toRight("Missing field 'activeflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && accountnumber.isRight && name.isRight && creditrating.isRight && purchasingwebserviceurl.isRight && preferredvendorstatus.isRight && activeflag.isRight && modifieddate.isRight) + Right(VendorRowUnsaved(businessentityid = businessentityid.toOption.get, accountnumber = accountnumber.toOption.get, name = name.toOption.get, creditrating = creditrating.toOption.get, purchasingwebserviceurl = purchasingwebserviceurl.toOption.get, preferredvendorstatus = preferredvendorstatus.toOption.get, activeflag = activeflag.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, accountnumber, name, creditrating, purchasingwebserviceurl, preferredvendorstatus, activeflag, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VendorRowUnsaved] = new JsonEncoder[VendorRowUnsaved] { + override def unsafeEncode(a: VendorRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""accountnumber":""") + AccountNumber.jsonEncoder.unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""creditrating":""") + TypoShort.jsonEncoder.unsafeEncode(a.creditrating, indent, out) + out.write(",") + out.write(""""purchasingwebserviceurl":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.purchasingwebserviceurl, indent, out) + out.write(",") + out.write(""""preferredvendorstatus":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.preferredvendorstatus, indent, out) + out.write(",") + out.write(""""activeflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.activeflag, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorStructure.scala new file mode 100644 index 0000000000..dea19ffaa1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vendor/VendorStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vendor + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VendorStructure[Row](val prefix: Option[String], val extract: Row => VendorRow, val merge: (Row, VendorRow) => Row) + extends Relation[VendorFields, VendorRow, Row] + with VendorFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val accountnumber = new Field[AccountNumber, Row](prefix, "accountnumber", None, Some("varchar"))(x => extract(x).accountnumber, (row, value) => merge(row, extract(row).copy(accountnumber = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val creditrating = new Field[TypoShort, Row](prefix, "creditrating", None, Some("int2"))(x => extract(x).creditrating, (row, value) => merge(row, extract(row).copy(creditrating = value))) + override val preferredvendorstatus = new Field[Flag, Row](prefix, "preferredvendorstatus", None, Some("bool"))(x => extract(x).preferredvendorstatus, (row, value) => merge(row, extract(row).copy(preferredvendorstatus = value))) + override val activeflag = new Field[Flag, Row](prefix, "activeflag", None, Some("bool"))(x => extract(x).activeflag, (row, value) => merge(row, extract(row).copy(activeflag = value))) + override val purchasingwebserviceurl = new OptField[/* max 1024 chars */ String, Row](prefix, "purchasingwebserviceurl", None, None)(x => extract(x).purchasingwebserviceurl, (row, value) => merge(row, extract(row).copy(purchasingwebserviceurl = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, accountnumber, name, creditrating, preferredvendorstatus, activeflag, purchasingwebserviceurl, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VendorRow, merge: (NewRow, VendorRow) => NewRow): VendorStructure[NewRow] = + new VendorStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewFields.scala new file mode 100644 index 0000000000..9b5004aa23 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VvendorwithaddressesViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val addresstype: Field[Name, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovincename: Field[Name, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val countryregionname: Field[Name, Row] +} +object VvendorwithaddressesViewFields extends VvendorwithaddressesViewStructure[VvendorwithaddressesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepo.scala new file mode 100644 index 0000000000..82b219ce9d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithaddresses + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VvendorwithaddressesViewRepo { + def select: SelectBuilder[VvendorwithaddressesViewFields, VvendorwithaddressesViewRow] + def selectAll: ZStream[ZConnection, Throwable, VvendorwithaddressesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepoImpl.scala new file mode 100644 index 0000000000..d0dc8a9a49 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithaddresses + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VvendorwithaddressesViewRepoImpl extends VvendorwithaddressesViewRepo { + override def select: SelectBuilder[VvendorwithaddressesViewFields, VvendorwithaddressesViewRow] = { + SelectBuilderSql("purchasing.vvendorwithaddresses", VvendorwithaddressesViewFields, VvendorwithaddressesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VvendorwithaddressesViewRow] = { + sql"""select "businessentityid", "name", "addresstype", "addressline1", "addressline2", "city", "stateprovincename", "postalcode", "countryregionname" from purchasing.vvendorwithaddresses""".query(VvendorwithaddressesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRow.scala new file mode 100644 index 0000000000..3c0301f90b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewRow.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VvendorwithaddressesViewRow( + /** Points to [[vendor.VendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[vendor.VendorRow.name]] */ + name: Name, + /** Points to [[person.addresstype.AddresstypeRow.name]] */ + addresstype: Name, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + countryregionname: Name +) + +object VvendorwithaddressesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VvendorwithaddressesViewRow] = new JdbcDecoder[VvendorwithaddressesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VvendorwithaddressesViewRow) = + columIndex + 8 -> + VvendorwithaddressesViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + addresstype = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VvendorwithaddressesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val addresstype = jsonObj.get("addresstype").toRight("Missing field 'addresstype'").flatMap(_.as(Name.jsonDecoder)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + if (businessentityid.isRight && name.isRight && addresstype.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovincename.isRight && postalcode.isRight && countryregionname.isRight) + Right(VvendorwithaddressesViewRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, addresstype = addresstype.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovincename = stateprovincename.toOption.get, postalcode = postalcode.toOption.get, countryregionname = countryregionname.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VvendorwithaddressesViewRow] = new JsonEncoder[VvendorwithaddressesViewRow] { + override def unsafeEncode(a: VvendorwithaddressesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""addresstype":""") + Name.jsonEncoder.unsafeEncode(a.addresstype, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewStructure.scala new file mode 100644 index 0000000000..01e59470ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithaddresses/VvendorwithaddressesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VvendorwithaddressesViewStructure[Row](val prefix: Option[String], val extract: Row => VvendorwithaddressesViewRow, val merge: (Row, VvendorwithaddressesViewRow) => Row) + extends Relation[VvendorwithaddressesViewFields, VvendorwithaddressesViewRow, Row] + with VvendorwithaddressesViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val addresstype = new Field[Name, Row](prefix, "addresstype", None, None)(x => extract(x).addresstype, (row, value) => merge(row, extract(row).copy(addresstype = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VvendorwithaddressesViewRow, merge: (NewRow, VvendorwithaddressesViewRow) => NewRow): VvendorwithaddressesViewStructure[NewRow] = + new VvendorwithaddressesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewFields.scala new file mode 100644 index 0000000000..6208dfdd89 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VvendorwithcontactsViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val contacttype: Field[Name, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val phonenumber: OptField[Phone, Row] + val phonenumbertype: OptField[Name, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val emailpromotion: Field[Int, Row] +} +object VvendorwithcontactsViewFields extends VvendorwithcontactsViewStructure[VvendorwithcontactsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepo.scala new file mode 100644 index 0000000000..49cd50a44b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithcontacts + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VvendorwithcontactsViewRepo { + def select: SelectBuilder[VvendorwithcontactsViewFields, VvendorwithcontactsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VvendorwithcontactsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepoImpl.scala new file mode 100644 index 0000000000..6d08645e01 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithcontacts + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VvendorwithcontactsViewRepoImpl extends VvendorwithcontactsViewRepo { + override def select: SelectBuilder[VvendorwithcontactsViewFields, VvendorwithcontactsViewRow] = { + SelectBuilderSql("purchasing.vvendorwithcontacts", VvendorwithcontactsViewFields, VvendorwithcontactsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VvendorwithcontactsViewRow] = { + sql"""select "businessentityid", "name", "contacttype", "title", "firstname", "middlename", "lastname", "suffix", "phonenumber", "phonenumbertype", "emailaddress", "emailpromotion" from purchasing.vvendorwithcontacts""".query(VvendorwithcontactsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRow.scala new file mode 100644 index 0000000000..e45682905f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewRow.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VvendorwithcontactsViewRow( + /** Points to [[vendor.VendorRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[vendor.VendorRow.name]] */ + name: Name, + /** Points to [[person.contacttype.ContacttypeRow.name]] */ + contacttype: Name, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Option[Phone], + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + phonenumbertype: Option[Name], + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int +) + +object VvendorwithcontactsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VvendorwithcontactsViewRow] = new JdbcDecoder[VvendorwithcontactsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VvendorwithcontactsViewRow) = + columIndex + 11 -> + VvendorwithcontactsViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + contacttype = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + phonenumber = JdbcDecoder.optionDecoder(Phone.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + phonenumbertype = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VvendorwithcontactsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val contacttype = jsonObj.get("contacttype").toRight("Missing field 'contacttype'").flatMap(_.as(Name.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val phonenumber = jsonObj.get("phonenumber").fold[Either[String, Option[Phone]]](Right(None))(_.as(JsonDecoder.option(Phone.jsonDecoder))) + val phonenumbertype = jsonObj.get("phonenumbertype").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + if (businessentityid.isRight && name.isRight && contacttype.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && phonenumber.isRight && phonenumbertype.isRight && emailaddress.isRight && emailpromotion.isRight) + Right(VvendorwithcontactsViewRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, contacttype = contacttype.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertype = phonenumbertype.toOption.get, emailaddress = emailaddress.toOption.get, emailpromotion = emailpromotion.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, contacttype, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VvendorwithcontactsViewRow] = new JsonEncoder[VvendorwithcontactsViewRow] { + override def unsafeEncode(a: VvendorwithcontactsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""contacttype":""") + Name.jsonEncoder.unsafeEncode(a.contacttype, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""phonenumber":""") + JsonEncoder.option(Phone.jsonEncoder).unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertype":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.phonenumbertype, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewStructure.scala new file mode 100644 index 0000000000..d0e892230d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/purchasing/vvendorwithcontacts/VvendorwithcontactsViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package purchasing +package vvendorwithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VvendorwithcontactsViewStructure[Row](val prefix: Option[String], val extract: Row => VvendorwithcontactsViewRow, val merge: (Row, VvendorwithcontactsViewRow) => Row) + extends Relation[VvendorwithcontactsViewFields, VvendorwithcontactsViewRow, Row] + with VvendorwithcontactsViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val contacttype = new Field[Name, Row](prefix, "contacttype", None, None)(x => extract(x).contacttype, (row, value) => merge(row, extract(row).copy(contacttype = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val phonenumber = new OptField[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertype = new OptField[Name, Row](prefix, "phonenumbertype", None, None)(x => extract(x).phonenumbertype, (row, value) => merge(row, extract(row).copy(phonenumbertype = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, contacttype, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VvendorwithcontactsViewRow, merge: (NewRow, VvendorwithcontactsViewRow) => NewRow): VvendorwithcontactsViewStructure[NewRow] = + new VvendorwithcontactsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewFields.scala new file mode 100644 index 0000000000..9abdec14b2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait CViewFields[Row] { + val id: Field[CustomerId, Row] + val customerid: Field[CustomerId, Row] + val personid: OptField[BusinessentityId, Row] + val storeid: OptField[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CViewFields extends CViewStructure[CViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepo.scala new file mode 100644 index 0000000000..6ba7c0ef40 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package c + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CViewRepo { + def select: SelectBuilder[CViewFields, CViewRow] + def selectAll: ZStream[ZConnection, Throwable, CViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepoImpl.scala new file mode 100644 index 0000000000..38a8f89368 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package c + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CViewRepoImpl extends CViewRepo { + override def select: SelectBuilder[CViewFields, CViewRow] = { + SelectBuilderSql("sa.c", CViewFields, CViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CViewRow] = { + sql"""select "id", "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text from sa.c""".query(CViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRow.scala new file mode 100644 index 0000000000..fc4cf16e67 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CViewRow( + /** Points to [[sales.customer.CustomerRow.customerid]] */ + id: CustomerId, + /** Points to [[sales.customer.CustomerRow.customerid]] */ + customerid: CustomerId, + /** Points to [[sales.customer.CustomerRow.personid]] */ + personid: Option[BusinessentityId], + /** Points to [[sales.customer.CustomerRow.storeid]] */ + storeid: Option[BusinessentityId], + /** Points to [[sales.customer.CustomerRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Points to [[sales.customer.CustomerRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.customer.CustomerRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CViewRow] = new JdbcDecoder[CViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CViewRow) = + columIndex + 6 -> + CViewRow( + id = CustomerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + customerid = CustomerId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + personid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + storeid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(CustomerId.jsonDecoder)) + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(CustomerId.jsonDecoder)) + val personid = jsonObj.get("personid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val storeid = jsonObj.get("storeid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && customerid.isRight && personid.isRight && storeid.isRight && territoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(CViewRow(id = id.toOption.get, customerid = customerid.toOption.get, personid = personid.toOption.get, storeid = storeid.toOption.get, territoryid = territoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, customerid, personid, storeid, territoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CViewRow] = new JsonEncoder[CViewRow] { + override def unsafeEncode(a: CViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + CustomerId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""customerid":""") + CustomerId.jsonEncoder.unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""personid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""storeid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.storeid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewStructure.scala new file mode 100644 index 0000000000..973be24e13 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/c/CViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package c + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CViewStructure[Row](val prefix: Option[String], val extract: Row => CViewRow, val merge: (Row, CViewRow) => Row) + extends Relation[CViewFields, CViewRow, Row] + with CViewFields[Row] { outer => + + override val id = new Field[CustomerId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val customerid = new Field[CustomerId, Row](prefix, "customerid", None, None)(x => extract(x).customerid, (row, value) => merge(row, extract(row).copy(customerid = value))) + override val personid = new OptField[BusinessentityId, Row](prefix, "personid", None, None)(x => extract(x).personid, (row, value) => merge(row, extract(row).copy(personid = value))) + override val storeid = new OptField[BusinessentityId, Row](prefix, "storeid", None, None)(x => extract(x).storeid, (row, value) => merge(row, extract(row).copy(storeid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, customerid, personid, storeid, territoryid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CViewRow, merge: (NewRow, CViewRow) => NewRow): CViewStructure[NewRow] = + new CViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewFields.scala new file mode 100644 index 0000000000..1ac3a32ec9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field + +trait CcViewFields[Row] { + val id: Field[/* user-picked */ CustomCreditcardId, Row] + val creditcardid: Field[/* user-picked */ CustomCreditcardId, Row] + val cardtype: Field[/* max 50 chars */ String, Row] + val cardnumber: Field[/* max 25 chars */ String, Row] + val expmonth: Field[TypoShort, Row] + val expyear: Field[TypoShort, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CcViewFields extends CcViewStructure[CcViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepo.scala new file mode 100644 index 0000000000..bbc1708e8d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CcViewRepo { + def select: SelectBuilder[CcViewFields, CcViewRow] + def selectAll: ZStream[ZConnection, Throwable, CcViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepoImpl.scala new file mode 100644 index 0000000000..c114df27fc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CcViewRepoImpl extends CcViewRepo { + override def select: SelectBuilder[CcViewFields, CcViewRow] = { + SelectBuilderSql("sa.cc", CcViewFields, CcViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CcViewRow] = { + sql"""select "id", "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text from sa.cc""".query(CcViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRow.scala new file mode 100644 index 0000000000..4e16b366e0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CcViewRow( + /** Points to [[sales.creditcard.CreditcardRow.creditcardid]] */ + id: /* user-picked */ CustomCreditcardId, + /** Points to [[sales.creditcard.CreditcardRow.creditcardid]] */ + creditcardid: /* user-picked */ CustomCreditcardId, + /** Points to [[sales.creditcard.CreditcardRow.cardtype]] */ + cardtype: /* max 50 chars */ String, + /** Points to [[sales.creditcard.CreditcardRow.cardnumber]] */ + cardnumber: /* max 25 chars */ String, + /** Points to [[sales.creditcard.CreditcardRow.expmonth]] */ + expmonth: TypoShort, + /** Points to [[sales.creditcard.CreditcardRow.expyear]] */ + expyear: TypoShort, + /** Points to [[sales.creditcard.CreditcardRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CcViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CcViewRow] = new JdbcDecoder[CcViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CcViewRow) = + columIndex + 6 -> + CcViewRow( + id = CustomCreditcardId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + creditcardid = CustomCreditcardId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + cardtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + cardnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + expmonth = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + expyear = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CcViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val cardtype = jsonObj.get("cardtype").toRight("Missing field 'cardtype'").flatMap(_.as(JsonDecoder.string)) + val cardnumber = jsonObj.get("cardnumber").toRight("Missing field 'cardnumber'").flatMap(_.as(JsonDecoder.string)) + val expmonth = jsonObj.get("expmonth").toRight("Missing field 'expmonth'").flatMap(_.as(TypoShort.jsonDecoder)) + val expyear = jsonObj.get("expyear").toRight("Missing field 'expyear'").flatMap(_.as(TypoShort.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && creditcardid.isRight && cardtype.isRight && cardnumber.isRight && expmonth.isRight && expyear.isRight && modifieddate.isRight) + Right(CcViewRow(id = id.toOption.get, creditcardid = creditcardid.toOption.get, cardtype = cardtype.toOption.get, cardnumber = cardnumber.toOption.get, expmonth = expmonth.toOption.get, expyear = expyear.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, creditcardid, cardtype, cardnumber, expmonth, expyear, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CcViewRow] = new JsonEncoder[CcViewRow] { + override def unsafeEncode(a: CcViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""cardtype":""") + JsonEncoder.string.unsafeEncode(a.cardtype, indent, out) + out.write(",") + out.write(""""cardnumber":""") + JsonEncoder.string.unsafeEncode(a.cardnumber, indent, out) + out.write(",") + out.write(""""expmonth":""") + TypoShort.jsonEncoder.unsafeEncode(a.expmonth, indent, out) + out.write(",") + out.write(""""expyear":""") + TypoShort.jsonEncoder.unsafeEncode(a.expyear, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewStructure.scala new file mode 100644 index 0000000000..247390ff7b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cc/CcViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CcViewStructure[Row](val prefix: Option[String], val extract: Row => CcViewRow, val merge: (Row, CcViewRow) => Row) + extends Relation[CcViewFields, CcViewRow, Row] + with CcViewFields[Row] { outer => + + override val id = new Field[/* user-picked */ CustomCreditcardId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val creditcardid = new Field[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, None)(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val cardtype = new Field[/* max 50 chars */ String, Row](prefix, "cardtype", None, None)(x => extract(x).cardtype, (row, value) => merge(row, extract(row).copy(cardtype = value))) + override val cardnumber = new Field[/* max 25 chars */ String, Row](prefix, "cardnumber", None, None)(x => extract(x).cardnumber, (row, value) => merge(row, extract(row).copy(cardnumber = value))) + override val expmonth = new Field[TypoShort, Row](prefix, "expmonth", None, None)(x => extract(x).expmonth, (row, value) => merge(row, extract(row).copy(expmonth = value))) + override val expyear = new Field[TypoShort, Row](prefix, "expyear", None, None)(x => extract(x).expyear, (row, value) => merge(row, extract(row).copy(expyear = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, creditcardid, cardtype, cardnumber, expmonth, expyear, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CcViewRow, merge: (NewRow, CcViewRow) => NewRow): CcViewStructure[NewRow] = + new CcViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewFields.scala new file mode 100644 index 0000000000..d4e16756d0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import adventureworks.sales.currencyrate.CurrencyrateId +import typo.dsl.SqlExpr.Field + +trait CrViewFields[Row] { + val currencyrateid: Field[CurrencyrateId, Row] + val currencyratedate: Field[TypoLocalDateTime, Row] + val fromcurrencycode: Field[CurrencyId, Row] + val tocurrencycode: Field[CurrencyId, Row] + val averagerate: Field[BigDecimal, Row] + val endofdayrate: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CrViewFields extends CrViewStructure[CrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepo.scala new file mode 100644 index 0000000000..441eb40edd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CrViewRepo { + def select: SelectBuilder[CrViewFields, CrViewRow] + def selectAll: ZStream[ZConnection, Throwable, CrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepoImpl.scala new file mode 100644 index 0000000000..40505d593f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CrViewRepoImpl extends CrViewRepo { + override def select: SelectBuilder[CrViewFields, CrViewRow] = { + SelectBuilderSql("sa.cr", CrViewFields, CrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CrViewRow] = { + sql"""select "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text from sa.cr""".query(CrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRow.scala new file mode 100644 index 0000000000..acbe0f0799 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import adventureworks.sales.currencyrate.CurrencyrateId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CrViewRow( + /** Points to [[sales.currencyrate.CurrencyrateRow.currencyrateid]] */ + currencyrateid: CurrencyrateId, + /** Points to [[sales.currencyrate.CurrencyrateRow.currencyratedate]] */ + currencyratedate: TypoLocalDateTime, + /** Points to [[sales.currencyrate.CurrencyrateRow.fromcurrencycode]] */ + fromcurrencycode: CurrencyId, + /** Points to [[sales.currencyrate.CurrencyrateRow.tocurrencycode]] */ + tocurrencycode: CurrencyId, + /** Points to [[sales.currencyrate.CurrencyrateRow.averagerate]] */ + averagerate: BigDecimal, + /** Points to [[sales.currencyrate.CurrencyrateRow.endofdayrate]] */ + endofdayrate: BigDecimal, + /** Points to [[sales.currencyrate.CurrencyrateRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CrViewRow] = new JdbcDecoder[CrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CrViewRow) = + columIndex + 6 -> + CrViewRow( + currencyrateid = CurrencyrateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + currencyratedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + fromcurrencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + tocurrencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + averagerate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + endofdayrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val currencyrateid = jsonObj.get("currencyrateid").toRight("Missing field 'currencyrateid'").flatMap(_.as(CurrencyrateId.jsonDecoder)) + val currencyratedate = jsonObj.get("currencyratedate").toRight("Missing field 'currencyratedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val fromcurrencycode = jsonObj.get("fromcurrencycode").toRight("Missing field 'fromcurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val tocurrencycode = jsonObj.get("tocurrencycode").toRight("Missing field 'tocurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val averagerate = jsonObj.get("averagerate").toRight("Missing field 'averagerate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val endofdayrate = jsonObj.get("endofdayrate").toRight("Missing field 'endofdayrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (currencyrateid.isRight && currencyratedate.isRight && fromcurrencycode.isRight && tocurrencycode.isRight && averagerate.isRight && endofdayrate.isRight && modifieddate.isRight) + Right(CrViewRow(currencyrateid = currencyrateid.toOption.get, currencyratedate = currencyratedate.toOption.get, fromcurrencycode = fromcurrencycode.toOption.get, tocurrencycode = tocurrencycode.toOption.get, averagerate = averagerate.toOption.get, endofdayrate = endofdayrate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](currencyrateid, currencyratedate, fromcurrencycode, tocurrencycode, averagerate, endofdayrate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CrViewRow] = new JsonEncoder[CrViewRow] { + override def unsafeEncode(a: CrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""currencyrateid":""") + CurrencyrateId.jsonEncoder.unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""currencyratedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.currencyratedate, indent, out) + out.write(",") + out.write(""""fromcurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.fromcurrencycode, indent, out) + out.write(",") + out.write(""""tocurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.tocurrencycode, indent, out) + out.write(",") + out.write(""""averagerate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.averagerate, indent, out) + out.write(",") + out.write(""""endofdayrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.endofdayrate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewStructure.scala new file mode 100644 index 0000000000..0d386f89eb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cr/CrViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import adventureworks.sales.currencyrate.CurrencyrateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CrViewStructure[Row](val prefix: Option[String], val extract: Row => CrViewRow, val merge: (Row, CrViewRow) => Row) + extends Relation[CrViewFields, CrViewRow, Row] + with CrViewFields[Row] { outer => + + override val currencyrateid = new Field[CurrencyrateId, Row](prefix, "currencyrateid", None, None)(x => extract(x).currencyrateid, (row, value) => merge(row, extract(row).copy(currencyrateid = value))) + override val currencyratedate = new Field[TypoLocalDateTime, Row](prefix, "currencyratedate", Some("text"), None)(x => extract(x).currencyratedate, (row, value) => merge(row, extract(row).copy(currencyratedate = value))) + override val fromcurrencycode = new Field[CurrencyId, Row](prefix, "fromcurrencycode", None, None)(x => extract(x).fromcurrencycode, (row, value) => merge(row, extract(row).copy(fromcurrencycode = value))) + override val tocurrencycode = new Field[CurrencyId, Row](prefix, "tocurrencycode", None, None)(x => extract(x).tocurrencycode, (row, value) => merge(row, extract(row).copy(tocurrencycode = value))) + override val averagerate = new Field[BigDecimal, Row](prefix, "averagerate", None, None)(x => extract(x).averagerate, (row, value) => merge(row, extract(row).copy(averagerate = value))) + override val endofdayrate = new Field[BigDecimal, Row](prefix, "endofdayrate", None, None)(x => extract(x).endofdayrate, (row, value) => merge(row, extract(row).copy(endofdayrate = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](currencyrateid, currencyratedate, fromcurrencycode, tocurrencycode, averagerate, endofdayrate, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CrViewRow, merge: (NewRow, CrViewRow) => NewRow): CrViewStructure[NewRow] = + new CrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewFields.scala new file mode 100644 index 0000000000..37d0698bdc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package crc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field + +trait CrcViewFields[Row] { + val countryregioncode: Field[CountryregionId, Row] + val currencycode: Field[CurrencyId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CrcViewFields extends CrcViewStructure[CrcViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepo.scala new file mode 100644 index 0000000000..3c765619a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package crc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CrcViewRepo { + def select: SelectBuilder[CrcViewFields, CrcViewRow] + def selectAll: ZStream[ZConnection, Throwable, CrcViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepoImpl.scala new file mode 100644 index 0000000000..c2e62111d1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package crc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CrcViewRepoImpl extends CrcViewRepo { + override def select: SelectBuilder[CrcViewFields, CrcViewRow] = { + SelectBuilderSql("sa.crc", CrcViewFields, CrcViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CrcViewRow] = { + sql"""select "countryregioncode", "currencycode", "modifieddate"::text from sa.crc""".query(CrcViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRow.scala new file mode 100644 index 0000000000..6d668dfaab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package crc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CrcViewRow( + /** Points to [[sales.countryregioncurrency.CountryregioncurrencyRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Points to [[sales.countryregioncurrency.CountryregioncurrencyRow.currencycode]] */ + currencycode: CurrencyId, + /** Points to [[sales.countryregioncurrency.CountryregioncurrencyRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CrcViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CrcViewRow] = new JdbcDecoder[CrcViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CrcViewRow) = + columIndex + 2 -> + CrcViewRow( + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + currencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CrcViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (countryregioncode.isRight && currencycode.isRight && modifieddate.isRight) + Right(CrcViewRow(countryregioncode = countryregioncode.toOption.get, currencycode = currencycode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, currencycode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CrcViewRow] = new JsonEncoder[CrcViewRow] { + override def unsafeEncode(a: CrcViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewStructure.scala new file mode 100644 index 0000000000..5b718a802d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/crc/CrcViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package crc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CrcViewStructure[Row](val prefix: Option[String], val extract: Row => CrcViewRow, val merge: (Row, CrcViewRow) => Row) + extends Relation[CrcViewFields, CrcViewRow, Row] + with CrcViewFields[Row] { outer => + + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val currencycode = new Field[CurrencyId, Row](prefix, "currencycode", None, None)(x => extract(x).currencycode, (row, value) => merge(row, extract(row).copy(currencycode = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](countryregioncode, currencycode, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CrcViewRow, merge: (NewRow, CrcViewRow) => NewRow): CrcViewStructure[NewRow] = + new CrcViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewFields.scala new file mode 100644 index 0000000000..561a3cbd51 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cu + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field + +trait CuViewFields[Row] { + val id: Field[CurrencyId, Row] + val currencycode: Field[CurrencyId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CuViewFields extends CuViewStructure[CuViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepo.scala new file mode 100644 index 0000000000..19d86ecee8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cu + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CuViewRepo { + def select: SelectBuilder[CuViewFields, CuViewRow] + def selectAll: ZStream[ZConnection, Throwable, CuViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepoImpl.scala new file mode 100644 index 0000000000..bc28e41e9a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cu + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CuViewRepoImpl extends CuViewRepo { + override def select: SelectBuilder[CuViewFields, CuViewRow] = { + SelectBuilderSql("sa.cu", CuViewFields, CuViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CuViewRow] = { + sql"""select "id", "currencycode", "name", "modifieddate"::text from sa.cu""".query(CuViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRow.scala new file mode 100644 index 0000000000..d8a00fdf6d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cu + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.currency.CurrencyId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CuViewRow( + /** Points to [[sales.currency.CurrencyRow.currencycode]] */ + id: CurrencyId, + /** Points to [[sales.currency.CurrencyRow.currencycode]] */ + currencycode: CurrencyId, + /** Points to [[sales.currency.CurrencyRow.name]] */ + name: Name, + /** Points to [[sales.currency.CurrencyRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object CuViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CuViewRow] = new JdbcDecoder[CuViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CuViewRow) = + columIndex + 3 -> + CuViewRow( + id = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + currencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CuViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(CurrencyId.jsonDecoder)) + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && currencycode.isRight && name.isRight && modifieddate.isRight) + Right(CuViewRow(id = id.toOption.get, currencycode = currencycode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, currencycode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CuViewRow] = new JsonEncoder[CuViewRow] { + override def unsafeEncode(a: CuViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + CurrencyId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewStructure.scala new file mode 100644 index 0000000000..309775518a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/cu/CuViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package cu + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class CuViewStructure[Row](val prefix: Option[String], val extract: Row => CuViewRow, val merge: (Row, CuViewRow) => Row) + extends Relation[CuViewFields, CuViewRow, Row] + with CuViewFields[Row] { outer => + + override val id = new Field[CurrencyId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val currencycode = new Field[CurrencyId, Row](prefix, "currencycode", None, None)(x => extract(x).currencycode, (row, value) => merge(row, extract(row).copy(currencycode = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, currencycode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CuViewRow, merge: (NewRow, CuViewRow) => NewRow): CuViewStructure[NewRow] = + new CuViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewFields.scala new file mode 100644 index 0000000000..b6907470a9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package pcc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field + +trait PccViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val creditcardid: Field[/* user-picked */ CustomCreditcardId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PccViewFields extends PccViewStructure[PccViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepo.scala new file mode 100644 index 0000000000..4af06d37b1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package pcc + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PccViewRepo { + def select: SelectBuilder[PccViewFields, PccViewRow] + def selectAll: ZStream[ZConnection, Throwable, PccViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepoImpl.scala new file mode 100644 index 0000000000..90d6f63e38 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package pcc + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PccViewRepoImpl extends PccViewRepo { + override def select: SelectBuilder[PccViewFields, PccViewRow] = { + SelectBuilderSql("sa.pcc", PccViewFields, PccViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PccViewRow] = { + sql"""select "id", "businessentityid", "creditcardid", "modifieddate"::text from sa.pcc""".query(PccViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRow.scala new file mode 100644 index 0000000000..f8d9eca5f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewRow.scala @@ -0,0 +1,68 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package pcc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PccViewRow( + /** Points to [[sales.personcreditcard.PersoncreditcardRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[sales.personcreditcard.PersoncreditcardRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[sales.personcreditcard.PersoncreditcardRow.creditcardid]] */ + creditcardid: /* user-picked */ CustomCreditcardId, + /** Points to [[sales.personcreditcard.PersoncreditcardRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object PccViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PccViewRow] = new JdbcDecoder[PccViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PccViewRow) = + columIndex + 3 -> + PccViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + creditcardid = CustomCreditcardId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PccViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && creditcardid.isRight && modifieddate.isRight) + Right(PccViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, creditcardid = creditcardid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, creditcardid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PccViewRow] = new JsonEncoder[PccViewRow] { + override def unsafeEncode(a: PccViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewStructure.scala new file mode 100644 index 0000000000..9332c2a157 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/pcc/PccViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package pcc + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class PccViewStructure[Row](val prefix: Option[String], val extract: Row => PccViewRow, val merge: (Row, PccViewRow) => Row) + extends Relation[PccViewFields, PccViewRow, Row] + with PccViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val creditcardid = new Field[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, None)(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, creditcardid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PccViewRow, merge: (NewRow, PccViewRow) => NewRow): PccViewStructure[NewRow] = + new PccViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewFields.scala new file mode 100644 index 0000000000..3ed9b93bd2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val salespersonid: OptField[BusinessentityId, Row] + val demographics: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SViewFields extends SViewStructure[SViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepo.scala new file mode 100644 index 0000000000..5cae7b666d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package s + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SViewRepo { + def select: SelectBuilder[SViewFields, SViewRow] + def selectAll: ZStream[ZConnection, Throwable, SViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepoImpl.scala new file mode 100644 index 0000000000..0bece2f89a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package s + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SViewRepoImpl extends SViewRepo { + override def select: SelectBuilder[SViewFields, SViewRow] = { + SelectBuilderSql("sa.s", SViewFields, SViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SViewRow] = { + sql"""select "id", "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text from sa.s""".query(SViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRow.scala new file mode 100644 index 0000000000..58b57be4f9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SViewRow( + /** Points to [[sales.store.StoreRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[sales.store.StoreRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[sales.store.StoreRow.name]] */ + name: Name, + /** Points to [[sales.store.StoreRow.salespersonid]] */ + salespersonid: Option[BusinessentityId], + /** Points to [[sales.store.StoreRow.demographics]] */ + demographics: Option[TypoXml], + /** Points to [[sales.store.StoreRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.store.StoreRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SViewRow] = new JdbcDecoder[SViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SViewRow) = + columIndex + 6 -> + SViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + salespersonid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + demographics = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && name.isRight && salespersonid.isRight && demographics.isRight && rowguid.isRight && modifieddate.isRight) + Right(SViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, name = name.toOption.get, salespersonid = salespersonid.toOption.get, demographics = demographics.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, name, salespersonid, demographics, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SViewRow] = new JsonEncoder[SViewRow] { + override def unsafeEncode(a: SViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewStructure.scala new file mode 100644 index 0000000000..3a1ef7e533 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/s/SViewStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package s + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SViewStructure[Row](val prefix: Option[String], val extract: Row => SViewRow, val merge: (Row, SViewRow) => Row) + extends Relation[SViewFields, SViewRow, Row] + with SViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val salespersonid = new OptField[BusinessentityId, Row](prefix, "salespersonid", None, None)(x => extract(x).salespersonid, (row, value) => merge(row, extract(row).copy(salespersonid = value))) + override val demographics = new OptField[TypoXml, Row](prefix, "demographics", None, None)(x => extract(x).demographics, (row, value) => merge(row, extract(row).copy(demographics = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, name, salespersonid, demographics, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SViewRow, merge: (NewRow, SViewRow) => NewRow): SViewStructure[NewRow] = + new SViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewFields.scala new file mode 100644 index 0000000000..6dc86bbbd5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sci + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.sales.shoppingcartitem.ShoppingcartitemId +import typo.dsl.SqlExpr.Field + +trait SciViewFields[Row] { + val id: Field[ShoppingcartitemId, Row] + val shoppingcartitemid: Field[ShoppingcartitemId, Row] + val shoppingcartid: Field[/* max 50 chars */ String, Row] + val quantity: Field[Int, Row] + val productid: Field[ProductId, Row] + val datecreated: Field[TypoLocalDateTime, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SciViewFields extends SciViewStructure[SciViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepo.scala new file mode 100644 index 0000000000..a4e8009524 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sci + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SciViewRepo { + def select: SelectBuilder[SciViewFields, SciViewRow] + def selectAll: ZStream[ZConnection, Throwable, SciViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepoImpl.scala new file mode 100644 index 0000000000..ac8f580065 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sci + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SciViewRepoImpl extends SciViewRepo { + override def select: SelectBuilder[SciViewFields, SciViewRow] = { + SelectBuilderSql("sa.sci", SciViewFields, SciViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SciViewRow] = { + sql"""select "id", "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text from sa.sci""".query(SciViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRow.scala new file mode 100644 index 0000000000..d0a8454e03 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sci + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.sales.shoppingcartitem.ShoppingcartitemId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SciViewRow( + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.shoppingcartitemid]] */ + id: ShoppingcartitemId, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.shoppingcartitemid]] */ + shoppingcartitemid: ShoppingcartitemId, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.shoppingcartid]] */ + shoppingcartid: /* max 50 chars */ String, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.quantity]] */ + quantity: Int, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.productid]] */ + productid: ProductId, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.datecreated]] */ + datecreated: TypoLocalDateTime, + /** Points to [[sales.shoppingcartitem.ShoppingcartitemRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SciViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SciViewRow] = new JdbcDecoder[SciViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SciViewRow) = + columIndex + 6 -> + SciViewRow( + id = ShoppingcartitemId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + shoppingcartitemid = ShoppingcartitemId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + shoppingcartid = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 3, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + datecreated = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SciViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(ShoppingcartitemId.jsonDecoder)) + val shoppingcartitemid = jsonObj.get("shoppingcartitemid").toRight("Missing field 'shoppingcartitemid'").flatMap(_.as(ShoppingcartitemId.jsonDecoder)) + val shoppingcartid = jsonObj.get("shoppingcartid").toRight("Missing field 'shoppingcartid'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val datecreated = jsonObj.get("datecreated").toRight("Missing field 'datecreated'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && shoppingcartitemid.isRight && shoppingcartid.isRight && quantity.isRight && productid.isRight && datecreated.isRight && modifieddate.isRight) + Right(SciViewRow(id = id.toOption.get, shoppingcartitemid = shoppingcartitemid.toOption.get, shoppingcartid = shoppingcartid.toOption.get, quantity = quantity.toOption.get, productid = productid.toOption.get, datecreated = datecreated.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, shoppingcartitemid, shoppingcartid, quantity, productid, datecreated, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SciViewRow] = new JsonEncoder[SciViewRow] { + override def unsafeEncode(a: SciViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + ShoppingcartitemId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""shoppingcartitemid":""") + ShoppingcartitemId.jsonEncoder.unsafeEncode(a.shoppingcartitemid, indent, out) + out.write(",") + out.write(""""shoppingcartid":""") + JsonEncoder.string.unsafeEncode(a.shoppingcartid, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""datecreated":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.datecreated, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewStructure.scala new file mode 100644 index 0000000000..f253da1923 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sci/SciViewStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sci + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import adventureworks.sales.shoppingcartitem.ShoppingcartitemId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SciViewStructure[Row](val prefix: Option[String], val extract: Row => SciViewRow, val merge: (Row, SciViewRow) => Row) + extends Relation[SciViewFields, SciViewRow, Row] + with SciViewFields[Row] { outer => + + override val id = new Field[ShoppingcartitemId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val shoppingcartitemid = new Field[ShoppingcartitemId, Row](prefix, "shoppingcartitemid", None, None)(x => extract(x).shoppingcartitemid, (row, value) => merge(row, extract(row).copy(shoppingcartitemid = value))) + override val shoppingcartid = new Field[/* max 50 chars */ String, Row](prefix, "shoppingcartid", None, None)(x => extract(x).shoppingcartid, (row, value) => merge(row, extract(row).copy(shoppingcartid = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, None)(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val datecreated = new Field[TypoLocalDateTime, Row](prefix, "datecreated", Some("text"), None)(x => extract(x).datecreated, (row, value) => merge(row, extract(row).copy(datecreated = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, shoppingcartitemid, shoppingcartid, quantity, productid, datecreated, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SciViewRow, merge: (NewRow, SciViewRow) => NewRow): SciViewStructure[NewRow] = + new SciViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewFields.scala new file mode 100644 index 0000000000..4c304c3efa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package so + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SoViewFields[Row] { + val id: Field[SpecialofferId, Row] + val specialofferid: Field[SpecialofferId, Row] + val description: Field[/* max 255 chars */ String, Row] + val discountpct: Field[BigDecimal, Row] + val `type`: Field[/* max 50 chars */ String, Row] + val category: Field[/* max 50 chars */ String, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: Field[TypoLocalDateTime, Row] + val minqty: Field[Int, Row] + val maxqty: OptField[Int, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SoViewFields extends SoViewStructure[SoViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepo.scala new file mode 100644 index 0000000000..ea36e6dbbd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package so + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SoViewRepo { + def select: SelectBuilder[SoViewFields, SoViewRow] + def selectAll: ZStream[ZConnection, Throwable, SoViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepoImpl.scala new file mode 100644 index 0000000000..28e0734c13 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package so + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SoViewRepoImpl extends SoViewRepo { + override def select: SelectBuilder[SoViewFields, SoViewRow] = { + SelectBuilderSql("sa.so", SoViewFields, SoViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SoViewRow] = { + sql"""select "id", "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text from sa.so""".query(SoViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRow.scala new file mode 100644 index 0000000000..d7bbd57a18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewRow.scala @@ -0,0 +1,124 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package so + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.sales.specialoffer.SpecialofferId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SoViewRow( + /** Points to [[sales.specialoffer.SpecialofferRow.specialofferid]] */ + id: SpecialofferId, + /** Points to [[sales.specialoffer.SpecialofferRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Points to [[sales.specialoffer.SpecialofferRow.description]] */ + description: /* max 255 chars */ String, + /** Points to [[sales.specialoffer.SpecialofferRow.discountpct]] */ + discountpct: BigDecimal, + /** Points to [[sales.specialoffer.SpecialofferRow.type]] */ + `type`: /* max 50 chars */ String, + /** Points to [[sales.specialoffer.SpecialofferRow.category]] */ + category: /* max 50 chars */ String, + /** Points to [[sales.specialoffer.SpecialofferRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[sales.specialoffer.SpecialofferRow.enddate]] */ + enddate: TypoLocalDateTime, + /** Points to [[sales.specialoffer.SpecialofferRow.minqty]] */ + minqty: Int, + /** Points to [[sales.specialoffer.SpecialofferRow.maxqty]] */ + maxqty: Option[Int], + /** Points to [[sales.specialoffer.SpecialofferRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.specialoffer.SpecialofferRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SoViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SoViewRow] = new JdbcDecoder[SoViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SoViewRow) = + columIndex + 11 -> + SoViewRow( + id = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + discountpct = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + `type` = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + category = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + enddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + minqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 8, rs)._2, + maxqty = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 9, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SoViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val discountpct = jsonObj.get("discountpct").toRight("Missing field 'discountpct'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val `type` = jsonObj.get("type").toRight("Missing field 'type'").flatMap(_.as(JsonDecoder.string)) + val category = jsonObj.get("category").toRight("Missing field 'category'").flatMap(_.as(JsonDecoder.string)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").toRight("Missing field 'enddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val minqty = jsonObj.get("minqty").toRight("Missing field 'minqty'").flatMap(_.as(JsonDecoder.int)) + val maxqty = jsonObj.get("maxqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && specialofferid.isRight && description.isRight && discountpct.isRight && `type`.isRight && category.isRight && startdate.isRight && enddate.isRight && minqty.isRight && maxqty.isRight && rowguid.isRight && modifieddate.isRight) + Right(SoViewRow(id = id.toOption.get, specialofferid = specialofferid.toOption.get, description = description.toOption.get, discountpct = discountpct.toOption.get, `type` = `type`.toOption.get, category = category.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, minqty = minqty.toOption.get, maxqty = maxqty.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, specialofferid, description, discountpct, `type`, category, startdate, enddate, minqty, maxqty, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SoViewRow] = new JsonEncoder[SoViewRow] { + override def unsafeEncode(a: SoViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""discountpct":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.discountpct, indent, out) + out.write(",") + out.write(""""type":""") + JsonEncoder.string.unsafeEncode(a.`type`, indent, out) + out.write(",") + out.write(""""category":""") + JsonEncoder.string.unsafeEncode(a.category, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""minqty":""") + JsonEncoder.int.unsafeEncode(a.minqty, indent, out) + out.write(",") + out.write(""""maxqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maxqty, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewStructure.scala new file mode 100644 index 0000000000..520a7fbf2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/so/SoViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package so + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SoViewStructure[Row](val prefix: Option[String], val extract: Row => SoViewRow, val merge: (Row, SoViewRow) => Row) + extends Relation[SoViewFields, SoViewRow, Row] + with SoViewFields[Row] { outer => + + override val id = new Field[SpecialofferId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val specialofferid = new Field[SpecialofferId, Row](prefix, "specialofferid", None, None)(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val description = new Field[/* max 255 chars */ String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + override val discountpct = new Field[BigDecimal, Row](prefix, "discountpct", None, None)(x => extract(x).discountpct, (row, value) => merge(row, extract(row).copy(discountpct = value))) + override val `type` = new Field[/* max 50 chars */ String, Row](prefix, "type", None, None)(x => extract(x).`type`, (row, value) => merge(row, extract(row).copy(`type` = value))) + override val category = new Field[/* max 50 chars */ String, Row](prefix, "category", None, None)(x => extract(x).category, (row, value) => merge(row, extract(row).copy(category = 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))) + override val enddate = new Field[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val minqty = new Field[Int, Row](prefix, "minqty", None, None)(x => extract(x).minqty, (row, value) => merge(row, extract(row).copy(minqty = value))) + override val maxqty = new OptField[Int, Row](prefix, "maxqty", None, None)(x => extract(x).maxqty, (row, value) => merge(row, extract(row).copy(maxqty = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, specialofferid, description, discountpct, `type`, category, startdate, enddate, minqty, maxqty, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SoViewRow, merge: (NewRow, SoViewRow) => NewRow): SoViewStructure[NewRow] = + new SoViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewFields.scala new file mode 100644 index 0000000000..cf7338e74f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SodViewFields[Row] { + val id: Field[Int, Row] + val salesorderid: Field[SalesorderheaderId, Row] + val salesorderdetailid: Field[Int, Row] + val carriertrackingnumber: OptField[/* max 25 chars */ String, Row] + val orderqty: Field[TypoShort, Row] + val productid: Field[ProductId, Row] + val specialofferid: Field[SpecialofferId, Row] + val unitprice: Field[BigDecimal, Row] + val unitpricediscount: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SodViewFields extends SodViewStructure[SodViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepo.scala new file mode 100644 index 0000000000..063ef4e5e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sod + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SodViewRepo { + def select: SelectBuilder[SodViewFields, SodViewRow] + def selectAll: ZStream[ZConnection, Throwable, SodViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepoImpl.scala new file mode 100644 index 0000000000..7c6030a846 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sod + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SodViewRepoImpl extends SodViewRepo { + override def select: SelectBuilder[SodViewFields, SodViewRow] = { + SelectBuilderSql("sa.sod", SodViewFields, SodViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SodViewRow] = { + sql"""select "id", "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text from sa.sod""".query(SodViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRow.scala new file mode 100644 index 0000000000..e8b1b01e1a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewRow.scala @@ -0,0 +1,120 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SodViewRow( + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.salesorderdetailid]] */ + id: Int, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.salesorderdetailid]] */ + salesorderdetailid: Int, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.carriertrackingnumber]] */ + carriertrackingnumber: Option[/* max 25 chars */ String], + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.orderqty]] */ + orderqty: TypoShort, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.productid]] */ + productid: ProductId, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.unitprice]] */ + unitprice: BigDecimal, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.unitpricediscount]] */ + unitpricediscount: BigDecimal, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salesorderdetail.SalesorderdetailRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SodViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SodViewRow] = new JdbcDecoder[SodViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SodViewRow) = + columIndex + 10 -> + SodViewRow( + id = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + salesorderdetailid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + carriertrackingnumber = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + orderqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + unitprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + unitpricediscount = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SodViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(JsonDecoder.int)) + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesorderdetailid = jsonObj.get("salesorderdetailid").toRight("Missing field 'salesorderdetailid'").flatMap(_.as(JsonDecoder.int)) + val carriertrackingnumber = jsonObj.get("carriertrackingnumber").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val unitpricediscount = jsonObj.get("unitpricediscount").toRight("Missing field 'unitpricediscount'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && salesorderid.isRight && salesorderdetailid.isRight && carriertrackingnumber.isRight && orderqty.isRight && productid.isRight && specialofferid.isRight && unitprice.isRight && unitpricediscount.isRight && rowguid.isRight && modifieddate.isRight) + Right(SodViewRow(id = id.toOption.get, salesorderid = salesorderid.toOption.get, salesorderdetailid = salesorderdetailid.toOption.get, carriertrackingnumber = carriertrackingnumber.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, specialofferid = specialofferid.toOption.get, unitprice = unitprice.toOption.get, unitpricediscount = unitpricediscount.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, salesorderid, salesorderdetailid, carriertrackingnumber, orderqty, productid, specialofferid, unitprice, unitpricediscount, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SodViewRow] = new JsonEncoder[SodViewRow] { + override def unsafeEncode(a: SodViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + JsonEncoder.int.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.salesorderdetailid, indent, out) + out.write(",") + out.write(""""carriertrackingnumber":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.carriertrackingnumber, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""unitpricediscount":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitpricediscount, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewStructure.scala new file mode 100644 index 0000000000..8fbde8f240 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sod/SodViewStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sod + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SodViewStructure[Row](val prefix: Option[String], val extract: Row => SodViewRow, val merge: (Row, SodViewRow) => Row) + extends Relation[SodViewFields, SodViewRow, Row] + with SodViewFields[Row] { outer => + + 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 salesorderid = new Field[SalesorderheaderId, Row](prefix, "salesorderid", None, None)(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val salesorderdetailid = new Field[Int, Row](prefix, "salesorderdetailid", None, None)(x => extract(x).salesorderdetailid, (row, value) => merge(row, extract(row).copy(salesorderdetailid = value))) + override val carriertrackingnumber = new OptField[/* max 25 chars */ String, Row](prefix, "carriertrackingnumber", None, None)(x => extract(x).carriertrackingnumber, (row, value) => merge(row, extract(row).copy(carriertrackingnumber = value))) + override val orderqty = new Field[TypoShort, Row](prefix, "orderqty", None, None)(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val specialofferid = new Field[SpecialofferId, Row](prefix, "specialofferid", None, None)(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val unitprice = new Field[BigDecimal, Row](prefix, "unitprice", None, None)(x => extract(x).unitprice, (row, value) => merge(row, extract(row).copy(unitprice = value))) + override val unitpricediscount = new Field[BigDecimal, Row](prefix, "unitpricediscount", None, None)(x => extract(x).unitpricediscount, (row, value) => merge(row, extract(row).copy(unitpricediscount = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, salesorderid, salesorderdetailid, carriertrackingnumber, orderqty, productid, specialofferid, unitprice, unitpricediscount, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SodViewRow, merge: (NewRow, SodViewRow) => NewRow): SodViewStructure[NewRow] = + new SodViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewFields.scala new file mode 100644 index 0000000000..6c1c92f5dc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewFields.scala @@ -0,0 +1,56 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package soh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SohViewFields[Row] { + val id: Field[SalesorderheaderId, Row] + val salesorderid: Field[SalesorderheaderId, Row] + val revisionnumber: Field[TypoShort, Row] + val orderdate: Field[TypoLocalDateTime, Row] + val duedate: Field[TypoLocalDateTime, Row] + val shipdate: OptField[TypoLocalDateTime, Row] + val status: Field[TypoShort, Row] + val onlineorderflag: Field[Flag, Row] + val purchaseordernumber: OptField[OrderNumber, Row] + val accountnumber: OptField[AccountNumber, Row] + val customerid: Field[CustomerId, Row] + val salespersonid: OptField[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val billtoaddressid: Field[AddressId, Row] + val shiptoaddressid: Field[AddressId, Row] + val shipmethodid: Field[ShipmethodId, Row] + val creditcardid: OptField[/* user-picked */ CustomCreditcardId, Row] + val creditcardapprovalcode: OptField[/* max 15 chars */ String, Row] + val currencyrateid: OptField[CurrencyrateId, Row] + val subtotal: Field[BigDecimal, Row] + val taxamt: Field[BigDecimal, Row] + val freight: Field[BigDecimal, Row] + val totaldue: OptField[BigDecimal, Row] + val comment: OptField[/* max 128 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SohViewFields extends SohViewStructure[SohViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepo.scala new file mode 100644 index 0000000000..ca021b1c9e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package soh + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SohViewRepo { + def select: SelectBuilder[SohViewFields, SohViewRow] + def selectAll: ZStream[ZConnection, Throwable, SohViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepoImpl.scala new file mode 100644 index 0000000000..50b9da56f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package soh + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SohViewRepoImpl extends SohViewRepo { + override def select: SelectBuilder[SohViewFields, SohViewRow] = { + SelectBuilderSql("sa.soh", SohViewFields, SohViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SohViewRow] = { + sql"""select "id", "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text from sa.soh""".query(SohViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRow.scala new file mode 100644 index 0000000000..276451cd91 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewRow.scala @@ -0,0 +1,233 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package soh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SohViewRow( + /** Points to [[sales.salesorderheader.SalesorderheaderRow.salesorderid]] */ + id: SalesorderheaderId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.revisionnumber]] */ + revisionnumber: TypoShort, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.orderdate]] */ + orderdate: TypoLocalDateTime, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.duedate]] */ + duedate: TypoLocalDateTime, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.shipdate]] */ + shipdate: Option[TypoLocalDateTime], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.status]] */ + status: TypoShort, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.onlineorderflag]] */ + onlineorderflag: Flag, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.purchaseordernumber]] */ + purchaseordernumber: Option[OrderNumber], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.accountnumber]] */ + accountnumber: Option[AccountNumber], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.customerid]] */ + customerid: CustomerId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.salespersonid]] */ + salespersonid: Option[BusinessentityId], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.billtoaddressid]] */ + billtoaddressid: AddressId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.shiptoaddressid]] */ + shiptoaddressid: AddressId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.creditcardid]] */ + creditcardid: Option[/* user-picked */ CustomCreditcardId], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.creditcardapprovalcode]] */ + creditcardapprovalcode: Option[/* max 15 chars */ String], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.currencyrateid]] */ + currencyrateid: Option[CurrencyrateId], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.subtotal]] */ + subtotal: BigDecimal, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.taxamt]] */ + taxamt: BigDecimal, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.freight]] */ + freight: BigDecimal, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.totaldue]] */ + totaldue: Option[BigDecimal], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.comment]] */ + comment: Option[/* max 128 chars */ String], + /** Points to [[sales.salesorderheader.SalesorderheaderRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salesorderheader.SalesorderheaderRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SohViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SohViewRow] = new JdbcDecoder[SohViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SohViewRow) = + columIndex + 25 -> + SohViewRow( + id = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + revisionnumber = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + orderdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + shipdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + onlineorderflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + purchaseordernumber = JdbcDecoder.optionDecoder(OrderNumber.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + accountnumber = JdbcDecoder.optionDecoder(AccountNumber.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + customerid = CustomerId.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + salespersonid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 12, rs)._2, + billtoaddressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + shiptoaddressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 15, rs)._2, + creditcardid = JdbcDecoder.optionDecoder(CustomCreditcardId.jdbcDecoder).unsafeDecode(columIndex + 16, rs)._2, + creditcardapprovalcode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 17, rs)._2, + currencyrateid = JdbcDecoder.optionDecoder(CurrencyrateId.jdbcDecoder).unsafeDecode(columIndex + 18, rs)._2, + subtotal = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 19, rs)._2, + taxamt = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 20, rs)._2, + freight = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 21, rs)._2, + totaldue = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 22, rs)._2, + comment = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 23, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 24, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 25, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SohViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(TypoShort.jsonDecoder)) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val onlineorderflag = jsonObj.get("onlineorderflag").toRight("Missing field 'onlineorderflag'").flatMap(_.as(Flag.jsonDecoder)) + val purchaseordernumber = jsonObj.get("purchaseordernumber").fold[Either[String, Option[OrderNumber]]](Right(None))(_.as(JsonDecoder.option(OrderNumber.jsonDecoder))) + val accountnumber = jsonObj.get("accountnumber").fold[Either[String, Option[AccountNumber]]](Right(None))(_.as(JsonDecoder.option(AccountNumber.jsonDecoder))) + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(CustomerId.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val billtoaddressid = jsonObj.get("billtoaddressid").toRight("Missing field 'billtoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shiptoaddressid = jsonObj.get("shiptoaddressid").toRight("Missing field 'shiptoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").fold[Either[String, Option[CustomCreditcardId]]](Right(None))(_.as(JsonDecoder.option(CustomCreditcardId.jsonDecoder))) + val creditcardapprovalcode = jsonObj.get("creditcardapprovalcode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val currencyrateid = jsonObj.get("currencyrateid").fold[Either[String, Option[CurrencyrateId]]](Right(None))(_.as(JsonDecoder.option(CurrencyrateId.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val totaldue = jsonObj.get("totaldue").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val comment = jsonObj.get("comment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && salesorderid.isRight && revisionnumber.isRight && orderdate.isRight && duedate.isRight && shipdate.isRight && status.isRight && onlineorderflag.isRight && purchaseordernumber.isRight && accountnumber.isRight && customerid.isRight && salespersonid.isRight && territoryid.isRight && billtoaddressid.isRight && shiptoaddressid.isRight && shipmethodid.isRight && creditcardid.isRight && creditcardapprovalcode.isRight && currencyrateid.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && totaldue.isRight && comment.isRight && rowguid.isRight && modifieddate.isRight) + Right(SohViewRow(id = id.toOption.get, salesorderid = salesorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, orderdate = orderdate.toOption.get, duedate = duedate.toOption.get, shipdate = shipdate.toOption.get, status = status.toOption.get, onlineorderflag = onlineorderflag.toOption.get, purchaseordernumber = purchaseordernumber.toOption.get, accountnumber = accountnumber.toOption.get, customerid = customerid.toOption.get, salespersonid = salespersonid.toOption.get, territoryid = territoryid.toOption.get, billtoaddressid = billtoaddressid.toOption.get, shiptoaddressid = shiptoaddressid.toOption.get, shipmethodid = shipmethodid.toOption.get, creditcardid = creditcardid.toOption.get, creditcardapprovalcode = creditcardapprovalcode.toOption.get, currencyrateid = currencyrateid.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, totaldue = totaldue.toOption.get, comment = comment.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, salesorderid, revisionnumber, orderdate, duedate, shipdate, status, onlineorderflag, purchaseordernumber, accountnumber, customerid, salespersonid, territoryid, billtoaddressid, shiptoaddressid, shipmethodid, creditcardid, creditcardapprovalcode, currencyrateid, subtotal, taxamt, freight, totaldue, comment, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SohViewRow] = new JsonEncoder[SohViewRow] { + override def unsafeEncode(a: SohViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + TypoShort.jsonEncoder.unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""orderdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""onlineorderflag":""") + Flag.jsonEncoder.unsafeEncode(a.onlineorderflag, indent, out) + out.write(",") + out.write(""""purchaseordernumber":""") + JsonEncoder.option(OrderNumber.jsonEncoder).unsafeEncode(a.purchaseordernumber, indent, out) + out.write(",") + out.write(""""accountnumber":""") + JsonEncoder.option(AccountNumber.jsonEncoder).unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""customerid":""") + CustomerId.jsonEncoder.unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""billtoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.billtoaddressid, indent, out) + out.write(",") + out.write(""""shiptoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.shiptoaddressid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + JsonEncoder.option(CustomCreditcardId.jsonEncoder).unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""creditcardapprovalcode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.creditcardapprovalcode, indent, out) + out.write(",") + out.write(""""currencyrateid":""") + JsonEncoder.option(CurrencyrateId.jsonEncoder).unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""subtotal":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""totaldue":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.totaldue, indent, out) + out.write(",") + out.write(""""comment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comment, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewStructure.scala new file mode 100644 index 0000000000..3dbb6fb70e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/soh/SohViewStructure.scala @@ -0,0 +1,65 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package soh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SohViewStructure[Row](val prefix: Option[String], val extract: Row => SohViewRow, val merge: (Row, SohViewRow) => Row) + extends Relation[SohViewFields, SohViewRow, Row] + with SohViewFields[Row] { outer => + + override val id = new Field[SalesorderheaderId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val salesorderid = new Field[SalesorderheaderId, Row](prefix, "salesorderid", None, None)(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val revisionnumber = new Field[TypoShort, Row](prefix, "revisionnumber", None, None)(x => extract(x).revisionnumber, (row, value) => merge(row, extract(row).copy(revisionnumber = value))) + override val orderdate = new Field[TypoLocalDateTime, Row](prefix, "orderdate", Some("text"), None)(x => extract(x).orderdate, (row, value) => merge(row, extract(row).copy(orderdate = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), None)(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val shipdate = new OptField[TypoLocalDateTime, Row](prefix, "shipdate", Some("text"), None)(x => extract(x).shipdate, (row, value) => merge(row, extract(row).copy(shipdate = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, None)(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val onlineorderflag = new Field[Flag, Row](prefix, "onlineorderflag", None, None)(x => extract(x).onlineorderflag, (row, value) => merge(row, extract(row).copy(onlineorderflag = value))) + override val purchaseordernumber = new OptField[OrderNumber, Row](prefix, "purchaseordernumber", None, None)(x => extract(x).purchaseordernumber, (row, value) => merge(row, extract(row).copy(purchaseordernumber = value))) + override val accountnumber = new OptField[AccountNumber, Row](prefix, "accountnumber", None, None)(x => extract(x).accountnumber, (row, value) => merge(row, extract(row).copy(accountnumber = value))) + override val customerid = new Field[CustomerId, Row](prefix, "customerid", None, None)(x => extract(x).customerid, (row, value) => merge(row, extract(row).copy(customerid = value))) + override val salespersonid = new OptField[BusinessentityId, Row](prefix, "salespersonid", None, None)(x => extract(x).salespersonid, (row, value) => merge(row, extract(row).copy(salespersonid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val billtoaddressid = new Field[AddressId, Row](prefix, "billtoaddressid", None, None)(x => extract(x).billtoaddressid, (row, value) => merge(row, extract(row).copy(billtoaddressid = value))) + override val shiptoaddressid = new Field[AddressId, Row](prefix, "shiptoaddressid", None, None)(x => extract(x).shiptoaddressid, (row, value) => merge(row, extract(row).copy(shiptoaddressid = value))) + override val shipmethodid = new Field[ShipmethodId, Row](prefix, "shipmethodid", None, None)(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val creditcardid = new OptField[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, None)(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val creditcardapprovalcode = new OptField[/* max 15 chars */ String, Row](prefix, "creditcardapprovalcode", None, None)(x => extract(x).creditcardapprovalcode, (row, value) => merge(row, extract(row).copy(creditcardapprovalcode = value))) + override val currencyrateid = new OptField[CurrencyrateId, Row](prefix, "currencyrateid", None, None)(x => extract(x).currencyrateid, (row, value) => merge(row, extract(row).copy(currencyrateid = value))) + override val subtotal = new Field[BigDecimal, Row](prefix, "subtotal", None, None)(x => extract(x).subtotal, (row, value) => merge(row, extract(row).copy(subtotal = value))) + override val taxamt = new Field[BigDecimal, Row](prefix, "taxamt", None, None)(x => extract(x).taxamt, (row, value) => merge(row, extract(row).copy(taxamt = value))) + override val freight = new Field[BigDecimal, Row](prefix, "freight", None, None)(x => extract(x).freight, (row, value) => merge(row, extract(row).copy(freight = value))) + override val totaldue = new OptField[BigDecimal, Row](prefix, "totaldue", None, None)(x => extract(x).totaldue, (row, value) => merge(row, extract(row).copy(totaldue = value))) + override val comment = new OptField[/* max 128 chars */ String, Row](prefix, "comment", None, None)(x => extract(x).comment, (row, value) => merge(row, extract(row).copy(comment = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, salesorderid, revisionnumber, orderdate, duedate, shipdate, status, onlineorderflag, purchaseordernumber, accountnumber, customerid, salespersonid, territoryid, billtoaddressid, shiptoaddressid, shipmethodid, creditcardid, creditcardapprovalcode, currencyrateid, subtotal, taxamt, freight, totaldue, comment, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SohViewRow, merge: (NewRow, SohViewRow) => NewRow): SohViewStructure[NewRow] = + new SohViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewFields.scala new file mode 100644 index 0000000000..dec06a94ba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sohsr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field + +trait SohsrViewFields[Row] { + val salesorderid: Field[SalesorderheaderId, Row] + val salesreasonid: Field[SalesreasonId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SohsrViewFields extends SohsrViewStructure[SohsrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepo.scala new file mode 100644 index 0000000000..b2c52c43b5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sohsr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SohsrViewRepo { + def select: SelectBuilder[SohsrViewFields, SohsrViewRow] + def selectAll: ZStream[ZConnection, Throwable, SohsrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepoImpl.scala new file mode 100644 index 0000000000..3fcc568245 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sohsr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SohsrViewRepoImpl extends SohsrViewRepo { + override def select: SelectBuilder[SohsrViewFields, SohsrViewRow] = { + SelectBuilderSql("sa.sohsr", SohsrViewFields, SohsrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SohsrViewRow] = { + sql"""select "salesorderid", "salesreasonid", "modifieddate"::text from sa.sohsr""".query(SohsrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRow.scala new file mode 100644 index 0000000000..4e4fdd485d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewRow.scala @@ -0,0 +1,61 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sohsr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SohsrViewRow( + /** Points to [[sales.salesorderheadersalesreason.SalesorderheadersalesreasonRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Points to [[sales.salesorderheadersalesreason.SalesorderheadersalesreasonRow.salesreasonid]] */ + salesreasonid: SalesreasonId, + /** Points to [[sales.salesorderheadersalesreason.SalesorderheadersalesreasonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SohsrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SohsrViewRow] = new JdbcDecoder[SohsrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SohsrViewRow) = + columIndex + 2 -> + SohsrViewRow( + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesreasonid = SalesreasonId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SohsrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salesorderid.isRight && salesreasonid.isRight && modifieddate.isRight) + Right(SohsrViewRow(salesorderid = salesorderid.toOption.get, salesreasonid = salesreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SohsrViewRow] = new JsonEncoder[SohsrViewRow] { + override def unsafeEncode(a: SohsrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewStructure.scala new file mode 100644 index 0000000000..9fa9d7c4bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sohsr/SohsrViewStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sohsr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SohsrViewStructure[Row](val prefix: Option[String], val extract: Row => SohsrViewRow, val merge: (Row, SohsrViewRow) => Row) + extends Relation[SohsrViewFields, SohsrViewRow, Row] + with SohsrViewFields[Row] { outer => + + override val salesorderid = new Field[SalesorderheaderId, Row](prefix, "salesorderid", None, None)(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val salesreasonid = new Field[SalesreasonId, Row](prefix, "salesreasonid", None, None)(x => extract(x).salesreasonid, (row, value) => merge(row, extract(row).copy(salesreasonid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salesorderid, salesreasonid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SohsrViewRow, merge: (NewRow, SohsrViewRow) => NewRow): SohsrViewStructure[NewRow] = + new SohsrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewFields.scala new file mode 100644 index 0000000000..5a3d272dc3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sop + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field + +trait SopViewFields[Row] { + val id: Field[SpecialofferId, Row] + val specialofferid: Field[SpecialofferId, Row] + val productid: Field[ProductId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SopViewFields extends SopViewStructure[SopViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepo.scala new file mode 100644 index 0000000000..f950fc9ffc --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sop + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SopViewRepo { + def select: SelectBuilder[SopViewFields, SopViewRow] + def selectAll: ZStream[ZConnection, Throwable, SopViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepoImpl.scala new file mode 100644 index 0000000000..8540dc38bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sop + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SopViewRepoImpl extends SopViewRepo { + override def select: SelectBuilder[SopViewFields, SopViewRow] = { + SelectBuilderSql("sa.sop", SopViewFields, SopViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SopViewRow] = { + sql"""select "id", "specialofferid", "productid", "rowguid", "modifieddate"::text from sa.sop""".query(SopViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRow.scala new file mode 100644 index 0000000000..5eebad0de8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewRow.scala @@ -0,0 +1,76 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sop + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SopViewRow( + /** Points to [[sales.specialofferproduct.SpecialofferproductRow.specialofferid]] */ + id: SpecialofferId, + /** Points to [[sales.specialofferproduct.SpecialofferproductRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Points to [[sales.specialofferproduct.SpecialofferproductRow.productid]] */ + productid: ProductId, + /** Points to [[sales.specialofferproduct.SpecialofferproductRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.specialofferproduct.SpecialofferproductRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SopViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SopViewRow] = new JdbcDecoder[SopViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SopViewRow) = + columIndex + 4 -> + SopViewRow( + id = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SopViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && specialofferid.isRight && productid.isRight && rowguid.isRight && modifieddate.isRight) + Right(SopViewRow(id = id.toOption.get, specialofferid = specialofferid.toOption.get, productid = productid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, specialofferid, productid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SopViewRow] = new JsonEncoder[SopViewRow] { + override def unsafeEncode(a: SopViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewStructure.scala new file mode 100644 index 0000000000..c08095d790 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sop/SopViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sop + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SopViewStructure[Row](val prefix: Option[String], val extract: Row => SopViewRow, val merge: (Row, SopViewRow) => Row) + extends Relation[SopViewFields, SopViewRow, Row] + with SopViewFields[Row] { outer => + + override val id = new Field[SpecialofferId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val specialofferid = new Field[SpecialofferId, Row](prefix, "specialofferid", None, None)(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, None)(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, specialofferid, productid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SopViewRow, merge: (NewRow, SopViewRow) => NewRow): SopViewStructure[NewRow] = + new SopViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewFields.scala new file mode 100644 index 0000000000..e7971f3a5c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SpViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val salesquota: OptField[BigDecimal, Row] + val bonus: Field[BigDecimal, Row] + val commissionpct: Field[BigDecimal, Row] + val salesytd: Field[BigDecimal, Row] + val saleslastyear: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SpViewFields extends SpViewStructure[SpViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepo.scala new file mode 100644 index 0000000000..df15469419 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sp + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SpViewRepo { + def select: SelectBuilder[SpViewFields, SpViewRow] + def selectAll: ZStream[ZConnection, Throwable, SpViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepoImpl.scala new file mode 100644 index 0000000000..b7e9f2526b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sp + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SpViewRepoImpl extends SpViewRepo { + override def select: SelectBuilder[SpViewFields, SpViewRow] = { + SelectBuilderSql("sa.sp", SpViewFields, SpViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SpViewRow] = { + sql"""select "id", "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text from sa.sp""".query(SpViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRow.scala new file mode 100644 index 0000000000..37036f6696 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewRow.scala @@ -0,0 +1,111 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SpViewRow( + /** Points to [[sales.salesperson.SalespersonRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[sales.salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[sales.salesperson.SalespersonRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Points to [[sales.salesperson.SalespersonRow.salesquota]] */ + salesquota: Option[BigDecimal], + /** Points to [[sales.salesperson.SalespersonRow.bonus]] */ + bonus: BigDecimal, + /** Points to [[sales.salesperson.SalespersonRow.commissionpct]] */ + commissionpct: BigDecimal, + /** Points to [[sales.salesperson.SalespersonRow.salesytd]] */ + salesytd: BigDecimal, + /** Points to [[sales.salesperson.SalespersonRow.saleslastyear]] */ + saleslastyear: BigDecimal, + /** Points to [[sales.salesperson.SalespersonRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salesperson.SalespersonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SpViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SpViewRow] = new JdbcDecoder[SpViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SpViewRow) = + columIndex + 9 -> + SpViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + salesquota = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 3, rs)._2, + bonus = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + commissionpct = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + salesytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + saleslastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SpViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val salesquota = jsonObj.get("salesquota").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val bonus = jsonObj.get("bonus").toRight("Missing field 'bonus'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val commissionpct = jsonObj.get("commissionpct").toRight("Missing field 'commissionpct'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && territoryid.isRight && salesquota.isRight && bonus.isRight && commissionpct.isRight && salesytd.isRight && saleslastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, salesquota = salesquota.toOption.get, bonus = bonus.toOption.get, commissionpct = commissionpct.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, territoryid, salesquota, bonus, commissionpct, salesytd, saleslastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpViewRow] = new JsonEncoder[SpViewRow] { + override def unsafeEncode(a: SpViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""bonus":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.bonus, indent, out) + out.write(",") + out.write(""""commissionpct":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.commissionpct, indent, out) + out.write(",") + out.write(""""salesytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewStructure.scala new file mode 100644 index 0000000000..0c0b5a2eaa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sp/SpViewStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sp + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SpViewStructure[Row](val prefix: Option[String], val extract: Row => SpViewRow, val merge: (Row, SpViewRow) => Row) + extends Relation[SpViewFields, SpViewRow, Row] + with SpViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val salesquota = new OptField[BigDecimal, Row](prefix, "salesquota", None, None)(x => extract(x).salesquota, (row, value) => merge(row, extract(row).copy(salesquota = value))) + override val bonus = new Field[BigDecimal, Row](prefix, "bonus", None, None)(x => extract(x).bonus, (row, value) => merge(row, extract(row).copy(bonus = value))) + override val commissionpct = new Field[BigDecimal, Row](prefix, "commissionpct", None, None)(x => extract(x).commissionpct, (row, value) => merge(row, extract(row).copy(commissionpct = value))) + override val salesytd = new Field[BigDecimal, Row](prefix, "salesytd", None, None)(x => extract(x).salesytd, (row, value) => merge(row, extract(row).copy(salesytd = value))) + override val saleslastyear = new Field[BigDecimal, Row](prefix, "saleslastyear", None, None)(x => extract(x).saleslastyear, (row, value) => merge(row, extract(row).copy(saleslastyear = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, territoryid, salesquota, bonus, commissionpct, salesytd, saleslastyear, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SpViewRow, merge: (NewRow, SpViewRow) => NewRow): SpViewStructure[NewRow] = + new SpViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewFields.scala new file mode 100644 index 0000000000..bb06ed4ef0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package spqh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field + +trait SpqhViewFields[Row] { + val id: Field[BusinessentityId, Row] + val businessentityid: Field[BusinessentityId, Row] + val quotadate: Field[TypoLocalDateTime, Row] + val salesquota: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SpqhViewFields extends SpqhViewStructure[SpqhViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepo.scala new file mode 100644 index 0000000000..62920f6436 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package spqh + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SpqhViewRepo { + def select: SelectBuilder[SpqhViewFields, SpqhViewRow] + def selectAll: ZStream[ZConnection, Throwable, SpqhViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepoImpl.scala new file mode 100644 index 0000000000..6c6d3099ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package spqh + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SpqhViewRepoImpl extends SpqhViewRepo { + override def select: SelectBuilder[SpqhViewFields, SpqhViewRow] = { + SelectBuilderSql("sa.spqh", SpqhViewFields, SpqhViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SpqhViewRow] = { + sql"""select "id", "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text from sa.spqh""".query(SpqhViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRow.scala new file mode 100644 index 0000000000..c14e9bca85 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package spqh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SpqhViewRow( + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.businessentityid]] */ + id: BusinessentityId, + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.quotadate]] */ + quotadate: TypoLocalDateTime, + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.salesquota]] */ + salesquota: BigDecimal, + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salespersonquotahistory.SalespersonquotahistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SpqhViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SpqhViewRow] = new JdbcDecoder[SpqhViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SpqhViewRow) = + columIndex + 5 -> + SpqhViewRow( + id = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + quotadate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + salesquota = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SpqhViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val quotadate = jsonObj.get("quotadate").toRight("Missing field 'quotadate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val salesquota = jsonObj.get("salesquota").toRight("Missing field 'salesquota'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && quotadate.isRight && salesquota.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpqhViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, quotadate = quotadate.toOption.get, salesquota = salesquota.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, quotadate, salesquota, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpqhViewRow] = new JsonEncoder[SpqhViewRow] { + override def unsafeEncode(a: SpqhViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""quotadate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.quotadate, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewStructure.scala new file mode 100644 index 0000000000..34b89696d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/spqh/SpqhViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package spqh + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SpqhViewStructure[Row](val prefix: Option[String], val extract: Row => SpqhViewRow, val merge: (Row, SpqhViewRow) => Row) + extends Relation[SpqhViewFields, SpqhViewRow, Row] + with SpqhViewFields[Row] { outer => + + override val id = new Field[BusinessentityId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val quotadate = new Field[TypoLocalDateTime, Row](prefix, "quotadate", Some("text"), None)(x => extract(x).quotadate, (row, value) => merge(row, extract(row).copy(quotadate = value))) + override val salesquota = new Field[BigDecimal, Row](prefix, "salesquota", None, None)(x => extract(x).salesquota, (row, value) => merge(row, extract(row).copy(salesquota = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, quotadate, salesquota, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SpqhViewRow, merge: (NewRow, SpqhViewRow) => NewRow): SpqhViewStructure[NewRow] = + new SpqhViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewFields.scala new file mode 100644 index 0000000000..ba8f474bc0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewFields.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field + +trait SrViewFields[Row] { + val id: Field[SalesreasonId, Row] + val salesreasonid: Field[SalesreasonId, Row] + val name: Field[Name, Row] + val reasontype: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SrViewFields extends SrViewStructure[SrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepo.scala new file mode 100644 index 0000000000..a0d493cbdd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SrViewRepo { + def select: SelectBuilder[SrViewFields, SrViewRow] + def selectAll: ZStream[ZConnection, Throwable, SrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepoImpl.scala new file mode 100644 index 0000000000..8f13195d9a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SrViewRepoImpl extends SrViewRepo { + override def select: SelectBuilder[SrViewFields, SrViewRow] = { + SelectBuilderSql("sa.sr", SrViewFields, SrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SrViewRow] = { + sql"""select "id", "salesreasonid", "name", "reasontype", "modifieddate"::text from sa.sr""".query(SrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRow.scala new file mode 100644 index 0000000000..9fa6915bbf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewRow.scala @@ -0,0 +1,75 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.salesreason.SalesreasonId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SrViewRow( + /** Points to [[sales.salesreason.SalesreasonRow.salesreasonid]] */ + id: SalesreasonId, + /** Points to [[sales.salesreason.SalesreasonRow.salesreasonid]] */ + salesreasonid: SalesreasonId, + /** Points to [[sales.salesreason.SalesreasonRow.name]] */ + name: Name, + /** Points to [[sales.salesreason.SalesreasonRow.reasontype]] */ + reasontype: Name, + /** Points to [[sales.salesreason.SalesreasonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SrViewRow] = new JdbcDecoder[SrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SrViewRow) = + columIndex + 4 -> + SrViewRow( + id = SalesreasonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesreasonid = SalesreasonId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + reasontype = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val reasontype = jsonObj.get("reasontype").toRight("Missing field 'reasontype'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && salesreasonid.isRight && name.isRight && reasontype.isRight && modifieddate.isRight) + Right(SrViewRow(id = id.toOption.get, salesreasonid = salesreasonid.toOption.get, name = name.toOption.get, reasontype = reasontype.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, salesreasonid, name, reasontype, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SrViewRow] = new JsonEncoder[SrViewRow] { + override def unsafeEncode(a: SrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""reasontype":""") + Name.jsonEncoder.unsafeEncode(a.reasontype, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewStructure.scala new file mode 100644 index 0000000000..1e139ef1a5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sr/SrViewStructure.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class SrViewStructure[Row](val prefix: Option[String], val extract: Row => SrViewRow, val merge: (Row, SrViewRow) => Row) + extends Relation[SrViewFields, SrViewRow, Row] + with SrViewFields[Row] { outer => + + override val id = new Field[SalesreasonId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val salesreasonid = new Field[SalesreasonId, Row](prefix, "salesreasonid", None, None)(x => extract(x).salesreasonid, (row, value) => merge(row, extract(row).copy(salesreasonid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val reasontype = new Field[Name, Row](prefix, "reasontype", None, None)(x => extract(x).reasontype, (row, value) => merge(row, extract(row).copy(reasontype = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, salesreasonid, name, reasontype, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SrViewRow, merge: (NewRow, SrViewRow) => NewRow): SrViewStructure[NewRow] = + new SrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewFields.scala new file mode 100644 index 0000000000..3a4d8cb334 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package st + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field + +trait StViewFields[Row] { + val id: Field[SalesterritoryId, Row] + val territoryid: Field[SalesterritoryId, Row] + val name: Field[Name, Row] + val countryregioncode: Field[CountryregionId, Row] + val group: Field[/* max 50 chars */ String, Row] + val salesytd: Field[BigDecimal, Row] + val saleslastyear: Field[BigDecimal, Row] + val costytd: Field[BigDecimal, Row] + val costlastyear: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object StViewFields extends StViewStructure[StViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepo.scala new file mode 100644 index 0000000000..d8a73243d9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package st + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait StViewRepo { + def select: SelectBuilder[StViewFields, StViewRow] + def selectAll: ZStream[ZConnection, Throwable, StViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepoImpl.scala new file mode 100644 index 0000000000..5deca05af0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package st + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object StViewRepoImpl extends StViewRepo { + override def select: SelectBuilder[StViewFields, StViewRow] = { + SelectBuilderSql("sa.st", StViewFields, StViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, StViewRow] = { + sql"""select "id", "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text from sa.st""".query(StViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRow.scala new file mode 100644 index 0000000000..1af98ad759 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewRow.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package st + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class StViewRow( + /** Points to [[sales.salesterritory.SalesterritoryRow.territoryid]] */ + id: SalesterritoryId, + /** Points to [[sales.salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Points to [[sales.salesterritory.SalesterritoryRow.name]] */ + name: Name, + /** Points to [[sales.salesterritory.SalesterritoryRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Points to [[sales.salesterritory.SalesterritoryRow.group]] */ + group: /* max 50 chars */ String, + /** Points to [[sales.salesterritory.SalesterritoryRow.salesytd]] */ + salesytd: BigDecimal, + /** Points to [[sales.salesterritory.SalesterritoryRow.saleslastyear]] */ + saleslastyear: BigDecimal, + /** Points to [[sales.salesterritory.SalesterritoryRow.costytd]] */ + costytd: BigDecimal, + /** Points to [[sales.salesterritory.SalesterritoryRow.costlastyear]] */ + costlastyear: BigDecimal, + /** Points to [[sales.salesterritory.SalesterritoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salesterritory.SalesterritoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object StViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[StViewRow] = new JdbcDecoder[StViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, StViewRow) = + columIndex + 10 -> + StViewRow( + id = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + group = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + salesytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + saleslastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + costytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + costlastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 8, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[StViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val group = jsonObj.get("group").toRight("Missing field 'group'").flatMap(_.as(JsonDecoder.string)) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val costytd = jsonObj.get("costytd").toRight("Missing field 'costytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val costlastyear = jsonObj.get("costlastyear").toRight("Missing field 'costlastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && territoryid.isRight && name.isRight && countryregioncode.isRight && group.isRight && salesytd.isRight && saleslastyear.isRight && costytd.isRight && costlastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(StViewRow(id = id.toOption.get, territoryid = territoryid.toOption.get, name = name.toOption.get, countryregioncode = countryregioncode.toOption.get, group = group.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, costytd = costytd.toOption.get, costlastyear = costlastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, territoryid, name, countryregioncode, group, salesytd, saleslastyear, costytd, costlastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[StViewRow] = new JsonEncoder[StViewRow] { + override def unsafeEncode(a: StViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""group":""") + JsonEncoder.string.unsafeEncode(a.group, indent, out) + out.write(",") + out.write(""""salesytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""costytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costytd, indent, out) + out.write(",") + out.write(""""costlastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costlastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewStructure.scala new file mode 100644 index 0000000000..eb457f7da7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/st/StViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package st + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class StViewStructure[Row](val prefix: Option[String], val extract: Row => StViewRow, val merge: (Row, StViewRow) => Row) + extends Relation[StViewFields, StViewRow, Row] + with StViewFields[Row] { outer => + + override val id = new Field[SalesterritoryId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val territoryid = new Field[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val group = new Field[/* max 50 chars */ String, Row](prefix, "group", None, None)(x => extract(x).group, (row, value) => merge(row, extract(row).copy(group = value))) + override val salesytd = new Field[BigDecimal, Row](prefix, "salesytd", None, None)(x => extract(x).salesytd, (row, value) => merge(row, extract(row).copy(salesytd = value))) + override val saleslastyear = new Field[BigDecimal, Row](prefix, "saleslastyear", None, None)(x => extract(x).saleslastyear, (row, value) => merge(row, extract(row).copy(saleslastyear = value))) + override val costytd = new Field[BigDecimal, Row](prefix, "costytd", None, None)(x => extract(x).costytd, (row, value) => merge(row, extract(row).copy(costytd = value))) + override val costlastyear = new Field[BigDecimal, Row](prefix, "costlastyear", None, None)(x => extract(x).costlastyear, (row, value) => merge(row, extract(row).copy(costlastyear = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, territoryid, name, countryregioncode, group, salesytd, saleslastyear, costytd, costlastyear, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => StViewRow, merge: (NewRow, StViewRow) => NewRow): StViewStructure[NewRow] = + new StViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewFields.scala new file mode 100644 index 0000000000..9b2188ab3b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sth + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait SthViewFields[Row] { + val id: Field[SalesterritoryId, Row] + val businessentityid: Field[BusinessentityId, Row] + val territoryid: Field[SalesterritoryId, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SthViewFields extends SthViewStructure[SthViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepo.scala new file mode 100644 index 0000000000..6915799101 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sth + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SthViewRepo { + def select: SelectBuilder[SthViewFields, SthViewRow] + def selectAll: ZStream[ZConnection, Throwable, SthViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepoImpl.scala new file mode 100644 index 0000000000..6fc6fac5a8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sth + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SthViewRepoImpl extends SthViewRepo { + override def select: SelectBuilder[SthViewFields, SthViewRow] = { + SelectBuilderSql("sa.sth", SthViewFields, SthViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SthViewRow] = { + sql"""select "id", "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text from sa.sth""".query(SthViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRow.scala new file mode 100644 index 0000000000..7b0e21c52e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewRow.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sth + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SthViewRow( + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.territoryid]] */ + id: SalesterritoryId, + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.startdate]] */ + startdate: TypoLocalDateTime, + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.enddate]] */ + enddate: Option[TypoLocalDateTime], + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salesterritoryhistory.SalesterritoryhistoryRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object SthViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SthViewRow] = new JdbcDecoder[SthViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SthViewRow) = + columIndex + 6 -> + SthViewRow( + id = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SthViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && businessentityid.isRight && territoryid.isRight && startdate.isRight && enddate.isRight && rowguid.isRight && modifieddate.isRight) + Right(SthViewRow(id = id.toOption.get, businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, businessentityid, territoryid, startdate, enddate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SthViewRow] = new JsonEncoder[SthViewRow] { + override def unsafeEncode(a: SthViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewStructure.scala new file mode 100644 index 0000000000..77b4f4a831 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/sth/SthViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package sth + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SthViewStructure[Row](val prefix: Option[String], val extract: Row => SthViewRow, val merge: (Row, SthViewRow) => Row) + extends Relation[SthViewFields, SthViewRow, Row] + with SthViewFields[Row] { outer => + + override val id = new Field[SalesterritoryId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val territoryid = new Field[SalesterritoryId, Row](prefix, "territoryid", None, None)(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = 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))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), None)(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, businessentityid, territoryid, startdate, enddate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SthViewRow, merge: (NewRow, SthViewRow) => NewRow): SthViewStructure[NewRow] = + new SthViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewFields.scala new file mode 100644 index 0000000000..3a2d182b62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewFields.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package tr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import adventureworks.sales.salestaxrate.SalestaxrateId +import typo.dsl.SqlExpr.Field + +trait TrViewFields[Row] { + val id: Field[SalestaxrateId, Row] + val salestaxrateid: Field[SalestaxrateId, Row] + val stateprovinceid: Field[StateprovinceId, Row] + val taxtype: Field[TypoShort, Row] + val taxrate: Field[BigDecimal, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object TrViewFields extends TrViewStructure[TrViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepo.scala new file mode 100644 index 0000000000..52e52b655e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package tr + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait TrViewRepo { + def select: SelectBuilder[TrViewFields, TrViewRow] + def selectAll: ZStream[ZConnection, Throwable, TrViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepoImpl.scala new file mode 100644 index 0000000000..6f1e261811 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package tr + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object TrViewRepoImpl extends TrViewRepo { + override def select: SelectBuilder[TrViewFields, TrViewRow] = { + SelectBuilderSql("sa.tr", TrViewFields, TrViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, TrViewRow] = { + sql"""select "id", "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text from sa.tr""".query(TrViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRow.scala new file mode 100644 index 0000000000..906eb2d911 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewRow.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package tr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import adventureworks.sales.salestaxrate.SalestaxrateId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class TrViewRow( + /** Points to [[sales.salestaxrate.SalestaxrateRow.salestaxrateid]] */ + id: SalestaxrateId, + /** Points to [[sales.salestaxrate.SalestaxrateRow.salestaxrateid]] */ + salestaxrateid: SalestaxrateId, + /** Points to [[sales.salestaxrate.SalestaxrateRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** Points to [[sales.salestaxrate.SalestaxrateRow.taxtype]] */ + taxtype: TypoShort, + /** Points to [[sales.salestaxrate.SalestaxrateRow.taxrate]] */ + taxrate: BigDecimal, + /** Points to [[sales.salestaxrate.SalestaxrateRow.name]] */ + name: Name, + /** Points to [[sales.salestaxrate.SalestaxrateRow.rowguid]] */ + rowguid: TypoUUID, + /** Points to [[sales.salestaxrate.SalestaxrateRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object TrViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[TrViewRow] = new JdbcDecoder[TrViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, TrViewRow) = + columIndex + 7 -> + TrViewRow( + id = SalestaxrateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salestaxrateid = SalestaxrateId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + taxtype = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + taxrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[TrViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val id = jsonObj.get("id").toRight("Missing field 'id'").flatMap(_.as(SalestaxrateId.jsonDecoder)) + val salestaxrateid = jsonObj.get("salestaxrateid").toRight("Missing field 'salestaxrateid'").flatMap(_.as(SalestaxrateId.jsonDecoder)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val taxtype = jsonObj.get("taxtype").toRight("Missing field 'taxtype'").flatMap(_.as(TypoShort.jsonDecoder)) + val taxrate = jsonObj.get("taxrate").toRight("Missing field 'taxrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (id.isRight && salestaxrateid.isRight && stateprovinceid.isRight && taxtype.isRight && taxrate.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(TrViewRow(id = id.toOption.get, salestaxrateid = salestaxrateid.toOption.get, stateprovinceid = stateprovinceid.toOption.get, taxtype = taxtype.toOption.get, taxrate = taxrate.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](id, salestaxrateid, stateprovinceid, taxtype, taxrate, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[TrViewRow] = new JsonEncoder[TrViewRow] { + override def unsafeEncode(a: TrViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""id":""") + SalestaxrateId.jsonEncoder.unsafeEncode(a.id, indent, out) + out.write(",") + out.write(""""salestaxrateid":""") + SalestaxrateId.jsonEncoder.unsafeEncode(a.salestaxrateid, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""taxtype":""") + TypoShort.jsonEncoder.unsafeEncode(a.taxtype, indent, out) + out.write(",") + out.write(""""taxrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxrate, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewStructure.scala new file mode 100644 index 0000000000..2726f9efad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sa/tr/TrViewStructure.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sa +package tr + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import adventureworks.sales.salestaxrate.SalestaxrateId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.Structure.Relation + +class TrViewStructure[Row](val prefix: Option[String], val extract: Row => TrViewRow, val merge: (Row, TrViewRow) => Row) + extends Relation[TrViewFields, TrViewRow, Row] + with TrViewFields[Row] { outer => + + override val id = new Field[SalestaxrateId, Row](prefix, "id", None, None)(x => extract(x).id, (row, value) => merge(row, extract(row).copy(id = value))) + override val salestaxrateid = new Field[SalestaxrateId, Row](prefix, "salestaxrateid", None, None)(x => extract(x).salestaxrateid, (row, value) => merge(row, extract(row).copy(salestaxrateid = value))) + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, None)(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val taxtype = new Field[TypoShort, Row](prefix, "taxtype", None, None)(x => extract(x).taxtype, (row, value) => merge(row, extract(row).copy(taxtype = value))) + override val taxrate = new Field[BigDecimal, Row](prefix, "taxrate", None, None)(x => extract(x).taxrate, (row, value) => merge(row, extract(row).copy(taxrate = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, None)(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), None)(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](id, salestaxrateid, stateprovinceid, taxtype, taxrate, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => TrViewRow, merge: (NewRow, TrViewRow) => NewRow): TrViewStructure[NewRow] = + new TrViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyFields.scala new file mode 100644 index 0000000000..e63f0dd19c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CountryregioncurrencyFields[Row] { + val countryregioncode: IdField[CountryregionId, Row] + val currencycode: IdField[CurrencyId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CountryregioncurrencyFields extends CountryregioncurrencyStructure[CountryregioncurrencyRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyId.scala new file mode 100644 index 0000000000..1f7e7ec8ef --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.countryregioncurrency` */ +case class CountryregioncurrencyId(countryregioncode: CountryregionId, currencycode: CurrencyId) +object CountryregioncurrencyId { + implicit lazy val jsonDecoder: JsonDecoder[CountryregioncurrencyId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + if (countryregioncode.isRight && currencycode.isRight) + Right(CountryregioncurrencyId(countryregioncode = countryregioncode.toOption.get, currencycode = currencycode.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, currencycode).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CountryregioncurrencyId] = new JsonEncoder[CountryregioncurrencyId] { + override def unsafeEncode(a: CountryregioncurrencyId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[CountryregioncurrencyId] = Ordering.by(x => (x.countryregioncode, x.currencycode)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepo.scala new file mode 100644 index 0000000000..cc8357a4d1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CountryregioncurrencyRepo { + def delete(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] + def insert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] + def insert(unsaved: CountryregioncurrencyRowUnsaved): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] + def select: SelectBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] + def selectAll: ZStream[ZConnection, Throwable, CountryregioncurrencyRow] + def selectById(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Option[CountryregioncurrencyRow]] + def update(row: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] + def upsert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregioncurrencyRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoImpl.scala new file mode 100644 index 0000000000..2fdb65591f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoImpl.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CountryregioncurrencyRepoImpl extends CountryregioncurrencyRepo { + override def delete(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.countryregioncurrency where "countryregioncode" = ${Segment.paramSegment(compositeId.countryregioncode)(CountryregionId.setter)} AND "currencycode" = ${Segment.paramSegment(compositeId.currencycode)(CurrencyId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + DeleteBuilder("sales.countryregioncurrency", CountryregioncurrencyFields) + } + override def insert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] = { + sql"""insert into sales.countryregioncurrency("countryregioncode", "currencycode", "modifieddate") + values (${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, ${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "countryregioncode", "currencycode", "modifieddate"::text + """.insertReturning(CountryregioncurrencyRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CountryregioncurrencyRowUnsaved): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] = { + val fs = List( + Some((sql""""countryregioncode"""", sql"${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}")), + Some((sql""""currencycode"""", sql"${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.countryregioncurrency default values + returning "countryregioncode", "currencycode", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.countryregioncurrency($names) values ($values) returning "countryregioncode", "currencycode", "modifieddate"::text""" + } + q.insertReturning(CountryregioncurrencyRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + SelectBuilderSql("sales.countryregioncurrency", CountryregioncurrencyFields, CountryregioncurrencyRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CountryregioncurrencyRow] = { + sql"""select "countryregioncode", "currencycode", "modifieddate"::text from sales.countryregioncurrency""".query(CountryregioncurrencyRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Option[CountryregioncurrencyRow]] = { + sql"""select "countryregioncode", "currencycode", "modifieddate"::text from sales.countryregioncurrency where "countryregioncode" = ${Segment.paramSegment(compositeId.countryregioncode)(CountryregionId.setter)} AND "currencycode" = ${Segment.paramSegment(compositeId.currencycode)(CurrencyId.setter)}""".query(CountryregioncurrencyRow.jdbcDecoder).selectOne + } + override def update(row: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.countryregioncurrency + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "countryregioncode" = ${Segment.paramSegment(compositeId.countryregioncode)(CountryregionId.setter)} AND "currencycode" = ${Segment.paramSegment(compositeId.currencycode)(CurrencyId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + UpdateBuilder("sales.countryregioncurrency", CountryregioncurrencyFields, CountryregioncurrencyRow.jdbcDecoder) + } + override def upsert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregioncurrencyRow]] = { + sql"""insert into sales.countryregioncurrency("countryregioncode", "currencycode", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, + ${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("countryregioncode", "currencycode") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "countryregioncode", "currencycode", "modifieddate"::text""".insertReturning(CountryregioncurrencyRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoMock.scala new file mode 100644 index 0000000000..154332a1e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CountryregioncurrencyRepoMock(toRow: Function1[CountryregioncurrencyRowUnsaved, CountryregioncurrencyRow], + map: scala.collection.mutable.Map[CountryregioncurrencyId, CountryregioncurrencyRow] = scala.collection.mutable.Map.empty) extends CountryregioncurrencyRepo { + override def delete(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + DeleteBuilderMock(DeleteParams.empty, CountryregioncurrencyFields, map) + } + override def insert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: CountryregioncurrencyRowUnsaved): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + SelectBuilderMock(CountryregioncurrencyFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CountryregioncurrencyRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: CountryregioncurrencyId): ZIO[ZConnection, Throwable, Option[CountryregioncurrencyRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CountryregioncurrencyFields, CountryregioncurrencyRow] = { + UpdateBuilderMock(UpdateParams.empty, CountryregioncurrencyFields, map) + } + override def upsert(unsaved: CountryregioncurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CountryregioncurrencyRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRow.scala new file mode 100644 index 0000000000..2105daf8d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CountryregioncurrencyRow( + /** ISO code for countries and regions. Foreign key to CountryRegion.CountryRegionCode. + Points to [[person.countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** ISO standard currency code. Foreign key to Currency.CurrencyCode. + Points to [[currency.CurrencyRow.currencycode]] */ + currencycode: CurrencyId, + modifieddate: TypoLocalDateTime +){ + val compositeId: CountryregioncurrencyId = CountryregioncurrencyId(countryregioncode, currencycode) + } + +object CountryregioncurrencyRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CountryregioncurrencyRow] = new JdbcDecoder[CountryregioncurrencyRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CountryregioncurrencyRow) = + columIndex + 2 -> + CountryregioncurrencyRow( + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + currencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CountryregioncurrencyRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (countryregioncode.isRight && currencycode.isRight && modifieddate.isRight) + Right(CountryregioncurrencyRow(countryregioncode = countryregioncode.toOption.get, currencycode = currencycode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, currencycode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CountryregioncurrencyRow] = new JsonEncoder[CountryregioncurrencyRow] { + override def unsafeEncode(a: CountryregioncurrencyRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRowUnsaved.scala new file mode 100644 index 0000000000..740924114e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyRowUnsaved.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.countryregioncurrency` which has not been persisted yet */ +case class CountryregioncurrencyRowUnsaved( + /** ISO code for countries and regions. Foreign key to CountryRegion.CountryRegionCode. + Points to [[person.countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** ISO standard currency code. Foreign key to Currency.CurrencyCode. + Points to [[currency.CurrencyRow.currencycode]] */ + currencycode: CurrencyId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): CountryregioncurrencyRow = + CountryregioncurrencyRow( + countryregioncode = countryregioncode, + currencycode = currencycode, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CountryregioncurrencyRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CountryregioncurrencyRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (countryregioncode.isRight && currencycode.isRight && modifieddate.isRight) + Right(CountryregioncurrencyRowUnsaved(countryregioncode = countryregioncode.toOption.get, currencycode = currencycode.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](countryregioncode, currencycode, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CountryregioncurrencyRowUnsaved] = new JsonEncoder[CountryregioncurrencyRowUnsaved] { + override def unsafeEncode(a: CountryregioncurrencyRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyStructure.scala new file mode 100644 index 0000000000..fe119bdf72 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/countryregioncurrency/CountryregioncurrencyStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package countryregioncurrency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.countryregion.CountryregionId +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CountryregioncurrencyStructure[Row](val prefix: Option[String], val extract: Row => CountryregioncurrencyRow, val merge: (Row, CountryregioncurrencyRow) => Row) + extends Relation[CountryregioncurrencyFields, CountryregioncurrencyRow, Row] + with CountryregioncurrencyFields[Row] { outer => + + override val countryregioncode = new IdField[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val currencycode = new IdField[CurrencyId, Row](prefix, "currencycode", None, Some("bpchar"))(x => extract(x).currencycode, (row, value) => merge(row, extract(row).copy(currencycode = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](countryregioncode, currencycode, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CountryregioncurrencyRow, merge: (NewRow, CountryregioncurrencyRow) => NewRow): CountryregioncurrencyStructure[NewRow] = + new CountryregioncurrencyStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardFields.scala new file mode 100644 index 0000000000..b21f8ef928 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CreditcardFields[Row] { + val creditcardid: IdField[/* user-picked */ CustomCreditcardId, Row] + val cardtype: Field[/* max 50 chars */ String, Row] + val cardnumber: Field[/* max 25 chars */ String, Row] + val expmonth: Field[TypoShort, Row] + val expyear: Field[TypoShort, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CreditcardFields extends CreditcardStructure[CreditcardRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepo.scala new file mode 100644 index 0000000000..2bb4d94249 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepo.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.JdbcEncoder +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CreditcardRepo { + def delete(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CreditcardFields, CreditcardRow] + def insert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, CreditcardRow] + def insert(unsaved: CreditcardRowUnsaved): ZIO[ZConnection, Throwable, CreditcardRow] + def select: SelectBuilder[CreditcardFields, CreditcardRow] + def selectAll: ZStream[ZConnection, Throwable, CreditcardRow] + def selectById(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Option[CreditcardRow]] + def selectByIds(creditcardids: Array[/* user-picked */ CustomCreditcardId])(implicit encoder: JdbcEncoder[Array[/* user-picked */ CustomCreditcardId]]): ZStream[ZConnection, Throwable, CreditcardRow] + def update(row: CreditcardRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CreditcardFields, CreditcardRow] + def upsert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[CreditcardRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoImpl.scala new file mode 100644 index 0000000000..269a3ba9ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoImpl.scala @@ -0,0 +1,113 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.JdbcEncoder +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CreditcardRepoImpl extends CreditcardRepo { + override def delete(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.creditcard where "creditcardid" = ${Segment.paramSegment(creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CreditcardFields, CreditcardRow] = { + DeleteBuilder("sales.creditcard", CreditcardFields) + } + override def insert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, CreditcardRow] = { + sql"""insert into sales.creditcard("creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate") + values (${Segment.paramSegment(unsaved.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}::int4, ${Segment.paramSegment(unsaved.cardtype)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.cardnumber)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.expmonth)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.expyear)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text + """.insertReturning(CreditcardRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CreditcardRowUnsaved): ZIO[ZConnection, Throwable, CreditcardRow] = { + val fs = List( + Some((sql""""cardtype"""", sql"${Segment.paramSegment(unsaved.cardtype)(Setter.stringSetter)}")), + Some((sql""""cardnumber"""", sql"${Segment.paramSegment(unsaved.cardnumber)(Setter.stringSetter)}")), + Some((sql""""expmonth"""", sql"${Segment.paramSegment(unsaved.expmonth)(TypoShort.setter)}::int2")), + Some((sql""""expyear"""", sql"${Segment.paramSegment(unsaved.expyear)(TypoShort.setter)}::int2")), + unsaved.creditcardid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""creditcardid"""", sql"${Segment.paramSegment(value: /* user-picked */ CustomCreditcardId)(/* user-picked */ CustomCreditcardId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.creditcard default values + returning "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.creditcard($names) values ($values) returning "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text""" + } + q.insertReturning(CreditcardRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CreditcardFields, CreditcardRow] = { + SelectBuilderSql("sales.creditcard", CreditcardFields, CreditcardRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CreditcardRow] = { + sql"""select "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text from sales.creditcard""".query(CreditcardRow.jdbcDecoder).selectStream + } + override def selectById(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Option[CreditcardRow]] = { + sql"""select "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text from sales.creditcard where "creditcardid" = ${Segment.paramSegment(creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".query(CreditcardRow.jdbcDecoder).selectOne + } + override def selectByIds(creditcardids: Array[/* user-picked */ CustomCreditcardId])(implicit encoder: JdbcEncoder[Array[/* user-picked */ CustomCreditcardId]]): ZStream[ZConnection, Throwable, CreditcardRow] = { + sql"""select "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text from sales.creditcard where "creditcardid" = ANY(${Segment.paramSegment(creditcardids)(CustomCreditcardId.arraySetter)})""".query(CreditcardRow.jdbcDecoder).selectStream + } + override def update(row: CreditcardRow): ZIO[ZConnection, Throwable, Boolean] = { + val creditcardid = row.creditcardid + sql"""update sales.creditcard + set "cardtype" = ${Segment.paramSegment(row.cardtype)(Setter.stringSetter)}, + "cardnumber" = ${Segment.paramSegment(row.cardnumber)(Setter.stringSetter)}, + "expmonth" = ${Segment.paramSegment(row.expmonth)(TypoShort.setter)}::int2, + "expyear" = ${Segment.paramSegment(row.expyear)(TypoShort.setter)}::int2, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "creditcardid" = ${Segment.paramSegment(creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CreditcardFields, CreditcardRow] = { + UpdateBuilder("sales.creditcard", CreditcardFields, CreditcardRow.jdbcDecoder) + } + override def upsert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[CreditcardRow]] = { + sql"""insert into sales.creditcard("creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}::int4, + ${Segment.paramSegment(unsaved.cardtype)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.cardnumber)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.expmonth)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.expyear)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("creditcardid") + do update set + "cardtype" = EXCLUDED."cardtype", + "cardnumber" = EXCLUDED."cardnumber", + "expmonth" = EXCLUDED."expmonth", + "expyear" = EXCLUDED."expyear", + "modifieddate" = EXCLUDED."modifieddate" + returning "creditcardid", "cardtype", "cardnumber", "expmonth", "expyear", "modifieddate"::text""".insertReturning(CreditcardRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoMock.scala new file mode 100644 index 0000000000..2f86bfb047 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRepoMock.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.userdefined.CustomCreditcardId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.JdbcEncoder +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CreditcardRepoMock(toRow: Function1[CreditcardRowUnsaved, CreditcardRow], + map: scala.collection.mutable.Map[/* user-picked */ CustomCreditcardId, CreditcardRow] = scala.collection.mutable.Map.empty) extends CreditcardRepo { + override def delete(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(creditcardid).isDefined) + } + override def delete: DeleteBuilder[CreditcardFields, CreditcardRow] = { + DeleteBuilderMock(DeleteParams.empty, CreditcardFields, map) + } + override def insert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, CreditcardRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.creditcardid)) + sys.error(s"id ${unsaved.creditcardid} already exists") + else + map.put(unsaved.creditcardid, unsaved) + + unsaved + } + } + override def insert(unsaved: CreditcardRowUnsaved): ZIO[ZConnection, Throwable, CreditcardRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CreditcardFields, CreditcardRow] = { + SelectBuilderMock(CreditcardFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CreditcardRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(creditcardid: /* user-picked */ CustomCreditcardId): ZIO[ZConnection, Throwable, Option[CreditcardRow]] = { + ZIO.succeed(map.get(creditcardid)) + } + override def selectByIds(creditcardids: Array[/* user-picked */ CustomCreditcardId])(implicit encoder: JdbcEncoder[Array[/* user-picked */ CustomCreditcardId]]): ZStream[ZConnection, Throwable, CreditcardRow] = { + ZStream.fromIterable(creditcardids.flatMap(map.get)) + } + override def update(row: CreditcardRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.creditcardid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.creditcardid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CreditcardFields, CreditcardRow] = { + UpdateBuilderMock(UpdateParams.empty, CreditcardFields, map) + } + override def upsert(unsaved: CreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[CreditcardRow]] = { + ZIO.succeed { + map.put(unsaved.creditcardid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRow.scala new file mode 100644 index 0000000000..f9ab5155da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRow.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CreditcardRow( + /** Primary key for CreditCard records. */ + creditcardid: /* user-picked */ CustomCreditcardId, + /** Credit card name. */ + cardtype: /* max 50 chars */ String, + /** Credit card number. */ + cardnumber: /* max 25 chars */ String, + /** Credit card expiration month. */ + expmonth: TypoShort, + /** Credit card expiration year. */ + expyear: TypoShort, + modifieddate: TypoLocalDateTime +) + +object CreditcardRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CreditcardRow] = new JdbcDecoder[CreditcardRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CreditcardRow) = + columIndex + 5 -> + CreditcardRow( + creditcardid = CustomCreditcardId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + cardtype = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + cardnumber = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + expmonth = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + expyear = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CreditcardRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val cardtype = jsonObj.get("cardtype").toRight("Missing field 'cardtype'").flatMap(_.as(JsonDecoder.string)) + val cardnumber = jsonObj.get("cardnumber").toRight("Missing field 'cardnumber'").flatMap(_.as(JsonDecoder.string)) + val expmonth = jsonObj.get("expmonth").toRight("Missing field 'expmonth'").flatMap(_.as(TypoShort.jsonDecoder)) + val expyear = jsonObj.get("expyear").toRight("Missing field 'expyear'").flatMap(_.as(TypoShort.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (creditcardid.isRight && cardtype.isRight && cardnumber.isRight && expmonth.isRight && expyear.isRight && modifieddate.isRight) + Right(CreditcardRow(creditcardid = creditcardid.toOption.get, cardtype = cardtype.toOption.get, cardnumber = cardnumber.toOption.get, expmonth = expmonth.toOption.get, expyear = expyear.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](creditcardid, cardtype, cardnumber, expmonth, expyear, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CreditcardRow] = new JsonEncoder[CreditcardRow] { + override def unsafeEncode(a: CreditcardRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""cardtype":""") + JsonEncoder.string.unsafeEncode(a.cardtype, indent, out) + out.write(",") + out.write(""""cardnumber":""") + JsonEncoder.string.unsafeEncode(a.cardnumber, indent, out) + out.write(",") + out.write(""""expmonth":""") + TypoShort.jsonEncoder.unsafeEncode(a.expmonth, indent, out) + out.write(",") + out.write(""""expyear":""") + TypoShort.jsonEncoder.unsafeEncode(a.expyear, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRowUnsaved.scala new file mode 100644 index 0000000000..811a360463 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardRowUnsaved.scala @@ -0,0 +1,86 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.creditcard` which has not been persisted yet */ +case class CreditcardRowUnsaved( + /** Credit card name. */ + cardtype: /* max 50 chars */ String, + /** Credit card number. */ + cardnumber: /* max 25 chars */ String, + /** Credit card expiration month. */ + expmonth: TypoShort, + /** Credit card expiration year. */ + expyear: TypoShort, + /** Default: nextval('sales.creditcard_creditcardid_seq'::regclass) + Primary key for CreditCard records. */ + creditcardid: Defaulted[/* user-picked */ CustomCreditcardId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(creditcardidDefault: => /* user-picked */ CustomCreditcardId, modifieddateDefault: => TypoLocalDateTime): CreditcardRow = + CreditcardRow( + cardtype = cardtype, + cardnumber = cardnumber, + expmonth = expmonth, + expyear = expyear, + creditcardid = creditcardid match { + case Defaulted.UseDefault => creditcardidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CreditcardRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CreditcardRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val cardtype = jsonObj.get("cardtype").toRight("Missing field 'cardtype'").flatMap(_.as(JsonDecoder.string)) + val cardnumber = jsonObj.get("cardnumber").toRight("Missing field 'cardnumber'").flatMap(_.as(JsonDecoder.string)) + val expmonth = jsonObj.get("expmonth").toRight("Missing field 'expmonth'").flatMap(_.as(TypoShort.jsonDecoder)) + val expyear = jsonObj.get("expyear").toRight("Missing field 'expyear'").flatMap(_.as(TypoShort.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(Defaulted.jsonDecoder(CustomCreditcardId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (cardtype.isRight && cardnumber.isRight && expmonth.isRight && expyear.isRight && creditcardid.isRight && modifieddate.isRight) + Right(CreditcardRowUnsaved(cardtype = cardtype.toOption.get, cardnumber = cardnumber.toOption.get, expmonth = expmonth.toOption.get, expyear = expyear.toOption.get, creditcardid = creditcardid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](cardtype, cardnumber, expmonth, expyear, creditcardid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CreditcardRowUnsaved] = new JsonEncoder[CreditcardRowUnsaved] { + override def unsafeEncode(a: CreditcardRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""cardtype":""") + JsonEncoder.string.unsafeEncode(a.cardtype, indent, out) + out.write(",") + out.write(""""cardnumber":""") + JsonEncoder.string.unsafeEncode(a.cardnumber, indent, out) + out.write(",") + out.write(""""expmonth":""") + TypoShort.jsonEncoder.unsafeEncode(a.expmonth, indent, out) + out.write(",") + out.write(""""expyear":""") + TypoShort.jsonEncoder.unsafeEncode(a.expyear, indent, out) + out.write(",") + out.write(""""creditcardid":""") + Defaulted.jsonEncoder(CustomCreditcardId.jsonEncoder).unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardStructure.scala new file mode 100644 index 0000000000..4f259e9545 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/creditcard/CreditcardStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package creditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CreditcardStructure[Row](val prefix: Option[String], val extract: Row => CreditcardRow, val merge: (Row, CreditcardRow) => Row) + extends Relation[CreditcardFields, CreditcardRow, Row] + with CreditcardFields[Row] { outer => + + override val creditcardid = new IdField[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, Some("int4"))(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val cardtype = new Field[/* max 50 chars */ String, Row](prefix, "cardtype", None, None)(x => extract(x).cardtype, (row, value) => merge(row, extract(row).copy(cardtype = value))) + override val cardnumber = new Field[/* max 25 chars */ String, Row](prefix, "cardnumber", None, None)(x => extract(x).cardnumber, (row, value) => merge(row, extract(row).copy(cardnumber = value))) + override val expmonth = new Field[TypoShort, Row](prefix, "expmonth", None, Some("int2"))(x => extract(x).expmonth, (row, value) => merge(row, extract(row).copy(expmonth = value))) + override val expyear = new Field[TypoShort, Row](prefix, "expyear", None, Some("int2"))(x => extract(x).expyear, (row, value) => merge(row, extract(row).copy(expyear = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](creditcardid, cardtype, cardnumber, expmonth, expyear, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CreditcardRow, merge: (NewRow, CreditcardRow) => NewRow): CreditcardStructure[NewRow] = + new CreditcardStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyFields.scala new file mode 100644 index 0000000000..079f2ff5cf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyFields.scala @@ -0,0 +1,21 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CurrencyFields[Row] { + val currencycode: IdField[CurrencyId, Row] + val name: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CurrencyFields extends CurrencyStructure[CurrencyRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyId.scala new file mode 100644 index 0000000000..f5ae0fb619 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +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 `sales.currency` */ +case class CurrencyId(value: /* bpchar, max 3 chars */ String) extends AnyVal +object CurrencyId { + implicit lazy val arraySetter: Setter[Array[CurrencyId]] = adventureworks.StringArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CurrencyId, /* bpchar, max 3 chars */ String] = Bijection[CurrencyId, /* bpchar, max 3 chars */ String](_.value)(CurrencyId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CurrencyId] = JdbcDecoder.stringDecoder.map(CurrencyId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CurrencyId] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CurrencyId] = JsonDecoder.string.map(CurrencyId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CurrencyId] = JsonEncoder.string.contramap(_.value) + implicit lazy val ordering: Ordering[CurrencyId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CurrencyId] = ParameterMetaData.instance[CurrencyId](ParameterMetaData.StringParameterMetaData.sqlType, ParameterMetaData.StringParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CurrencyId] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepo.scala new file mode 100644 index 0000000000..e5b6e3d708 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CurrencyRepo { + def delete(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CurrencyFields, CurrencyRow] + def insert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, CurrencyRow] + def insert(unsaved: CurrencyRowUnsaved): ZIO[ZConnection, Throwable, CurrencyRow] + def select: SelectBuilder[CurrencyFields, CurrencyRow] + def selectAll: ZStream[ZConnection, Throwable, CurrencyRow] + def selectById(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Option[CurrencyRow]] + def selectByIds(currencycodes: Array[CurrencyId]): ZStream[ZConnection, Throwable, CurrencyRow] + def update(row: CurrencyRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CurrencyFields, CurrencyRow] + def upsert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoImpl.scala new file mode 100644 index 0000000000..41cd6cb9a9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoImpl.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CurrencyRepoImpl extends CurrencyRepo { + override def delete(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.currency where "currencycode" = ${Segment.paramSegment(currencycode)(CurrencyId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CurrencyFields, CurrencyRow] = { + DeleteBuilder("sales.currency", CurrencyFields) + } + override def insert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, CurrencyRow] = { + sql"""insert into sales.currency("currencycode", "name", "modifieddate") + values (${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "currencycode", "name", "modifieddate"::text + """.insertReturning(CurrencyRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CurrencyRowUnsaved): ZIO[ZConnection, Throwable, CurrencyRow] = { + val fs = List( + Some((sql""""currencycode"""", sql"${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.currency default values + returning "currencycode", "name", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.currency($names) values ($values) returning "currencycode", "name", "modifieddate"::text""" + } + q.insertReturning(CurrencyRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CurrencyFields, CurrencyRow] = { + SelectBuilderSql("sales.currency", CurrencyFields, CurrencyRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CurrencyRow] = { + sql"""select "currencycode", "name", "modifieddate"::text from sales.currency""".query(CurrencyRow.jdbcDecoder).selectStream + } + override def selectById(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Option[CurrencyRow]] = { + sql"""select "currencycode", "name", "modifieddate"::text from sales.currency where "currencycode" = ${Segment.paramSegment(currencycode)(CurrencyId.setter)}""".query(CurrencyRow.jdbcDecoder).selectOne + } + override def selectByIds(currencycodes: Array[CurrencyId]): ZStream[ZConnection, Throwable, CurrencyRow] = { + sql"""select "currencycode", "name", "modifieddate"::text from sales.currency where "currencycode" = ANY(${Segment.paramSegment(currencycodes)(CurrencyId.arraySetter)})""".query(CurrencyRow.jdbcDecoder).selectStream + } + override def update(row: CurrencyRow): ZIO[ZConnection, Throwable, Boolean] = { + val currencycode = row.currencycode + sql"""update sales.currency + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "currencycode" = ${Segment.paramSegment(currencycode)(CurrencyId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CurrencyFields, CurrencyRow] = { + UpdateBuilder("sales.currency", CurrencyFields, CurrencyRow.jdbcDecoder) + } + override def upsert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyRow]] = { + sql"""insert into sales.currency("currencycode", "name", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.currencycode)(CurrencyId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("currencycode") + do update set + "name" = EXCLUDED."name", + "modifieddate" = EXCLUDED."modifieddate" + returning "currencycode", "name", "modifieddate"::text""".insertReturning(CurrencyRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoMock.scala new file mode 100644 index 0000000000..20bd45ba57 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CurrencyRepoMock(toRow: Function1[CurrencyRowUnsaved, CurrencyRow], + map: scala.collection.mutable.Map[CurrencyId, CurrencyRow] = scala.collection.mutable.Map.empty) extends CurrencyRepo { + override def delete(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(currencycode).isDefined) + } + override def delete: DeleteBuilder[CurrencyFields, CurrencyRow] = { + DeleteBuilderMock(DeleteParams.empty, CurrencyFields, map) + } + override def insert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, CurrencyRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.currencycode)) + sys.error(s"id ${unsaved.currencycode} already exists") + else + map.put(unsaved.currencycode, unsaved) + + unsaved + } + } + override def insert(unsaved: CurrencyRowUnsaved): ZIO[ZConnection, Throwable, CurrencyRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CurrencyFields, CurrencyRow] = { + SelectBuilderMock(CurrencyFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CurrencyRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(currencycode: CurrencyId): ZIO[ZConnection, Throwable, Option[CurrencyRow]] = { + ZIO.succeed(map.get(currencycode)) + } + override def selectByIds(currencycodes: Array[CurrencyId]): ZStream[ZConnection, Throwable, CurrencyRow] = { + ZStream.fromIterable(currencycodes.flatMap(map.get)) + } + override def update(row: CurrencyRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.currencycode) match { + case Some(`row`) => false + case Some(_) => + map.put(row.currencycode, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CurrencyFields, CurrencyRow] = { + UpdateBuilderMock(UpdateParams.empty, CurrencyFields, map) + } + override def upsert(unsaved: CurrencyRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyRow]] = { + ZIO.succeed { + map.put(unsaved.currencycode, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRow.scala new file mode 100644 index 0000000000..f3e7192dba --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRow.scala @@ -0,0 +1,59 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CurrencyRow( + /** The ISO code for the Currency. */ + currencycode: CurrencyId, + /** Currency name. */ + name: Name, + modifieddate: TypoLocalDateTime +) + +object CurrencyRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CurrencyRow] = new JdbcDecoder[CurrencyRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CurrencyRow) = + columIndex + 2 -> + CurrencyRow( + currencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CurrencyRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (currencycode.isRight && name.isRight && modifieddate.isRight) + Right(CurrencyRow(currencycode = currencycode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](currencycode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CurrencyRow] = new JsonEncoder[CurrencyRow] { + override def unsafeEncode(a: CurrencyRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRowUnsaved.scala new file mode 100644 index 0000000000..356e9f3466 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyRowUnsaved.scala @@ -0,0 +1,60 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.currency` which has not been persisted yet */ +case class CurrencyRowUnsaved( + /** The ISO code for the Currency. */ + currencycode: CurrencyId, + /** Currency name. */ + name: Name, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): CurrencyRow = + CurrencyRow( + currencycode = currencycode, + name = name, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CurrencyRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CurrencyRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val currencycode = jsonObj.get("currencycode").toRight("Missing field 'currencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (currencycode.isRight && name.isRight && modifieddate.isRight) + Right(CurrencyRowUnsaved(currencycode = currencycode.toOption.get, name = name.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](currencycode, name, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CurrencyRowUnsaved] = new JsonEncoder[CurrencyRowUnsaved] { + override def unsafeEncode(a: CurrencyRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""currencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.currencycode, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyStructure.scala new file mode 100644 index 0000000000..7eeeac8bd7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currency/CurrencyStructure.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currency + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CurrencyStructure[Row](val prefix: Option[String], val extract: Row => CurrencyRow, val merge: (Row, CurrencyRow) => Row) + extends Relation[CurrencyFields, CurrencyRow, Row] + with CurrencyFields[Row] { outer => + + override val currencycode = new IdField[CurrencyId, Row](prefix, "currencycode", None, Some("bpchar"))(x => extract(x).currencycode, (row, value) => merge(row, extract(row).copy(currencycode = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](currencycode, name, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CurrencyRow, merge: (NewRow, CurrencyRow) => NewRow): CurrencyStructure[NewRow] = + new CurrencyStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateFields.scala new file mode 100644 index 0000000000..ec65aaace3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateFields.scala @@ -0,0 +1,25 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait CurrencyrateFields[Row] { + val currencyrateid: IdField[CurrencyrateId, Row] + val currencyratedate: Field[TypoLocalDateTime, Row] + val fromcurrencycode: Field[CurrencyId, Row] + val tocurrencycode: Field[CurrencyId, Row] + val averagerate: Field[BigDecimal, Row] + val endofdayrate: Field[BigDecimal, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CurrencyrateFields extends CurrencyrateStructure[CurrencyrateRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateId.scala new file mode 100644 index 0000000000..2de6fede35 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +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 `sales.currencyrate` */ +case class CurrencyrateId(value: Int) extends AnyVal +object CurrencyrateId { + implicit lazy val arraySetter: Setter[Array[CurrencyrateId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CurrencyrateId, Int] = Bijection[CurrencyrateId, Int](_.value)(CurrencyrateId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CurrencyrateId] = JdbcDecoder.intDecoder.map(CurrencyrateId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CurrencyrateId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CurrencyrateId] = JsonDecoder.int.map(CurrencyrateId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CurrencyrateId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[CurrencyrateId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CurrencyrateId] = ParameterMetaData.instance[CurrencyrateId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CurrencyrateId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepo.scala new file mode 100644 index 0000000000..79eb19b838 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CurrencyrateRepo { + def delete(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CurrencyrateFields, CurrencyrateRow] + def insert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, CurrencyrateRow] + def insert(unsaved: CurrencyrateRowUnsaved): ZIO[ZConnection, Throwable, CurrencyrateRow] + def select: SelectBuilder[CurrencyrateFields, CurrencyrateRow] + def selectAll: ZStream[ZConnection, Throwable, CurrencyrateRow] + def selectById(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Option[CurrencyrateRow]] + def selectByIds(currencyrateids: Array[CurrencyrateId]): ZStream[ZConnection, Throwable, CurrencyrateRow] + def update(row: CurrencyrateRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CurrencyrateFields, CurrencyrateRow] + def upsert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyrateRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoImpl.scala new file mode 100644 index 0000000000..b4324d7d04 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoImpl.scala @@ -0,0 +1,115 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CurrencyrateRepoImpl extends CurrencyrateRepo { + override def delete(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.currencyrate where "currencyrateid" = ${Segment.paramSegment(currencyrateid)(CurrencyrateId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CurrencyrateFields, CurrencyrateRow] = { + DeleteBuilder("sales.currencyrate", CurrencyrateFields) + } + override def insert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, CurrencyrateRow] = { + sql"""insert into sales.currencyrate("currencyrateid", "currencyratedate", "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate") + values (${Segment.paramSegment(unsaved.currencyrateid)(CurrencyrateId.setter)}::int4, ${Segment.paramSegment(unsaved.currencyratedate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.fromcurrencycode)(CurrencyId.setter)}::bpchar, ${Segment.paramSegment(unsaved.tocurrencycode)(CurrencyId.setter)}::bpchar, ${Segment.paramSegment(unsaved.averagerate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.endofdayrate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text + """.insertReturning(CurrencyrateRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CurrencyrateRowUnsaved): ZIO[ZConnection, Throwable, CurrencyrateRow] = { + val fs = List( + Some((sql""""currencyratedate"""", sql"${Segment.paramSegment(unsaved.currencyratedate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""fromcurrencycode"""", sql"${Segment.paramSegment(unsaved.fromcurrencycode)(CurrencyId.setter)}::bpchar")), + Some((sql""""tocurrencycode"""", sql"${Segment.paramSegment(unsaved.tocurrencycode)(CurrencyId.setter)}::bpchar")), + Some((sql""""averagerate"""", sql"${Segment.paramSegment(unsaved.averagerate)(Setter.bigDecimalScalaSetter)}::numeric")), + Some((sql""""endofdayrate"""", sql"${Segment.paramSegment(unsaved.endofdayrate)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.currencyrateid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""currencyrateid"""", sql"${Segment.paramSegment(value: CurrencyrateId)(CurrencyrateId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.currencyrate default values + returning "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.currencyrate($names) values ($values) returning "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text""" + } + q.insertReturning(CurrencyrateRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CurrencyrateFields, CurrencyrateRow] = { + SelectBuilderSql("sales.currencyrate", CurrencyrateFields, CurrencyrateRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CurrencyrateRow] = { + sql"""select "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text from sales.currencyrate""".query(CurrencyrateRow.jdbcDecoder).selectStream + } + override def selectById(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Option[CurrencyrateRow]] = { + sql"""select "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text from sales.currencyrate where "currencyrateid" = ${Segment.paramSegment(currencyrateid)(CurrencyrateId.setter)}""".query(CurrencyrateRow.jdbcDecoder).selectOne + } + override def selectByIds(currencyrateids: Array[CurrencyrateId]): ZStream[ZConnection, Throwable, CurrencyrateRow] = { + sql"""select "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text from sales.currencyrate where "currencyrateid" = ANY(${Segment.paramSegment(currencyrateids)(CurrencyrateId.arraySetter)})""".query(CurrencyrateRow.jdbcDecoder).selectStream + } + override def update(row: CurrencyrateRow): ZIO[ZConnection, Throwable, Boolean] = { + val currencyrateid = row.currencyrateid + sql"""update sales.currencyrate + set "currencyratedate" = ${Segment.paramSegment(row.currencyratedate)(TypoLocalDateTime.setter)}::timestamp, + "fromcurrencycode" = ${Segment.paramSegment(row.fromcurrencycode)(CurrencyId.setter)}::bpchar, + "tocurrencycode" = ${Segment.paramSegment(row.tocurrencycode)(CurrencyId.setter)}::bpchar, + "averagerate" = ${Segment.paramSegment(row.averagerate)(Setter.bigDecimalScalaSetter)}::numeric, + "endofdayrate" = ${Segment.paramSegment(row.endofdayrate)(Setter.bigDecimalScalaSetter)}::numeric, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "currencyrateid" = ${Segment.paramSegment(currencyrateid)(CurrencyrateId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CurrencyrateFields, CurrencyrateRow] = { + UpdateBuilder("sales.currencyrate", CurrencyrateFields, CurrencyrateRow.jdbcDecoder) + } + override def upsert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyrateRow]] = { + sql"""insert into sales.currencyrate("currencyrateid", "currencyratedate", "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.currencyrateid)(CurrencyrateId.setter)}::int4, + ${Segment.paramSegment(unsaved.currencyratedate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.fromcurrencycode)(CurrencyId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.tocurrencycode)(CurrencyId.setter)}::bpchar, + ${Segment.paramSegment(unsaved.averagerate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.endofdayrate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("currencyrateid") + do update set + "currencyratedate" = EXCLUDED."currencyratedate", + "fromcurrencycode" = EXCLUDED."fromcurrencycode", + "tocurrencycode" = EXCLUDED."tocurrencycode", + "averagerate" = EXCLUDED."averagerate", + "endofdayrate" = EXCLUDED."endofdayrate", + "modifieddate" = EXCLUDED."modifieddate" + returning "currencyrateid", "currencyratedate"::text, "fromcurrencycode", "tocurrencycode", "averagerate", "endofdayrate", "modifieddate"::text""".insertReturning(CurrencyrateRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoMock.scala new file mode 100644 index 0000000000..9c6e6b8388 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CurrencyrateRepoMock(toRow: Function1[CurrencyrateRowUnsaved, CurrencyrateRow], + map: scala.collection.mutable.Map[CurrencyrateId, CurrencyrateRow] = scala.collection.mutable.Map.empty) extends CurrencyrateRepo { + override def delete(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(currencyrateid).isDefined) + } + override def delete: DeleteBuilder[CurrencyrateFields, CurrencyrateRow] = { + DeleteBuilderMock(DeleteParams.empty, CurrencyrateFields, map) + } + override def insert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, CurrencyrateRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.currencyrateid)) + sys.error(s"id ${unsaved.currencyrateid} already exists") + else + map.put(unsaved.currencyrateid, unsaved) + + unsaved + } + } + override def insert(unsaved: CurrencyrateRowUnsaved): ZIO[ZConnection, Throwable, CurrencyrateRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CurrencyrateFields, CurrencyrateRow] = { + SelectBuilderMock(CurrencyrateFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CurrencyrateRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(currencyrateid: CurrencyrateId): ZIO[ZConnection, Throwable, Option[CurrencyrateRow]] = { + ZIO.succeed(map.get(currencyrateid)) + } + override def selectByIds(currencyrateids: Array[CurrencyrateId]): ZStream[ZConnection, Throwable, CurrencyrateRow] = { + ZStream.fromIterable(currencyrateids.flatMap(map.get)) + } + override def update(row: CurrencyrateRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.currencyrateid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.currencyrateid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CurrencyrateFields, CurrencyrateRow] = { + UpdateBuilderMock(UpdateParams.empty, CurrencyrateFields, map) + } + override def upsert(unsaved: CurrencyrateRow): ZIO[ZConnection, Throwable, UpdateResult[CurrencyrateRow]] = { + ZIO.succeed { + map.put(unsaved.currencyrateid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRow.scala new file mode 100644 index 0000000000..a9c4b02ac7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRow.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CurrencyrateRow( + /** Primary key for CurrencyRate records. */ + currencyrateid: CurrencyrateId, + /** Date and time the exchange rate was obtained. */ + currencyratedate: TypoLocalDateTime, + /** Exchange rate was converted from this currency code. + Points to [[currency.CurrencyRow.currencycode]] */ + fromcurrencycode: CurrencyId, + /** Exchange rate was converted to this currency code. + Points to [[currency.CurrencyRow.currencycode]] */ + tocurrencycode: CurrencyId, + /** Average exchange rate for the day. */ + averagerate: BigDecimal, + /** Final exchange rate for the day. */ + endofdayrate: BigDecimal, + modifieddate: TypoLocalDateTime +) + +object CurrencyrateRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CurrencyrateRow] = new JdbcDecoder[CurrencyrateRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CurrencyrateRow) = + columIndex + 6 -> + CurrencyrateRow( + currencyrateid = CurrencyrateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + currencyratedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + fromcurrencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + tocurrencycode = CurrencyId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + averagerate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + endofdayrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CurrencyrateRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val currencyrateid = jsonObj.get("currencyrateid").toRight("Missing field 'currencyrateid'").flatMap(_.as(CurrencyrateId.jsonDecoder)) + val currencyratedate = jsonObj.get("currencyratedate").toRight("Missing field 'currencyratedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val fromcurrencycode = jsonObj.get("fromcurrencycode").toRight("Missing field 'fromcurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val tocurrencycode = jsonObj.get("tocurrencycode").toRight("Missing field 'tocurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val averagerate = jsonObj.get("averagerate").toRight("Missing field 'averagerate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val endofdayrate = jsonObj.get("endofdayrate").toRight("Missing field 'endofdayrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (currencyrateid.isRight && currencyratedate.isRight && fromcurrencycode.isRight && tocurrencycode.isRight && averagerate.isRight && endofdayrate.isRight && modifieddate.isRight) + Right(CurrencyrateRow(currencyrateid = currencyrateid.toOption.get, currencyratedate = currencyratedate.toOption.get, fromcurrencycode = fromcurrencycode.toOption.get, tocurrencycode = tocurrencycode.toOption.get, averagerate = averagerate.toOption.get, endofdayrate = endofdayrate.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](currencyrateid, currencyratedate, fromcurrencycode, tocurrencycode, averagerate, endofdayrate, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CurrencyrateRow] = new JsonEncoder[CurrencyrateRow] { + override def unsafeEncode(a: CurrencyrateRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""currencyrateid":""") + CurrencyrateId.jsonEncoder.unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""currencyratedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.currencyratedate, indent, out) + out.write(",") + out.write(""""fromcurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.fromcurrencycode, indent, out) + out.write(",") + out.write(""""tocurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.tocurrencycode, indent, out) + out.write(",") + out.write(""""averagerate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.averagerate, indent, out) + out.write(",") + out.write(""""endofdayrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.endofdayrate, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRowUnsaved.scala new file mode 100644 index 0000000000..914060a000 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateRowUnsaved.scala @@ -0,0 +1,94 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.currencyrate` which has not been persisted yet */ +case class CurrencyrateRowUnsaved( + /** Date and time the exchange rate was obtained. */ + currencyratedate: TypoLocalDateTime, + /** Exchange rate was converted from this currency code. + Points to [[currency.CurrencyRow.currencycode]] */ + fromcurrencycode: CurrencyId, + /** Exchange rate was converted to this currency code. + Points to [[currency.CurrencyRow.currencycode]] */ + tocurrencycode: CurrencyId, + /** Average exchange rate for the day. */ + averagerate: BigDecimal, + /** Final exchange rate for the day. */ + endofdayrate: BigDecimal, + /** Default: nextval('sales.currencyrate_currencyrateid_seq'::regclass) + Primary key for CurrencyRate records. */ + currencyrateid: Defaulted[CurrencyrateId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(currencyrateidDefault: => CurrencyrateId, modifieddateDefault: => TypoLocalDateTime): CurrencyrateRow = + CurrencyrateRow( + currencyratedate = currencyratedate, + fromcurrencycode = fromcurrencycode, + tocurrencycode = tocurrencycode, + averagerate = averagerate, + endofdayrate = endofdayrate, + currencyrateid = currencyrateid match { + case Defaulted.UseDefault => currencyrateidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CurrencyrateRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CurrencyrateRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val currencyratedate = jsonObj.get("currencyratedate").toRight("Missing field 'currencyratedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val fromcurrencycode = jsonObj.get("fromcurrencycode").toRight("Missing field 'fromcurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val tocurrencycode = jsonObj.get("tocurrencycode").toRight("Missing field 'tocurrencycode'").flatMap(_.as(CurrencyId.jsonDecoder)) + val averagerate = jsonObj.get("averagerate").toRight("Missing field 'averagerate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val endofdayrate = jsonObj.get("endofdayrate").toRight("Missing field 'endofdayrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val currencyrateid = jsonObj.get("currencyrateid").toRight("Missing field 'currencyrateid'").flatMap(_.as(Defaulted.jsonDecoder(CurrencyrateId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (currencyratedate.isRight && fromcurrencycode.isRight && tocurrencycode.isRight && averagerate.isRight && endofdayrate.isRight && currencyrateid.isRight && modifieddate.isRight) + Right(CurrencyrateRowUnsaved(currencyratedate = currencyratedate.toOption.get, fromcurrencycode = fromcurrencycode.toOption.get, tocurrencycode = tocurrencycode.toOption.get, averagerate = averagerate.toOption.get, endofdayrate = endofdayrate.toOption.get, currencyrateid = currencyrateid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](currencyratedate, fromcurrencycode, tocurrencycode, averagerate, endofdayrate, currencyrateid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CurrencyrateRowUnsaved] = new JsonEncoder[CurrencyrateRowUnsaved] { + override def unsafeEncode(a: CurrencyrateRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""currencyratedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.currencyratedate, indent, out) + out.write(",") + out.write(""""fromcurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.fromcurrencycode, indent, out) + out.write(",") + out.write(""""tocurrencycode":""") + CurrencyId.jsonEncoder.unsafeEncode(a.tocurrencycode, indent, out) + out.write(",") + out.write(""""averagerate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.averagerate, indent, out) + out.write(",") + out.write(""""endofdayrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.endofdayrate, indent, out) + out.write(",") + out.write(""""currencyrateid":""") + Defaulted.jsonEncoder(CurrencyrateId.jsonEncoder).unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateStructure.scala new file mode 100644 index 0000000000..72836802d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/currencyrate/CurrencyrateStructure.scala @@ -0,0 +1,34 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package currencyrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.currency.CurrencyId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class CurrencyrateStructure[Row](val prefix: Option[String], val extract: Row => CurrencyrateRow, val merge: (Row, CurrencyrateRow) => Row) + extends Relation[CurrencyrateFields, CurrencyrateRow, Row] + with CurrencyrateFields[Row] { outer => + + override val currencyrateid = new IdField[CurrencyrateId, Row](prefix, "currencyrateid", None, Some("int4"))(x => extract(x).currencyrateid, (row, value) => merge(row, extract(row).copy(currencyrateid = value))) + override val currencyratedate = new Field[TypoLocalDateTime, Row](prefix, "currencyratedate", Some("text"), Some("timestamp"))(x => extract(x).currencyratedate, (row, value) => merge(row, extract(row).copy(currencyratedate = value))) + override val fromcurrencycode = new Field[CurrencyId, Row](prefix, "fromcurrencycode", None, Some("bpchar"))(x => extract(x).fromcurrencycode, (row, value) => merge(row, extract(row).copy(fromcurrencycode = value))) + override val tocurrencycode = new Field[CurrencyId, Row](prefix, "tocurrencycode", None, Some("bpchar"))(x => extract(x).tocurrencycode, (row, value) => merge(row, extract(row).copy(tocurrencycode = value))) + override val averagerate = new Field[BigDecimal, Row](prefix, "averagerate", None, Some("numeric"))(x => extract(x).averagerate, (row, value) => merge(row, extract(row).copy(averagerate = value))) + override val endofdayrate = new Field[BigDecimal, Row](prefix, "endofdayrate", None, Some("numeric"))(x => extract(x).endofdayrate, (row, value) => merge(row, extract(row).copy(endofdayrate = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](currencyrateid, currencyratedate, fromcurrencycode, tocurrencycode, averagerate, endofdayrate, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CurrencyrateRow, merge: (NewRow, CurrencyrateRow) => NewRow): CurrencyrateStructure[NewRow] = + new CurrencyrateStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerFields.scala new file mode 100644 index 0000000000..1710962884 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait CustomerFields[Row] { + val customerid: IdField[CustomerId, Row] + val personid: OptField[BusinessentityId, Row] + val storeid: OptField[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object CustomerFields extends CustomerStructure[CustomerRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerId.scala new file mode 100644 index 0000000000..ea91737a66 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +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 `sales.customer` */ +case class CustomerId(value: Int) extends AnyVal +object CustomerId { + implicit lazy val arraySetter: Setter[Array[CustomerId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CustomerId, Int] = Bijection[CustomerId, Int](_.value)(CustomerId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[CustomerId] = JdbcDecoder.intDecoder.map(CustomerId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CustomerId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[CustomerId] = JsonDecoder.int.map(CustomerId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CustomerId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[CustomerId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[CustomerId] = ParameterMetaData.instance[CustomerId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[CustomerId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepo.scala new file mode 100644 index 0000000000..e34d094b66 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait CustomerRepo { + def delete(customerid: CustomerId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[CustomerFields, CustomerRow] + def insert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, CustomerRow] + def insert(unsaved: CustomerRowUnsaved): ZIO[ZConnection, Throwable, CustomerRow] + def select: SelectBuilder[CustomerFields, CustomerRow] + def selectAll: ZStream[ZConnection, Throwable, CustomerRow] + def selectById(customerid: CustomerId): ZIO[ZConnection, Throwable, Option[CustomerRow]] + def selectByIds(customerids: Array[CustomerId]): ZStream[ZConnection, Throwable, CustomerRow] + def update(row: CustomerRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[CustomerFields, CustomerRow] + def upsert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, UpdateResult[CustomerRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoImpl.scala new file mode 100644 index 0000000000..c2ac98086b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoImpl.scala @@ -0,0 +1,116 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object CustomerRepoImpl extends CustomerRepo { + override def delete(customerid: CustomerId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.customer where "customerid" = ${Segment.paramSegment(customerid)(CustomerId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[CustomerFields, CustomerRow] = { + DeleteBuilder("sales.customer", CustomerFields) + } + override def insert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, CustomerRow] = { + sql"""insert into sales.customer("customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.customerid)(CustomerId.setter)}::int4, ${Segment.paramSegment(unsaved.personid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, ${Segment.paramSegment(unsaved.storeid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text + """.insertReturning(CustomerRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: CustomerRowUnsaved): ZIO[ZConnection, Throwable, CustomerRow] = { + val fs = List( + Some((sql""""personid"""", sql"${Segment.paramSegment(unsaved.personid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4")), + Some((sql""""storeid"""", sql"${Segment.paramSegment(unsaved.storeid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4")), + Some((sql""""territoryid"""", sql"${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4")), + unsaved.customerid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""customerid"""", sql"${Segment.paramSegment(value: CustomerId)(CustomerId.setter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.customer default values + returning "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.customer($names) values ($values) returning "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(CustomerRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[CustomerFields, CustomerRow] = { + SelectBuilderSql("sales.customer", CustomerFields, CustomerRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, CustomerRow] = { + sql"""select "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text from sales.customer""".query(CustomerRow.jdbcDecoder).selectStream + } + override def selectById(customerid: CustomerId): ZIO[ZConnection, Throwable, Option[CustomerRow]] = { + sql"""select "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text from sales.customer where "customerid" = ${Segment.paramSegment(customerid)(CustomerId.setter)}""".query(CustomerRow.jdbcDecoder).selectOne + } + override def selectByIds(customerids: Array[CustomerId]): ZStream[ZConnection, Throwable, CustomerRow] = { + sql"""select "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text from sales.customer where "customerid" = ANY(${Segment.paramSegment(customerids)(CustomerId.arraySetter)})""".query(CustomerRow.jdbcDecoder).selectStream + } + override def update(row: CustomerRow): ZIO[ZConnection, Throwable, Boolean] = { + val customerid = row.customerid + sql"""update sales.customer + set "personid" = ${Segment.paramSegment(row.personid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + "storeid" = ${Segment.paramSegment(row.storeid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + "territoryid" = ${Segment.paramSegment(row.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "customerid" = ${Segment.paramSegment(customerid)(CustomerId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[CustomerFields, CustomerRow] = { + UpdateBuilder("sales.customer", CustomerFields, CustomerRow.jdbcDecoder) + } + override def upsert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, UpdateResult[CustomerRow]] = { + sql"""insert into sales.customer("customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.customerid)(CustomerId.setter)}::int4, + ${Segment.paramSegment(unsaved.personid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + ${Segment.paramSegment(unsaved.storeid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("customerid") + do update set + "personid" = EXCLUDED."personid", + "storeid" = EXCLUDED."storeid", + "territoryid" = EXCLUDED."territoryid", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "customerid", "personid", "storeid", "territoryid", "rowguid", "modifieddate"::text""".insertReturning(CustomerRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoMock.scala new file mode 100644 index 0000000000..b7ac9aaf08 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class CustomerRepoMock(toRow: Function1[CustomerRowUnsaved, CustomerRow], + map: scala.collection.mutable.Map[CustomerId, CustomerRow] = scala.collection.mutable.Map.empty) extends CustomerRepo { + override def delete(customerid: CustomerId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(customerid).isDefined) + } + override def delete: DeleteBuilder[CustomerFields, CustomerRow] = { + DeleteBuilderMock(DeleteParams.empty, CustomerFields, map) + } + override def insert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, CustomerRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.customerid)) + sys.error(s"id ${unsaved.customerid} already exists") + else + map.put(unsaved.customerid, unsaved) + + unsaved + } + } + override def insert(unsaved: CustomerRowUnsaved): ZIO[ZConnection, Throwable, CustomerRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[CustomerFields, CustomerRow] = { + SelectBuilderMock(CustomerFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, CustomerRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(customerid: CustomerId): ZIO[ZConnection, Throwable, Option[CustomerRow]] = { + ZIO.succeed(map.get(customerid)) + } + override def selectByIds(customerids: Array[CustomerId]): ZStream[ZConnection, Throwable, CustomerRow] = { + ZStream.fromIterable(customerids.flatMap(map.get)) + } + override def update(row: CustomerRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.customerid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.customerid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[CustomerFields, CustomerRow] = { + UpdateBuilderMock(UpdateParams.empty, CustomerFields, map) + } + override def upsert(unsaved: CustomerRow): ZIO[ZConnection, Throwable, UpdateResult[CustomerRow]] = { + ZIO.succeed { + map.put(unsaved.customerid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRow.scala new file mode 100644 index 0000000000..a5e052f10a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRow.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class CustomerRow( + /** Primary key. */ + customerid: CustomerId, + /** Foreign key to Person.BusinessEntityID + Points to [[person.person.PersonRow.businessentityid]] */ + personid: Option[BusinessentityId], + /** Foreign key to Store.BusinessEntityID + Points to [[store.StoreRow.businessentityid]] */ + storeid: Option[BusinessentityId], + /** ID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object CustomerRow { + implicit lazy val jdbcDecoder: JdbcDecoder[CustomerRow] = new JdbcDecoder[CustomerRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, CustomerRow) = + columIndex + 5 -> + CustomerRow( + customerid = CustomerId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + personid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + storeid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[CustomerRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(CustomerId.jsonDecoder)) + val personid = jsonObj.get("personid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val storeid = jsonObj.get("storeid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (customerid.isRight && personid.isRight && storeid.isRight && territoryid.isRight && rowguid.isRight && modifieddate.isRight) + Right(CustomerRow(customerid = customerid.toOption.get, personid = personid.toOption.get, storeid = storeid.toOption.get, territoryid = territoryid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](customerid, personid, storeid, territoryid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CustomerRow] = new JsonEncoder[CustomerRow] { + override def unsafeEncode(a: CustomerRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""customerid":""") + CustomerId.jsonEncoder.unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""personid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""storeid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.storeid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRowUnsaved.scala new file mode 100644 index 0000000000..d1328b1ac7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerRowUnsaved.scala @@ -0,0 +1,93 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.customer` which has not been persisted yet */ +case class CustomerRowUnsaved( + /** Foreign key to Person.BusinessEntityID + Points to [[person.person.PersonRow.businessentityid]] */ + personid: Option[BusinessentityId], + /** Foreign key to Store.BusinessEntityID + Points to [[store.StoreRow.businessentityid]] */ + storeid: Option[BusinessentityId], + /** ID of the territory in which the customer is located. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Default: nextval('sales.customer_customerid_seq'::regclass) + Primary key. */ + customerid: Defaulted[CustomerId] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(customeridDefault: => CustomerId, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): CustomerRow = + CustomerRow( + personid = personid, + storeid = storeid, + territoryid = territoryid, + customerid = customerid match { + case Defaulted.UseDefault => customeridDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object CustomerRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[CustomerRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val personid = jsonObj.get("personid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val storeid = jsonObj.get("storeid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(Defaulted.jsonDecoder(CustomerId.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (personid.isRight && storeid.isRight && territoryid.isRight && customerid.isRight && rowguid.isRight && modifieddate.isRight) + Right(CustomerRowUnsaved(personid = personid.toOption.get, storeid = storeid.toOption.get, territoryid = territoryid.toOption.get, customerid = customerid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](personid, storeid, territoryid, customerid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[CustomerRowUnsaved] = new JsonEncoder[CustomerRowUnsaved] { + override def unsafeEncode(a: CustomerRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""personid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.personid, indent, out) + out.write(",") + out.write(""""storeid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.storeid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""customerid":""") + Defaulted.jsonEncoder(CustomerId.jsonEncoder).unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerStructure.scala new file mode 100644 index 0000000000..079a4d5365 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/customer/CustomerStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package customer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class CustomerStructure[Row](val prefix: Option[String], val extract: Row => CustomerRow, val merge: (Row, CustomerRow) => Row) + extends Relation[CustomerFields, CustomerRow, Row] + with CustomerFields[Row] { outer => + + override val customerid = new IdField[CustomerId, Row](prefix, "customerid", None, Some("int4"))(x => extract(x).customerid, (row, value) => merge(row, extract(row).copy(customerid = value))) + override val personid = new OptField[BusinessentityId, Row](prefix, "personid", None, Some("int4"))(x => extract(x).personid, (row, value) => merge(row, extract(row).copy(personid = value))) + override val storeid = new OptField[BusinessentityId, Row](prefix, "storeid", None, Some("int4"))(x => extract(x).storeid, (row, value) => merge(row, extract(row).copy(storeid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](customerid, personid, storeid, territoryid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => CustomerRow, merge: (NewRow, CustomerRow) => NewRow): CustomerStructure[NewRow] = + new CustomerStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardFields.scala new file mode 100644 index 0000000000..be1477987f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait PersoncreditcardFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val creditcardid: IdField[/* user-picked */ CustomCreditcardId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object PersoncreditcardFields extends PersoncreditcardStructure[PersoncreditcardRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardId.scala new file mode 100644 index 0000000000..a12d2bb352 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.personcreditcard` */ +case class PersoncreditcardId(businessentityid: BusinessentityId, creditcardid: /* user-picked */ CustomCreditcardId) +object PersoncreditcardId { + implicit lazy val jsonDecoder: JsonDecoder[PersoncreditcardId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + if (businessentityid.isRight && creditcardid.isRight) + Right(PersoncreditcardId(businessentityid = businessentityid.toOption.get, creditcardid = creditcardid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, creditcardid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersoncreditcardId] = new JsonEncoder[PersoncreditcardId] { + override def unsafeEncode(a: PersoncreditcardId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[PersoncreditcardId] = Ordering.by(x => (x.businessentityid, x.creditcardid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepo.scala new file mode 100644 index 0000000000..a38c38a257 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait PersoncreditcardRepo { + def delete(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[PersoncreditcardFields, PersoncreditcardRow] + def insert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, PersoncreditcardRow] + def insert(unsaved: PersoncreditcardRowUnsaved): ZIO[ZConnection, Throwable, PersoncreditcardRow] + def select: SelectBuilder[PersoncreditcardFields, PersoncreditcardRow] + def selectAll: ZStream[ZConnection, Throwable, PersoncreditcardRow] + def selectById(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Option[PersoncreditcardRow]] + def update(row: PersoncreditcardRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[PersoncreditcardFields, PersoncreditcardRow] + def upsert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[PersoncreditcardRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoImpl.scala new file mode 100644 index 0000000000..48277420d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoImpl.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object PersoncreditcardRepoImpl extends PersoncreditcardRepo { + override def delete(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.personcreditcard where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "creditcardid" = ${Segment.paramSegment(compositeId.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + DeleteBuilder("sales.personcreditcard", PersoncreditcardFields) + } + override def insert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, PersoncreditcardRow] = { + sql"""insert into sales.personcreditcard("businessentityid", "creditcardid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}::int4, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "creditcardid", "modifieddate"::text + """.insertReturning(PersoncreditcardRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: PersoncreditcardRowUnsaved): ZIO[ZConnection, Throwable, PersoncreditcardRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""creditcardid"""", sql"${Segment.paramSegment(unsaved.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}::int4")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.personcreditcard default values + returning "businessentityid", "creditcardid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.personcreditcard($names) values ($values) returning "businessentityid", "creditcardid", "modifieddate"::text""" + } + q.insertReturning(PersoncreditcardRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + SelectBuilderSql("sales.personcreditcard", PersoncreditcardFields, PersoncreditcardRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, PersoncreditcardRow] = { + sql"""select "businessentityid", "creditcardid", "modifieddate"::text from sales.personcreditcard""".query(PersoncreditcardRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Option[PersoncreditcardRow]] = { + sql"""select "businessentityid", "creditcardid", "modifieddate"::text from sales.personcreditcard where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "creditcardid" = ${Segment.paramSegment(compositeId.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".query(PersoncreditcardRow.jdbcDecoder).selectOne + } + override def update(row: PersoncreditcardRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.personcreditcard + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "creditcardid" = ${Segment.paramSegment(compositeId.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + UpdateBuilder("sales.personcreditcard", PersoncreditcardFields, PersoncreditcardRow.jdbcDecoder) + } + override def upsert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[PersoncreditcardRow]] = { + sql"""insert into sales.personcreditcard("businessentityid", "creditcardid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.creditcardid)(/* user-picked */ CustomCreditcardId.setter)}::int4, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "creditcardid") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "creditcardid", "modifieddate"::text""".insertReturning(PersoncreditcardRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoMock.scala new file mode 100644 index 0000000000..2eab392ed9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class PersoncreditcardRepoMock(toRow: Function1[PersoncreditcardRowUnsaved, PersoncreditcardRow], + map: scala.collection.mutable.Map[PersoncreditcardId, PersoncreditcardRow] = scala.collection.mutable.Map.empty) extends PersoncreditcardRepo { + override def delete(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + DeleteBuilderMock(DeleteParams.empty, PersoncreditcardFields, map) + } + override def insert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, PersoncreditcardRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: PersoncreditcardRowUnsaved): ZIO[ZConnection, Throwable, PersoncreditcardRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + SelectBuilderMock(PersoncreditcardFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, PersoncreditcardRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: PersoncreditcardId): ZIO[ZConnection, Throwable, Option[PersoncreditcardRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: PersoncreditcardRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[PersoncreditcardFields, PersoncreditcardRow] = { + UpdateBuilderMock(UpdateParams.empty, PersoncreditcardFields, map) + } + override def upsert(unsaved: PersoncreditcardRow): ZIO[ZConnection, Throwable, UpdateResult[PersoncreditcardRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRow.scala new file mode 100644 index 0000000000..92f7e33768 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class PersoncreditcardRow( + /** Business entity identification number. Foreign key to Person.BusinessEntityID. + Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Credit card identification number. Foreign key to CreditCard.CreditCardID. + Points to [[creditcard.CreditcardRow.creditcardid]] */ + creditcardid: /* user-picked */ CustomCreditcardId, + modifieddate: TypoLocalDateTime +){ + val compositeId: PersoncreditcardId = PersoncreditcardId(businessentityid, creditcardid) + } + +object PersoncreditcardRow { + implicit lazy val jdbcDecoder: JdbcDecoder[PersoncreditcardRow] = new JdbcDecoder[PersoncreditcardRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, PersoncreditcardRow) = + columIndex + 2 -> + PersoncreditcardRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + creditcardid = CustomCreditcardId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[PersoncreditcardRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && creditcardid.isRight && modifieddate.isRight) + Right(PersoncreditcardRow(businessentityid = businessentityid.toOption.get, creditcardid = creditcardid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, creditcardid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersoncreditcardRow] = new JsonEncoder[PersoncreditcardRow] { + override def unsafeEncode(a: PersoncreditcardRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRowUnsaved.scala new file mode 100644 index 0000000000..411855e0d3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardRowUnsaved.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.personcreditcard` which has not been persisted yet */ +case class PersoncreditcardRowUnsaved( + /** Business entity identification number. Foreign key to Person.BusinessEntityID. + Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Credit card identification number. Foreign key to CreditCard.CreditCardID. + Points to [[creditcard.CreditcardRow.creditcardid]] */ + creditcardid: /* user-picked */ CustomCreditcardId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): PersoncreditcardRow = + PersoncreditcardRow( + businessentityid = businessentityid, + creditcardid = creditcardid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object PersoncreditcardRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[PersoncreditcardRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").toRight("Missing field 'creditcardid'").flatMap(_.as(CustomCreditcardId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && creditcardid.isRight && modifieddate.isRight) + Right(PersoncreditcardRowUnsaved(businessentityid = businessentityid.toOption.get, creditcardid = creditcardid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, creditcardid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[PersoncreditcardRowUnsaved] = new JsonEncoder[PersoncreditcardRowUnsaved] { + override def unsafeEncode(a: PersoncreditcardRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + CustomCreditcardId.jsonEncoder.unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardStructure.scala new file mode 100644 index 0000000000..a2f37949c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/personcreditcard/PersoncreditcardStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package personcreditcard + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class PersoncreditcardStructure[Row](val prefix: Option[String], val extract: Row => PersoncreditcardRow, val merge: (Row, PersoncreditcardRow) => Row) + extends Relation[PersoncreditcardFields, PersoncreditcardRow, Row] + with PersoncreditcardFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val creditcardid = new IdField[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, Some("int4"))(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, creditcardid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => PersoncreditcardRow, merge: (NewRow, PersoncreditcardRow) => NewRow): PersoncreditcardStructure[NewRow] = + new PersoncreditcardStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailFields.scala new file mode 100644 index 0000000000..010bff8ba2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailFields.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait SalesorderdetailFields[Row] { + val salesorderid: IdField[SalesorderheaderId, Row] + val salesorderdetailid: IdField[Int, Row] + val carriertrackingnumber: OptField[/* max 25 chars */ String, Row] + val orderqty: Field[TypoShort, Row] + val productid: Field[ProductId, Row] + val specialofferid: Field[SpecialofferId, Row] + val unitprice: Field[BigDecimal, Row] + val unitpricediscount: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesorderdetailFields extends SalesorderdetailStructure[SalesorderdetailRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailId.scala new file mode 100644 index 0000000000..2d76ef8ae2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailId.scala @@ -0,0 +1,38 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.sales.salesorderheader.SalesorderheaderId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.salesorderdetail` */ +case class SalesorderdetailId(salesorderid: SalesorderheaderId, salesorderdetailid: Int) +object SalesorderdetailId { + implicit lazy val jsonDecoder: JsonDecoder[SalesorderdetailId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesorderdetailid = jsonObj.get("salesorderdetailid").toRight("Missing field 'salesorderdetailid'").flatMap(_.as(JsonDecoder.int)) + if (salesorderid.isRight && salesorderdetailid.isRight) + Right(SalesorderdetailId(salesorderid = salesorderid.toOption.get, salesorderdetailid = salesorderdetailid.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesorderdetailid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderdetailId] = new JsonEncoder[SalesorderdetailId] { + override def unsafeEncode(a: SalesorderdetailId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.salesorderdetailid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[SalesorderdetailId] = Ordering.by(x => (x.salesorderid, x.salesorderdetailid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepo.scala new file mode 100644 index 0000000000..04ab7fce2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesorderdetailRepo { + def delete(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesorderdetailFields, SalesorderdetailRow] + def insert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, SalesorderdetailRow] + def insert(unsaved: SalesorderdetailRowUnsaved): ZIO[ZConnection, Throwable, SalesorderdetailRow] + def select: SelectBuilder[SalesorderdetailFields, SalesorderdetailRow] + def selectAll: ZStream[ZConnection, Throwable, SalesorderdetailRow] + def selectById(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Option[SalesorderdetailRow]] + def update(row: SalesorderdetailRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesorderdetailFields, SalesorderdetailRow] + def upsert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderdetailRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoImpl.scala new file mode 100644 index 0000000000..bd799a8e18 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoImpl.scala @@ -0,0 +1,132 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesorderdetailRepoImpl extends SalesorderdetailRepo { + override def delete(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesorderdetail where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesorderdetailid" = ${Segment.paramSegment(compositeId.salesorderdetailid)(Setter.intSetter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + DeleteBuilder("sales.salesorderdetail", SalesorderdetailFields) + } + override def insert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, SalesorderdetailRow] = { + sql"""insert into sales.salesorderdetail("salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, ${Segment.paramSegment(unsaved.salesorderdetailid)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.carriertrackingnumber)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.orderqty)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, ${Segment.paramSegment(unsaved.unitprice)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.unitpricediscount)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text + """.insertReturning(SalesorderdetailRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesorderdetailRowUnsaved): ZIO[ZConnection, Throwable, SalesorderdetailRow] = { + val fs = List( + Some((sql""""salesorderid"""", sql"${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4")), + Some((sql""""carriertrackingnumber"""", sql"${Segment.paramSegment(unsaved.carriertrackingnumber)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""orderqty"""", sql"${Segment.paramSegment(unsaved.orderqty)(TypoShort.setter)}::int2")), + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + Some((sql""""specialofferid"""", sql"${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4")), + Some((sql""""unitprice"""", sql"${Segment.paramSegment(unsaved.unitprice)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.salesorderdetailid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salesorderdetailid"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.unitpricediscount match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""unitpricediscount"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesorderdetail default values + returning "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesorderdetail($names) values ($values) returning "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalesorderdetailRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + SelectBuilderSql("sales.salesorderdetail", SalesorderdetailFields, SalesorderdetailRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderdetailRow] = { + sql"""select "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text from sales.salesorderdetail""".query(SalesorderdetailRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Option[SalesorderdetailRow]] = { + sql"""select "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text from sales.salesorderdetail where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesorderdetailid" = ${Segment.paramSegment(compositeId.salesorderdetailid)(Setter.intSetter)}""".query(SalesorderdetailRow.jdbcDecoder).selectOne + } + override def update(row: SalesorderdetailRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.salesorderdetail + set "carriertrackingnumber" = ${Segment.paramSegment(row.carriertrackingnumber)(Setter.optionParamSetter(Setter.stringSetter))}, + "orderqty" = ${Segment.paramSegment(row.orderqty)(TypoShort.setter)}::int2, + "productid" = ${Segment.paramSegment(row.productid)(ProductId.setter)}::int4, + "specialofferid" = ${Segment.paramSegment(row.specialofferid)(SpecialofferId.setter)}::int4, + "unitprice" = ${Segment.paramSegment(row.unitprice)(Setter.bigDecimalScalaSetter)}::numeric, + "unitpricediscount" = ${Segment.paramSegment(row.unitpricediscount)(Setter.bigDecimalScalaSetter)}::numeric, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesorderdetailid" = ${Segment.paramSegment(compositeId.salesorderdetailid)(Setter.intSetter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + UpdateBuilder("sales.salesorderdetail", SalesorderdetailFields, SalesorderdetailRow.jdbcDecoder) + } + override def upsert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderdetailRow]] = { + sql"""insert into sales.salesorderdetail("salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, + ${Segment.paramSegment(unsaved.salesorderdetailid)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.carriertrackingnumber)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.orderqty)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, + ${Segment.paramSegment(unsaved.unitprice)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.unitpricediscount)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("salesorderid", "salesorderdetailid") + do update set + "carriertrackingnumber" = EXCLUDED."carriertrackingnumber", + "orderqty" = EXCLUDED."orderqty", + "productid" = EXCLUDED."productid", + "specialofferid" = EXCLUDED."specialofferid", + "unitprice" = EXCLUDED."unitprice", + "unitpricediscount" = EXCLUDED."unitpricediscount", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "salesorderid", "salesorderdetailid", "carriertrackingnumber", "orderqty", "productid", "specialofferid", "unitprice", "unitpricediscount", "rowguid", "modifieddate"::text""".insertReturning(SalesorderdetailRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoMock.scala new file mode 100644 index 0000000000..21ea74b02e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesorderdetailRepoMock(toRow: Function1[SalesorderdetailRowUnsaved, SalesorderdetailRow], + map: scala.collection.mutable.Map[SalesorderdetailId, SalesorderdetailRow] = scala.collection.mutable.Map.empty) extends SalesorderdetailRepo { + override def delete(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesorderdetailFields, map) + } + override def insert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, SalesorderdetailRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesorderdetailRowUnsaved): ZIO[ZConnection, Throwable, SalesorderdetailRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + SelectBuilderMock(SalesorderdetailFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderdetailRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: SalesorderdetailId): ZIO[ZConnection, Throwable, Option[SalesorderdetailRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: SalesorderdetailRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesorderdetailFields, SalesorderdetailRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesorderdetailFields, map) + } + override def upsert(unsaved: SalesorderdetailRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderdetailRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRow.scala new file mode 100644 index 0000000000..47412c6418 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRow.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesorderdetailRow( + /** Primary key. Foreign key to SalesOrderHeader.SalesOrderID. + Points to [[salesorderheader.SalesorderheaderRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Primary key. One incremental unique number per product sold. */ + salesorderdetailid: Int, + /** Shipment tracking number supplied by the shipper. */ + carriertrackingnumber: Option[/* max 25 chars */ String], + /** Quantity ordered per product. + Constraint CK_SalesOrderDetail_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: TypoShort, + /** Product sold to customer. Foreign key to Product.ProductID. + Points to [[specialofferproduct.SpecialofferproductRow.productid]] */ + productid: ProductId, + /** Promotional code. Foreign key to SpecialOffer.SpecialOfferID. + Points to [[specialofferproduct.SpecialofferproductRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Selling price of a single product. + Constraint CK_SalesOrderDetail_UnitPrice affecting columns "unitprice": ((unitprice >= 0.00)) */ + unitprice: BigDecimal, + /** Discount amount. + Constraint CK_SalesOrderDetail_UnitPriceDiscount affecting columns "unitpricediscount": ((unitpricediscount >= 0.00)) */ + unitpricediscount: BigDecimal, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: SalesorderdetailId = SalesorderdetailId(salesorderid, salesorderdetailid) + } + +object SalesorderdetailRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesorderdetailRow] = new JdbcDecoder[SalesorderdetailRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesorderdetailRow) = + columIndex + 9 -> + SalesorderdetailRow( + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesorderdetailid = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 1, rs)._2, + carriertrackingnumber = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + orderqty = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + unitprice = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + unitpricediscount = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesorderdetailRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesorderdetailid = jsonObj.get("salesorderdetailid").toRight("Missing field 'salesorderdetailid'").flatMap(_.as(JsonDecoder.int)) + val carriertrackingnumber = jsonObj.get("carriertrackingnumber").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val unitpricediscount = jsonObj.get("unitpricediscount").toRight("Missing field 'unitpricediscount'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salesorderid.isRight && salesorderdetailid.isRight && carriertrackingnumber.isRight && orderqty.isRight && productid.isRight && specialofferid.isRight && unitprice.isRight && unitpricediscount.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesorderdetailRow(salesorderid = salesorderid.toOption.get, salesorderdetailid = salesorderdetailid.toOption.get, carriertrackingnumber = carriertrackingnumber.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, specialofferid = specialofferid.toOption.get, unitprice = unitprice.toOption.get, unitpricediscount = unitpricediscount.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesorderdetailid, carriertrackingnumber, orderqty, productid, specialofferid, unitprice, unitpricediscount, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderdetailRow] = new JsonEncoder[SalesorderdetailRow] { + override def unsafeEncode(a: SalesorderdetailRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesorderdetailid":""") + JsonEncoder.int.unsafeEncode(a.salesorderdetailid, indent, out) + out.write(",") + out.write(""""carriertrackingnumber":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.carriertrackingnumber, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""unitpricediscount":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitpricediscount, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRowUnsaved.scala new file mode 100644 index 0000000000..101ef401ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailRowUnsaved.scala @@ -0,0 +1,130 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesorderdetail` which has not been persisted yet */ +case class SalesorderdetailRowUnsaved( + /** Primary key. Foreign key to SalesOrderHeader.SalesOrderID. + Points to [[salesorderheader.SalesorderheaderRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Shipment tracking number supplied by the shipper. */ + carriertrackingnumber: Option[/* max 25 chars */ String], + /** Quantity ordered per product. + Constraint CK_SalesOrderDetail_OrderQty affecting columns "orderqty": ((orderqty > 0)) */ + orderqty: TypoShort, + /** Product sold to customer. Foreign key to Product.ProductID. + Points to [[specialofferproduct.SpecialofferproductRow.productid]] */ + productid: ProductId, + /** Promotional code. Foreign key to SpecialOffer.SpecialOfferID. + Points to [[specialofferproduct.SpecialofferproductRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Selling price of a single product. + Constraint CK_SalesOrderDetail_UnitPrice affecting columns "unitprice": ((unitprice >= 0.00)) */ + unitprice: BigDecimal, + /** Default: nextval('sales.salesorderdetail_salesorderdetailid_seq'::regclass) + Primary key. One incremental unique number per product sold. */ + salesorderdetailid: Defaulted[Int] = Defaulted.UseDefault, + /** Default: 0.0 + Discount amount. + Constraint CK_SalesOrderDetail_UnitPriceDiscount affecting columns "unitpricediscount": ((unitpricediscount >= 0.00)) */ + unitpricediscount: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(salesorderdetailidDefault: => Int, unitpricediscountDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalesorderdetailRow = + SalesorderdetailRow( + salesorderid = salesorderid, + carriertrackingnumber = carriertrackingnumber, + orderqty = orderqty, + productid = productid, + specialofferid = specialofferid, + unitprice = unitprice, + salesorderdetailid = salesorderdetailid match { + case Defaulted.UseDefault => salesorderdetailidDefault + case Defaulted.Provided(value) => value + }, + unitpricediscount = unitpricediscount match { + case Defaulted.UseDefault => unitpricediscountDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesorderdetailRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesorderdetailRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val carriertrackingnumber = jsonObj.get("carriertrackingnumber").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val orderqty = jsonObj.get("orderqty").toRight("Missing field 'orderqty'").flatMap(_.as(TypoShort.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val unitprice = jsonObj.get("unitprice").toRight("Missing field 'unitprice'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val salesorderdetailid = jsonObj.get("salesorderdetailid").toRight("Missing field 'salesorderdetailid'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val unitpricediscount = jsonObj.get("unitpricediscount").toRight("Missing field 'unitpricediscount'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (salesorderid.isRight && carriertrackingnumber.isRight && orderqty.isRight && productid.isRight && specialofferid.isRight && unitprice.isRight && salesorderdetailid.isRight && unitpricediscount.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesorderdetailRowUnsaved(salesorderid = salesorderid.toOption.get, carriertrackingnumber = carriertrackingnumber.toOption.get, orderqty = orderqty.toOption.get, productid = productid.toOption.get, specialofferid = specialofferid.toOption.get, unitprice = unitprice.toOption.get, salesorderdetailid = salesorderdetailid.toOption.get, unitpricediscount = unitpricediscount.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, carriertrackingnumber, orderqty, productid, specialofferid, unitprice, salesorderdetailid, unitpricediscount, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderdetailRowUnsaved] = new JsonEncoder[SalesorderdetailRowUnsaved] { + override def unsafeEncode(a: SalesorderdetailRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""carriertrackingnumber":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.carriertrackingnumber, indent, out) + out.write(",") + out.write(""""orderqty":""") + TypoShort.jsonEncoder.unsafeEncode(a.orderqty, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""unitprice":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.unitprice, indent, out) + out.write(",") + out.write(""""salesorderdetailid":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.salesorderdetailid, indent, out) + out.write(",") + out.write(""""unitpricediscount":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.unitpricediscount, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailStructure.scala new file mode 100644 index 0000000000..c078344b97 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderdetail/SalesorderdetailStructure.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderdetail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SalesorderdetailStructure[Row](val prefix: Option[String], val extract: Row => SalesorderdetailRow, val merge: (Row, SalesorderdetailRow) => Row) + extends Relation[SalesorderdetailFields, SalesorderdetailRow, Row] + with SalesorderdetailFields[Row] { outer => + + override val salesorderid = new IdField[SalesorderheaderId, Row](prefix, "salesorderid", None, Some("int4"))(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val salesorderdetailid = new IdField[Int, Row](prefix, "salesorderdetailid", None, Some("int4"))(x => extract(x).salesorderdetailid, (row, value) => merge(row, extract(row).copy(salesorderdetailid = value))) + override val carriertrackingnumber = new OptField[/* max 25 chars */ String, Row](prefix, "carriertrackingnumber", None, None)(x => extract(x).carriertrackingnumber, (row, value) => merge(row, extract(row).copy(carriertrackingnumber = value))) + override val orderqty = new Field[TypoShort, Row](prefix, "orderqty", None, Some("int2"))(x => extract(x).orderqty, (row, value) => merge(row, extract(row).copy(orderqty = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val specialofferid = new Field[SpecialofferId, Row](prefix, "specialofferid", None, Some("int4"))(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val unitprice = new Field[BigDecimal, Row](prefix, "unitprice", None, Some("numeric"))(x => extract(x).unitprice, (row, value) => merge(row, extract(row).copy(unitprice = value))) + override val unitpricediscount = new Field[BigDecimal, Row](prefix, "unitpricediscount", None, Some("numeric"))(x => extract(x).unitpricediscount, (row, value) => merge(row, extract(row).copy(unitpricediscount = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salesorderid, salesorderdetailid, carriertrackingnumber, orderqty, productid, specialofferid, unitprice, unitpricediscount, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesorderdetailRow, merge: (NewRow, SalesorderdetailRow) => NewRow): SalesorderdetailStructure[NewRow] = + new SalesorderdetailStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderFields.scala new file mode 100644 index 0000000000..f1460d2735 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderFields.scala @@ -0,0 +1,55 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait SalesorderheaderFields[Row] { + val salesorderid: IdField[SalesorderheaderId, Row] + val revisionnumber: Field[TypoShort, Row] + val orderdate: Field[TypoLocalDateTime, Row] + val duedate: Field[TypoLocalDateTime, Row] + val shipdate: OptField[TypoLocalDateTime, Row] + val status: Field[TypoShort, Row] + val onlineorderflag: Field[Flag, Row] + val purchaseordernumber: OptField[OrderNumber, Row] + val accountnumber: OptField[AccountNumber, Row] + val customerid: Field[CustomerId, Row] + val salespersonid: OptField[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val billtoaddressid: Field[AddressId, Row] + val shiptoaddressid: Field[AddressId, Row] + val shipmethodid: Field[ShipmethodId, Row] + val creditcardid: OptField[/* user-picked */ CustomCreditcardId, Row] + val creditcardapprovalcode: OptField[/* max 15 chars */ String, Row] + val currencyrateid: OptField[CurrencyrateId, Row] + val subtotal: Field[BigDecimal, Row] + val taxamt: Field[BigDecimal, Row] + val freight: Field[BigDecimal, Row] + val totaldue: OptField[BigDecimal, Row] + val comment: OptField[/* max 128 chars */ String, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesorderheaderFields extends SalesorderheaderStructure[SalesorderheaderRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderId.scala new file mode 100644 index 0000000000..302b0ced8f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +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 `sales.salesorderheader` */ +case class SalesorderheaderId(value: Int) extends AnyVal +object SalesorderheaderId { + implicit lazy val arraySetter: Setter[Array[SalesorderheaderId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[SalesorderheaderId, Int] = Bijection[SalesorderheaderId, Int](_.value)(SalesorderheaderId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[SalesorderheaderId] = JdbcDecoder.intDecoder.map(SalesorderheaderId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[SalesorderheaderId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheaderId] = JsonDecoder.int.map(SalesorderheaderId.apply) + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheaderId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[SalesorderheaderId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[SalesorderheaderId] = ParameterMetaData.instance[SalesorderheaderId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[SalesorderheaderId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepo.scala new file mode 100644 index 0000000000..97656ccf8a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesorderheaderRepo { + def delete(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesorderheaderFields, SalesorderheaderRow] + def insert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, SalesorderheaderRow] + def insert(unsaved: SalesorderheaderRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheaderRow] + def select: SelectBuilder[SalesorderheaderFields, SalesorderheaderRow] + def selectAll: ZStream[ZConnection, Throwable, SalesorderheaderRow] + def selectById(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Option[SalesorderheaderRow]] + def selectByIds(salesorderids: Array[SalesorderheaderId]): ZStream[ZConnection, Throwable, SalesorderheaderRow] + def update(row: SalesorderheaderRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesorderheaderFields, SalesorderheaderRow] + def upsert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheaderRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoImpl.scala new file mode 100644 index 0000000000..0ca851161d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoImpl.scala @@ -0,0 +1,222 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesorderheaderRepoImpl extends SalesorderheaderRepo { + override def delete(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesorderheader where "salesorderid" = ${Segment.paramSegment(salesorderid)(SalesorderheaderId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + DeleteBuilder("sales.salesorderheader", SalesorderheaderFields) + } + override def insert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, SalesorderheaderRow] = { + sql"""insert into sales.salesorderheader("salesorderid", "revisionnumber", "orderdate", "duedate", "shipdate", "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, ${Segment.paramSegment(unsaved.revisionnumber)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.orderdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.onlineorderflag)(Flag.setter)}::bool, ${Segment.paramSegment(unsaved.purchaseordernumber)(Setter.optionParamSetter(OrderNumber.setter))}::varchar, ${Segment.paramSegment(unsaved.accountnumber)(Setter.optionParamSetter(AccountNumber.setter))}::varchar, ${Segment.paramSegment(unsaved.customerid)(CustomerId.setter)}::int4, ${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, ${Segment.paramSegment(unsaved.billtoaddressid)(AddressId.setter)}::int4, ${Segment.paramSegment(unsaved.shiptoaddressid)(AddressId.setter)}::int4, ${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, ${Segment.paramSegment(unsaved.creditcardid)(Setter.optionParamSetter(CustomCreditcardId.setter))}::int4, ${Segment.paramSegment(unsaved.creditcardapprovalcode)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.currencyrateid)(Setter.optionParamSetter(CurrencyrateId.setter))}::int4, ${Segment.paramSegment(unsaved.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.freight)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.totaldue)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.comment)(Setter.optionParamSetter(Setter.stringSetter))}, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text + """.insertReturning(SalesorderheaderRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesorderheaderRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheaderRow] = { + val fs = List( + Some((sql""""duedate"""", sql"${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""shipdate"""", sql"${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + Some((sql""""purchaseordernumber"""", sql"${Segment.paramSegment(unsaved.purchaseordernumber)(Setter.optionParamSetter(OrderNumber.setter))}::varchar")), + Some((sql""""accountnumber"""", sql"${Segment.paramSegment(unsaved.accountnumber)(Setter.optionParamSetter(AccountNumber.setter))}::varchar")), + Some((sql""""customerid"""", sql"${Segment.paramSegment(unsaved.customerid)(CustomerId.setter)}::int4")), + Some((sql""""salespersonid"""", sql"${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4")), + Some((sql""""territoryid"""", sql"${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4")), + Some((sql""""billtoaddressid"""", sql"${Segment.paramSegment(unsaved.billtoaddressid)(AddressId.setter)}::int4")), + Some((sql""""shiptoaddressid"""", sql"${Segment.paramSegment(unsaved.shiptoaddressid)(AddressId.setter)}::int4")), + Some((sql""""shipmethodid"""", sql"${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4")), + Some((sql""""creditcardid"""", sql"${Segment.paramSegment(unsaved.creditcardid)(Setter.optionParamSetter(CustomCreditcardId.setter))}::int4")), + Some((sql""""creditcardapprovalcode"""", sql"${Segment.paramSegment(unsaved.creditcardapprovalcode)(Setter.optionParamSetter(Setter.stringSetter))}")), + Some((sql""""currencyrateid"""", sql"${Segment.paramSegment(unsaved.currencyrateid)(Setter.optionParamSetter(CurrencyrateId.setter))}::int4")), + Some((sql""""totaldue"""", sql"${Segment.paramSegment(unsaved.totaldue)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + Some((sql""""comment"""", sql"${Segment.paramSegment(unsaved.comment)(Setter.optionParamSetter(Setter.stringSetter))}")), + unsaved.salesorderid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salesorderid"""", sql"${Segment.paramSegment(value: SalesorderheaderId)(SalesorderheaderId.setter)}::int4")) + }, + unsaved.revisionnumber match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""revisionnumber"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.orderdate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""orderdate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.status match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""status"""", sql"${Segment.paramSegment(value: TypoShort)(TypoShort.setter)}::int2")) + }, + unsaved.onlineorderflag match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""onlineorderflag"""", sql"${Segment.paramSegment(value: Flag)(Flag.setter)}::bool")) + }, + unsaved.subtotal match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""subtotal"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.taxamt match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""taxamt"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.freight match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""freight"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesorderheader default values + returning "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesorderheader($names) values ($values) returning "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalesorderheaderRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + SelectBuilderSql("sales.salesorderheader", SalesorderheaderFields, SalesorderheaderRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderheaderRow] = { + sql"""select "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text from sales.salesorderheader""".query(SalesorderheaderRow.jdbcDecoder).selectStream + } + override def selectById(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Option[SalesorderheaderRow]] = { + sql"""select "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text from sales.salesorderheader where "salesorderid" = ${Segment.paramSegment(salesorderid)(SalesorderheaderId.setter)}""".query(SalesorderheaderRow.jdbcDecoder).selectOne + } + override def selectByIds(salesorderids: Array[SalesorderheaderId]): ZStream[ZConnection, Throwable, SalesorderheaderRow] = { + sql"""select "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text from sales.salesorderheader where "salesorderid" = ANY(${Segment.paramSegment(salesorderids)(SalesorderheaderId.arraySetter)})""".query(SalesorderheaderRow.jdbcDecoder).selectStream + } + override def update(row: SalesorderheaderRow): ZIO[ZConnection, Throwable, Boolean] = { + val salesorderid = row.salesorderid + sql"""update sales.salesorderheader + set "revisionnumber" = ${Segment.paramSegment(row.revisionnumber)(TypoShort.setter)}::int2, + "orderdate" = ${Segment.paramSegment(row.orderdate)(TypoLocalDateTime.setter)}::timestamp, + "duedate" = ${Segment.paramSegment(row.duedate)(TypoLocalDateTime.setter)}::timestamp, + "shipdate" = ${Segment.paramSegment(row.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "status" = ${Segment.paramSegment(row.status)(TypoShort.setter)}::int2, + "onlineorderflag" = ${Segment.paramSegment(row.onlineorderflag)(Flag.setter)}::bool, + "purchaseordernumber" = ${Segment.paramSegment(row.purchaseordernumber)(Setter.optionParamSetter(OrderNumber.setter))}::varchar, + "accountnumber" = ${Segment.paramSegment(row.accountnumber)(Setter.optionParamSetter(AccountNumber.setter))}::varchar, + "customerid" = ${Segment.paramSegment(row.customerid)(CustomerId.setter)}::int4, + "salespersonid" = ${Segment.paramSegment(row.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + "territoryid" = ${Segment.paramSegment(row.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + "billtoaddressid" = ${Segment.paramSegment(row.billtoaddressid)(AddressId.setter)}::int4, + "shiptoaddressid" = ${Segment.paramSegment(row.shiptoaddressid)(AddressId.setter)}::int4, + "shipmethodid" = ${Segment.paramSegment(row.shipmethodid)(ShipmethodId.setter)}::int4, + "creditcardid" = ${Segment.paramSegment(row.creditcardid)(Setter.optionParamSetter(CustomCreditcardId.setter))}::int4, + "creditcardapprovalcode" = ${Segment.paramSegment(row.creditcardapprovalcode)(Setter.optionParamSetter(Setter.stringSetter))}, + "currencyrateid" = ${Segment.paramSegment(row.currencyrateid)(Setter.optionParamSetter(CurrencyrateId.setter))}::int4, + "subtotal" = ${Segment.paramSegment(row.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, + "taxamt" = ${Segment.paramSegment(row.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, + "freight" = ${Segment.paramSegment(row.freight)(Setter.bigDecimalScalaSetter)}::numeric, + "totaldue" = ${Segment.paramSegment(row.totaldue)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "comment" = ${Segment.paramSegment(row.comment)(Setter.optionParamSetter(Setter.stringSetter))}, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "salesorderid" = ${Segment.paramSegment(salesorderid)(SalesorderheaderId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + UpdateBuilder("sales.salesorderheader", SalesorderheaderFields, SalesorderheaderRow.jdbcDecoder) + } + override def upsert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheaderRow]] = { + sql"""insert into sales.salesorderheader("salesorderid", "revisionnumber", "orderdate", "duedate", "shipdate", "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, + ${Segment.paramSegment(unsaved.revisionnumber)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.orderdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.duedate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.shipdate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.status)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.onlineorderflag)(Flag.setter)}::bool, + ${Segment.paramSegment(unsaved.purchaseordernumber)(Setter.optionParamSetter(OrderNumber.setter))}::varchar, + ${Segment.paramSegment(unsaved.accountnumber)(Setter.optionParamSetter(AccountNumber.setter))}::varchar, + ${Segment.paramSegment(unsaved.customerid)(CustomerId.setter)}::int4, + ${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + ${Segment.paramSegment(unsaved.billtoaddressid)(AddressId.setter)}::int4, + ${Segment.paramSegment(unsaved.shiptoaddressid)(AddressId.setter)}::int4, + ${Segment.paramSegment(unsaved.shipmethodid)(ShipmethodId.setter)}::int4, + ${Segment.paramSegment(unsaved.creditcardid)(Setter.optionParamSetter(CustomCreditcardId.setter))}::int4, + ${Segment.paramSegment(unsaved.creditcardapprovalcode)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.currencyrateid)(Setter.optionParamSetter(CurrencyrateId.setter))}::int4, + ${Segment.paramSegment(unsaved.subtotal)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.taxamt)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.freight)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.totaldue)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.comment)(Setter.optionParamSetter(Setter.stringSetter))}, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("salesorderid") + do update set + "revisionnumber" = EXCLUDED."revisionnumber", + "orderdate" = EXCLUDED."orderdate", + "duedate" = EXCLUDED."duedate", + "shipdate" = EXCLUDED."shipdate", + "status" = EXCLUDED."status", + "onlineorderflag" = EXCLUDED."onlineorderflag", + "purchaseordernumber" = EXCLUDED."purchaseordernumber", + "accountnumber" = EXCLUDED."accountnumber", + "customerid" = EXCLUDED."customerid", + "salespersonid" = EXCLUDED."salespersonid", + "territoryid" = EXCLUDED."territoryid", + "billtoaddressid" = EXCLUDED."billtoaddressid", + "shiptoaddressid" = EXCLUDED."shiptoaddressid", + "shipmethodid" = EXCLUDED."shipmethodid", + "creditcardid" = EXCLUDED."creditcardid", + "creditcardapprovalcode" = EXCLUDED."creditcardapprovalcode", + "currencyrateid" = EXCLUDED."currencyrateid", + "subtotal" = EXCLUDED."subtotal", + "taxamt" = EXCLUDED."taxamt", + "freight" = EXCLUDED."freight", + "totaldue" = EXCLUDED."totaldue", + "comment" = EXCLUDED."comment", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "salesorderid", "revisionnumber", "orderdate"::text, "duedate"::text, "shipdate"::text, "status", "onlineorderflag", "purchaseordernumber", "accountnumber", "customerid", "salespersonid", "territoryid", "billtoaddressid", "shiptoaddressid", "shipmethodid", "creditcardid", "creditcardapprovalcode", "currencyrateid", "subtotal", "taxamt", "freight", "totaldue", "comment", "rowguid", "modifieddate"::text""".insertReturning(SalesorderheaderRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoMock.scala new file mode 100644 index 0000000000..9c3ec24215 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesorderheaderRepoMock(toRow: Function1[SalesorderheaderRowUnsaved, SalesorderheaderRow], + map: scala.collection.mutable.Map[SalesorderheaderId, SalesorderheaderRow] = scala.collection.mutable.Map.empty) extends SalesorderheaderRepo { + override def delete(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(salesorderid).isDefined) + } + override def delete: DeleteBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesorderheaderFields, map) + } + override def insert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, SalesorderheaderRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.salesorderid)) + sys.error(s"id ${unsaved.salesorderid} already exists") + else + map.put(unsaved.salesorderid, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesorderheaderRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheaderRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + SelectBuilderMock(SalesorderheaderFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderheaderRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(salesorderid: SalesorderheaderId): ZIO[ZConnection, Throwable, Option[SalesorderheaderRow]] = { + ZIO.succeed(map.get(salesorderid)) + } + override def selectByIds(salesorderids: Array[SalesorderheaderId]): ZStream[ZConnection, Throwable, SalesorderheaderRow] = { + ZStream.fromIterable(salesorderids.flatMap(map.get)) + } + override def update(row: SalesorderheaderRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.salesorderid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.salesorderid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesorderheaderFields, SalesorderheaderRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesorderheaderFields, map) + } + override def upsert(unsaved: SalesorderheaderRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheaderRow]] = { + ZIO.succeed { + map.put(unsaved.salesorderid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRow.scala new file mode 100644 index 0000000000..70f5961083 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRow.scala @@ -0,0 +1,239 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesorderheaderRow( + /** Primary key. */ + salesorderid: SalesorderheaderId, + /** Incremental number to track changes to the sales order over time. */ + revisionnumber: TypoShort, + /** Dates the sales order was created. + Constraint CK_SalesOrderHeader_DueDate affecting columns "duedate", "orderdate": ((duedate >= orderdate)) + Constraint CK_SalesOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + orderdate: TypoLocalDateTime, + /** Date the order is due to the customer. + Constraint CK_SalesOrderHeader_DueDate affecting columns "duedate", "orderdate": ((duedate >= orderdate)) */ + duedate: TypoLocalDateTime, + /** Date the order was shipped to the customer. + Constraint CK_SalesOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + shipdate: Option[TypoLocalDateTime], + /** Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled + Constraint CK_SalesOrderHeader_Status affecting columns "status": (((status >= 0) AND (status <= 8))) */ + status: TypoShort, + /** 0 = Order placed by sales person. 1 = Order placed online by customer. */ + onlineorderflag: Flag, + /** Customer purchase order number reference. */ + purchaseordernumber: Option[OrderNumber], + /** Financial accounting number reference. */ + accountnumber: Option[AccountNumber], + /** Customer identification number. Foreign key to Customer.BusinessEntityID. + Points to [[customer.CustomerRow.customerid]] */ + customerid: CustomerId, + /** Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + salespersonid: Option[BusinessentityId], + /** Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Customer billing address. Foreign key to Address.AddressID. + Points to [[person.address.AddressRow.addressid]] */ + billtoaddressid: AddressId, + /** Customer shipping address. Foreign key to Address.AddressID. + Points to [[person.address.AddressRow.addressid]] */ + shiptoaddressid: AddressId, + /** Shipping method. Foreign key to ShipMethod.ShipMethodID. + Points to [[purchasing.shipmethod.ShipmethodRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Credit card identification number. Foreign key to CreditCard.CreditCardID. + Points to [[creditcard.CreditcardRow.creditcardid]] */ + creditcardid: Option[/* user-picked */ CustomCreditcardId], + /** Approval code provided by the credit card company. */ + creditcardapprovalcode: Option[/* max 15 chars */ String], + /** Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID. + Points to [[currencyrate.CurrencyrateRow.currencyrateid]] */ + currencyrateid: Option[CurrencyrateId], + /** Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID. + Constraint CK_SalesOrderHeader_SubTotal affecting columns "subtotal": ((subtotal >= 0.00)) */ + subtotal: BigDecimal, + /** Tax amount. + Constraint CK_SalesOrderHeader_TaxAmt affecting columns "taxamt": ((taxamt >= 0.00)) */ + taxamt: BigDecimal, + /** Shipping cost. + Constraint CK_SalesOrderHeader_Freight affecting columns "freight": ((freight >= 0.00)) */ + freight: BigDecimal, + /** Total due from customer. Computed as Subtotal + TaxAmt + Freight. */ + totaldue: Option[BigDecimal], + /** Sales representative comments. */ + comment: Option[/* max 128 chars */ String], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object SalesorderheaderRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesorderheaderRow] = new JdbcDecoder[SalesorderheaderRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesorderheaderRow) = + columIndex + 24 -> + SalesorderheaderRow( + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + revisionnumber = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + orderdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + duedate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + shipdate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 4, rs)._2, + status = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + onlineorderflag = Flag.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + purchaseordernumber = JdbcDecoder.optionDecoder(OrderNumber.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + accountnumber = JdbcDecoder.optionDecoder(AccountNumber.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + customerid = CustomerId.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + salespersonid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 10, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 11, rs)._2, + billtoaddressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 12, rs)._2, + shiptoaddressid = AddressId.jdbcDecoder.unsafeDecode(columIndex + 13, rs)._2, + shipmethodid = ShipmethodId.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + creditcardid = JdbcDecoder.optionDecoder(CustomCreditcardId.jdbcDecoder).unsafeDecode(columIndex + 15, rs)._2, + creditcardapprovalcode = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 16, rs)._2, + currencyrateid = JdbcDecoder.optionDecoder(CurrencyrateId.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + subtotal = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 18, rs)._2, + taxamt = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 19, rs)._2, + freight = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 20, rs)._2, + totaldue = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 21, rs)._2, + comment = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 22, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 23, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 24, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheaderRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(TypoShort.jsonDecoder)) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(TypoShort.jsonDecoder)) + val onlineorderflag = jsonObj.get("onlineorderflag").toRight("Missing field 'onlineorderflag'").flatMap(_.as(Flag.jsonDecoder)) + val purchaseordernumber = jsonObj.get("purchaseordernumber").fold[Either[String, Option[OrderNumber]]](Right(None))(_.as(JsonDecoder.option(OrderNumber.jsonDecoder))) + val accountnumber = jsonObj.get("accountnumber").fold[Either[String, Option[AccountNumber]]](Right(None))(_.as(JsonDecoder.option(AccountNumber.jsonDecoder))) + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(CustomerId.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val billtoaddressid = jsonObj.get("billtoaddressid").toRight("Missing field 'billtoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shiptoaddressid = jsonObj.get("shiptoaddressid").toRight("Missing field 'shiptoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").fold[Either[String, Option[CustomCreditcardId]]](Right(None))(_.as(JsonDecoder.option(CustomCreditcardId.jsonDecoder))) + val creditcardapprovalcode = jsonObj.get("creditcardapprovalcode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val currencyrateid = jsonObj.get("currencyrateid").fold[Either[String, Option[CurrencyrateId]]](Right(None))(_.as(JsonDecoder.option(CurrencyrateId.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val totaldue = jsonObj.get("totaldue").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val comment = jsonObj.get("comment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salesorderid.isRight && revisionnumber.isRight && orderdate.isRight && duedate.isRight && shipdate.isRight && status.isRight && onlineorderflag.isRight && purchaseordernumber.isRight && accountnumber.isRight && customerid.isRight && salespersonid.isRight && territoryid.isRight && billtoaddressid.isRight && shiptoaddressid.isRight && shipmethodid.isRight && creditcardid.isRight && creditcardapprovalcode.isRight && currencyrateid.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && totaldue.isRight && comment.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesorderheaderRow(salesorderid = salesorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, orderdate = orderdate.toOption.get, duedate = duedate.toOption.get, shipdate = shipdate.toOption.get, status = status.toOption.get, onlineorderflag = onlineorderflag.toOption.get, purchaseordernumber = purchaseordernumber.toOption.get, accountnumber = accountnumber.toOption.get, customerid = customerid.toOption.get, salespersonid = salespersonid.toOption.get, territoryid = territoryid.toOption.get, billtoaddressid = billtoaddressid.toOption.get, shiptoaddressid = shiptoaddressid.toOption.get, shipmethodid = shipmethodid.toOption.get, creditcardid = creditcardid.toOption.get, creditcardapprovalcode = creditcardapprovalcode.toOption.get, currencyrateid = currencyrateid.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, totaldue = totaldue.toOption.get, comment = comment.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, revisionnumber, orderdate, duedate, shipdate, status, onlineorderflag, purchaseordernumber, accountnumber, customerid, salespersonid, territoryid, billtoaddressid, shiptoaddressid, shipmethodid, creditcardid, creditcardapprovalcode, currencyrateid, subtotal, taxamt, freight, totaldue, comment, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheaderRow] = new JsonEncoder[SalesorderheaderRow] { + override def unsafeEncode(a: SalesorderheaderRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + TypoShort.jsonEncoder.unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""orderdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""status":""") + TypoShort.jsonEncoder.unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""onlineorderflag":""") + Flag.jsonEncoder.unsafeEncode(a.onlineorderflag, indent, out) + out.write(",") + out.write(""""purchaseordernumber":""") + JsonEncoder.option(OrderNumber.jsonEncoder).unsafeEncode(a.purchaseordernumber, indent, out) + out.write(",") + out.write(""""accountnumber":""") + JsonEncoder.option(AccountNumber.jsonEncoder).unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""customerid":""") + CustomerId.jsonEncoder.unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""billtoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.billtoaddressid, indent, out) + out.write(",") + out.write(""""shiptoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.shiptoaddressid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + JsonEncoder.option(CustomCreditcardId.jsonEncoder).unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""creditcardapprovalcode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.creditcardapprovalcode, indent, out) + out.write(",") + out.write(""""currencyrateid":""") + JsonEncoder.option(CurrencyrateId.jsonEncoder).unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""subtotal":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""totaldue":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.totaldue, indent, out) + out.write(",") + out.write(""""comment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comment, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRowUnsaved.scala new file mode 100644 index 0000000000..71995efc3c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderRowUnsaved.scala @@ -0,0 +1,276 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesorderheader` which has not been persisted yet */ +case class SalesorderheaderRowUnsaved( + /** Date the order is due to the customer. + Constraint CK_SalesOrderHeader_DueDate affecting columns "duedate", "orderdate": ((duedate >= orderdate)) */ + duedate: TypoLocalDateTime, + /** Date the order was shipped to the customer. + Constraint CK_SalesOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + shipdate: Option[TypoLocalDateTime], + /** Customer purchase order number reference. */ + purchaseordernumber: Option[OrderNumber], + /** Financial accounting number reference. */ + accountnumber: Option[AccountNumber], + /** Customer identification number. Foreign key to Customer.BusinessEntityID. + Points to [[customer.CustomerRow.customerid]] */ + customerid: CustomerId, + /** Sales person who created the sales order. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + salespersonid: Option[BusinessentityId], + /** Territory in which the sale was made. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Customer billing address. Foreign key to Address.AddressID. + Points to [[person.address.AddressRow.addressid]] */ + billtoaddressid: AddressId, + /** Customer shipping address. Foreign key to Address.AddressID. + Points to [[person.address.AddressRow.addressid]] */ + shiptoaddressid: AddressId, + /** Shipping method. Foreign key to ShipMethod.ShipMethodID. + Points to [[purchasing.shipmethod.ShipmethodRow.shipmethodid]] */ + shipmethodid: ShipmethodId, + /** Credit card identification number. Foreign key to CreditCard.CreditCardID. + Points to [[creditcard.CreditcardRow.creditcardid]] */ + creditcardid: Option[/* user-picked */ CustomCreditcardId], + /** Approval code provided by the credit card company. */ + creditcardapprovalcode: Option[/* max 15 chars */ String], + /** Currency exchange rate used. Foreign key to CurrencyRate.CurrencyRateID. + Points to [[currencyrate.CurrencyrateRow.currencyrateid]] */ + currencyrateid: Option[CurrencyrateId], + /** Total due from customer. Computed as Subtotal + TaxAmt + Freight. */ + totaldue: Option[BigDecimal], + /** Sales representative comments. */ + comment: Option[/* max 128 chars */ String], + /** Default: nextval('sales.salesorderheader_salesorderid_seq'::regclass) + Primary key. */ + salesorderid: Defaulted[SalesorderheaderId] = Defaulted.UseDefault, + /** Default: 0 + Incremental number to track changes to the sales order over time. */ + revisionnumber: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: now() + Dates the sales order was created. + Constraint CK_SalesOrderHeader_DueDate affecting columns "duedate", "orderdate": ((duedate >= orderdate)) + Constraint CK_SalesOrderHeader_ShipDate affecting columns "orderdate", "shipdate": (((shipdate >= orderdate) OR (shipdate IS NULL))) */ + orderdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: 1 + Order current status. 1 = In process; 2 = Approved; 3 = Backordered; 4 = Rejected; 5 = Shipped; 6 = Cancelled + Constraint CK_SalesOrderHeader_Status affecting columns "status": (((status >= 0) AND (status <= 8))) */ + status: Defaulted[TypoShort] = Defaulted.UseDefault, + /** Default: true + 0 = Order placed by sales person. 1 = Order placed online by customer. */ + onlineorderflag: Defaulted[Flag] = Defaulted.UseDefault, + /** Default: 0.00 + Sales subtotal. Computed as SUM(SalesOrderDetail.LineTotal)for the appropriate SalesOrderID. + Constraint CK_SalesOrderHeader_SubTotal affecting columns "subtotal": ((subtotal >= 0.00)) */ + subtotal: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Tax amount. + Constraint CK_SalesOrderHeader_TaxAmt affecting columns "taxamt": ((taxamt >= 0.00)) */ + taxamt: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Shipping cost. + Constraint CK_SalesOrderHeader_Freight affecting columns "freight": ((freight >= 0.00)) */ + freight: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(salesorderidDefault: => SalesorderheaderId, revisionnumberDefault: => TypoShort, orderdateDefault: => TypoLocalDateTime, statusDefault: => TypoShort, onlineorderflagDefault: => Flag, subtotalDefault: => BigDecimal, taxamtDefault: => BigDecimal, freightDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalesorderheaderRow = + SalesorderheaderRow( + duedate = duedate, + shipdate = shipdate, + purchaseordernumber = purchaseordernumber, + accountnumber = accountnumber, + customerid = customerid, + salespersonid = salespersonid, + territoryid = territoryid, + billtoaddressid = billtoaddressid, + shiptoaddressid = shiptoaddressid, + shipmethodid = shipmethodid, + creditcardid = creditcardid, + creditcardapprovalcode = creditcardapprovalcode, + currencyrateid = currencyrateid, + totaldue = totaldue, + comment = comment, + salesorderid = salesorderid match { + case Defaulted.UseDefault => salesorderidDefault + case Defaulted.Provided(value) => value + }, + revisionnumber = revisionnumber match { + case Defaulted.UseDefault => revisionnumberDefault + case Defaulted.Provided(value) => value + }, + orderdate = orderdate match { + case Defaulted.UseDefault => orderdateDefault + case Defaulted.Provided(value) => value + }, + status = status match { + case Defaulted.UseDefault => statusDefault + case Defaulted.Provided(value) => value + }, + onlineorderflag = onlineorderflag match { + case Defaulted.UseDefault => onlineorderflagDefault + case Defaulted.Provided(value) => value + }, + subtotal = subtotal match { + case Defaulted.UseDefault => subtotalDefault + case Defaulted.Provided(value) => value + }, + taxamt = taxamt match { + case Defaulted.UseDefault => taxamtDefault + case Defaulted.Provided(value) => value + }, + freight = freight match { + case Defaulted.UseDefault => freightDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesorderheaderRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheaderRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val duedate = jsonObj.get("duedate").toRight("Missing field 'duedate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val shipdate = jsonObj.get("shipdate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val purchaseordernumber = jsonObj.get("purchaseordernumber").fold[Either[String, Option[OrderNumber]]](Right(None))(_.as(JsonDecoder.option(OrderNumber.jsonDecoder))) + val accountnumber = jsonObj.get("accountnumber").fold[Either[String, Option[AccountNumber]]](Right(None))(_.as(JsonDecoder.option(AccountNumber.jsonDecoder))) + val customerid = jsonObj.get("customerid").toRight("Missing field 'customerid'").flatMap(_.as(CustomerId.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val billtoaddressid = jsonObj.get("billtoaddressid").toRight("Missing field 'billtoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shiptoaddressid = jsonObj.get("shiptoaddressid").toRight("Missing field 'shiptoaddressid'").flatMap(_.as(AddressId.jsonDecoder)) + val shipmethodid = jsonObj.get("shipmethodid").toRight("Missing field 'shipmethodid'").flatMap(_.as(ShipmethodId.jsonDecoder)) + val creditcardid = jsonObj.get("creditcardid").fold[Either[String, Option[CustomCreditcardId]]](Right(None))(_.as(JsonDecoder.option(CustomCreditcardId.jsonDecoder))) + val creditcardapprovalcode = jsonObj.get("creditcardapprovalcode").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val currencyrateid = jsonObj.get("currencyrateid").fold[Either[String, Option[CurrencyrateId]]](Right(None))(_.as(JsonDecoder.option(CurrencyrateId.jsonDecoder))) + val totaldue = jsonObj.get("totaldue").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val comment = jsonObj.get("comment").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(Defaulted.jsonDecoder(SalesorderheaderId.jsonDecoder))) + val revisionnumber = jsonObj.get("revisionnumber").toRight("Missing field 'revisionnumber'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val orderdate = jsonObj.get("orderdate").toRight("Missing field 'orderdate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val status = jsonObj.get("status").toRight("Missing field 'status'").flatMap(_.as(Defaulted.jsonDecoder(TypoShort.jsonDecoder))) + val onlineorderflag = jsonObj.get("onlineorderflag").toRight("Missing field 'onlineorderflag'").flatMap(_.as(Defaulted.jsonDecoder(Flag.jsonDecoder))) + val subtotal = jsonObj.get("subtotal").toRight("Missing field 'subtotal'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val taxamt = jsonObj.get("taxamt").toRight("Missing field 'taxamt'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val freight = jsonObj.get("freight").toRight("Missing field 'freight'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (duedate.isRight && shipdate.isRight && purchaseordernumber.isRight && accountnumber.isRight && customerid.isRight && salespersonid.isRight && territoryid.isRight && billtoaddressid.isRight && shiptoaddressid.isRight && shipmethodid.isRight && creditcardid.isRight && creditcardapprovalcode.isRight && currencyrateid.isRight && totaldue.isRight && comment.isRight && salesorderid.isRight && revisionnumber.isRight && orderdate.isRight && status.isRight && onlineorderflag.isRight && subtotal.isRight && taxamt.isRight && freight.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesorderheaderRowUnsaved(duedate = duedate.toOption.get, shipdate = shipdate.toOption.get, purchaseordernumber = purchaseordernumber.toOption.get, accountnumber = accountnumber.toOption.get, customerid = customerid.toOption.get, salespersonid = salespersonid.toOption.get, territoryid = territoryid.toOption.get, billtoaddressid = billtoaddressid.toOption.get, shiptoaddressid = shiptoaddressid.toOption.get, shipmethodid = shipmethodid.toOption.get, creditcardid = creditcardid.toOption.get, creditcardapprovalcode = creditcardapprovalcode.toOption.get, currencyrateid = currencyrateid.toOption.get, totaldue = totaldue.toOption.get, comment = comment.toOption.get, salesorderid = salesorderid.toOption.get, revisionnumber = revisionnumber.toOption.get, orderdate = orderdate.toOption.get, status = status.toOption.get, onlineorderflag = onlineorderflag.toOption.get, subtotal = subtotal.toOption.get, taxamt = taxamt.toOption.get, freight = freight.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](duedate, shipdate, purchaseordernumber, accountnumber, customerid, salespersonid, territoryid, billtoaddressid, shiptoaddressid, shipmethodid, creditcardid, creditcardapprovalcode, currencyrateid, totaldue, comment, salesorderid, revisionnumber, orderdate, status, onlineorderflag, subtotal, taxamt, freight, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheaderRowUnsaved] = new JsonEncoder[SalesorderheaderRowUnsaved] { + override def unsafeEncode(a: SalesorderheaderRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""duedate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.duedate, indent, out) + out.write(",") + out.write(""""shipdate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.shipdate, indent, out) + out.write(",") + out.write(""""purchaseordernumber":""") + JsonEncoder.option(OrderNumber.jsonEncoder).unsafeEncode(a.purchaseordernumber, indent, out) + out.write(",") + out.write(""""accountnumber":""") + JsonEncoder.option(AccountNumber.jsonEncoder).unsafeEncode(a.accountnumber, indent, out) + out.write(",") + out.write(""""customerid":""") + CustomerId.jsonEncoder.unsafeEncode(a.customerid, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""billtoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.billtoaddressid, indent, out) + out.write(",") + out.write(""""shiptoaddressid":""") + AddressId.jsonEncoder.unsafeEncode(a.shiptoaddressid, indent, out) + out.write(",") + out.write(""""shipmethodid":""") + ShipmethodId.jsonEncoder.unsafeEncode(a.shipmethodid, indent, out) + out.write(",") + out.write(""""creditcardid":""") + JsonEncoder.option(CustomCreditcardId.jsonEncoder).unsafeEncode(a.creditcardid, indent, out) + out.write(",") + out.write(""""creditcardapprovalcode":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.creditcardapprovalcode, indent, out) + out.write(",") + out.write(""""currencyrateid":""") + JsonEncoder.option(CurrencyrateId.jsonEncoder).unsafeEncode(a.currencyrateid, indent, out) + out.write(",") + out.write(""""totaldue":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.totaldue, indent, out) + out.write(",") + out.write(""""comment":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.comment, indent, out) + out.write(",") + out.write(""""salesorderid":""") + Defaulted.jsonEncoder(SalesorderheaderId.jsonEncoder).unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""revisionnumber":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.revisionnumber, indent, out) + out.write(",") + out.write(""""orderdate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.orderdate, indent, out) + out.write(",") + out.write(""""status":""") + Defaulted.jsonEncoder(TypoShort.jsonEncoder).unsafeEncode(a.status, indent, out) + out.write(",") + out.write(""""onlineorderflag":""") + Defaulted.jsonEncoder(Flag.jsonEncoder).unsafeEncode(a.onlineorderflag, indent, out) + out.write(",") + out.write(""""subtotal":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.subtotal, indent, out) + out.write(",") + out.write(""""taxamt":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.taxamt, indent, out) + out.write(",") + out.write(""""freight":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.freight, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderStructure.scala new file mode 100644 index 0000000000..8e071107e4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheader/SalesorderheaderStructure.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheader + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.address.AddressId +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.OrderNumber +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.userdefined.CustomCreditcardId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SalesorderheaderStructure[Row](val prefix: Option[String], val extract: Row => SalesorderheaderRow, val merge: (Row, SalesorderheaderRow) => Row) + extends Relation[SalesorderheaderFields, SalesorderheaderRow, Row] + with SalesorderheaderFields[Row] { outer => + + override val salesorderid = new IdField[SalesorderheaderId, Row](prefix, "salesorderid", None, Some("int4"))(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val revisionnumber = new Field[TypoShort, Row](prefix, "revisionnumber", None, Some("int2"))(x => extract(x).revisionnumber, (row, value) => merge(row, extract(row).copy(revisionnumber = value))) + override val orderdate = new Field[TypoLocalDateTime, Row](prefix, "orderdate", Some("text"), Some("timestamp"))(x => extract(x).orderdate, (row, value) => merge(row, extract(row).copy(orderdate = value))) + override val duedate = new Field[TypoLocalDateTime, Row](prefix, "duedate", Some("text"), Some("timestamp"))(x => extract(x).duedate, (row, value) => merge(row, extract(row).copy(duedate = value))) + override val shipdate = new OptField[TypoLocalDateTime, Row](prefix, "shipdate", Some("text"), Some("timestamp"))(x => extract(x).shipdate, (row, value) => merge(row, extract(row).copy(shipdate = value))) + override val status = new Field[TypoShort, Row](prefix, "status", None, Some("int2"))(x => extract(x).status, (row, value) => merge(row, extract(row).copy(status = value))) + override val onlineorderflag = new Field[Flag, Row](prefix, "onlineorderflag", None, Some("bool"))(x => extract(x).onlineorderflag, (row, value) => merge(row, extract(row).copy(onlineorderflag = value))) + override val purchaseordernumber = new OptField[OrderNumber, Row](prefix, "purchaseordernumber", None, Some("varchar"))(x => extract(x).purchaseordernumber, (row, value) => merge(row, extract(row).copy(purchaseordernumber = value))) + override val accountnumber = new OptField[AccountNumber, Row](prefix, "accountnumber", None, Some("varchar"))(x => extract(x).accountnumber, (row, value) => merge(row, extract(row).copy(accountnumber = value))) + override val customerid = new Field[CustomerId, Row](prefix, "customerid", None, Some("int4"))(x => extract(x).customerid, (row, value) => merge(row, extract(row).copy(customerid = value))) + override val salespersonid = new OptField[BusinessentityId, Row](prefix, "salespersonid", None, Some("int4"))(x => extract(x).salespersonid, (row, value) => merge(row, extract(row).copy(salespersonid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val billtoaddressid = new Field[AddressId, Row](prefix, "billtoaddressid", None, Some("int4"))(x => extract(x).billtoaddressid, (row, value) => merge(row, extract(row).copy(billtoaddressid = value))) + override val shiptoaddressid = new Field[AddressId, Row](prefix, "shiptoaddressid", None, Some("int4"))(x => extract(x).shiptoaddressid, (row, value) => merge(row, extract(row).copy(shiptoaddressid = value))) + override val shipmethodid = new Field[ShipmethodId, Row](prefix, "shipmethodid", None, Some("int4"))(x => extract(x).shipmethodid, (row, value) => merge(row, extract(row).copy(shipmethodid = value))) + override val creditcardid = new OptField[/* user-picked */ CustomCreditcardId, Row](prefix, "creditcardid", None, Some("int4"))(x => extract(x).creditcardid, (row, value) => merge(row, extract(row).copy(creditcardid = value))) + override val creditcardapprovalcode = new OptField[/* max 15 chars */ String, Row](prefix, "creditcardapprovalcode", None, None)(x => extract(x).creditcardapprovalcode, (row, value) => merge(row, extract(row).copy(creditcardapprovalcode = value))) + override val currencyrateid = new OptField[CurrencyrateId, Row](prefix, "currencyrateid", None, Some("int4"))(x => extract(x).currencyrateid, (row, value) => merge(row, extract(row).copy(currencyrateid = value))) + override val subtotal = new Field[BigDecimal, Row](prefix, "subtotal", None, Some("numeric"))(x => extract(x).subtotal, (row, value) => merge(row, extract(row).copy(subtotal = value))) + override val taxamt = new Field[BigDecimal, Row](prefix, "taxamt", None, Some("numeric"))(x => extract(x).taxamt, (row, value) => merge(row, extract(row).copy(taxamt = value))) + override val freight = new Field[BigDecimal, Row](prefix, "freight", None, Some("numeric"))(x => extract(x).freight, (row, value) => merge(row, extract(row).copy(freight = value))) + override val totaldue = new OptField[BigDecimal, Row](prefix, "totaldue", None, Some("numeric"))(x => extract(x).totaldue, (row, value) => merge(row, extract(row).copy(totaldue = value))) + override val comment = new OptField[/* max 128 chars */ String, Row](prefix, "comment", None, None)(x => extract(x).comment, (row, value) => merge(row, extract(row).copy(comment = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salesorderid, revisionnumber, orderdate, duedate, shipdate, status, onlineorderflag, purchaseordernumber, accountnumber, customerid, salespersonid, territoryid, billtoaddressid, shiptoaddressid, shipmethodid, creditcardid, creditcardapprovalcode, currencyrateid, subtotal, taxamt, freight, totaldue, comment, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesorderheaderRow, merge: (NewRow, SalesorderheaderRow) => NewRow): SalesorderheaderStructure[NewRow] = + new SalesorderheaderStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonFields.scala new file mode 100644 index 0000000000..cb32083660 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SalesorderheadersalesreasonFields[Row] { + val salesorderid: IdField[SalesorderheaderId, Row] + val salesreasonid: IdField[SalesreasonId, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesorderheadersalesreasonFields extends SalesorderheadersalesreasonStructure[SalesorderheadersalesreasonRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonId.scala new file mode 100644 index 0000000000..7e4b8f42c1 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.salesorderheadersalesreason` */ +case class SalesorderheadersalesreasonId(salesorderid: SalesorderheaderId, salesreasonid: SalesreasonId) +object SalesorderheadersalesreasonId { + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheadersalesreasonId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + if (salesorderid.isRight && salesreasonid.isRight) + Right(SalesorderheadersalesreasonId(salesorderid = salesorderid.toOption.get, salesreasonid = salesreasonid.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesreasonid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheadersalesreasonId] = new JsonEncoder[SalesorderheadersalesreasonId] { + override def unsafeEncode(a: SalesorderheadersalesreasonId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[SalesorderheadersalesreasonId] = Ordering.by(x => (x.salesorderid, x.salesreasonid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepo.scala new file mode 100644 index 0000000000..ae1490a55b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesorderheadersalesreasonRepo { + def delete(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] + def insert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] + def insert(unsaved: SalesorderheadersalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] + def select: SelectBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] + def selectAll: ZStream[ZConnection, Throwable, SalesorderheadersalesreasonRow] + def selectById(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Option[SalesorderheadersalesreasonRow]] + def update(row: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] + def upsert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheadersalesreasonRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoImpl.scala new file mode 100644 index 0000000000..cc575963e5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoImpl.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesorderheadersalesreasonRepoImpl extends SalesorderheadersalesreasonRepo { + override def delete(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesorderheadersalesreason where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesreasonid" = ${Segment.paramSegment(compositeId.salesreasonid)(SalesreasonId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + DeleteBuilder("sales.salesorderheadersalesreason", SalesorderheadersalesreasonFields) + } + override def insert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + sql"""insert into sales.salesorderheadersalesreason("salesorderid", "salesreasonid", "modifieddate") + values (${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, ${Segment.paramSegment(unsaved.salesreasonid)(SalesreasonId.setter)}::int4, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "salesorderid", "salesreasonid", "modifieddate"::text + """.insertReturning(SalesorderheadersalesreasonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesorderheadersalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + val fs = List( + Some((sql""""salesorderid"""", sql"${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4")), + Some((sql""""salesreasonid"""", sql"${Segment.paramSegment(unsaved.salesreasonid)(SalesreasonId.setter)}::int4")), + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesorderheadersalesreason default values + returning "salesorderid", "salesreasonid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesorderheadersalesreason($names) values ($values) returning "salesorderid", "salesreasonid", "modifieddate"::text""" + } + q.insertReturning(SalesorderheadersalesreasonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + SelectBuilderSql("sales.salesorderheadersalesreason", SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + sql"""select "salesorderid", "salesreasonid", "modifieddate"::text from sales.salesorderheadersalesreason""".query(SalesorderheadersalesreasonRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Option[SalesorderheadersalesreasonRow]] = { + sql"""select "salesorderid", "salesreasonid", "modifieddate"::text from sales.salesorderheadersalesreason where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesreasonid" = ${Segment.paramSegment(compositeId.salesreasonid)(SalesreasonId.setter)}""".query(SalesorderheadersalesreasonRow.jdbcDecoder).selectOne + } + override def update(row: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.salesorderheadersalesreason + set "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "salesorderid" = ${Segment.paramSegment(compositeId.salesorderid)(SalesorderheaderId.setter)} AND "salesreasonid" = ${Segment.paramSegment(compositeId.salesreasonid)(SalesreasonId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + UpdateBuilder("sales.salesorderheadersalesreason", SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow.jdbcDecoder) + } + override def upsert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheadersalesreasonRow]] = { + sql"""insert into sales.salesorderheadersalesreason("salesorderid", "salesreasonid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.salesorderid)(SalesorderheaderId.setter)}::int4, + ${Segment.paramSegment(unsaved.salesreasonid)(SalesreasonId.setter)}::int4, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("salesorderid", "salesreasonid") + do update set + "modifieddate" = EXCLUDED."modifieddate" + returning "salesorderid", "salesreasonid", "modifieddate"::text""".insertReturning(SalesorderheadersalesreasonRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoMock.scala new file mode 100644 index 0000000000..3e035ea5be --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesorderheadersalesreasonRepoMock(toRow: Function1[SalesorderheadersalesreasonRowUnsaved, SalesorderheadersalesreasonRow], + map: scala.collection.mutable.Map[SalesorderheadersalesreasonId, SalesorderheadersalesreasonRow] = scala.collection.mutable.Map.empty) extends SalesorderheadersalesreasonRepo { + override def delete(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesorderheadersalesreasonFields, map) + } + override def insert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesorderheadersalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + SelectBuilderMock(SalesorderheadersalesreasonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesorderheadersalesreasonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: SalesorderheadersalesreasonId): ZIO[ZConnection, Throwable, Option[SalesorderheadersalesreasonRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesorderheadersalesreasonFields, map) + } + override def upsert(unsaved: SalesorderheadersalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesorderheadersalesreasonRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRow.scala new file mode 100644 index 0000000000..0ff9bb2018 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRow.scala @@ -0,0 +1,64 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesorderheadersalesreasonRow( + /** Primary key. Foreign key to SalesOrderHeader.SalesOrderID. + Points to [[salesorderheader.SalesorderheaderRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Primary key. Foreign key to SalesReason.SalesReasonID. + Points to [[salesreason.SalesreasonRow.salesreasonid]] */ + salesreasonid: SalesreasonId, + modifieddate: TypoLocalDateTime +){ + val compositeId: SalesorderheadersalesreasonId = SalesorderheadersalesreasonId(salesorderid, salesreasonid) + } + +object SalesorderheadersalesreasonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesorderheadersalesreasonRow] = new JdbcDecoder[SalesorderheadersalesreasonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesorderheadersalesreasonRow) = + columIndex + 2 -> + SalesorderheadersalesreasonRow( + salesorderid = SalesorderheaderId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + salesreasonid = SalesreasonId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheadersalesreasonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salesorderid.isRight && salesreasonid.isRight && modifieddate.isRight) + Right(SalesorderheadersalesreasonRow(salesorderid = salesorderid.toOption.get, salesreasonid = salesreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheadersalesreasonRow] = new JsonEncoder[SalesorderheadersalesreasonRow] { + override def unsafeEncode(a: SalesorderheadersalesreasonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRowUnsaved.scala new file mode 100644 index 0000000000..efbcf521ea --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonRowUnsaved.scala @@ -0,0 +1,63 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesorderheadersalesreason` which has not been persisted yet */ +case class SalesorderheadersalesreasonRowUnsaved( + /** Primary key. Foreign key to SalesOrderHeader.SalesOrderID. + Points to [[salesorderheader.SalesorderheaderRow.salesorderid]] */ + salesorderid: SalesorderheaderId, + /** Primary key. Foreign key to SalesReason.SalesReasonID. + Points to [[salesreason.SalesreasonRow.salesreasonid]] */ + salesreasonid: SalesreasonId, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(modifieddateDefault: => TypoLocalDateTime): SalesorderheadersalesreasonRow = + SalesorderheadersalesreasonRow( + salesorderid = salesorderid, + salesreasonid = salesreasonid, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesorderheadersalesreasonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesorderheadersalesreasonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesorderid = jsonObj.get("salesorderid").toRight("Missing field 'salesorderid'").flatMap(_.as(SalesorderheaderId.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (salesorderid.isRight && salesreasonid.isRight && modifieddate.isRight) + Right(SalesorderheadersalesreasonRowUnsaved(salesorderid = salesorderid.toOption.get, salesreasonid = salesreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesorderid, salesreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesorderheadersalesreasonRowUnsaved] = new JsonEncoder[SalesorderheadersalesreasonRowUnsaved] { + override def unsafeEncode(a: SalesorderheadersalesreasonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesorderid":""") + SalesorderheaderId.jsonEncoder.unsafeEncode(a.salesorderid, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonStructure.scala new file mode 100644 index 0000000000..d463ac686b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesorderheadersalesreason/SalesorderheadersalesreasonStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesorderheadersalesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesreason.SalesreasonId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SalesorderheadersalesreasonStructure[Row](val prefix: Option[String], val extract: Row => SalesorderheadersalesreasonRow, val merge: (Row, SalesorderheadersalesreasonRow) => Row) + extends Relation[SalesorderheadersalesreasonFields, SalesorderheadersalesreasonRow, Row] + with SalesorderheadersalesreasonFields[Row] { outer => + + override val salesorderid = new IdField[SalesorderheaderId, Row](prefix, "salesorderid", None, Some("int4"))(x => extract(x).salesorderid, (row, value) => merge(row, extract(row).copy(salesorderid = value))) + override val salesreasonid = new IdField[SalesreasonId, Row](prefix, "salesreasonid", None, Some("int4"))(x => extract(x).salesreasonid, (row, value) => merge(row, extract(row).copy(salesreasonid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salesorderid, salesreasonid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesorderheadersalesreasonRow, merge: (NewRow, SalesorderheadersalesreasonRow) => NewRow): SalesorderheadersalesreasonStructure[NewRow] = + new SalesorderheadersalesreasonStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonFields.scala new file mode 100644 index 0000000000..8d4bf9c6e2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait SalespersonFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val territoryid: OptField[SalesterritoryId, Row] + val salesquota: OptField[BigDecimal, Row] + val bonus: Field[BigDecimal, Row] + val commissionpct: Field[BigDecimal, Row] + val salesytd: Field[BigDecimal, Row] + val saleslastyear: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalespersonFields extends SalespersonStructure[SalespersonRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepo.scala new file mode 100644 index 0000000000..c2cc8f460d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalespersonRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalespersonFields, SalespersonRow] + def insert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, SalespersonRow] + def insert(unsaved: SalespersonRowUnsaved): ZIO[ZConnection, Throwable, SalespersonRow] + def select: SelectBuilder[SalespersonFields, SalespersonRow] + def selectAll: ZStream[ZConnection, Throwable, SalespersonRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[SalespersonRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, SalespersonRow] + def update(row: SalespersonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalespersonFields, SalespersonRow] + def upsert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoImpl.scala new file mode 100644 index 0000000000..c931e7294c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoImpl.scala @@ -0,0 +1,137 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalespersonRepoImpl extends SalespersonRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesperson where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalespersonFields, SalespersonRow] = { + DeleteBuilder("sales.salesperson", SalespersonFields) + } + override def insert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, SalespersonRow] = { + sql"""insert into sales.salesperson("businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, ${Segment.paramSegment(unsaved.salesquota)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, ${Segment.paramSegment(unsaved.bonus)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.commissionpct)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text + """.insertReturning(SalespersonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalespersonRowUnsaved): ZIO[ZConnection, Throwable, SalespersonRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""territoryid"""", sql"${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4")), + Some((sql""""salesquota"""", sql"${Segment.paramSegment(unsaved.salesquota)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric")), + unsaved.bonus match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""bonus"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.commissionpct match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""commissionpct"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.salesytd match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salesytd"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.saleslastyear match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""saleslastyear"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesperson default values + returning "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesperson($names) values ($values) returning "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalespersonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalespersonFields, SalespersonRow] = { + SelectBuilderSql("sales.salesperson", SalespersonFields, SalespersonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalespersonRow] = { + sql"""select "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text from sales.salesperson""".query(SalespersonRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[SalespersonRow]] = { + sql"""select "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text from sales.salesperson where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(SalespersonRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, SalespersonRow] = { + sql"""select "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text from sales.salesperson where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(SalespersonRow.jdbcDecoder).selectStream + } + override def update(row: SalespersonRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update sales.salesperson + set "territoryid" = ${Segment.paramSegment(row.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + "salesquota" = ${Segment.paramSegment(row.salesquota)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + "bonus" = ${Segment.paramSegment(row.bonus)(Setter.bigDecimalScalaSetter)}::numeric, + "commissionpct" = ${Segment.paramSegment(row.commissionpct)(Setter.bigDecimalScalaSetter)}::numeric, + "salesytd" = ${Segment.paramSegment(row.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, + "saleslastyear" = ${Segment.paramSegment(row.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalespersonFields, SalespersonRow] = { + UpdateBuilder("sales.salesperson", SalespersonFields, SalespersonRow.jdbcDecoder) + } + override def upsert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonRow]] = { + sql"""insert into sales.salesperson("businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.territoryid)(Setter.optionParamSetter(SalesterritoryId.setter))}::int4, + ${Segment.paramSegment(unsaved.salesquota)(Setter.optionParamSetter(Setter.bigDecimalScalaSetter))}::numeric, + ${Segment.paramSegment(unsaved.bonus)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.commissionpct)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "territoryid" = EXCLUDED."territoryid", + "salesquota" = EXCLUDED."salesquota", + "bonus" = EXCLUDED."bonus", + "commissionpct" = EXCLUDED."commissionpct", + "salesytd" = EXCLUDED."salesytd", + "saleslastyear" = EXCLUDED."saleslastyear", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "territoryid", "salesquota", "bonus", "commissionpct", "salesytd", "saleslastyear", "rowguid", "modifieddate"::text""".insertReturning(SalespersonRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoMock.scala new file mode 100644 index 0000000000..541c6e90a3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalespersonRepoMock(toRow: Function1[SalespersonRowUnsaved, SalespersonRow], + map: scala.collection.mutable.Map[BusinessentityId, SalespersonRow] = scala.collection.mutable.Map.empty) extends SalespersonRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[SalespersonFields, SalespersonRow] = { + DeleteBuilderMock(DeleteParams.empty, SalespersonFields, map) + } + override def insert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, SalespersonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: SalespersonRowUnsaved): ZIO[ZConnection, Throwable, SalespersonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalespersonFields, SalespersonRow] = { + SelectBuilderMock(SalespersonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalespersonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[SalespersonRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, SalespersonRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: SalespersonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalespersonFields, SalespersonRow] = { + UpdateBuilderMock(UpdateParams.empty, SalespersonFields, map) + } + override def upsert(unsaved: SalespersonRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRow.scala new file mode 100644 index 0000000000..46962a8ba4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRow.scala @@ -0,0 +1,109 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalespersonRow( + /** Primary key for SalesPerson records. Foreign key to Employee.BusinessEntityID + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Territory currently assigned to. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Projected yearly sales. + Constraint CK_SalesPerson_SalesQuota affecting columns "salesquota": ((salesquota > 0.00)) */ + salesquota: Option[BigDecimal], + /** Bonus due if quota is met. + Constraint CK_SalesPerson_Bonus affecting columns "bonus": ((bonus >= 0.00)) */ + bonus: BigDecimal, + /** Commision percent received per sale. + Constraint CK_SalesPerson_CommissionPct affecting columns "commissionpct": ((commissionpct >= 0.00)) */ + commissionpct: BigDecimal, + /** Sales total year to date. + Constraint CK_SalesPerson_SalesYTD affecting columns "salesytd": ((salesytd >= 0.00)) */ + salesytd: BigDecimal, + /** Sales total of previous year. + Constraint CK_SalesPerson_SalesLastYear affecting columns "saleslastyear": ((saleslastyear >= 0.00)) */ + saleslastyear: BigDecimal, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object SalespersonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalespersonRow] = new JdbcDecoder[SalespersonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalespersonRow) = + columIndex + 8 -> + SalespersonRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + territoryid = JdbcDecoder.optionDecoder(SalesterritoryId.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + salesquota = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 2, rs)._2, + bonus = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + commissionpct = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + salesytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + saleslastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 7, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalespersonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val salesquota = jsonObj.get("salesquota").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val bonus = jsonObj.get("bonus").toRight("Missing field 'bonus'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val commissionpct = jsonObj.get("commissionpct").toRight("Missing field 'commissionpct'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && territoryid.isRight && salesquota.isRight && bonus.isRight && commissionpct.isRight && salesytd.isRight && saleslastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalespersonRow(businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, salesquota = salesquota.toOption.get, bonus = bonus.toOption.get, commissionpct = commissionpct.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, territoryid, salesquota, bonus, commissionpct, salesytd, saleslastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalespersonRow] = new JsonEncoder[SalespersonRow] { + override def unsafeEncode(a: SalespersonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""bonus":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.bonus, indent, out) + out.write(",") + out.write(""""commissionpct":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.commissionpct, indent, out) + out.write(",") + out.write(""""salesytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRowUnsaved.scala new file mode 100644 index 0000000000..970dee703e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonRowUnsaved.scala @@ -0,0 +1,130 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesperson` which has not been persisted yet */ +case class SalespersonRowUnsaved( + /** Primary key for SalesPerson records. Foreign key to Employee.BusinessEntityID + Points to [[humanresources.employee.EmployeeRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Territory currently assigned to. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: Option[SalesterritoryId], + /** Projected yearly sales. + Constraint CK_SalesPerson_SalesQuota affecting columns "salesquota": ((salesquota > 0.00)) */ + salesquota: Option[BigDecimal], + /** Default: 0.00 + Bonus due if quota is met. + Constraint CK_SalesPerson_Bonus affecting columns "bonus": ((bonus >= 0.00)) */ + bonus: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Commision percent received per sale. + Constraint CK_SalesPerson_CommissionPct affecting columns "commissionpct": ((commissionpct >= 0.00)) */ + commissionpct: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Sales total year to date. + Constraint CK_SalesPerson_SalesYTD affecting columns "salesytd": ((salesytd >= 0.00)) */ + salesytd: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Sales total of previous year. + Constraint CK_SalesPerson_SalesLastYear affecting columns "saleslastyear": ((saleslastyear >= 0.00)) */ + saleslastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(bonusDefault: => BigDecimal, commissionpctDefault: => BigDecimal, salesytdDefault: => BigDecimal, saleslastyearDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalespersonRow = + SalespersonRow( + businessentityid = businessentityid, + territoryid = territoryid, + salesquota = salesquota, + bonus = bonus match { + case Defaulted.UseDefault => bonusDefault + case Defaulted.Provided(value) => value + }, + commissionpct = commissionpct match { + case Defaulted.UseDefault => commissionpctDefault + case Defaulted.Provided(value) => value + }, + salesytd = salesytd match { + case Defaulted.UseDefault => salesytdDefault + case Defaulted.Provided(value) => value + }, + saleslastyear = saleslastyear match { + case Defaulted.UseDefault => saleslastyearDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalespersonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalespersonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").fold[Either[String, Option[SalesterritoryId]]](Right(None))(_.as(JsonDecoder.option(SalesterritoryId.jsonDecoder))) + val salesquota = jsonObj.get("salesquota").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val bonus = jsonObj.get("bonus").toRight("Missing field 'bonus'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val commissionpct = jsonObj.get("commissionpct").toRight("Missing field 'commissionpct'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && territoryid.isRight && salesquota.isRight && bonus.isRight && commissionpct.isRight && salesytd.isRight && saleslastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalespersonRowUnsaved(businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, salesquota = salesquota.toOption.get, bonus = bonus.toOption.get, commissionpct = commissionpct.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, territoryid, salesquota, bonus, commissionpct, salesytd, saleslastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalespersonRowUnsaved] = new JsonEncoder[SalespersonRowUnsaved] { + override def unsafeEncode(a: SalespersonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + JsonEncoder.option(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""bonus":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.bonus, indent, out) + out.write(",") + out.write(""""commissionpct":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.commissionpct, indent, out) + out.write(",") + out.write(""""salesytd":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonStructure.scala new file mode 100644 index 0000000000..91c6def14d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesperson/SalespersonStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesperson + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SalespersonStructure[Row](val prefix: Option[String], val extract: Row => SalespersonRow, val merge: (Row, SalespersonRow) => Row) + extends Relation[SalespersonFields, SalespersonRow, Row] + with SalespersonFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val territoryid = new OptField[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val salesquota = new OptField[BigDecimal, Row](prefix, "salesquota", None, Some("numeric"))(x => extract(x).salesquota, (row, value) => merge(row, extract(row).copy(salesquota = value))) + override val bonus = new Field[BigDecimal, Row](prefix, "bonus", None, Some("numeric"))(x => extract(x).bonus, (row, value) => merge(row, extract(row).copy(bonus = value))) + override val commissionpct = new Field[BigDecimal, Row](prefix, "commissionpct", None, Some("numeric"))(x => extract(x).commissionpct, (row, value) => merge(row, extract(row).copy(commissionpct = value))) + override val salesytd = new Field[BigDecimal, Row](prefix, "salesytd", None, Some("numeric"))(x => extract(x).salesytd, (row, value) => merge(row, extract(row).copy(salesytd = value))) + override val saleslastyear = new Field[BigDecimal, Row](prefix, "saleslastyear", None, Some("numeric"))(x => extract(x).saleslastyear, (row, value) => merge(row, extract(row).copy(saleslastyear = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, territoryid, salesquota, bonus, commissionpct, salesytd, saleslastyear, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalespersonRow, merge: (NewRow, SalespersonRow) => NewRow): SalespersonStructure[NewRow] = + new SalespersonStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryFields.scala new file mode 100644 index 0000000000..176e9e51e8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SalespersonquotahistoryFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val quotadate: IdField[TypoLocalDateTime, Row] + val salesquota: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalespersonquotahistoryFields extends SalespersonquotahistoryStructure[SalespersonquotahistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryId.scala new file mode 100644 index 0000000000..92da49d576 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.salespersonquotahistory` */ +case class SalespersonquotahistoryId(businessentityid: BusinessentityId, quotadate: TypoLocalDateTime) +object SalespersonquotahistoryId { + implicit lazy val jsonDecoder: JsonDecoder[SalespersonquotahistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val quotadate = jsonObj.get("quotadate").toRight("Missing field 'quotadate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && quotadate.isRight) + Right(SalespersonquotahistoryId(businessentityid = businessentityid.toOption.get, quotadate = quotadate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, quotadate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalespersonquotahistoryId] = new JsonEncoder[SalespersonquotahistoryId] { + override def unsafeEncode(a: SalespersonquotahistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""quotadate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.quotadate, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDateTime]): Ordering[SalespersonquotahistoryId] = Ordering.by(x => (x.businessentityid, x.quotadate)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepo.scala new file mode 100644 index 0000000000..9b1d8c253b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalespersonquotahistoryRepo { + def delete(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] + def insert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] + def insert(unsaved: SalespersonquotahistoryRowUnsaved): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] + def select: SelectBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] + def selectAll: ZStream[ZConnection, Throwable, SalespersonquotahistoryRow] + def selectById(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Option[SalespersonquotahistoryRow]] + def update(row: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] + def upsert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonquotahistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoImpl.scala new file mode 100644 index 0000000000..30338d06f4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoImpl.scala @@ -0,0 +1,103 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalespersonquotahistoryRepoImpl extends SalespersonquotahistoryRepo { + override def delete(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salespersonquotahistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "quotadate" = ${Segment.paramSegment(compositeId.quotadate)(TypoLocalDateTime.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + DeleteBuilder("sales.salespersonquotahistory", SalespersonquotahistoryFields) + } + override def insert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] = { + sql"""insert into sales.salespersonquotahistory("businessentityid", "quotadate", "salesquota", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.quotadate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.salesquota)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text + """.insertReturning(SalespersonquotahistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalespersonquotahistoryRowUnsaved): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""quotadate"""", sql"${Segment.paramSegment(unsaved.quotadate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""salesquota"""", sql"${Segment.paramSegment(unsaved.salesquota)(Setter.bigDecimalScalaSetter)}::numeric")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salespersonquotahistory default values + returning "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salespersonquotahistory($names) values ($values) returning "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalespersonquotahistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + SelectBuilderSql("sales.salespersonquotahistory", SalespersonquotahistoryFields, SalespersonquotahistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalespersonquotahistoryRow] = { + sql"""select "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text from sales.salespersonquotahistory""".query(SalespersonquotahistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Option[SalespersonquotahistoryRow]] = { + sql"""select "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text from sales.salespersonquotahistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "quotadate" = ${Segment.paramSegment(compositeId.quotadate)(TypoLocalDateTime.setter)}""".query(SalespersonquotahistoryRow.jdbcDecoder).selectOne + } + override def update(row: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.salespersonquotahistory + set "salesquota" = ${Segment.paramSegment(row.salesquota)(Setter.bigDecimalScalaSetter)}::numeric, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "quotadate" = ${Segment.paramSegment(compositeId.quotadate)(TypoLocalDateTime.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + UpdateBuilder("sales.salespersonquotahistory", SalespersonquotahistoryFields, SalespersonquotahistoryRow.jdbcDecoder) + } + override def upsert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonquotahistoryRow]] = { + sql"""insert into sales.salespersonquotahistory("businessentityid", "quotadate", "salesquota", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.quotadate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.salesquota)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "quotadate") + do update set + "salesquota" = EXCLUDED."salesquota", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "quotadate"::text, "salesquota", "rowguid", "modifieddate"::text""".insertReturning(SalespersonquotahistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoMock.scala new file mode 100644 index 0000000000..7ff213e9bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalespersonquotahistoryRepoMock(toRow: Function1[SalespersonquotahistoryRowUnsaved, SalespersonquotahistoryRow], + map: scala.collection.mutable.Map[SalespersonquotahistoryId, SalespersonquotahistoryRow] = scala.collection.mutable.Map.empty) extends SalespersonquotahistoryRepo { + override def delete(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, SalespersonquotahistoryFields, map) + } + override def insert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: SalespersonquotahistoryRowUnsaved): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + SelectBuilderMock(SalespersonquotahistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalespersonquotahistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: SalespersonquotahistoryId): ZIO[ZConnection, Throwable, Option[SalespersonquotahistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalespersonquotahistoryFields, SalespersonquotahistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, SalespersonquotahistoryFields, map) + } + override def upsert(unsaved: SalespersonquotahistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalespersonquotahistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRow.scala new file mode 100644 index 0000000000..8f28a26afa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRow.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalespersonquotahistoryRow( + /** Sales person identification number. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Sales quota date. */ + quotadate: TypoLocalDateTime, + /** Sales quota amount. + Constraint CK_SalesPersonQuotaHistory_SalesQuota affecting columns "salesquota": ((salesquota > 0.00)) */ + salesquota: BigDecimal, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: SalespersonquotahistoryId = SalespersonquotahistoryId(businessentityid, quotadate) + } + +object SalespersonquotahistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalespersonquotahistoryRow] = new JdbcDecoder[SalespersonquotahistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalespersonquotahistoryRow) = + columIndex + 4 -> + SalespersonquotahistoryRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + quotadate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + salesquota = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 2, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalespersonquotahistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val quotadate = jsonObj.get("quotadate").toRight("Missing field 'quotadate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val salesquota = jsonObj.get("salesquota").toRight("Missing field 'salesquota'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && quotadate.isRight && salesquota.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalespersonquotahistoryRow(businessentityid = businessentityid.toOption.get, quotadate = quotadate.toOption.get, salesquota = salesquota.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, quotadate, salesquota, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalespersonquotahistoryRow] = new JsonEncoder[SalespersonquotahistoryRow] { + override def unsafeEncode(a: SalespersonquotahistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""quotadate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.quotadate, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRowUnsaved.scala new file mode 100644 index 0000000000..3b294c5a2d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryRowUnsaved.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salespersonquotahistory` which has not been persisted yet */ +case class SalespersonquotahistoryRowUnsaved( + /** Sales person identification number. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Sales quota date. */ + quotadate: TypoLocalDateTime, + /** Sales quota amount. + Constraint CK_SalesPersonQuotaHistory_SalesQuota affecting columns "salesquota": ((salesquota > 0.00)) */ + salesquota: BigDecimal, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalespersonquotahistoryRow = + SalespersonquotahistoryRow( + businessentityid = businessentityid, + quotadate = quotadate, + salesquota = salesquota, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalespersonquotahistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalespersonquotahistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val quotadate = jsonObj.get("quotadate").toRight("Missing field 'quotadate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val salesquota = jsonObj.get("salesquota").toRight("Missing field 'salesquota'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && quotadate.isRight && salesquota.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalespersonquotahistoryRowUnsaved(businessentityid = businessentityid.toOption.get, quotadate = quotadate.toOption.get, salesquota = salesquota.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, quotadate, salesquota, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalespersonquotahistoryRowUnsaved] = new JsonEncoder[SalespersonquotahistoryRowUnsaved] { + override def unsafeEncode(a: SalespersonquotahistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""quotadate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.quotadate, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryStructure.scala new file mode 100644 index 0000000000..9a540fa924 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salespersonquotahistory/SalespersonquotahistoryStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salespersonquotahistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SalespersonquotahistoryStructure[Row](val prefix: Option[String], val extract: Row => SalespersonquotahistoryRow, val merge: (Row, SalespersonquotahistoryRow) => Row) + extends Relation[SalespersonquotahistoryFields, SalespersonquotahistoryRow, Row] + with SalespersonquotahistoryFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val quotadate = new IdField[TypoLocalDateTime, Row](prefix, "quotadate", Some("text"), Some("timestamp"))(x => extract(x).quotadate, (row, value) => merge(row, extract(row).copy(quotadate = value))) + override val salesquota = new Field[BigDecimal, Row](prefix, "salesquota", None, Some("numeric"))(x => extract(x).salesquota, (row, value) => merge(row, extract(row).copy(salesquota = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, quotadate, salesquota, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalespersonquotahistoryRow, merge: (NewRow, SalespersonquotahistoryRow) => NewRow): SalespersonquotahistoryStructure[NewRow] = + new SalespersonquotahistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonFields.scala new file mode 100644 index 0000000000..daf8632644 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SalesreasonFields[Row] { + val salesreasonid: IdField[SalesreasonId, Row] + val name: Field[Name, Row] + val reasontype: Field[Name, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesreasonFields extends SalesreasonStructure[SalesreasonRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonId.scala new file mode 100644 index 0000000000..c005c96f73 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +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 `sales.salesreason` */ +case class SalesreasonId(value: Int) extends AnyVal +object SalesreasonId { + implicit lazy val arraySetter: Setter[Array[SalesreasonId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[SalesreasonId, Int] = Bijection[SalesreasonId, Int](_.value)(SalesreasonId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[SalesreasonId] = JdbcDecoder.intDecoder.map(SalesreasonId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[SalesreasonId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[SalesreasonId] = JsonDecoder.int.map(SalesreasonId.apply) + implicit lazy val jsonEncoder: JsonEncoder[SalesreasonId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[SalesreasonId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[SalesreasonId] = ParameterMetaData.instance[SalesreasonId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[SalesreasonId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepo.scala new file mode 100644 index 0000000000..63554d9b28 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesreasonRepo { + def delete(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesreasonFields, SalesreasonRow] + def insert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, SalesreasonRow] + def insert(unsaved: SalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesreasonRow] + def select: SelectBuilder[SalesreasonFields, SalesreasonRow] + def selectAll: ZStream[ZConnection, Throwable, SalesreasonRow] + def selectById(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Option[SalesreasonRow]] + def selectByIds(salesreasonids: Array[SalesreasonId]): ZStream[ZConnection, Throwable, SalesreasonRow] + def update(row: SalesreasonRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesreasonFields, SalesreasonRow] + def upsert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesreasonRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoImpl.scala new file mode 100644 index 0000000000..b4ab912d3b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoImpl.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesreasonRepoImpl extends SalesreasonRepo { + override def delete(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesreason where "salesreasonid" = ${Segment.paramSegment(salesreasonid)(SalesreasonId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesreasonFields, SalesreasonRow] = { + DeleteBuilder("sales.salesreason", SalesreasonFields) + } + override def insert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, SalesreasonRow] = { + sql"""insert into sales.salesreason("salesreasonid", "name", "reasontype", "modifieddate") + values (${Segment.paramSegment(unsaved.salesreasonid)(SalesreasonId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.reasontype)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "salesreasonid", "name", "reasontype", "modifieddate"::text + """.insertReturning(SalesreasonRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesreasonRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""reasontype"""", sql"${Segment.paramSegment(unsaved.reasontype)(Name.setter)}::varchar")), + unsaved.salesreasonid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salesreasonid"""", sql"${Segment.paramSegment(value: SalesreasonId)(SalesreasonId.setter)}::int4")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesreason default values + returning "salesreasonid", "name", "reasontype", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesreason($names) values ($values) returning "salesreasonid", "name", "reasontype", "modifieddate"::text""" + } + q.insertReturning(SalesreasonRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesreasonFields, SalesreasonRow] = { + SelectBuilderSql("sales.salesreason", SalesreasonFields, SalesreasonRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesreasonRow] = { + sql"""select "salesreasonid", "name", "reasontype", "modifieddate"::text from sales.salesreason""".query(SalesreasonRow.jdbcDecoder).selectStream + } + override def selectById(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Option[SalesreasonRow]] = { + sql"""select "salesreasonid", "name", "reasontype", "modifieddate"::text from sales.salesreason where "salesreasonid" = ${Segment.paramSegment(salesreasonid)(SalesreasonId.setter)}""".query(SalesreasonRow.jdbcDecoder).selectOne + } + override def selectByIds(salesreasonids: Array[SalesreasonId]): ZStream[ZConnection, Throwable, SalesreasonRow] = { + sql"""select "salesreasonid", "name", "reasontype", "modifieddate"::text from sales.salesreason where "salesreasonid" = ANY(${Segment.paramSegment(salesreasonids)(SalesreasonId.arraySetter)})""".query(SalesreasonRow.jdbcDecoder).selectStream + } + override def update(row: SalesreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + val salesreasonid = row.salesreasonid + sql"""update sales.salesreason + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "reasontype" = ${Segment.paramSegment(row.reasontype)(Name.setter)}::varchar, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "salesreasonid" = ${Segment.paramSegment(salesreasonid)(SalesreasonId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesreasonFields, SalesreasonRow] = { + UpdateBuilder("sales.salesreason", SalesreasonFields, SalesreasonRow.jdbcDecoder) + } + override def upsert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesreasonRow]] = { + sql"""insert into sales.salesreason("salesreasonid", "name", "reasontype", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.salesreasonid)(SalesreasonId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.reasontype)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("salesreasonid") + do update set + "name" = EXCLUDED."name", + "reasontype" = EXCLUDED."reasontype", + "modifieddate" = EXCLUDED."modifieddate" + returning "salesreasonid", "name", "reasontype", "modifieddate"::text""".insertReturning(SalesreasonRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoMock.scala new file mode 100644 index 0000000000..aa4bba0fae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesreasonRepoMock(toRow: Function1[SalesreasonRowUnsaved, SalesreasonRow], + map: scala.collection.mutable.Map[SalesreasonId, SalesreasonRow] = scala.collection.mutable.Map.empty) extends SalesreasonRepo { + override def delete(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(salesreasonid).isDefined) + } + override def delete: DeleteBuilder[SalesreasonFields, SalesreasonRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesreasonFields, map) + } + override def insert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, SalesreasonRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.salesreasonid)) + sys.error(s"id ${unsaved.salesreasonid} already exists") + else + map.put(unsaved.salesreasonid, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesreasonRowUnsaved): ZIO[ZConnection, Throwable, SalesreasonRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesreasonFields, SalesreasonRow] = { + SelectBuilderMock(SalesreasonFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesreasonRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(salesreasonid: SalesreasonId): ZIO[ZConnection, Throwable, Option[SalesreasonRow]] = { + ZIO.succeed(map.get(salesreasonid)) + } + override def selectByIds(salesreasonids: Array[SalesreasonId]): ZStream[ZConnection, Throwable, SalesreasonRow] = { + ZStream.fromIterable(salesreasonids.flatMap(map.get)) + } + override def update(row: SalesreasonRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.salesreasonid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.salesreasonid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesreasonFields, SalesreasonRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesreasonFields, map) + } + override def upsert(unsaved: SalesreasonRow): ZIO[ZConnection, Throwable, UpdateResult[SalesreasonRow]] = { + ZIO.succeed { + map.put(unsaved.salesreasonid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRow.scala new file mode 100644 index 0000000000..21a1b4cf14 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRow.scala @@ -0,0 +1,66 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesreasonRow( + /** Primary key for SalesReason records. */ + salesreasonid: SalesreasonId, + /** Sales reason description. */ + name: Name, + /** Category the sales reason belongs to. */ + reasontype: Name, + modifieddate: TypoLocalDateTime +) + +object SalesreasonRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesreasonRow] = new JdbcDecoder[SalesreasonRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesreasonRow) = + columIndex + 3 -> + SalesreasonRow( + salesreasonid = SalesreasonId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + reasontype = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesreasonRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(SalesreasonId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val reasontype = jsonObj.get("reasontype").toRight("Missing field 'reasontype'").flatMap(_.as(Name.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salesreasonid.isRight && name.isRight && reasontype.isRight && modifieddate.isRight) + Right(SalesreasonRow(salesreasonid = salesreasonid.toOption.get, name = name.toOption.get, reasontype = reasontype.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salesreasonid, name, reasontype, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesreasonRow] = new JsonEncoder[SalesreasonRow] { + override def unsafeEncode(a: SalesreasonRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salesreasonid":""") + SalesreasonId.jsonEncoder.unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""reasontype":""") + Name.jsonEncoder.unsafeEncode(a.reasontype, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRowUnsaved.scala new file mode 100644 index 0000000000..6509a49a8c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonRowUnsaved.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesreason` which has not been persisted yet */ +case class SalesreasonRowUnsaved( + /** Sales reason description. */ + name: Name, + /** Category the sales reason belongs to. */ + reasontype: Name, + /** Default: nextval('sales.salesreason_salesreasonid_seq'::regclass) + Primary key for SalesReason records. */ + salesreasonid: Defaulted[SalesreasonId] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(salesreasonidDefault: => SalesreasonId, modifieddateDefault: => TypoLocalDateTime): SalesreasonRow = + SalesreasonRow( + name = name, + reasontype = reasontype, + salesreasonid = salesreasonid match { + case Defaulted.UseDefault => salesreasonidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesreasonRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesreasonRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val reasontype = jsonObj.get("reasontype").toRight("Missing field 'reasontype'").flatMap(_.as(Name.jsonDecoder)) + val salesreasonid = jsonObj.get("salesreasonid").toRight("Missing field 'salesreasonid'").flatMap(_.as(Defaulted.jsonDecoder(SalesreasonId.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && reasontype.isRight && salesreasonid.isRight && modifieddate.isRight) + Right(SalesreasonRowUnsaved(name = name.toOption.get, reasontype = reasontype.toOption.get, salesreasonid = salesreasonid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, reasontype, salesreasonid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesreasonRowUnsaved] = new JsonEncoder[SalesreasonRowUnsaved] { + override def unsafeEncode(a: SalesreasonRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""reasontype":""") + Name.jsonEncoder.unsafeEncode(a.reasontype, indent, out) + out.write(",") + out.write(""""salesreasonid":""") + Defaulted.jsonEncoder(SalesreasonId.jsonEncoder).unsafeEncode(a.salesreasonid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonStructure.scala new file mode 100644 index 0000000000..53f0e42c64 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesreason/SalesreasonStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesreason + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SalesreasonStructure[Row](val prefix: Option[String], val extract: Row => SalesreasonRow, val merge: (Row, SalesreasonRow) => Row) + extends Relation[SalesreasonFields, SalesreasonRow, Row] + with SalesreasonFields[Row] { outer => + + override val salesreasonid = new IdField[SalesreasonId, Row](prefix, "salesreasonid", None, Some("int4"))(x => extract(x).salesreasonid, (row, value) => merge(row, extract(row).copy(salesreasonid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val reasontype = new Field[Name, Row](prefix, "reasontype", None, Some("varchar"))(x => extract(x).reasontype, (row, value) => merge(row, extract(row).copy(reasontype = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salesreasonid, name, reasontype, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesreasonRow, merge: (NewRow, SalesreasonRow) => NewRow): SalesreasonStructure[NewRow] = + new SalesreasonStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateFields.scala new file mode 100644 index 0000000000..197f428841 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SalestaxrateFields[Row] { + val salestaxrateid: IdField[SalestaxrateId, Row] + val stateprovinceid: Field[StateprovinceId, Row] + val taxtype: Field[TypoShort, Row] + val taxrate: Field[BigDecimal, Row] + val name: Field[Name, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalestaxrateFields extends SalestaxrateStructure[SalestaxrateRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateId.scala new file mode 100644 index 0000000000..c1c6b3281b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +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 `sales.salestaxrate` */ +case class SalestaxrateId(value: Int) extends AnyVal +object SalestaxrateId { + implicit lazy val arraySetter: Setter[Array[SalestaxrateId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[SalestaxrateId, Int] = Bijection[SalestaxrateId, Int](_.value)(SalestaxrateId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[SalestaxrateId] = JdbcDecoder.intDecoder.map(SalestaxrateId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[SalestaxrateId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[SalestaxrateId] = JsonDecoder.int.map(SalestaxrateId.apply) + implicit lazy val jsonEncoder: JsonEncoder[SalestaxrateId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[SalestaxrateId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[SalestaxrateId] = ParameterMetaData.instance[SalestaxrateId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[SalestaxrateId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepo.scala new file mode 100644 index 0000000000..1a33c96406 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalestaxrateRepo { + def delete(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalestaxrateFields, SalestaxrateRow] + def insert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, SalestaxrateRow] + def insert(unsaved: SalestaxrateRowUnsaved): ZIO[ZConnection, Throwable, SalestaxrateRow] + def select: SelectBuilder[SalestaxrateFields, SalestaxrateRow] + def selectAll: ZStream[ZConnection, Throwable, SalestaxrateRow] + def selectById(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Option[SalestaxrateRow]] + def selectByIds(salestaxrateids: Array[SalestaxrateId]): ZStream[ZConnection, Throwable, SalestaxrateRow] + def update(row: SalestaxrateRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalestaxrateFields, SalestaxrateRow] + def upsert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, UpdateResult[SalestaxrateRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoImpl.scala new file mode 100644 index 0000000000..fcda81e76a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoImpl.scala @@ -0,0 +1,124 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalestaxrateRepoImpl extends SalestaxrateRepo { + override def delete(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salestaxrate where "salestaxrateid" = ${Segment.paramSegment(salestaxrateid)(SalestaxrateId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalestaxrateFields, SalestaxrateRow] = { + DeleteBuilder("sales.salestaxrate", SalestaxrateFields) + } + override def insert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, SalestaxrateRow] = { + sql"""insert into sales.salestaxrate("salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.salestaxrateid)(SalestaxrateId.setter)}::int4, ${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, ${Segment.paramSegment(unsaved.taxtype)(TypoShort.setter)}::int2, ${Segment.paramSegment(unsaved.taxrate)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text + """.insertReturning(SalestaxrateRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalestaxrateRowUnsaved): ZIO[ZConnection, Throwable, SalestaxrateRow] = { + val fs = List( + Some((sql""""stateprovinceid"""", sql"${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4")), + Some((sql""""taxtype"""", sql"${Segment.paramSegment(unsaved.taxtype)(TypoShort.setter)}::int2")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + unsaved.salestaxrateid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salestaxrateid"""", sql"${Segment.paramSegment(value: SalestaxrateId)(SalestaxrateId.setter)}::int4")) + }, + unsaved.taxrate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""taxrate"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salestaxrate default values + returning "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salestaxrate($names) values ($values) returning "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalestaxrateRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalestaxrateFields, SalestaxrateRow] = { + SelectBuilderSql("sales.salestaxrate", SalestaxrateFields, SalestaxrateRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalestaxrateRow] = { + sql"""select "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text from sales.salestaxrate""".query(SalestaxrateRow.jdbcDecoder).selectStream + } + override def selectById(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Option[SalestaxrateRow]] = { + sql"""select "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text from sales.salestaxrate where "salestaxrateid" = ${Segment.paramSegment(salestaxrateid)(SalestaxrateId.setter)}""".query(SalestaxrateRow.jdbcDecoder).selectOne + } + override def selectByIds(salestaxrateids: Array[SalestaxrateId]): ZStream[ZConnection, Throwable, SalestaxrateRow] = { + sql"""select "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text from sales.salestaxrate where "salestaxrateid" = ANY(${Segment.paramSegment(salestaxrateids)(SalestaxrateId.arraySetter)})""".query(SalestaxrateRow.jdbcDecoder).selectStream + } + override def update(row: SalestaxrateRow): ZIO[ZConnection, Throwable, Boolean] = { + val salestaxrateid = row.salestaxrateid + sql"""update sales.salestaxrate + set "stateprovinceid" = ${Segment.paramSegment(row.stateprovinceid)(StateprovinceId.setter)}::int4, + "taxtype" = ${Segment.paramSegment(row.taxtype)(TypoShort.setter)}::int2, + "taxrate" = ${Segment.paramSegment(row.taxrate)(Setter.bigDecimalScalaSetter)}::numeric, + "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "salestaxrateid" = ${Segment.paramSegment(salestaxrateid)(SalestaxrateId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalestaxrateFields, SalestaxrateRow] = { + UpdateBuilder("sales.salestaxrate", SalestaxrateFields, SalestaxrateRow.jdbcDecoder) + } + override def upsert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, UpdateResult[SalestaxrateRow]] = { + sql"""insert into sales.salestaxrate("salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.salestaxrateid)(SalestaxrateId.setter)}::int4, + ${Segment.paramSegment(unsaved.stateprovinceid)(StateprovinceId.setter)}::int4, + ${Segment.paramSegment(unsaved.taxtype)(TypoShort.setter)}::int2, + ${Segment.paramSegment(unsaved.taxrate)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("salestaxrateid") + do update set + "stateprovinceid" = EXCLUDED."stateprovinceid", + "taxtype" = EXCLUDED."taxtype", + "taxrate" = EXCLUDED."taxrate", + "name" = EXCLUDED."name", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "salestaxrateid", "stateprovinceid", "taxtype", "taxrate", "name", "rowguid", "modifieddate"::text""".insertReturning(SalestaxrateRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoMock.scala new file mode 100644 index 0000000000..51318b82ab --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalestaxrateRepoMock(toRow: Function1[SalestaxrateRowUnsaved, SalestaxrateRow], + map: scala.collection.mutable.Map[SalestaxrateId, SalestaxrateRow] = scala.collection.mutable.Map.empty) extends SalestaxrateRepo { + override def delete(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(salestaxrateid).isDefined) + } + override def delete: DeleteBuilder[SalestaxrateFields, SalestaxrateRow] = { + DeleteBuilderMock(DeleteParams.empty, SalestaxrateFields, map) + } + override def insert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, SalestaxrateRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.salestaxrateid)) + sys.error(s"id ${unsaved.salestaxrateid} already exists") + else + map.put(unsaved.salestaxrateid, unsaved) + + unsaved + } + } + override def insert(unsaved: SalestaxrateRowUnsaved): ZIO[ZConnection, Throwable, SalestaxrateRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalestaxrateFields, SalestaxrateRow] = { + SelectBuilderMock(SalestaxrateFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalestaxrateRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(salestaxrateid: SalestaxrateId): ZIO[ZConnection, Throwable, Option[SalestaxrateRow]] = { + ZIO.succeed(map.get(salestaxrateid)) + } + override def selectByIds(salestaxrateids: Array[SalestaxrateId]): ZStream[ZConnection, Throwable, SalestaxrateRow] = { + ZStream.fromIterable(salestaxrateids.flatMap(map.get)) + } + override def update(row: SalestaxrateRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.salestaxrateid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.salestaxrateid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalestaxrateFields, SalestaxrateRow] = { + UpdateBuilderMock(UpdateParams.empty, SalestaxrateFields, map) + } + override def upsert(unsaved: SalestaxrateRow): ZIO[ZConnection, Throwable, UpdateResult[SalestaxrateRow]] = { + ZIO.succeed { + map.put(unsaved.salestaxrateid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRow.scala new file mode 100644 index 0000000000..bf0a6070d7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRow.scala @@ -0,0 +1,91 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalestaxrateRow( + /** Primary key for SalesTaxRate records. */ + salestaxrateid: SalestaxrateId, + /** State, province, or country/region the sales tax applies to. + Points to [[person.stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** 1 = Tax applied to retail transactions, 2 = Tax applied to wholesale transactions, 3 = Tax applied to all sales (retail and wholesale) transactions. + Constraint CK_SalesTaxRate_TaxType affecting columns "taxtype": (((taxtype >= 1) AND (taxtype <= 3))) */ + taxtype: TypoShort, + /** Tax rate amount. */ + taxrate: BigDecimal, + /** Tax rate description. */ + name: Name, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object SalestaxrateRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalestaxrateRow] = new JdbcDecoder[SalestaxrateRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalestaxrateRow) = + columIndex + 6 -> + SalestaxrateRow( + salestaxrateid = SalestaxrateId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + stateprovinceid = StateprovinceId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + taxtype = TypoShort.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + taxrate = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 3, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalestaxrateRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salestaxrateid = jsonObj.get("salestaxrateid").toRight("Missing field 'salestaxrateid'").flatMap(_.as(SalestaxrateId.jsonDecoder)) + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val taxtype = jsonObj.get("taxtype").toRight("Missing field 'taxtype'").flatMap(_.as(TypoShort.jsonDecoder)) + val taxrate = jsonObj.get("taxrate").toRight("Missing field 'taxrate'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (salestaxrateid.isRight && stateprovinceid.isRight && taxtype.isRight && taxrate.isRight && name.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalestaxrateRow(salestaxrateid = salestaxrateid.toOption.get, stateprovinceid = stateprovinceid.toOption.get, taxtype = taxtype.toOption.get, taxrate = taxrate.toOption.get, name = name.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](salestaxrateid, stateprovinceid, taxtype, taxrate, name, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalestaxrateRow] = new JsonEncoder[SalestaxrateRow] { + override def unsafeEncode(a: SalestaxrateRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salestaxrateid":""") + SalestaxrateId.jsonEncoder.unsafeEncode(a.salestaxrateid, indent, out) + out.write(",") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""taxtype":""") + TypoShort.jsonEncoder.unsafeEncode(a.taxtype, indent, out) + out.write(",") + out.write(""""taxrate":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.taxrate, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRowUnsaved.scala new file mode 100644 index 0000000000..669780a9f2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateRowUnsaved.scala @@ -0,0 +1,104 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salestaxrate` which has not been persisted yet */ +case class SalestaxrateRowUnsaved( + /** State, province, or country/region the sales tax applies to. + Points to [[person.stateprovince.StateprovinceRow.stateprovinceid]] */ + stateprovinceid: StateprovinceId, + /** 1 = Tax applied to retail transactions, 2 = Tax applied to wholesale transactions, 3 = Tax applied to all sales (retail and wholesale) transactions. + Constraint CK_SalesTaxRate_TaxType affecting columns "taxtype": (((taxtype >= 1) AND (taxtype <= 3))) */ + taxtype: TypoShort, + /** Tax rate description. */ + name: Name, + /** Default: nextval('sales.salestaxrate_salestaxrateid_seq'::regclass) + Primary key for SalesTaxRate records. */ + salestaxrateid: Defaulted[SalestaxrateId] = Defaulted.UseDefault, + /** Default: 0.00 + Tax rate amount. */ + taxrate: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(salestaxrateidDefault: => SalestaxrateId, taxrateDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalestaxrateRow = + SalestaxrateRow( + stateprovinceid = stateprovinceid, + taxtype = taxtype, + name = name, + salestaxrateid = salestaxrateid match { + case Defaulted.UseDefault => salestaxrateidDefault + case Defaulted.Provided(value) => value + }, + taxrate = taxrate match { + case Defaulted.UseDefault => taxrateDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalestaxrateRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalestaxrateRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val stateprovinceid = jsonObj.get("stateprovinceid").toRight("Missing field 'stateprovinceid'").flatMap(_.as(StateprovinceId.jsonDecoder)) + val taxtype = jsonObj.get("taxtype").toRight("Missing field 'taxtype'").flatMap(_.as(TypoShort.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val salestaxrateid = jsonObj.get("salestaxrateid").toRight("Missing field 'salestaxrateid'").flatMap(_.as(Defaulted.jsonDecoder(SalestaxrateId.jsonDecoder))) + val taxrate = jsonObj.get("taxrate").toRight("Missing field 'taxrate'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (stateprovinceid.isRight && taxtype.isRight && name.isRight && salestaxrateid.isRight && taxrate.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalestaxrateRowUnsaved(stateprovinceid = stateprovinceid.toOption.get, taxtype = taxtype.toOption.get, name = name.toOption.get, salestaxrateid = salestaxrateid.toOption.get, taxrate = taxrate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](stateprovinceid, taxtype, name, salestaxrateid, taxrate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalestaxrateRowUnsaved] = new JsonEncoder[SalestaxrateRowUnsaved] { + override def unsafeEncode(a: SalestaxrateRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""stateprovinceid":""") + StateprovinceId.jsonEncoder.unsafeEncode(a.stateprovinceid, indent, out) + out.write(",") + out.write(""""taxtype":""") + TypoShort.jsonEncoder.unsafeEncode(a.taxtype, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""salestaxrateid":""") + Defaulted.jsonEncoder(SalestaxrateId.jsonEncoder).unsafeEncode(a.salestaxrateid, indent, out) + out.write(",") + out.write(""""taxrate":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.taxrate, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateStructure.scala new file mode 100644 index 0000000000..116ca9b8e3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salestaxrate/SalestaxrateStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salestaxrate + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SalestaxrateStructure[Row](val prefix: Option[String], val extract: Row => SalestaxrateRow, val merge: (Row, SalestaxrateRow) => Row) + extends Relation[SalestaxrateFields, SalestaxrateRow, Row] + with SalestaxrateFields[Row] { outer => + + override val salestaxrateid = new IdField[SalestaxrateId, Row](prefix, "salestaxrateid", None, Some("int4"))(x => extract(x).salestaxrateid, (row, value) => merge(row, extract(row).copy(salestaxrateid = value))) + override val stateprovinceid = new Field[StateprovinceId, Row](prefix, "stateprovinceid", None, Some("int4"))(x => extract(x).stateprovinceid, (row, value) => merge(row, extract(row).copy(stateprovinceid = value))) + override val taxtype = new Field[TypoShort, Row](prefix, "taxtype", None, Some("int2"))(x => extract(x).taxtype, (row, value) => merge(row, extract(row).copy(taxtype = value))) + override val taxrate = new Field[BigDecimal, Row](prefix, "taxrate", None, Some("numeric"))(x => extract(x).taxrate, (row, value) => merge(row, extract(row).copy(taxrate = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salestaxrateid, stateprovinceid, taxtype, taxrate, name, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalestaxrateRow, merge: (NewRow, SalestaxrateRow) => NewRow): SalestaxrateStructure[NewRow] = + new SalestaxrateStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryFields.scala new file mode 100644 index 0000000000..79912180ae --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SalesterritoryFields[Row] { + val territoryid: IdField[SalesterritoryId, Row] + val name: Field[Name, Row] + val countryregioncode: Field[CountryregionId, Row] + val group: Field[/* max 50 chars */ String, Row] + val salesytd: Field[BigDecimal, Row] + val saleslastyear: Field[BigDecimal, Row] + val costytd: Field[BigDecimal, Row] + val costlastyear: Field[BigDecimal, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesterritoryFields extends SalesterritoryStructure[SalesterritoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryId.scala new file mode 100644 index 0000000000..8d86af3b62 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +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 `sales.salesterritory` */ +case class SalesterritoryId(value: Int) extends AnyVal +object SalesterritoryId { + implicit lazy val arraySetter: Setter[Array[SalesterritoryId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[SalesterritoryId, Int] = Bijection[SalesterritoryId, Int](_.value)(SalesterritoryId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[SalesterritoryId] = JdbcDecoder.intDecoder.map(SalesterritoryId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[SalesterritoryId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryId] = JsonDecoder.int.map(SalesterritoryId.apply) + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[SalesterritoryId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[SalesterritoryId] = ParameterMetaData.instance[SalesterritoryId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[SalesterritoryId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepo.scala new file mode 100644 index 0000000000..ffbcb394ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesterritoryRepo { + def delete(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesterritoryFields, SalesterritoryRow] + def insert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, SalesterritoryRow] + def insert(unsaved: SalesterritoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryRow] + def select: SelectBuilder[SalesterritoryFields, SalesterritoryRow] + def selectAll: ZStream[ZConnection, Throwable, SalesterritoryRow] + def selectById(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryRow]] + def selectByIds(territoryids: Array[SalesterritoryId]): ZStream[ZConnection, Throwable, SalesterritoryRow] + def update(row: SalesterritoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesterritoryFields, SalesterritoryRow] + def upsert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoImpl.scala new file mode 100644 index 0000000000..f5ca713cc6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoImpl.scala @@ -0,0 +1,144 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesterritoryRepoImpl extends SalesterritoryRepo { + override def delete(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesterritory where "territoryid" = ${Segment.paramSegment(territoryid)(SalesterritoryId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesterritoryFields, SalesterritoryRow] = { + DeleteBuilder("sales.salesterritory", SalesterritoryFields) + } + override def insert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, SalesterritoryRow] = { + sql"""insert into sales.salesterritory("territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, ${Segment.paramSegment(unsaved.group)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.costytd)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.costlastyear)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text + """.insertReturning(SalesterritoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesterritoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryRow] = { + val fs = List( + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""countryregioncode"""", sql"${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}")), + Some((sql""""group"""", sql"${Segment.paramSegment(unsaved.group)(Setter.stringSetter)}")), + unsaved.territoryid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""territoryid"""", sql"${Segment.paramSegment(value: SalesterritoryId)(SalesterritoryId.setter)}::int4")) + }, + unsaved.salesytd match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""salesytd"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.saleslastyear match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""saleslastyear"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.costytd match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""costytd"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.costlastyear match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""costlastyear"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesterritory default values + returning "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesterritory($names) values ($values) returning "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalesterritoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesterritoryFields, SalesterritoryRow] = { + SelectBuilderSql("sales.salesterritory", SalesterritoryFields, SalesterritoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesterritoryRow] = { + sql"""select "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text from sales.salesterritory""".query(SalesterritoryRow.jdbcDecoder).selectStream + } + override def selectById(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryRow]] = { + sql"""select "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text from sales.salesterritory where "territoryid" = ${Segment.paramSegment(territoryid)(SalesterritoryId.setter)}""".query(SalesterritoryRow.jdbcDecoder).selectOne + } + override def selectByIds(territoryids: Array[SalesterritoryId]): ZStream[ZConnection, Throwable, SalesterritoryRow] = { + sql"""select "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text from sales.salesterritory where "territoryid" = ANY(${Segment.paramSegment(territoryids)(SalesterritoryId.arraySetter)})""".query(SalesterritoryRow.jdbcDecoder).selectStream + } + override def update(row: SalesterritoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val territoryid = row.territoryid + sql"""update sales.salesterritory + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "countryregioncode" = ${Segment.paramSegment(row.countryregioncode)(CountryregionId.setter)}, + "group" = ${Segment.paramSegment(row.group)(Setter.stringSetter)}, + "salesytd" = ${Segment.paramSegment(row.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, + "saleslastyear" = ${Segment.paramSegment(row.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, + "costytd" = ${Segment.paramSegment(row.costytd)(Setter.bigDecimalScalaSetter)}::numeric, + "costlastyear" = ${Segment.paramSegment(row.costlastyear)(Setter.bigDecimalScalaSetter)}::numeric, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "territoryid" = ${Segment.paramSegment(territoryid)(SalesterritoryId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesterritoryFields, SalesterritoryRow] = { + UpdateBuilder("sales.salesterritory", SalesterritoryFields, SalesterritoryRow.jdbcDecoder) + } + override def upsert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryRow]] = { + sql"""insert into sales.salesterritory("territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.countryregioncode)(CountryregionId.setter)}, + ${Segment.paramSegment(unsaved.group)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.salesytd)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.saleslastyear)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.costytd)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.costlastyear)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("territoryid") + do update set + "name" = EXCLUDED."name", + "countryregioncode" = EXCLUDED."countryregioncode", + "group" = EXCLUDED."group", + "salesytd" = EXCLUDED."salesytd", + "saleslastyear" = EXCLUDED."saleslastyear", + "costytd" = EXCLUDED."costytd", + "costlastyear" = EXCLUDED."costlastyear", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "territoryid", "name", "countryregioncode", "group", "salesytd", "saleslastyear", "costytd", "costlastyear", "rowguid", "modifieddate"::text""".insertReturning(SalesterritoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoMock.scala new file mode 100644 index 0000000000..b5e78b619d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesterritoryRepoMock(toRow: Function1[SalesterritoryRowUnsaved, SalesterritoryRow], + map: scala.collection.mutable.Map[SalesterritoryId, SalesterritoryRow] = scala.collection.mutable.Map.empty) extends SalesterritoryRepo { + override def delete(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(territoryid).isDefined) + } + override def delete: DeleteBuilder[SalesterritoryFields, SalesterritoryRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesterritoryFields, map) + } + override def insert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, SalesterritoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.territoryid)) + sys.error(s"id ${unsaved.territoryid} already exists") + else + map.put(unsaved.territoryid, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesterritoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesterritoryFields, SalesterritoryRow] = { + SelectBuilderMock(SalesterritoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesterritoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(territoryid: SalesterritoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryRow]] = { + ZIO.succeed(map.get(territoryid)) + } + override def selectByIds(territoryids: Array[SalesterritoryId]): ZStream[ZConnection, Throwable, SalesterritoryRow] = { + ZStream.fromIterable(territoryids.flatMap(map.get)) + } + override def update(row: SalesterritoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.territoryid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.territoryid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesterritoryFields, SalesterritoryRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesterritoryFields, map) + } + override def upsert(unsaved: SalesterritoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryRow]] = { + ZIO.succeed { + map.put(unsaved.territoryid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRow.scala new file mode 100644 index 0000000000..da8b39decd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRow.scala @@ -0,0 +1,114 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesterritoryRow( + /** Primary key for SalesTerritory records. */ + territoryid: SalesterritoryId, + /** Sales territory description */ + name: Name, + /** ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. + Points to [[person.countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Geographic area to which the sales territory belong. */ + group: /* max 50 chars */ String, + /** Sales in the territory year to date. + Constraint CK_SalesTerritory_SalesYTD affecting columns "salesytd": ((salesytd >= 0.00)) */ + salesytd: BigDecimal, + /** Sales in the territory the previous year. + Constraint CK_SalesTerritory_SalesLastYear affecting columns "saleslastyear": ((saleslastyear >= 0.00)) */ + saleslastyear: BigDecimal, + /** Business costs in the territory year to date. + Constraint CK_SalesTerritory_CostYTD affecting columns "costytd": ((costytd >= 0.00)) */ + costytd: BigDecimal, + /** Business costs in the territory the previous year. + Constraint CK_SalesTerritory_CostLastYear affecting columns "costlastyear": ((costlastyear >= 0.00)) */ + costlastyear: BigDecimal, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object SalesterritoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesterritoryRow] = new JdbcDecoder[SalesterritoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesterritoryRow) = + columIndex + 9 -> + SalesterritoryRow( + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + countryregioncode = CountryregionId.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + group = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + salesytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 4, rs)._2, + saleslastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 5, rs)._2, + costytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 6, rs)._2, + costlastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 7, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val group = jsonObj.get("group").toRight("Missing field 'group'").flatMap(_.as(JsonDecoder.string)) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val costytd = jsonObj.get("costytd").toRight("Missing field 'costytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val costlastyear = jsonObj.get("costlastyear").toRight("Missing field 'costlastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (territoryid.isRight && name.isRight && countryregioncode.isRight && group.isRight && salesytd.isRight && saleslastyear.isRight && costytd.isRight && costlastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesterritoryRow(territoryid = territoryid.toOption.get, name = name.toOption.get, countryregioncode = countryregioncode.toOption.get, group = group.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, costytd = costytd.toOption.get, costlastyear = costlastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](territoryid, name, countryregioncode, group, salesytd, saleslastyear, costytd, costlastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryRow] = new JsonEncoder[SalesterritoryRow] { + override def unsafeEncode(a: SalesterritoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""group":""") + JsonEncoder.string.unsafeEncode(a.group, indent, out) + out.write(",") + out.write(""""salesytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""costytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costytd, indent, out) + out.write(",") + out.write(""""costlastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.costlastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRowUnsaved.scala new file mode 100644 index 0000000000..5e0be9b690 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryRowUnsaved.scala @@ -0,0 +1,139 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesterritory` which has not been persisted yet */ +case class SalesterritoryRowUnsaved( + /** Sales territory description */ + name: Name, + /** ISO standard country or region code. Foreign key to CountryRegion.CountryRegionCode. + Points to [[person.countryregion.CountryregionRow.countryregioncode]] */ + countryregioncode: CountryregionId, + /** Geographic area to which the sales territory belong. */ + group: /* max 50 chars */ String, + /** Default: nextval('sales.salesterritory_territoryid_seq'::regclass) + Primary key for SalesTerritory records. */ + territoryid: Defaulted[SalesterritoryId] = Defaulted.UseDefault, + /** Default: 0.00 + Sales in the territory year to date. + Constraint CK_SalesTerritory_SalesYTD affecting columns "salesytd": ((salesytd >= 0.00)) */ + salesytd: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Sales in the territory the previous year. + Constraint CK_SalesTerritory_SalesLastYear affecting columns "saleslastyear": ((saleslastyear >= 0.00)) */ + saleslastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Business costs in the territory year to date. + Constraint CK_SalesTerritory_CostYTD affecting columns "costytd": ((costytd >= 0.00)) */ + costytd: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0.00 + Business costs in the territory the previous year. + Constraint CK_SalesTerritory_CostLastYear affecting columns "costlastyear": ((costlastyear >= 0.00)) */ + costlastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(territoryidDefault: => SalesterritoryId, salesytdDefault: => BigDecimal, saleslastyearDefault: => BigDecimal, costytdDefault: => BigDecimal, costlastyearDefault: => BigDecimal, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalesterritoryRow = + SalesterritoryRow( + name = name, + countryregioncode = countryregioncode, + group = group, + territoryid = territoryid match { + case Defaulted.UseDefault => territoryidDefault + case Defaulted.Provided(value) => value + }, + salesytd = salesytd match { + case Defaulted.UseDefault => salesytdDefault + case Defaulted.Provided(value) => value + }, + saleslastyear = saleslastyear match { + case Defaulted.UseDefault => saleslastyearDefault + case Defaulted.Provided(value) => value + }, + costytd = costytd match { + case Defaulted.UseDefault => costytdDefault + case Defaulted.Provided(value) => value + }, + costlastyear = costlastyear match { + case Defaulted.UseDefault => costlastyearDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesterritoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val countryregioncode = jsonObj.get("countryregioncode").toRight("Missing field 'countryregioncode'").flatMap(_.as(CountryregionId.jsonDecoder)) + val group = jsonObj.get("group").toRight("Missing field 'group'").flatMap(_.as(JsonDecoder.string)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(Defaulted.jsonDecoder(SalesterritoryId.jsonDecoder))) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val costytd = jsonObj.get("costytd").toRight("Missing field 'costytd'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val costlastyear = jsonObj.get("costlastyear").toRight("Missing field 'costlastyear'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (name.isRight && countryregioncode.isRight && group.isRight && territoryid.isRight && salesytd.isRight && saleslastyear.isRight && costytd.isRight && costlastyear.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesterritoryRowUnsaved(name = name.toOption.get, countryregioncode = countryregioncode.toOption.get, group = group.toOption.get, territoryid = territoryid.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get, costytd = costytd.toOption.get, costlastyear = costlastyear.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](name, countryregioncode, group, territoryid, salesytd, saleslastyear, costytd, costlastyear, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryRowUnsaved] = new JsonEncoder[SalesterritoryRowUnsaved] { + override def unsafeEncode(a: SalesterritoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""countryregioncode":""") + CountryregionId.jsonEncoder.unsafeEncode(a.countryregioncode, indent, out) + out.write(",") + out.write(""""group":""") + JsonEncoder.string.unsafeEncode(a.group, indent, out) + out.write(",") + out.write(""""territoryid":""") + Defaulted.jsonEncoder(SalesterritoryId.jsonEncoder).unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""salesytd":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.saleslastyear, indent, out) + out.write(",") + out.write(""""costytd":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.costytd, indent, out) + out.write(",") + out.write(""""costlastyear":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.costlastyear, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryStructure.scala new file mode 100644 index 0000000000..9b43b2d769 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritory/SalesterritoryStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.countryregion.CountryregionId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SalesterritoryStructure[Row](val prefix: Option[String], val extract: Row => SalesterritoryRow, val merge: (Row, SalesterritoryRow) => Row) + extends Relation[SalesterritoryFields, SalesterritoryRow, Row] + with SalesterritoryFields[Row] { outer => + + override val territoryid = new IdField[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val countryregioncode = new Field[CountryregionId, Row](prefix, "countryregioncode", None, None)(x => extract(x).countryregioncode, (row, value) => merge(row, extract(row).copy(countryregioncode = value))) + override val group = new Field[/* max 50 chars */ String, Row](prefix, "group", None, None)(x => extract(x).group, (row, value) => merge(row, extract(row).copy(group = value))) + override val salesytd = new Field[BigDecimal, Row](prefix, "salesytd", None, Some("numeric"))(x => extract(x).salesytd, (row, value) => merge(row, extract(row).copy(salesytd = value))) + override val saleslastyear = new Field[BigDecimal, Row](prefix, "saleslastyear", None, Some("numeric"))(x => extract(x).saleslastyear, (row, value) => merge(row, extract(row).copy(saleslastyear = value))) + override val costytd = new Field[BigDecimal, Row](prefix, "costytd", None, Some("numeric"))(x => extract(x).costytd, (row, value) => merge(row, extract(row).copy(costytd = value))) + override val costlastyear = new Field[BigDecimal, Row](prefix, "costlastyear", None, Some("numeric"))(x => extract(x).costlastyear, (row, value) => merge(row, extract(row).copy(costlastyear = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](territoryid, name, countryregioncode, group, salesytd, saleslastyear, costytd, costlastyear, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesterritoryRow, merge: (NewRow, SalesterritoryRow) => NewRow): SalesterritoryStructure[NewRow] = + new SalesterritoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryFields.scala new file mode 100644 index 0000000000..20865db45f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait SalesterritoryhistoryFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val territoryid: IdField[SalesterritoryId, Row] + val startdate: IdField[TypoLocalDateTime, Row] + val enddate: OptField[TypoLocalDateTime, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SalesterritoryhistoryFields extends SalesterritoryhistoryStructure[SalesterritoryhistoryRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryId.scala new file mode 100644 index 0000000000..945403fb27 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryId.scala @@ -0,0 +1,44 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.salesterritoryhistory` */ +case class SalesterritoryhistoryId(businessentityid: BusinessentityId, startdate: TypoLocalDateTime, territoryid: SalesterritoryId) +object SalesterritoryhistoryId { + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryhistoryId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + if (businessentityid.isRight && startdate.isRight && territoryid.isRight) + Right(SalesterritoryhistoryId(businessentityid = businessentityid.toOption.get, startdate = startdate.toOption.get, territoryid = territoryid.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, startdate, territoryid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryhistoryId] = new JsonEncoder[SalesterritoryhistoryId] { + override def unsafeEncode(a: SalesterritoryhistoryId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write("}") + } + } + implicit def ordering(implicit O0: Ordering[TypoLocalDateTime]): Ordering[SalesterritoryhistoryId] = Ordering.by(x => (x.businessentityid, x.startdate, x.territoryid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepo.scala new file mode 100644 index 0000000000..af0c60c08f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SalesterritoryhistoryRepo { + def delete(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] + def insert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] + def insert(unsaved: SalesterritoryhistoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] + def select: SelectBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] + def selectAll: ZStream[ZConnection, Throwable, SalesterritoryhistoryRow] + def selectById(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryhistoryRow]] + def update(row: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] + def upsert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryhistoryRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoImpl.scala new file mode 100644 index 0000000000..a0c3fa11c5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoImpl.scala @@ -0,0 +1,106 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SalesterritoryhistoryRepoImpl extends SalesterritoryhistoryRepo { + override def delete(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.salesterritoryhistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)} AND "territoryid" = ${Segment.paramSegment(compositeId.territoryid)(SalesterritoryId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + DeleteBuilder("sales.salesterritoryhistory", SalesterritoryhistoryFields) + } + override def insert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] = { + sql"""insert into sales.salesterritoryhistory("businessentityid", "territoryid", "startdate", "enddate", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text + """.insertReturning(SalesterritoryhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SalesterritoryhistoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""territoryid"""", sql"${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.salesterritoryhistory default values + returning "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.salesterritoryhistory($names) values ($values) returning "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text""" + } + q.insertReturning(SalesterritoryhistoryRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + SelectBuilderSql("sales.salesterritoryhistory", SalesterritoryhistoryFields, SalesterritoryhistoryRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesterritoryhistoryRow] = { + sql"""select "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text from sales.salesterritoryhistory""".query(SalesterritoryhistoryRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryhistoryRow]] = { + sql"""select "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text from sales.salesterritoryhistory where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)} AND "territoryid" = ${Segment.paramSegment(compositeId.territoryid)(SalesterritoryId.setter)}""".query(SalesterritoryhistoryRow.jdbcDecoder).selectOne + } + override def update(row: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.salesterritoryhistory + set "enddate" = ${Segment.paramSegment(row.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(compositeId.businessentityid)(BusinessentityId.setter)} AND "startdate" = ${Segment.paramSegment(compositeId.startdate)(TypoLocalDateTime.setter)} AND "territoryid" = ${Segment.paramSegment(compositeId.territoryid)(SalesterritoryId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + UpdateBuilder("sales.salesterritoryhistory", SalesterritoryhistoryFields, SalesterritoryhistoryRow.jdbcDecoder) + } + override def upsert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryhistoryRow]] = { + sql"""insert into sales.salesterritoryhistory("businessentityid", "territoryid", "startdate", "enddate", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.territoryid)(SalesterritoryId.setter)}::int4, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.enddate)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid", "startdate", "territoryid") + do update set + "enddate" = EXCLUDED."enddate", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "territoryid", "startdate"::text, "enddate"::text, "rowguid", "modifieddate"::text""".insertReturning(SalesterritoryhistoryRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoMock.scala new file mode 100644 index 0000000000..c42d8139de --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SalesterritoryhistoryRepoMock(toRow: Function1[SalesterritoryhistoryRowUnsaved, SalesterritoryhistoryRow], + map: scala.collection.mutable.Map[SalesterritoryhistoryId, SalesterritoryhistoryRow] = scala.collection.mutable.Map.empty) extends SalesterritoryhistoryRepo { + override def delete(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + DeleteBuilderMock(DeleteParams.empty, SalesterritoryhistoryFields, map) + } + override def insert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: SalesterritoryhistoryRowUnsaved): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + SelectBuilderMock(SalesterritoryhistoryFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SalesterritoryhistoryRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: SalesterritoryhistoryId): ZIO[ZConnection, Throwable, Option[SalesterritoryhistoryRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SalesterritoryhistoryFields, SalesterritoryhistoryRow] = { + UpdateBuilderMock(UpdateParams.empty, SalesterritoryhistoryFields, map) + } + override def upsert(unsaved: SalesterritoryhistoryRow): ZIO[ZConnection, Throwable, UpdateResult[SalesterritoryhistoryRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRow.scala new file mode 100644 index 0000000000..568cc0d110 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRow.scala @@ -0,0 +1,87 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SalesterritoryhistoryRow( + /** Primary key. The sales rep. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Territory identification number. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Primary key. Date the sales representive started work in the territory. + Constraint CK_SalesTerritoryHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Date the sales representative left work in the territory. + Constraint CK_SalesTerritoryHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: SalesterritoryhistoryId = SalesterritoryhistoryId(businessentityid, startdate, territoryid) + } + +object SalesterritoryhistoryRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SalesterritoryhistoryRow] = new JdbcDecoder[SalesterritoryhistoryRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SalesterritoryhistoryRow) = + columIndex + 5 -> + SalesterritoryhistoryRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + territoryid = SalesterritoryId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + enddate = JdbcDecoder.optionDecoder(TypoLocalDateTime.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryhistoryRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && territoryid.isRight && startdate.isRight && enddate.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesterritoryhistoryRow(businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, territoryid, startdate, enddate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryhistoryRow] = new JsonEncoder[SalesterritoryhistoryRow] { + override def unsafeEncode(a: SalesterritoryhistoryRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRowUnsaved.scala new file mode 100644 index 0000000000..5292ec7f01 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryRowUnsaved.scala @@ -0,0 +1,90 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.salesterritoryhistory` which has not been persisted yet */ +case class SalesterritoryhistoryRowUnsaved( + /** Primary key. The sales rep. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Primary key. Territory identification number. Foreign key to SalesTerritory.SalesTerritoryID. + Points to [[salesterritory.SalesterritoryRow.territoryid]] */ + territoryid: SalesterritoryId, + /** Primary key. Date the sales representive started work in the territory. + Constraint CK_SalesTerritoryHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + startdate: TypoLocalDateTime, + /** Date the sales representative left work in the territory. + Constraint CK_SalesTerritoryHistory_EndDate affecting columns "enddate", "startdate": (((enddate >= startdate) OR (enddate IS NULL))) */ + enddate: Option[TypoLocalDateTime], + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SalesterritoryhistoryRow = + SalesterritoryhistoryRow( + businessentityid = businessentityid, + territoryid = territoryid, + startdate = startdate, + enddate = enddate, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SalesterritoryhistoryRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SalesterritoryhistoryRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val territoryid = jsonObj.get("territoryid").toRight("Missing field 'territoryid'").flatMap(_.as(SalesterritoryId.jsonDecoder)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").fold[Either[String, Option[TypoLocalDateTime]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDateTime.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && territoryid.isRight && startdate.isRight && enddate.isRight && rowguid.isRight && modifieddate.isRight) + Right(SalesterritoryhistoryRowUnsaved(businessentityid = businessentityid.toOption.get, territoryid = territoryid.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, territoryid, startdate, enddate, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SalesterritoryhistoryRowUnsaved] = new JsonEncoder[SalesterritoryhistoryRowUnsaved] { + override def unsafeEncode(a: SalesterritoryhistoryRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""territoryid":""") + SalesterritoryId.jsonEncoder.unsafeEncode(a.territoryid, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + JsonEncoder.option(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryStructure.scala new file mode 100644 index 0000000000..a8d599c781 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/salesterritoryhistory/SalesterritoryhistoryStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package salesterritoryhistory + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.sales.salesterritory.SalesterritoryId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SalesterritoryhistoryStructure[Row](val prefix: Option[String], val extract: Row => SalesterritoryhistoryRow, val merge: (Row, SalesterritoryhistoryRow) => Row) + extends Relation[SalesterritoryhistoryFields, SalesterritoryhistoryRow, Row] + with SalesterritoryhistoryFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val territoryid = new IdField[SalesterritoryId, Row](prefix, "territoryid", None, Some("int4"))(x => extract(x).territoryid, (row, value) => merge(row, extract(row).copy(territoryid = value))) + override val startdate = new IdField[TypoLocalDateTime, Row](prefix, "startdate", Some("text"), Some("timestamp"))(x => extract(x).startdate, (row, value) => merge(row, extract(row).copy(startdate = value))) + override val enddate = new OptField[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, territoryid, startdate, enddate, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SalesterritoryhistoryRow, merge: (NewRow, SalesterritoryhistoryRow) => NewRow): SalesterritoryhistoryStructure[NewRow] = + new SalesterritoryhistoryStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemFields.scala new file mode 100644 index 0000000000..74332491f5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait ShoppingcartitemFields[Row] { + val shoppingcartitemid: IdField[ShoppingcartitemId, Row] + val shoppingcartid: Field[/* max 50 chars */ String, Row] + val quantity: Field[Int, Row] + val productid: Field[ProductId, Row] + val datecreated: Field[TypoLocalDateTime, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object ShoppingcartitemFields extends ShoppingcartitemStructure[ShoppingcartitemRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemId.scala new file mode 100644 index 0000000000..3462ae0b7b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +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 `sales.shoppingcartitem` */ +case class ShoppingcartitemId(value: Int) extends AnyVal +object ShoppingcartitemId { + implicit lazy val arraySetter: Setter[Array[ShoppingcartitemId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[ShoppingcartitemId, Int] = Bijection[ShoppingcartitemId, Int](_.value)(ShoppingcartitemId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[ShoppingcartitemId] = JdbcDecoder.intDecoder.map(ShoppingcartitemId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[ShoppingcartitemId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[ShoppingcartitemId] = JsonDecoder.int.map(ShoppingcartitemId.apply) + implicit lazy val jsonEncoder: JsonEncoder[ShoppingcartitemId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[ShoppingcartitemId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[ShoppingcartitemId] = ParameterMetaData.instance[ShoppingcartitemId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[ShoppingcartitemId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepo.scala new file mode 100644 index 0000000000..315073604e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait ShoppingcartitemRepo { + def delete(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[ShoppingcartitemFields, ShoppingcartitemRow] + def insert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, ShoppingcartitemRow] + def insert(unsaved: ShoppingcartitemRowUnsaved): ZIO[ZConnection, Throwable, ShoppingcartitemRow] + def select: SelectBuilder[ShoppingcartitemFields, ShoppingcartitemRow] + def selectAll: ZStream[ZConnection, Throwable, ShoppingcartitemRow] + def selectById(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Option[ShoppingcartitemRow]] + def selectByIds(shoppingcartitemids: Array[ShoppingcartitemId]): ZStream[ZConnection, Throwable, ShoppingcartitemRow] + def update(row: ShoppingcartitemRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[ShoppingcartitemFields, ShoppingcartitemRow] + def upsert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, UpdateResult[ShoppingcartitemRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoImpl.scala new file mode 100644 index 0000000000..a5e8e0f585 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoImpl.scala @@ -0,0 +1,117 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object ShoppingcartitemRepoImpl extends ShoppingcartitemRepo { + override def delete(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.shoppingcartitem where "shoppingcartitemid" = ${Segment.paramSegment(shoppingcartitemid)(ShoppingcartitemId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + DeleteBuilder("sales.shoppingcartitem", ShoppingcartitemFields) + } + override def insert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, ShoppingcartitemRow] = { + sql"""insert into sales.shoppingcartitem("shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated", "modifieddate") + values (${Segment.paramSegment(unsaved.shoppingcartitemid)(ShoppingcartitemId.setter)}::int4, ${Segment.paramSegment(unsaved.shoppingcartid)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.datecreated)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text + """.insertReturning(ShoppingcartitemRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: ShoppingcartitemRowUnsaved): ZIO[ZConnection, Throwable, ShoppingcartitemRow] = { + val fs = List( + Some((sql""""shoppingcartid"""", sql"${Segment.paramSegment(unsaved.shoppingcartid)(Setter.stringSetter)}")), + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + unsaved.shoppingcartitemid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""shoppingcartitemid"""", sql"${Segment.paramSegment(value: ShoppingcartitemId)(ShoppingcartitemId.setter)}::int4")) + }, + unsaved.quantity match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""quantity"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.datecreated match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""datecreated"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.shoppingcartitem default values + returning "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.shoppingcartitem($names) values ($values) returning "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text""" + } + q.insertReturning(ShoppingcartitemRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + SelectBuilderSql("sales.shoppingcartitem", ShoppingcartitemFields, ShoppingcartitemRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, ShoppingcartitemRow] = { + sql"""select "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text from sales.shoppingcartitem""".query(ShoppingcartitemRow.jdbcDecoder).selectStream + } + override def selectById(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Option[ShoppingcartitemRow]] = { + sql"""select "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text from sales.shoppingcartitem where "shoppingcartitemid" = ${Segment.paramSegment(shoppingcartitemid)(ShoppingcartitemId.setter)}""".query(ShoppingcartitemRow.jdbcDecoder).selectOne + } + override def selectByIds(shoppingcartitemids: Array[ShoppingcartitemId]): ZStream[ZConnection, Throwable, ShoppingcartitemRow] = { + sql"""select "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text from sales.shoppingcartitem where "shoppingcartitemid" = ANY(${Segment.paramSegment(shoppingcartitemids)(ShoppingcartitemId.arraySetter)})""".query(ShoppingcartitemRow.jdbcDecoder).selectStream + } + override def update(row: ShoppingcartitemRow): ZIO[ZConnection, Throwable, Boolean] = { + val shoppingcartitemid = row.shoppingcartitemid + sql"""update sales.shoppingcartitem + set "shoppingcartid" = ${Segment.paramSegment(row.shoppingcartid)(Setter.stringSetter)}, + "quantity" = ${Segment.paramSegment(row.quantity)(Setter.intSetter)}::int4, + "productid" = ${Segment.paramSegment(row.productid)(ProductId.setter)}::int4, + "datecreated" = ${Segment.paramSegment(row.datecreated)(TypoLocalDateTime.setter)}::timestamp, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "shoppingcartitemid" = ${Segment.paramSegment(shoppingcartitemid)(ShoppingcartitemId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + UpdateBuilder("sales.shoppingcartitem", ShoppingcartitemFields, ShoppingcartitemRow.jdbcDecoder) + } + override def upsert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, UpdateResult[ShoppingcartitemRow]] = { + sql"""insert into sales.shoppingcartitem("shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.shoppingcartitemid)(ShoppingcartitemId.setter)}::int4, + ${Segment.paramSegment(unsaved.shoppingcartid)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.quantity)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.datecreated)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("shoppingcartitemid") + do update set + "shoppingcartid" = EXCLUDED."shoppingcartid", + "quantity" = EXCLUDED."quantity", + "productid" = EXCLUDED."productid", + "datecreated" = EXCLUDED."datecreated", + "modifieddate" = EXCLUDED."modifieddate" + returning "shoppingcartitemid", "shoppingcartid", "quantity", "productid", "datecreated"::text, "modifieddate"::text""".insertReturning(ShoppingcartitemRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoMock.scala new file mode 100644 index 0000000000..6a9c5c4694 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class ShoppingcartitemRepoMock(toRow: Function1[ShoppingcartitemRowUnsaved, ShoppingcartitemRow], + map: scala.collection.mutable.Map[ShoppingcartitemId, ShoppingcartitemRow] = scala.collection.mutable.Map.empty) extends ShoppingcartitemRepo { + override def delete(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(shoppingcartitemid).isDefined) + } + override def delete: DeleteBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + DeleteBuilderMock(DeleteParams.empty, ShoppingcartitemFields, map) + } + override def insert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, ShoppingcartitemRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.shoppingcartitemid)) + sys.error(s"id ${unsaved.shoppingcartitemid} already exists") + else + map.put(unsaved.shoppingcartitemid, unsaved) + + unsaved + } + } + override def insert(unsaved: ShoppingcartitemRowUnsaved): ZIO[ZConnection, Throwable, ShoppingcartitemRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + SelectBuilderMock(ShoppingcartitemFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, ShoppingcartitemRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(shoppingcartitemid: ShoppingcartitemId): ZIO[ZConnection, Throwable, Option[ShoppingcartitemRow]] = { + ZIO.succeed(map.get(shoppingcartitemid)) + } + override def selectByIds(shoppingcartitemids: Array[ShoppingcartitemId]): ZStream[ZConnection, Throwable, ShoppingcartitemRow] = { + ZStream.fromIterable(shoppingcartitemids.flatMap(map.get)) + } + override def update(row: ShoppingcartitemRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.shoppingcartitemid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.shoppingcartitemid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[ShoppingcartitemFields, ShoppingcartitemRow] = { + UpdateBuilderMock(UpdateParams.empty, ShoppingcartitemFields, map) + } + override def upsert(unsaved: ShoppingcartitemRow): ZIO[ZConnection, Throwable, UpdateResult[ShoppingcartitemRow]] = { + ZIO.succeed { + map.put(unsaved.shoppingcartitemid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRow.scala new file mode 100644 index 0000000000..9e42fef3f7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRow.scala @@ -0,0 +1,82 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class ShoppingcartitemRow( + /** Primary key for ShoppingCartItem records. */ + shoppingcartitemid: ShoppingcartitemId, + /** Shopping cart identification number. */ + shoppingcartid: /* max 50 chars */ String, + /** Product quantity ordered. + Constraint CK_ShoppingCartItem_Quantity affecting columns "quantity": ((quantity >= 1)) */ + quantity: Int, + /** Product ordered. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Date the time the record was created. */ + datecreated: TypoLocalDateTime, + modifieddate: TypoLocalDateTime +) + +object ShoppingcartitemRow { + implicit lazy val jdbcDecoder: JdbcDecoder[ShoppingcartitemRow] = new JdbcDecoder[ShoppingcartitemRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, ShoppingcartitemRow) = + columIndex + 5 -> + ShoppingcartitemRow( + shoppingcartitemid = ShoppingcartitemId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + shoppingcartid = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + quantity = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 2, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + datecreated = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[ShoppingcartitemRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val shoppingcartitemid = jsonObj.get("shoppingcartitemid").toRight("Missing field 'shoppingcartitemid'").flatMap(_.as(ShoppingcartitemId.jsonDecoder)) + val shoppingcartid = jsonObj.get("shoppingcartid").toRight("Missing field 'shoppingcartid'").flatMap(_.as(JsonDecoder.string)) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(JsonDecoder.int)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val datecreated = jsonObj.get("datecreated").toRight("Missing field 'datecreated'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (shoppingcartitemid.isRight && shoppingcartid.isRight && quantity.isRight && productid.isRight && datecreated.isRight && modifieddate.isRight) + Right(ShoppingcartitemRow(shoppingcartitemid = shoppingcartitemid.toOption.get, shoppingcartid = shoppingcartid.toOption.get, quantity = quantity.toOption.get, productid = productid.toOption.get, datecreated = datecreated.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](shoppingcartitemid, shoppingcartid, quantity, productid, datecreated, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShoppingcartitemRow] = new JsonEncoder[ShoppingcartitemRow] { + override def unsafeEncode(a: ShoppingcartitemRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""shoppingcartitemid":""") + ShoppingcartitemId.jsonEncoder.unsafeEncode(a.shoppingcartitemid, indent, out) + out.write(",") + out.write(""""shoppingcartid":""") + JsonEncoder.string.unsafeEncode(a.shoppingcartid, indent, out) + out.write(",") + out.write(""""quantity":""") + JsonEncoder.int.unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""datecreated":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.datecreated, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRowUnsaved.scala new file mode 100644 index 0000000000..d26745ef3c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemRowUnsaved.scala @@ -0,0 +1,95 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.shoppingcartitem` which has not been persisted yet */ +case class ShoppingcartitemRowUnsaved( + /** Shopping cart identification number. */ + shoppingcartid: /* max 50 chars */ String, + /** Product ordered. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Default: nextval('sales.shoppingcartitem_shoppingcartitemid_seq'::regclass) + Primary key for ShoppingCartItem records. */ + shoppingcartitemid: Defaulted[ShoppingcartitemId] = Defaulted.UseDefault, + /** Default: 1 + Product quantity ordered. + Constraint CK_ShoppingCartItem_Quantity affecting columns "quantity": ((quantity >= 1)) */ + quantity: Defaulted[Int] = Defaulted.UseDefault, + /** Default: now() + Date the time the record was created. */ + datecreated: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(shoppingcartitemidDefault: => ShoppingcartitemId, quantityDefault: => Int, datecreatedDefault: => TypoLocalDateTime, modifieddateDefault: => TypoLocalDateTime): ShoppingcartitemRow = + ShoppingcartitemRow( + shoppingcartid = shoppingcartid, + productid = productid, + shoppingcartitemid = shoppingcartitemid match { + case Defaulted.UseDefault => shoppingcartitemidDefault + case Defaulted.Provided(value) => value + }, + quantity = quantity match { + case Defaulted.UseDefault => quantityDefault + case Defaulted.Provided(value) => value + }, + datecreated = datecreated match { + case Defaulted.UseDefault => datecreatedDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object ShoppingcartitemRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[ShoppingcartitemRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val shoppingcartid = jsonObj.get("shoppingcartid").toRight("Missing field 'shoppingcartid'").flatMap(_.as(JsonDecoder.string)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val shoppingcartitemid = jsonObj.get("shoppingcartitemid").toRight("Missing field 'shoppingcartitemid'").flatMap(_.as(Defaulted.jsonDecoder(ShoppingcartitemId.jsonDecoder))) + val quantity = jsonObj.get("quantity").toRight("Missing field 'quantity'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val datecreated = jsonObj.get("datecreated").toRight("Missing field 'datecreated'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (shoppingcartid.isRight && productid.isRight && shoppingcartitemid.isRight && quantity.isRight && datecreated.isRight && modifieddate.isRight) + Right(ShoppingcartitemRowUnsaved(shoppingcartid = shoppingcartid.toOption.get, productid = productid.toOption.get, shoppingcartitemid = shoppingcartitemid.toOption.get, quantity = quantity.toOption.get, datecreated = datecreated.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](shoppingcartid, productid, shoppingcartitemid, quantity, datecreated, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[ShoppingcartitemRowUnsaved] = new JsonEncoder[ShoppingcartitemRowUnsaved] { + override def unsafeEncode(a: ShoppingcartitemRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""shoppingcartid":""") + JsonEncoder.string.unsafeEncode(a.shoppingcartid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""shoppingcartitemid":""") + Defaulted.jsonEncoder(ShoppingcartitemId.jsonEncoder).unsafeEncode(a.shoppingcartitemid, indent, out) + out.write(",") + out.write(""""quantity":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.quantity, indent, out) + out.write(",") + out.write(""""datecreated":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.datecreated, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemStructure.scala new file mode 100644 index 0000000000..d6abe08ac0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/shoppingcartitem/ShoppingcartitemStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package shoppingcartitem + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.production.product.ProductId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class ShoppingcartitemStructure[Row](val prefix: Option[String], val extract: Row => ShoppingcartitemRow, val merge: (Row, ShoppingcartitemRow) => Row) + extends Relation[ShoppingcartitemFields, ShoppingcartitemRow, Row] + with ShoppingcartitemFields[Row] { outer => + + override val shoppingcartitemid = new IdField[ShoppingcartitemId, Row](prefix, "shoppingcartitemid", None, Some("int4"))(x => extract(x).shoppingcartitemid, (row, value) => merge(row, extract(row).copy(shoppingcartitemid = value))) + override val shoppingcartid = new Field[/* max 50 chars */ String, Row](prefix, "shoppingcartid", None, None)(x => extract(x).shoppingcartid, (row, value) => merge(row, extract(row).copy(shoppingcartid = value))) + override val quantity = new Field[Int, Row](prefix, "quantity", None, Some("int4"))(x => extract(x).quantity, (row, value) => merge(row, extract(row).copy(quantity = value))) + override val productid = new Field[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val datecreated = new Field[TypoLocalDateTime, Row](prefix, "datecreated", Some("text"), Some("timestamp"))(x => extract(x).datecreated, (row, value) => merge(row, extract(row).copy(datecreated = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](shoppingcartitemid, shoppingcartid, quantity, productid, datecreated, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => ShoppingcartitemRow, merge: (NewRow, ShoppingcartitemRow) => NewRow): ShoppingcartitemStructure[NewRow] = + new ShoppingcartitemStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferFields.scala new file mode 100644 index 0000000000..4df6434691 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferFields.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait SpecialofferFields[Row] { + val specialofferid: IdField[SpecialofferId, Row] + val description: Field[/* max 255 chars */ String, Row] + val discountpct: Field[BigDecimal, Row] + val `type`: Field[/* max 50 chars */ String, Row] + val category: Field[/* max 50 chars */ String, Row] + val startdate: Field[TypoLocalDateTime, Row] + val enddate: Field[TypoLocalDateTime, Row] + val minqty: Field[Int, Row] + val maxqty: OptField[Int, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SpecialofferFields extends SpecialofferStructure[SpecialofferRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferId.scala new file mode 100644 index 0000000000..cbc824b3ec --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferId.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +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 `sales.specialoffer` */ +case class SpecialofferId(value: Int) extends AnyVal +object SpecialofferId { + implicit lazy val arraySetter: Setter[Array[SpecialofferId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[SpecialofferId, Int] = Bijection[SpecialofferId, Int](_.value)(SpecialofferId.apply) + implicit lazy val jdbcDecoder: JdbcDecoder[SpecialofferId] = JdbcDecoder.intDecoder.map(SpecialofferId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[SpecialofferId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferId] = JsonDecoder.int.map(SpecialofferId.apply) + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferId] = JsonEncoder.int.contramap(_.value) + implicit lazy val ordering: Ordering[SpecialofferId] = Ordering.by(_.value) + implicit lazy val parameterMetadata: ParameterMetaData[SpecialofferId] = ParameterMetaData.instance[SpecialofferId](ParameterMetaData.IntParameterMetaData.sqlType, ParameterMetaData.IntParameterMetaData.jdbcType) + implicit lazy val setter: Setter[SpecialofferId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepo.scala new file mode 100644 index 0000000000..2552e4c7c2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepo.scala @@ -0,0 +1,30 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SpecialofferRepo { + def delete(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SpecialofferFields, SpecialofferRow] + def insert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, SpecialofferRow] + def insert(unsaved: SpecialofferRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferRow] + def select: SelectBuilder[SpecialofferFields, SpecialofferRow] + def selectAll: ZStream[ZConnection, Throwable, SpecialofferRow] + def selectById(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Option[SpecialofferRow]] + def selectByIds(specialofferids: Array[SpecialofferId]): ZStream[ZConnection, Throwable, SpecialofferRow] + def update(row: SpecialofferRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SpecialofferFields, SpecialofferRow] + def upsert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoImpl.scala new file mode 100644 index 0000000000..ce6a2cdca5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoImpl.scala @@ -0,0 +1,140 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SpecialofferRepoImpl extends SpecialofferRepo { + override def delete(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.specialoffer where "specialofferid" = ${Segment.paramSegment(specialofferid)(SpecialofferId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SpecialofferFields, SpecialofferRow] = { + DeleteBuilder("sales.specialoffer", SpecialofferFields) + } + override def insert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, SpecialofferRow] = { + sql"""insert into sales.specialoffer("specialofferid", "description", "discountpct", "type", "category", "startdate", "enddate", "minqty", "maxqty", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.discountpct)(Setter.bigDecimalScalaSetter)}::numeric, ${Segment.paramSegment(unsaved.`type`)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.category)(Setter.stringSetter)}, ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.enddate)(TypoLocalDateTime.setter)}::timestamp, ${Segment.paramSegment(unsaved.minqty)(Setter.intSetter)}::int4, ${Segment.paramSegment(unsaved.maxqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text + """.insertReturning(SpecialofferRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SpecialofferRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferRow] = { + val fs = List( + Some((sql""""description"""", sql"${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}")), + Some((sql""""type"""", sql"${Segment.paramSegment(unsaved.`type`)(Setter.stringSetter)}")), + Some((sql""""category"""", sql"${Segment.paramSegment(unsaved.category)(Setter.stringSetter)}")), + Some((sql""""startdate"""", sql"${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""enddate"""", sql"${Segment.paramSegment(unsaved.enddate)(TypoLocalDateTime.setter)}::timestamp")), + Some((sql""""maxqty"""", sql"${Segment.paramSegment(unsaved.maxqty)(Setter.optionParamSetter(Setter.intSetter))}::int4")), + unsaved.specialofferid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""specialofferid"""", sql"${Segment.paramSegment(value: SpecialofferId)(SpecialofferId.setter)}::int4")) + }, + unsaved.discountpct match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""discountpct"""", sql"${Segment.paramSegment(value: BigDecimal)(Setter.bigDecimalScalaSetter)}::numeric")) + }, + unsaved.minqty match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""minqty"""", sql"${Segment.paramSegment(value: Int)(Setter.intSetter)}::int4")) + }, + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.specialoffer default values + returning "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.specialoffer($names) values ($values) returning "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SpecialofferRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SpecialofferFields, SpecialofferRow] = { + SelectBuilderSql("sales.specialoffer", SpecialofferFields, SpecialofferRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SpecialofferRow] = { + sql"""select "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text from sales.specialoffer""".query(SpecialofferRow.jdbcDecoder).selectStream + } + override def selectById(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Option[SpecialofferRow]] = { + sql"""select "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text from sales.specialoffer where "specialofferid" = ${Segment.paramSegment(specialofferid)(SpecialofferId.setter)}""".query(SpecialofferRow.jdbcDecoder).selectOne + } + override def selectByIds(specialofferids: Array[SpecialofferId]): ZStream[ZConnection, Throwable, SpecialofferRow] = { + sql"""select "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text from sales.specialoffer where "specialofferid" = ANY(${Segment.paramSegment(specialofferids)(SpecialofferId.arraySetter)})""".query(SpecialofferRow.jdbcDecoder).selectStream + } + override def update(row: SpecialofferRow): ZIO[ZConnection, Throwable, Boolean] = { + val specialofferid = row.specialofferid + sql"""update sales.specialoffer + set "description" = ${Segment.paramSegment(row.description)(Setter.stringSetter)}, + "discountpct" = ${Segment.paramSegment(row.discountpct)(Setter.bigDecimalScalaSetter)}::numeric, + "type" = ${Segment.paramSegment(row.`type`)(Setter.stringSetter)}, + "category" = ${Segment.paramSegment(row.category)(Setter.stringSetter)}, + "startdate" = ${Segment.paramSegment(row.startdate)(TypoLocalDateTime.setter)}::timestamp, + "enddate" = ${Segment.paramSegment(row.enddate)(TypoLocalDateTime.setter)}::timestamp, + "minqty" = ${Segment.paramSegment(row.minqty)(Setter.intSetter)}::int4, + "maxqty" = ${Segment.paramSegment(row.maxqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "specialofferid" = ${Segment.paramSegment(specialofferid)(SpecialofferId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SpecialofferFields, SpecialofferRow] = { + UpdateBuilder("sales.specialoffer", SpecialofferFields, SpecialofferRow.jdbcDecoder) + } + override def upsert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferRow]] = { + sql"""insert into sales.specialoffer("specialofferid", "description", "discountpct", "type", "category", "startdate", "enddate", "minqty", "maxqty", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, + ${Segment.paramSegment(unsaved.description)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.discountpct)(Setter.bigDecimalScalaSetter)}::numeric, + ${Segment.paramSegment(unsaved.`type`)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.category)(Setter.stringSetter)}, + ${Segment.paramSegment(unsaved.startdate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.enddate)(TypoLocalDateTime.setter)}::timestamp, + ${Segment.paramSegment(unsaved.minqty)(Setter.intSetter)}::int4, + ${Segment.paramSegment(unsaved.maxqty)(Setter.optionParamSetter(Setter.intSetter))}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("specialofferid") + do update set + "description" = EXCLUDED."description", + "discountpct" = EXCLUDED."discountpct", + "type" = EXCLUDED."type", + "category" = EXCLUDED."category", + "startdate" = EXCLUDED."startdate", + "enddate" = EXCLUDED."enddate", + "minqty" = EXCLUDED."minqty", + "maxqty" = EXCLUDED."maxqty", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "specialofferid", "description", "discountpct", "type", "category", "startdate"::text, "enddate"::text, "minqty", "maxqty", "rowguid", "modifieddate"::text""".insertReturning(SpecialofferRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoMock.scala new file mode 100644 index 0000000000..c35b33aa61 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRepoMock.scala @@ -0,0 +1,80 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SpecialofferRepoMock(toRow: Function1[SpecialofferRowUnsaved, SpecialofferRow], + map: scala.collection.mutable.Map[SpecialofferId, SpecialofferRow] = scala.collection.mutable.Map.empty) extends SpecialofferRepo { + override def delete(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(specialofferid).isDefined) + } + override def delete: DeleteBuilder[SpecialofferFields, SpecialofferRow] = { + DeleteBuilderMock(DeleteParams.empty, SpecialofferFields, map) + } + override def insert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, SpecialofferRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.specialofferid)) + sys.error(s"id ${unsaved.specialofferid} already exists") + else + map.put(unsaved.specialofferid, unsaved) + + unsaved + } + } + override def insert(unsaved: SpecialofferRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SpecialofferFields, SpecialofferRow] = { + SelectBuilderMock(SpecialofferFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SpecialofferRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(specialofferid: SpecialofferId): ZIO[ZConnection, Throwable, Option[SpecialofferRow]] = { + ZIO.succeed(map.get(specialofferid)) + } + override def selectByIds(specialofferids: Array[SpecialofferId]): ZStream[ZConnection, Throwable, SpecialofferRow] = { + ZStream.fromIterable(specialofferids.flatMap(map.get)) + } + override def update(row: SpecialofferRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.specialofferid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.specialofferid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SpecialofferFields, SpecialofferRow] = { + UpdateBuilderMock(UpdateParams.empty, SpecialofferFields, map) + } + override def upsert(unsaved: SpecialofferRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferRow]] = { + ZIO.succeed { + map.put(unsaved.specialofferid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRow.scala new file mode 100644 index 0000000000..f92f419a5d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRow.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SpecialofferRow( + /** Primary key for SpecialOffer records. */ + specialofferid: SpecialofferId, + /** Discount description. */ + description: /* max 255 chars */ String, + /** Discount precentage. + Constraint CK_SpecialOffer_DiscountPct affecting columns "discountpct": ((discountpct >= 0.00)) */ + discountpct: BigDecimal, + /** Discount type category. */ + `type`: /* max 50 chars */ String, + /** Group the discount applies to such as Reseller or Customer. */ + category: /* max 50 chars */ String, + /** Discount start date. + Constraint CK_SpecialOffer_EndDate affecting columns "enddate", "startdate": ((enddate >= startdate)) */ + startdate: TypoLocalDateTime, + /** Discount end date. + Constraint CK_SpecialOffer_EndDate affecting columns "enddate", "startdate": ((enddate >= startdate)) */ + enddate: TypoLocalDateTime, + /** Minimum discount percent allowed. + Constraint CK_SpecialOffer_MinQty affecting columns "minqty": ((minqty >= 0)) */ + minqty: Int, + /** Maximum discount percent allowed. + Constraint CK_SpecialOffer_MaxQty affecting columns "maxqty": ((maxqty >= 0)) */ + maxqty: Option[Int], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object SpecialofferRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SpecialofferRow] = new JdbcDecoder[SpecialofferRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SpecialofferRow) = + columIndex + 10 -> + SpecialofferRow( + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + description = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 1, rs)._2, + discountpct = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 2, rs)._2, + `type` = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + category = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 4, rs)._2, + startdate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2, + enddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + minqty = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 7, rs)._2, + maxqty = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 9, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val discountpct = jsonObj.get("discountpct").toRight("Missing field 'discountpct'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val `type` = jsonObj.get("type").toRight("Missing field 'type'").flatMap(_.as(JsonDecoder.string)) + val category = jsonObj.get("category").toRight("Missing field 'category'").flatMap(_.as(JsonDecoder.string)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").toRight("Missing field 'enddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val minqty = jsonObj.get("minqty").toRight("Missing field 'minqty'").flatMap(_.as(JsonDecoder.int)) + val maxqty = jsonObj.get("maxqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (specialofferid.isRight && description.isRight && discountpct.isRight && `type`.isRight && category.isRight && startdate.isRight && enddate.isRight && minqty.isRight && maxqty.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpecialofferRow(specialofferid = specialofferid.toOption.get, description = description.toOption.get, discountpct = discountpct.toOption.get, `type` = `type`.toOption.get, category = category.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, minqty = minqty.toOption.get, maxqty = maxqty.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](specialofferid, description, discountpct, `type`, category, startdate, enddate, minqty, maxqty, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferRow] = new JsonEncoder[SpecialofferRow] { + override def unsafeEncode(a: SpecialofferRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""discountpct":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.discountpct, indent, out) + out.write(",") + out.write(""""type":""") + JsonEncoder.string.unsafeEncode(a.`type`, indent, out) + out.write(",") + out.write(""""category":""") + JsonEncoder.string.unsafeEncode(a.category, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""minqty":""") + JsonEncoder.int.unsafeEncode(a.minqty, indent, out) + out.write(",") + out.write(""""maxqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maxqty, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRowUnsaved.scala new file mode 100644 index 0000000000..6ca8c86f6b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferRowUnsaved.scala @@ -0,0 +1,136 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.specialoffer` which has not been persisted yet */ +case class SpecialofferRowUnsaved( + /** Discount description. */ + description: /* max 255 chars */ String, + /** Discount type category. */ + `type`: /* max 50 chars */ String, + /** Group the discount applies to such as Reseller or Customer. */ + category: /* max 50 chars */ String, + /** Discount start date. + Constraint CK_SpecialOffer_EndDate affecting columns "enddate", "startdate": ((enddate >= startdate)) */ + startdate: TypoLocalDateTime, + /** Discount end date. + Constraint CK_SpecialOffer_EndDate affecting columns "enddate", "startdate": ((enddate >= startdate)) */ + enddate: TypoLocalDateTime, + /** Maximum discount percent allowed. + Constraint CK_SpecialOffer_MaxQty affecting columns "maxqty": ((maxqty >= 0)) */ + maxqty: Option[Int], + /** Default: nextval('sales.specialoffer_specialofferid_seq'::regclass) + Primary key for SpecialOffer records. */ + specialofferid: Defaulted[SpecialofferId] = Defaulted.UseDefault, + /** Default: 0.00 + Discount precentage. + Constraint CK_SpecialOffer_DiscountPct affecting columns "discountpct": ((discountpct >= 0.00)) */ + discountpct: Defaulted[BigDecimal] = Defaulted.UseDefault, + /** Default: 0 + Minimum discount percent allowed. + Constraint CK_SpecialOffer_MinQty affecting columns "minqty": ((minqty >= 0)) */ + minqty: Defaulted[Int] = Defaulted.UseDefault, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(specialofferidDefault: => SpecialofferId, discountpctDefault: => BigDecimal, minqtyDefault: => Int, rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SpecialofferRow = + SpecialofferRow( + description = description, + `type` = `type`, + category = category, + startdate = startdate, + enddate = enddate, + maxqty = maxqty, + specialofferid = specialofferid match { + case Defaulted.UseDefault => specialofferidDefault + case Defaulted.Provided(value) => value + }, + discountpct = discountpct match { + case Defaulted.UseDefault => discountpctDefault + case Defaulted.Provided(value) => value + }, + minqty = minqty match { + case Defaulted.UseDefault => minqtyDefault + case Defaulted.Provided(value) => value + }, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SpecialofferRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val description = jsonObj.get("description").toRight("Missing field 'description'").flatMap(_.as(JsonDecoder.string)) + val `type` = jsonObj.get("type").toRight("Missing field 'type'").flatMap(_.as(JsonDecoder.string)) + val category = jsonObj.get("category").toRight("Missing field 'category'").flatMap(_.as(JsonDecoder.string)) + val startdate = jsonObj.get("startdate").toRight("Missing field 'startdate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val enddate = jsonObj.get("enddate").toRight("Missing field 'enddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + val maxqty = jsonObj.get("maxqty").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(Defaulted.jsonDecoder(SpecialofferId.jsonDecoder))) + val discountpct = jsonObj.get("discountpct").toRight("Missing field 'discountpct'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.scalaBigDecimal))) + val minqty = jsonObj.get("minqty").toRight("Missing field 'minqty'").flatMap(_.as(Defaulted.jsonDecoder(JsonDecoder.int))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (description.isRight && `type`.isRight && category.isRight && startdate.isRight && enddate.isRight && maxqty.isRight && specialofferid.isRight && discountpct.isRight && minqty.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpecialofferRowUnsaved(description = description.toOption.get, `type` = `type`.toOption.get, category = category.toOption.get, startdate = startdate.toOption.get, enddate = enddate.toOption.get, maxqty = maxqty.toOption.get, specialofferid = specialofferid.toOption.get, discountpct = discountpct.toOption.get, minqty = minqty.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](description, `type`, category, startdate, enddate, maxqty, specialofferid, discountpct, minqty, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferRowUnsaved] = new JsonEncoder[SpecialofferRowUnsaved] { + override def unsafeEncode(a: SpecialofferRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""description":""") + JsonEncoder.string.unsafeEncode(a.description, indent, out) + out.write(",") + out.write(""""type":""") + JsonEncoder.string.unsafeEncode(a.`type`, indent, out) + out.write(",") + out.write(""""category":""") + JsonEncoder.string.unsafeEncode(a.category, indent, out) + out.write(",") + out.write(""""startdate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.startdate, indent, out) + out.write(",") + out.write(""""enddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.enddate, indent, out) + out.write(",") + out.write(""""maxqty":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.maxqty, indent, out) + out.write(",") + out.write(""""specialofferid":""") + Defaulted.jsonEncoder(SpecialofferId.jsonEncoder).unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""discountpct":""") + Defaulted.jsonEncoder(JsonEncoder.scalaBigDecimal).unsafeEncode(a.discountpct, indent, out) + out.write(",") + out.write(""""minqty":""") + Defaulted.jsonEncoder(JsonEncoder.int).unsafeEncode(a.minqty, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferStructure.scala new file mode 100644 index 0000000000..d642590d55 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialoffer/SpecialofferStructure.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialoffer + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class SpecialofferStructure[Row](val prefix: Option[String], val extract: Row => SpecialofferRow, val merge: (Row, SpecialofferRow) => Row) + extends Relation[SpecialofferFields, SpecialofferRow, Row] + with SpecialofferFields[Row] { outer => + + override val specialofferid = new IdField[SpecialofferId, Row](prefix, "specialofferid", None, Some("int4"))(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val description = new Field[/* max 255 chars */ String, Row](prefix, "description", None, None)(x => extract(x).description, (row, value) => merge(row, extract(row).copy(description = value))) + override val discountpct = new Field[BigDecimal, Row](prefix, "discountpct", None, Some("numeric"))(x => extract(x).discountpct, (row, value) => merge(row, extract(row).copy(discountpct = value))) + override val `type` = new Field[/* max 50 chars */ String, Row](prefix, "type", None, None)(x => extract(x).`type`, (row, value) => merge(row, extract(row).copy(`type` = value))) + override val category = new Field[/* max 50 chars */ String, Row](prefix, "category", None, None)(x => extract(x).category, (row, value) => merge(row, extract(row).copy(category = 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))) + override val enddate = new Field[TypoLocalDateTime, Row](prefix, "enddate", Some("text"), Some("timestamp"))(x => extract(x).enddate, (row, value) => merge(row, extract(row).copy(enddate = value))) + override val minqty = new Field[Int, Row](prefix, "minqty", None, Some("int4"))(x => extract(x).minqty, (row, value) => merge(row, extract(row).copy(minqty = value))) + override val maxqty = new OptField[Int, Row](prefix, "maxqty", None, Some("int4"))(x => extract(x).maxqty, (row, value) => merge(row, extract(row).copy(maxqty = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specialofferid, description, discountpct, `type`, category, startdate, enddate, minqty, maxqty, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SpecialofferRow, merge: (NewRow, SpecialofferRow) => NewRow): SpecialofferStructure[NewRow] = + new SpecialofferStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductFields.scala new file mode 100644 index 0000000000..76e69fd6ee --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField + +trait SpecialofferproductFields[Row] { + val specialofferid: IdField[SpecialofferId, Row] + val productid: IdField[ProductId, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object SpecialofferproductFields extends SpecialofferproductStructure[SpecialofferproductRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductId.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductId.scala new file mode 100644 index 0000000000..fc43205ae7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductId.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** Type for the composite primary key of table `sales.specialofferproduct` */ +case class SpecialofferproductId(specialofferid: SpecialofferId, productid: ProductId) +object SpecialofferproductId { + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferproductId] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + if (specialofferid.isRight && productid.isRight) + Right(SpecialofferproductId(specialofferid = specialofferid.toOption.get, productid = productid.toOption.get)) + else Left(List[Either[String, Any]](specialofferid, productid).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferproductId] = new JsonEncoder[SpecialofferproductId] { + override def unsafeEncode(a: SpecialofferproductId, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write("}") + } + } + implicit lazy val ordering: Ordering[SpecialofferproductId] = Ordering.by(x => (x.specialofferid, x.productid)) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepo.scala new file mode 100644 index 0000000000..ab1ecbeaad --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepo.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait SpecialofferproductRepo { + def delete(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[SpecialofferproductFields, SpecialofferproductRow] + def insert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, SpecialofferproductRow] + def insert(unsaved: SpecialofferproductRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferproductRow] + def select: SelectBuilder[SpecialofferproductFields, SpecialofferproductRow] + def selectAll: ZStream[ZConnection, Throwable, SpecialofferproductRow] + def selectById(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Option[SpecialofferproductRow]] + def update(row: SpecialofferproductRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[SpecialofferproductFields, SpecialofferproductRow] + def upsert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferproductRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoImpl.scala new file mode 100644 index 0000000000..cf30c437f0 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoImpl.scala @@ -0,0 +1,99 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object SpecialofferproductRepoImpl extends SpecialofferproductRepo { + override def delete(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.specialofferproduct where "specialofferid" = ${Segment.paramSegment(compositeId.specialofferid)(SpecialofferId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + DeleteBuilder("sales.specialofferproduct", SpecialofferproductFields) + } + override def insert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, SpecialofferproductRow] = { + sql"""insert into sales.specialofferproduct("specialofferid", "productid", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "specialofferid", "productid", "rowguid", "modifieddate"::text + """.insertReturning(SpecialofferproductRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: SpecialofferproductRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferproductRow] = { + val fs = List( + Some((sql""""specialofferid"""", sql"${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4")), + Some((sql""""productid"""", sql"${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.specialofferproduct default values + returning "specialofferid", "productid", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.specialofferproduct($names) values ($values) returning "specialofferid", "productid", "rowguid", "modifieddate"::text""" + } + q.insertReturning(SpecialofferproductRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + SelectBuilderSql("sales.specialofferproduct", SpecialofferproductFields, SpecialofferproductRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, SpecialofferproductRow] = { + sql"""select "specialofferid", "productid", "rowguid", "modifieddate"::text from sales.specialofferproduct""".query(SpecialofferproductRow.jdbcDecoder).selectStream + } + override def selectById(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Option[SpecialofferproductRow]] = { + sql"""select "specialofferid", "productid", "rowguid", "modifieddate"::text from sales.specialofferproduct where "specialofferid" = ${Segment.paramSegment(compositeId.specialofferid)(SpecialofferId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)}""".query(SpecialofferproductRow.jdbcDecoder).selectOne + } + override def update(row: SpecialofferproductRow): ZIO[ZConnection, Throwable, Boolean] = { + val compositeId = row.compositeId + sql"""update sales.specialofferproduct + set "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "specialofferid" = ${Segment.paramSegment(compositeId.specialofferid)(SpecialofferId.setter)} AND "productid" = ${Segment.paramSegment(compositeId.productid)(ProductId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + UpdateBuilder("sales.specialofferproduct", SpecialofferproductFields, SpecialofferproductRow.jdbcDecoder) + } + override def upsert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferproductRow]] = { + sql"""insert into sales.specialofferproduct("specialofferid", "productid", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.specialofferid)(SpecialofferId.setter)}::int4, + ${Segment.paramSegment(unsaved.productid)(ProductId.setter)}::int4, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("specialofferid", "productid") + do update set + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "specialofferid", "productid", "rowguid", "modifieddate"::text""".insertReturning(SpecialofferproductRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoMock.scala new file mode 100644 index 0000000000..871dcde5d5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRepoMock.scala @@ -0,0 +1,77 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class SpecialofferproductRepoMock(toRow: Function1[SpecialofferproductRowUnsaved, SpecialofferproductRow], + map: scala.collection.mutable.Map[SpecialofferproductId, SpecialofferproductRow] = scala.collection.mutable.Map.empty) extends SpecialofferproductRepo { + override def delete(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(compositeId).isDefined) + } + override def delete: DeleteBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + DeleteBuilderMock(DeleteParams.empty, SpecialofferproductFields, map) + } + override def insert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, SpecialofferproductRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.compositeId)) + sys.error(s"id ${unsaved.compositeId} already exists") + else + map.put(unsaved.compositeId, unsaved) + + unsaved + } + } + override def insert(unsaved: SpecialofferproductRowUnsaved): ZIO[ZConnection, Throwable, SpecialofferproductRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + SelectBuilderMock(SpecialofferproductFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, SpecialofferproductRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(compositeId: SpecialofferproductId): ZIO[ZConnection, Throwable, Option[SpecialofferproductRow]] = { + ZIO.succeed(map.get(compositeId)) + } + override def update(row: SpecialofferproductRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.compositeId) match { + case Some(`row`) => false + case Some(_) => + map.put(row.compositeId, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[SpecialofferproductFields, SpecialofferproductRow] = { + UpdateBuilderMock(UpdateParams.empty, SpecialofferproductFields, map) + } + override def upsert(unsaved: SpecialofferproductRow): ZIO[ZConnection, Throwable, UpdateResult[SpecialofferproductRow]] = { + ZIO.succeed { + map.put(unsaved.compositeId, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRow.scala new file mode 100644 index 0000000000..0796b5bdb8 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRow.scala @@ -0,0 +1,71 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class SpecialofferproductRow( + /** Primary key for SpecialOfferProduct records. + Points to [[specialoffer.SpecialofferRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +){ + val compositeId: SpecialofferproductId = SpecialofferproductId(specialofferid, productid) + } + +object SpecialofferproductRow { + implicit lazy val jdbcDecoder: JdbcDecoder[SpecialofferproductRow] = new JdbcDecoder[SpecialofferproductRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, SpecialofferproductRow) = + columIndex + 3 -> + SpecialofferproductRow( + specialofferid = SpecialofferId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + productid = ProductId.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferproductRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (specialofferid.isRight && productid.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpecialofferproductRow(specialofferid = specialofferid.toOption.get, productid = productid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](specialofferid, productid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferproductRow] = new JsonEncoder[SpecialofferproductRow] { + override def unsafeEncode(a: SpecialofferproductRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRowUnsaved.scala new file mode 100644 index 0000000000..be2635f45e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductRowUnsaved.scala @@ -0,0 +1,74 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.specialofferproduct` which has not been persisted yet */ +case class SpecialofferproductRowUnsaved( + /** Primary key for SpecialOfferProduct records. + Points to [[specialoffer.SpecialofferRow.specialofferid]] */ + specialofferid: SpecialofferId, + /** Product identification number. Foreign key to Product.ProductID. + Points to [[production.product.ProductRow.productid]] */ + productid: ProductId, + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): SpecialofferproductRow = + SpecialofferproductRow( + specialofferid = specialofferid, + productid = productid, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object SpecialofferproductRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[SpecialofferproductRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val specialofferid = jsonObj.get("specialofferid").toRight("Missing field 'specialofferid'").flatMap(_.as(SpecialofferId.jsonDecoder)) + val productid = jsonObj.get("productid").toRight("Missing field 'productid'").flatMap(_.as(ProductId.jsonDecoder)) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (specialofferid.isRight && productid.isRight && rowguid.isRight && modifieddate.isRight) + Right(SpecialofferproductRowUnsaved(specialofferid = specialofferid.toOption.get, productid = productid.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](specialofferid, productid, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[SpecialofferproductRowUnsaved] = new JsonEncoder[SpecialofferproductRowUnsaved] { + override def unsafeEncode(a: SpecialofferproductRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""specialofferid":""") + SpecialofferId.jsonEncoder.unsafeEncode(a.specialofferid, indent, out) + out.write(",") + out.write(""""productid":""") + ProductId.jsonEncoder.unsafeEncode(a.productid, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductStructure.scala new file mode 100644 index 0000000000..4acd01c6bb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/specialofferproduct/SpecialofferproductStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package specialofferproduct + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.production.product.ProductId +import adventureworks.sales.specialoffer.SpecialofferId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.Structure.Relation + +class SpecialofferproductStructure[Row](val prefix: Option[String], val extract: Row => SpecialofferproductRow, val merge: (Row, SpecialofferproductRow) => Row) + extends Relation[SpecialofferproductFields, SpecialofferproductRow, Row] + with SpecialofferproductFields[Row] { outer => + + override val specialofferid = new IdField[SpecialofferId, Row](prefix, "specialofferid", None, Some("int4"))(x => extract(x).specialofferid, (row, value) => merge(row, extract(row).copy(specialofferid = value))) + override val productid = new IdField[ProductId, Row](prefix, "productid", None, Some("int4"))(x => extract(x).productid, (row, value) => merge(row, extract(row).copy(productid = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](specialofferid, productid, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => SpecialofferproductRow, merge: (NewRow, SpecialofferproductRow) => NewRow): SpecialofferproductStructure[NewRow] = + new SpecialofferproductStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreFields.scala new file mode 100644 index 0000000000..f5e0398065 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreFields.scala @@ -0,0 +1,28 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField + +trait StoreFields[Row] { + val businessentityid: IdField[BusinessentityId, Row] + val name: Field[Name, Row] + val salespersonid: OptField[BusinessentityId, Row] + val demographics: OptField[TypoXml, Row] + val rowguid: Field[TypoUUID, Row] + val modifieddate: Field[TypoLocalDateTime, Row] +} +object StoreFields extends StoreStructure[StoreRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepo.scala new file mode 100644 index 0000000000..acab0de1cf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepo.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait StoreRepo { + def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] + def delete: DeleteBuilder[StoreFields, StoreRow] + def insert(unsaved: StoreRow): ZIO[ZConnection, Throwable, StoreRow] + def insert(unsaved: StoreRowUnsaved): ZIO[ZConnection, Throwable, StoreRow] + def select: SelectBuilder[StoreFields, StoreRow] + def selectAll: ZStream[ZConnection, Throwable, StoreRow] + def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[StoreRow]] + def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, StoreRow] + def update(row: StoreRow): ZIO[ZConnection, Throwable, Boolean] + def update: UpdateBuilder[StoreFields, StoreRow] + def upsert(unsaved: StoreRow): ZIO[ZConnection, Throwable, UpdateResult[StoreRow]] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoImpl.scala new file mode 100644 index 0000000000..b4f1056184 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoImpl.scala @@ -0,0 +1,114 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.DeleteBuilder +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import typo.dsl.UpdateBuilder +import zio.ZIO +import zio.jdbc.SqlFragment +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object StoreRepoImpl extends StoreRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + sql"""delete from sales.store where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".delete.map(_ > 0) + } + override def delete: DeleteBuilder[StoreFields, StoreRow] = { + DeleteBuilder("sales.store", StoreFields) + } + override def insert(unsaved: StoreRow): ZIO[ZConnection, Throwable, StoreRow] = { + sql"""insert into sales.store("businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate") + values (${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, ${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, ${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp) + returning "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text + """.insertReturning(StoreRow.jdbcDecoder).map(_.updatedKeys.head) + } + override def insert(unsaved: StoreRowUnsaved): ZIO[ZConnection, Throwable, StoreRow] = { + val fs = List( + Some((sql""""businessentityid"""", sql"${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4")), + Some((sql""""name"""", sql"${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar")), + Some((sql""""salespersonid"""", sql"${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4")), + Some((sql""""demographics"""", sql"${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml")), + unsaved.rowguid match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""rowguid"""", sql"${Segment.paramSegment(value: TypoUUID)(TypoUUID.setter)}::uuid")) + }, + unsaved.modifieddate match { + case Defaulted.UseDefault => None + case Defaulted.Provided(value) => Some((sql""""modifieddate"""", sql"${Segment.paramSegment(value: TypoLocalDateTime)(TypoLocalDateTime.setter)}::timestamp")) + } + ).flatten + + val q = if (fs.isEmpty) { + sql"""insert into sales.store default values + returning "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text + """ + } else { + val names = fs.map { case (n, _) => n }.mkFragment(SqlFragment(", ")) + val values = fs.map { case (_, f) => f }.mkFragment(SqlFragment(", ")) + sql"""insert into sales.store($names) values ($values) returning "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text""" + } + q.insertReturning(StoreRow.jdbcDecoder).map(_.updatedKeys.head) + + } + override def select: SelectBuilder[StoreFields, StoreRow] = { + SelectBuilderSql("sales.store", StoreFields, StoreRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, StoreRow] = { + sql"""select "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text from sales.store""".query(StoreRow.jdbcDecoder).selectStream + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[StoreRow]] = { + sql"""select "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text from sales.store where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".query(StoreRow.jdbcDecoder).selectOne + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, StoreRow] = { + sql"""select "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text from sales.store where "businessentityid" = ANY(${Segment.paramSegment(businessentityids)(BusinessentityId.arraySetter)})""".query(StoreRow.jdbcDecoder).selectStream + } + override def update(row: StoreRow): ZIO[ZConnection, Throwable, Boolean] = { + val businessentityid = row.businessentityid + sql"""update sales.store + set "name" = ${Segment.paramSegment(row.name)(Name.setter)}::varchar, + "salespersonid" = ${Segment.paramSegment(row.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + "demographics" = ${Segment.paramSegment(row.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, + "rowguid" = ${Segment.paramSegment(row.rowguid)(TypoUUID.setter)}::uuid, + "modifieddate" = ${Segment.paramSegment(row.modifieddate)(TypoLocalDateTime.setter)}::timestamp + where "businessentityid" = ${Segment.paramSegment(businessentityid)(BusinessentityId.setter)}""".update.map(_ > 0) + } + override def update: UpdateBuilder[StoreFields, StoreRow] = { + UpdateBuilder("sales.store", StoreFields, StoreRow.jdbcDecoder) + } + override def upsert(unsaved: StoreRow): ZIO[ZConnection, Throwable, UpdateResult[StoreRow]] = { + sql"""insert into sales.store("businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate") + values ( + ${Segment.paramSegment(unsaved.businessentityid)(BusinessentityId.setter)}::int4, + ${Segment.paramSegment(unsaved.name)(Name.setter)}::varchar, + ${Segment.paramSegment(unsaved.salespersonid)(Setter.optionParamSetter(BusinessentityId.setter))}::int4, + ${Segment.paramSegment(unsaved.demographics)(Setter.optionParamSetter(TypoXml.setter))}::xml, + ${Segment.paramSegment(unsaved.rowguid)(TypoUUID.setter)}::uuid, + ${Segment.paramSegment(unsaved.modifieddate)(TypoLocalDateTime.setter)}::timestamp + ) + on conflict ("businessentityid") + do update set + "name" = EXCLUDED."name", + "salespersonid" = EXCLUDED."salespersonid", + "demographics" = EXCLUDED."demographics", + "rowguid" = EXCLUDED."rowguid", + "modifieddate" = EXCLUDED."modifieddate" + returning "businessentityid", "name", "salespersonid", "demographics", "rowguid", "modifieddate"::text""".insertReturning(StoreRow.jdbcDecoder) + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoMock.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoMock.scala new file mode 100644 index 0000000000..d9680db44f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRepoMock.scala @@ -0,0 +1,81 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.person.businessentity.BusinessentityId +import scala.annotation.nowarn +import typo.dsl.DeleteBuilder +import typo.dsl.DeleteBuilder.DeleteBuilderMock +import typo.dsl.DeleteParams +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderMock +import typo.dsl.SelectParams +import typo.dsl.UpdateBuilder +import typo.dsl.UpdateBuilder.UpdateBuilderMock +import typo.dsl.UpdateParams +import zio.Chunk +import zio.ZIO +import zio.jdbc.UpdateResult +import zio.jdbc.ZConnection +import zio.stream.ZStream + +class StoreRepoMock(toRow: Function1[StoreRowUnsaved, StoreRow], + map: scala.collection.mutable.Map[BusinessentityId, StoreRow] = scala.collection.mutable.Map.empty) extends StoreRepo { + override def delete(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed(map.remove(businessentityid).isDefined) + } + override def delete: DeleteBuilder[StoreFields, StoreRow] = { + DeleteBuilderMock(DeleteParams.empty, StoreFields, map) + } + override def insert(unsaved: StoreRow): ZIO[ZConnection, Throwable, StoreRow] = { + ZIO.succeed { + val _ = + if (map.contains(unsaved.businessentityid)) + sys.error(s"id ${unsaved.businessentityid} already exists") + else + map.put(unsaved.businessentityid, unsaved) + + unsaved + } + } + override def insert(unsaved: StoreRowUnsaved): ZIO[ZConnection, Throwable, StoreRow] = { + insert(toRow(unsaved)) + } + override def select: SelectBuilder[StoreFields, StoreRow] = { + SelectBuilderMock(StoreFields, ZIO.succeed(Chunk.fromIterable(map.values)), SelectParams.empty) + } + override def selectAll: ZStream[ZConnection, Throwable, StoreRow] = { + ZStream.fromIterable(map.values) + } + override def selectById(businessentityid: BusinessentityId): ZIO[ZConnection, Throwable, Option[StoreRow]] = { + ZIO.succeed(map.get(businessentityid)) + } + override def selectByIds(businessentityids: Array[BusinessentityId]): ZStream[ZConnection, Throwable, StoreRow] = { + ZStream.fromIterable(businessentityids.flatMap(map.get)) + } + override def update(row: StoreRow): ZIO[ZConnection, Throwable, Boolean] = { + ZIO.succeed { + map.get(row.businessentityid) match { + case Some(`row`) => false + case Some(_) => + map.put(row.businessentityid, row): @nowarn + true + case None => false + } + } + } + override def update: UpdateBuilder[StoreFields, StoreRow] = { + UpdateBuilderMock(UpdateParams.empty, StoreFields, map) + } + override def upsert(unsaved: StoreRow): ZIO[ZConnection, Throwable, UpdateResult[StoreRow]] = { + ZIO.succeed { + map.put(unsaved.businessentityid, unsaved): @nowarn + UpdateResult(1, Chunk.single(unsaved)) + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRow.scala new file mode 100644 index 0000000000..4e5a6a35ac --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRow.scala @@ -0,0 +1,84 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class StoreRow( + /** Primary key. Foreign key to Customer.BusinessEntityID. + Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Name of the store. */ + name: Name, + /** ID of the sales person assigned to the customer. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + salespersonid: Option[BusinessentityId], + /** Demographic informationg about the store such as the number of employees, annual sales and store type. */ + demographics: Option[TypoXml], + rowguid: TypoUUID, + modifieddate: TypoLocalDateTime +) + +object StoreRow { + implicit lazy val jdbcDecoder: JdbcDecoder[StoreRow] = new JdbcDecoder[StoreRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, StoreRow) = + columIndex + 5 -> + StoreRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + salespersonid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + demographics = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + rowguid = TypoUUID.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[StoreRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(TypoUUID.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (businessentityid.isRight && name.isRight && salespersonid.isRight && demographics.isRight && rowguid.isRight && modifieddate.isRight) + Right(StoreRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, salespersonid = salespersonid.toOption.get, demographics = demographics.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, salespersonid, demographics, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[StoreRow] = new JsonEncoder[StoreRow] { + override def unsafeEncode(a: StoreRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""rowguid":""") + TypoUUID.jsonEncoder.unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRowUnsaved.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRowUnsaved.scala new file mode 100644 index 0000000000..40b7f8b646 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreRowUnsaved.scala @@ -0,0 +1,89 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +/** This class corresponds to a row in table `sales.store` which has not been persisted yet */ +case class StoreRowUnsaved( + /** Primary key. Foreign key to Customer.BusinessEntityID. + Points to [[person.businessentity.BusinessentityRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Name of the store. */ + name: Name, + /** ID of the sales person assigned to the customer. Foreign key to SalesPerson.BusinessEntityID. + Points to [[salesperson.SalespersonRow.businessentityid]] */ + salespersonid: Option[BusinessentityId], + /** Demographic informationg about the store such as the number of employees, annual sales and store type. */ + demographics: Option[TypoXml], + /** Default: uuid_generate_v1() */ + rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, + /** Default: now() */ + modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault +) { + def toRow(rowguidDefault: => TypoUUID, modifieddateDefault: => TypoLocalDateTime): StoreRow = + StoreRow( + businessentityid = businessentityid, + name = name, + salespersonid = salespersonid, + demographics = demographics, + rowguid = rowguid match { + case Defaulted.UseDefault => rowguidDefault + case Defaulted.Provided(value) => value + }, + modifieddate = modifieddate match { + case Defaulted.UseDefault => modifieddateDefault + case Defaulted.Provided(value) => value + } + ) +} +object StoreRowUnsaved { + implicit lazy val jsonDecoder: JsonDecoder[StoreRowUnsaved] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + val rowguid = jsonObj.get("rowguid").toRight("Missing field 'rowguid'").flatMap(_.as(Defaulted.jsonDecoder(TypoUUID.jsonDecoder))) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(Defaulted.jsonDecoder(TypoLocalDateTime.jsonDecoder))) + if (businessentityid.isRight && name.isRight && salespersonid.isRight && demographics.isRight && rowguid.isRight && modifieddate.isRight) + Right(StoreRowUnsaved(businessentityid = businessentityid.toOption.get, name = name.toOption.get, salespersonid = salespersonid.toOption.get, demographics = demographics.toOption.get, rowguid = rowguid.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, salespersonid, demographics, rowguid, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[StoreRowUnsaved] = new JsonEncoder[StoreRowUnsaved] { + override def unsafeEncode(a: StoreRowUnsaved, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write(",") + out.write(""""rowguid":""") + Defaulted.jsonEncoder(TypoUUID.jsonEncoder).unsafeEncode(a.rowguid, indent, out) + out.write(",") + out.write(""""modifieddate":""") + Defaulted.jsonEncoder(TypoLocalDateTime.jsonEncoder).unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreStructure.scala new file mode 100644 index 0000000000..45fddb7785 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/store/StoreStructure.scala @@ -0,0 +1,37 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package store + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.IdField +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class StoreStructure[Row](val prefix: Option[String], val extract: Row => StoreRow, val merge: (Row, StoreRow) => Row) + extends Relation[StoreFields, StoreRow, Row] + with StoreFields[Row] { outer => + + override val businessentityid = new IdField[BusinessentityId, Row](prefix, "businessentityid", None, Some("int4"))(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, Some("varchar"))(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val salespersonid = new OptField[BusinessentityId, Row](prefix, "salespersonid", None, Some("int4"))(x => extract(x).salespersonid, (row, value) => merge(row, extract(row).copy(salespersonid = value))) + override val demographics = new OptField[TypoXml, Row](prefix, "demographics", None, Some("xml"))(x => extract(x).demographics, (row, value) => merge(row, extract(row).copy(demographics = value))) + override val rowguid = new Field[TypoUUID, Row](prefix, "rowguid", None, Some("uuid"))(x => extract(x).rowguid, (row, value) => merge(row, extract(row).copy(rowguid = value))) + override val modifieddate = new Field[TypoLocalDateTime, Row](prefix, "modifieddate", Some("text"), Some("timestamp"))(x => extract(x).modifieddate, (row, value) => merge(row, extract(row).copy(modifieddate = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, salespersonid, demographics, rowguid, modifieddate) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => StoreRow, merge: (NewRow, StoreRow) => NewRow): StoreStructure[NewRow] = + new StoreStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewFields.scala new file mode 100644 index 0000000000..6476a979fa --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewFields.scala @@ -0,0 +1,39 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vindividualcustomer + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VindividualcustomerViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val phonenumber: OptField[Phone, Row] + val phonenumbertype: OptField[Name, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val emailpromotion: Field[Int, Row] + val addresstype: Field[Name, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovincename: Field[Name, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val countryregionname: Field[Name, Row] + val demographics: OptField[TypoXml, Row] +} +object VindividualcustomerViewFields extends VindividualcustomerViewStructure[VindividualcustomerViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepo.scala new file mode 100644 index 0000000000..5d14f62be9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vindividualcustomer + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VindividualcustomerViewRepo { + def select: SelectBuilder[VindividualcustomerViewFields, VindividualcustomerViewRow] + def selectAll: ZStream[ZConnection, Throwable, VindividualcustomerViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepoImpl.scala new file mode 100644 index 0000000000..ee2527078f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vindividualcustomer + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VindividualcustomerViewRepoImpl extends VindividualcustomerViewRepo { + override def select: SelectBuilder[VindividualcustomerViewFields, VindividualcustomerViewRow] = { + SelectBuilderSql("sales.vindividualcustomer", VindividualcustomerViewFields, VindividualcustomerViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VindividualcustomerViewRow] = { + sql"""select "businessentityid", "title", "firstname", "middlename", "lastname", "suffix", "phonenumber", "phonenumbertype", "emailaddress", "emailpromotion", "addresstype", "addressline1", "addressline2", "city", "stateprovincename", "postalcode", "countryregionname", "demographics" from sales.vindividualcustomer""".query(VindividualcustomerViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRow.scala new file mode 100644 index 0000000000..d31f16002c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewRow.scala @@ -0,0 +1,168 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vindividualcustomer + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VindividualcustomerViewRow( + /** Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Option[Phone], + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + phonenumbertype: Option[Name], + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int, + /** Points to [[person.addresstype.AddresstypeRow.name]] */ + addresstype: Name, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + countryregionname: Name, + /** Points to [[person.person.PersonRow.demographics]] */ + demographics: Option[TypoXml] +) + +object VindividualcustomerViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VindividualcustomerViewRow] = new JdbcDecoder[VindividualcustomerViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VindividualcustomerViewRow) = + columIndex + 17 -> + VindividualcustomerViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + phonenumber = JdbcDecoder.optionDecoder(Phone.jdbcDecoder).unsafeDecode(columIndex + 6, rs)._2, + phonenumbertype = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 8, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 9, rs)._2, + addresstype = Name.jdbcDecoder.unsafeDecode(columIndex + 10, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 11, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 13, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 15, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + demographics = JdbcDecoder.optionDecoder(TypoXml.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VindividualcustomerViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val phonenumber = jsonObj.get("phonenumber").fold[Either[String, Option[Phone]]](Right(None))(_.as(JsonDecoder.option(Phone.jsonDecoder))) + val phonenumbertype = jsonObj.get("phonenumbertype").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + val addresstype = jsonObj.get("addresstype").toRight("Missing field 'addresstype'").flatMap(_.as(Name.jsonDecoder)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + val demographics = jsonObj.get("demographics").fold[Either[String, Option[TypoXml]]](Right(None))(_.as(JsonDecoder.option(TypoXml.jsonDecoder))) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && phonenumber.isRight && phonenumbertype.isRight && emailaddress.isRight && emailpromotion.isRight && addresstype.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovincename.isRight && postalcode.isRight && countryregionname.isRight && demographics.isRight) + Right(VindividualcustomerViewRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertype = phonenumbertype.toOption.get, emailaddress = emailaddress.toOption.get, emailpromotion = emailpromotion.toOption.get, addresstype = addresstype.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovincename = stateprovincename.toOption.get, postalcode = postalcode.toOption.get, countryregionname = countryregionname.toOption.get, demographics = demographics.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, demographics).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VindividualcustomerViewRow] = new JsonEncoder[VindividualcustomerViewRow] { + override def unsafeEncode(a: VindividualcustomerViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""phonenumber":""") + JsonEncoder.option(Phone.jsonEncoder).unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertype":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.phonenumbertype, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""addresstype":""") + Name.jsonEncoder.unsafeEncode(a.addresstype, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write(",") + out.write(""""demographics":""") + JsonEncoder.option(TypoXml.jsonEncoder).unsafeEncode(a.demographics, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewStructure.scala new file mode 100644 index 0000000000..66a9abfd80 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vindividualcustomer/VindividualcustomerViewStructure.scala @@ -0,0 +1,48 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vindividualcustomer + +import adventureworks.customtypes.TypoXml +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VindividualcustomerViewStructure[Row](val prefix: Option[String], val extract: Row => VindividualcustomerViewRow, val merge: (Row, VindividualcustomerViewRow) => Row) + extends Relation[VindividualcustomerViewFields, VindividualcustomerViewRow, Row] + with VindividualcustomerViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val phonenumber = new OptField[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertype = new OptField[Name, Row](prefix, "phonenumbertype", None, None)(x => extract(x).phonenumbertype, (row, value) => merge(row, extract(row).copy(phonenumbertype = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + override val addresstype = new Field[Name, Row](prefix, "addresstype", None, None)(x => extract(x).addresstype, (row, value) => merge(row, extract(row).copy(addresstype = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + override val demographics = new OptField[TypoXml, Row](prefix, "demographics", None, None)(x => extract(x).demographics, (row, value) => merge(row, extract(row).copy(demographics = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, demographics) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VindividualcustomerViewRow, merge: (NewRow, VindividualcustomerViewRow) => NewRow): VindividualcustomerViewStructure[NewRow] = + new VindividualcustomerViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewFields.scala new file mode 100644 index 0000000000..65ad2184a6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vpersondemographics + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VpersondemographicsViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val totalpurchaseytd: OptField[TypoMoney, Row] + val datefirstpurchase: OptField[TypoLocalDate, Row] + val birthdate: OptField[TypoLocalDate, Row] + val maritalstatus: OptField[/* max 1 chars */ String, Row] + val yearlyincome: OptField[/* max 30 chars */ String, Row] + val gender: OptField[/* max 1 chars */ String, Row] + val totalchildren: OptField[Int, Row] + val numberchildrenathome: OptField[Int, Row] + val education: OptField[/* max 30 chars */ String, Row] + val occupation: OptField[/* max 30 chars */ String, Row] + val homeownerflag: OptField[Boolean, Row] + val numbercarsowned: OptField[Int, Row] +} +object VpersondemographicsViewFields extends VpersondemographicsViewStructure[VpersondemographicsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepo.scala new file mode 100644 index 0000000000..61dae4850a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vpersondemographics + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VpersondemographicsViewRepo { + def select: SelectBuilder[VpersondemographicsViewFields, VpersondemographicsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VpersondemographicsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepoImpl.scala new file mode 100644 index 0000000000..9e6d0ce880 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vpersondemographics + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VpersondemographicsViewRepoImpl extends VpersondemographicsViewRepo { + override def select: SelectBuilder[VpersondemographicsViewFields, VpersondemographicsViewRow] = { + SelectBuilderSql("sales.vpersondemographics", VpersondemographicsViewFields, VpersondemographicsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VpersondemographicsViewRow] = { + sql"""select "businessentityid", "totalpurchaseytd"::numeric, "datefirstpurchase"::text, "birthdate"::text, "maritalstatus", "yearlyincome", "gender", "totalchildren", "numberchildrenathome", "education", "occupation", "homeownerflag", "numbercarsowned" from sales.vpersondemographics""".query(VpersondemographicsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRow.scala new file mode 100644 index 0000000000..43002540b4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewRow.scala @@ -0,0 +1,119 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vpersondemographics + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VpersondemographicsViewRow( + /** Points to [[person.person.PersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + totalpurchaseytd: /* nullability unknown */ Option[TypoMoney], + datefirstpurchase: /* nullability unknown */ Option[TypoLocalDate], + birthdate: /* nullability unknown */ Option[TypoLocalDate], + maritalstatus: /* nullability unknown */ Option[/* max 1 chars */ String], + yearlyincome: /* nullability unknown */ Option[/* max 30 chars */ String], + gender: /* nullability unknown */ Option[/* max 1 chars */ String], + totalchildren: /* nullability unknown */ Option[Int], + numberchildrenathome: /* nullability unknown */ Option[Int], + education: /* nullability unknown */ Option[/* max 30 chars */ String], + occupation: /* nullability unknown */ Option[/* max 30 chars */ String], + homeownerflag: /* nullability unknown */ Option[Boolean], + numbercarsowned: /* nullability unknown */ Option[Int] +) + +object VpersondemographicsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VpersondemographicsViewRow] = new JdbcDecoder[VpersondemographicsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VpersondemographicsViewRow) = + columIndex + 12 -> + VpersondemographicsViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + totalpurchaseytd = JdbcDecoder.optionDecoder(TypoMoney.jdbcDecoder).unsafeDecode(columIndex + 1, rs)._2, + datefirstpurchase = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + birthdate = JdbcDecoder.optionDecoder(TypoLocalDate.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + maritalstatus = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + yearlyincome = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + gender = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 6, rs)._2, + totalchildren = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 7, rs)._2, + numberchildrenathome = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + education = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + occupation = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + homeownerflag = JdbcDecoder.optionDecoder(JdbcDecoder.booleanDecoder).unsafeDecode(columIndex + 11, rs)._2, + numbercarsowned = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 12, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VpersondemographicsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val totalpurchaseytd = jsonObj.get("totalpurchaseytd").fold[Either[String, Option[TypoMoney]]](Right(None))(_.as(JsonDecoder.option(TypoMoney.jsonDecoder))) + val datefirstpurchase = jsonObj.get("datefirstpurchase").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val birthdate = jsonObj.get("birthdate").fold[Either[String, Option[TypoLocalDate]]](Right(None))(_.as(JsonDecoder.option(TypoLocalDate.jsonDecoder))) + val maritalstatus = jsonObj.get("maritalstatus").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val yearlyincome = jsonObj.get("yearlyincome").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val gender = jsonObj.get("gender").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val totalchildren = jsonObj.get("totalchildren").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val numberchildrenathome = jsonObj.get("numberchildrenathome").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val education = jsonObj.get("education").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val occupation = jsonObj.get("occupation").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val homeownerflag = jsonObj.get("homeownerflag").fold[Either[String, Option[Boolean]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.boolean))) + val numbercarsowned = jsonObj.get("numbercarsowned").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + if (businessentityid.isRight && totalpurchaseytd.isRight && datefirstpurchase.isRight && birthdate.isRight && maritalstatus.isRight && yearlyincome.isRight && gender.isRight && totalchildren.isRight && numberchildrenathome.isRight && education.isRight && occupation.isRight && homeownerflag.isRight && numbercarsowned.isRight) + Right(VpersondemographicsViewRow(businessentityid = businessentityid.toOption.get, totalpurchaseytd = totalpurchaseytd.toOption.get, datefirstpurchase = datefirstpurchase.toOption.get, birthdate = birthdate.toOption.get, maritalstatus = maritalstatus.toOption.get, yearlyincome = yearlyincome.toOption.get, gender = gender.toOption.get, totalchildren = totalchildren.toOption.get, numberchildrenathome = numberchildrenathome.toOption.get, education = education.toOption.get, occupation = occupation.toOption.get, homeownerflag = homeownerflag.toOption.get, numbercarsowned = numbercarsowned.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, totalpurchaseytd, datefirstpurchase, birthdate, maritalstatus, yearlyincome, gender, totalchildren, numberchildrenathome, education, occupation, homeownerflag, numbercarsowned).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VpersondemographicsViewRow] = new JsonEncoder[VpersondemographicsViewRow] { + override def unsafeEncode(a: VpersondemographicsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""totalpurchaseytd":""") + JsonEncoder.option(TypoMoney.jsonEncoder).unsafeEncode(a.totalpurchaseytd, indent, out) + out.write(",") + out.write(""""datefirstpurchase":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.datefirstpurchase, indent, out) + out.write(",") + out.write(""""birthdate":""") + JsonEncoder.option(TypoLocalDate.jsonEncoder).unsafeEncode(a.birthdate, indent, out) + out.write(",") + out.write(""""maritalstatus":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.maritalstatus, indent, out) + out.write(",") + out.write(""""yearlyincome":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.yearlyincome, indent, out) + out.write(",") + out.write(""""gender":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.gender, indent, out) + out.write(",") + out.write(""""totalchildren":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.totalchildren, indent, out) + out.write(",") + out.write(""""numberchildrenathome":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numberchildrenathome, indent, out) + out.write(",") + out.write(""""education":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.education, indent, out) + out.write(",") + out.write(""""occupation":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.occupation, indent, out) + out.write(",") + out.write(""""homeownerflag":""") + JsonEncoder.option(JsonEncoder.boolean).unsafeEncode(a.homeownerflag, indent, out) + out.write(",") + out.write(""""numbercarsowned":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.numbercarsowned, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewStructure.scala new file mode 100644 index 0000000000..738b9fdca2 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vpersondemographics/VpersondemographicsViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vpersondemographics + +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VpersondemographicsViewStructure[Row](val prefix: Option[String], val extract: Row => VpersondemographicsViewRow, val merge: (Row, VpersondemographicsViewRow) => Row) + extends Relation[VpersondemographicsViewFields, VpersondemographicsViewRow, Row] + with VpersondemographicsViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val totalpurchaseytd = new OptField[TypoMoney, Row](prefix, "totalpurchaseytd", Some("numeric"), None)(x => extract(x).totalpurchaseytd, (row, value) => merge(row, extract(row).copy(totalpurchaseytd = value))) + override val datefirstpurchase = new OptField[TypoLocalDate, Row](prefix, "datefirstpurchase", Some("text"), None)(x => extract(x).datefirstpurchase, (row, value) => merge(row, extract(row).copy(datefirstpurchase = value))) + override val birthdate = new OptField[TypoLocalDate, Row](prefix, "birthdate", Some("text"), None)(x => extract(x).birthdate, (row, value) => merge(row, extract(row).copy(birthdate = value))) + override val maritalstatus = new OptField[/* max 1 chars */ String, Row](prefix, "maritalstatus", None, None)(x => extract(x).maritalstatus, (row, value) => merge(row, extract(row).copy(maritalstatus = value))) + override val yearlyincome = new OptField[/* max 30 chars */ String, Row](prefix, "yearlyincome", None, None)(x => extract(x).yearlyincome, (row, value) => merge(row, extract(row).copy(yearlyincome = value))) + override val gender = new OptField[/* max 1 chars */ String, Row](prefix, "gender", None, None)(x => extract(x).gender, (row, value) => merge(row, extract(row).copy(gender = value))) + override val totalchildren = new OptField[Int, Row](prefix, "totalchildren", None, None)(x => extract(x).totalchildren, (row, value) => merge(row, extract(row).copy(totalchildren = value))) + override val numberchildrenathome = new OptField[Int, Row](prefix, "numberchildrenathome", None, None)(x => extract(x).numberchildrenathome, (row, value) => merge(row, extract(row).copy(numberchildrenathome = value))) + override val education = new OptField[/* max 30 chars */ String, Row](prefix, "education", None, None)(x => extract(x).education, (row, value) => merge(row, extract(row).copy(education = value))) + override val occupation = new OptField[/* max 30 chars */ String, Row](prefix, "occupation", None, None)(x => extract(x).occupation, (row, value) => merge(row, extract(row).copy(occupation = value))) + override val homeownerflag = new OptField[Boolean, Row](prefix, "homeownerflag", None, None)(x => extract(x).homeownerflag, (row, value) => merge(row, extract(row).copy(homeownerflag = value))) + override val numbercarsowned = new OptField[Int, Row](prefix, "numbercarsowned", None, None)(x => extract(x).numbercarsowned, (row, value) => merge(row, extract(row).copy(numbercarsowned = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, totalpurchaseytd, datefirstpurchase, birthdate, maritalstatus, yearlyincome, gender, totalchildren, numberchildrenathome, education, occupation, homeownerflag, numbercarsowned) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VpersondemographicsViewRow, merge: (NewRow, VpersondemographicsViewRow) => NewRow): VpersondemographicsViewStructure[NewRow] = + new VpersondemographicsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewFields.scala new file mode 100644 index 0000000000..4d1274938b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewFields.scala @@ -0,0 +1,42 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalesperson + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VsalespersonViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val phonenumber: OptField[Phone, Row] + val phonenumbertype: OptField[Name, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val emailpromotion: Field[Int, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovincename: Field[Name, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val countryregionname: Field[Name, Row] + val territoryname: OptField[Name, Row] + val territorygroup: OptField[/* max 50 chars */ String, Row] + val salesquota: OptField[BigDecimal, Row] + val salesytd: Field[BigDecimal, Row] + val saleslastyear: Field[BigDecimal, Row] +} +object VsalespersonViewFields extends VsalespersonViewStructure[VsalespersonViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepo.scala new file mode 100644 index 0000000000..42d7572fa5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalesperson + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VsalespersonViewRepo { + def select: SelectBuilder[VsalespersonViewFields, VsalespersonViewRow] + def selectAll: ZStream[ZConnection, Throwable, VsalespersonViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepoImpl.scala new file mode 100644 index 0000000000..69dc9304db --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalesperson + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VsalespersonViewRepoImpl extends VsalespersonViewRepo { + override def select: SelectBuilder[VsalespersonViewFields, VsalespersonViewRow] = { + SelectBuilderSql("sales.vsalesperson", VsalespersonViewFields, VsalespersonViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VsalespersonViewRow] = { + sql"""select "businessentityid", "title", "firstname", "middlename", "lastname", "suffix", "jobtitle", "phonenumber", "phonenumbertype", "emailaddress", "emailpromotion", "addressline1", "addressline2", "city", "stateprovincename", "postalcode", "countryregionname", "territoryname", "territorygroup", "salesquota", "salesytd", "saleslastyear" from sales.vsalesperson""".query(VsalespersonViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRow.scala new file mode 100644 index 0000000000..8db18060b9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewRow.scala @@ -0,0 +1,195 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalesperson + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VsalespersonViewRow( + /** Points to [[salesperson.SalespersonRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[humanresources.employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Option[Phone], + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + phonenumbertype: Option[Name], + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + countryregionname: Name, + /** Points to [[salesterritory.SalesterritoryRow.name]] */ + territoryname: Option[Name], + /** Points to [[salesterritory.SalesterritoryRow.group]] */ + territorygroup: Option[/* max 50 chars */ String], + /** Points to [[salesperson.SalespersonRow.salesquota]] */ + salesquota: Option[BigDecimal], + /** Points to [[salesperson.SalespersonRow.salesytd]] */ + salesytd: BigDecimal, + /** Points to [[salesperson.SalespersonRow.saleslastyear]] */ + saleslastyear: BigDecimal +) + +object VsalespersonViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VsalespersonViewRow] = new JdbcDecoder[VsalespersonViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VsalespersonViewRow) = + columIndex + 21 -> + VsalespersonViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 6, rs)._2, + phonenumber = JdbcDecoder.optionDecoder(Phone.jdbcDecoder).unsafeDecode(columIndex + 7, rs)._2, + phonenumbertype = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 10, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 11, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 12, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 13, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 14, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 15, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 16, rs)._2, + territoryname = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 17, rs)._2, + territorygroup = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 18, rs)._2, + salesquota = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 19, rs)._2, + salesytd = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 20, rs)._2, + saleslastyear = JdbcDecoder.bigDecimalDecoderScala.unsafeDecode(columIndex + 21, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VsalespersonViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val phonenumber = jsonObj.get("phonenumber").fold[Either[String, Option[Phone]]](Right(None))(_.as(JsonDecoder.option(Phone.jsonDecoder))) + val phonenumbertype = jsonObj.get("phonenumbertype").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + val territoryname = jsonObj.get("territoryname").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val territorygroup = jsonObj.get("territorygroup").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val salesquota = jsonObj.get("salesquota").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val salesytd = jsonObj.get("salesytd").toRight("Missing field 'salesytd'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + val saleslastyear = jsonObj.get("saleslastyear").toRight("Missing field 'saleslastyear'").flatMap(_.as(JsonDecoder.scalaBigDecimal)) + if (businessentityid.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && jobtitle.isRight && phonenumber.isRight && phonenumbertype.isRight && emailaddress.isRight && emailpromotion.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovincename.isRight && postalcode.isRight && countryregionname.isRight && territoryname.isRight && territorygroup.isRight && salesquota.isRight && salesytd.isRight && saleslastyear.isRight) + Right(VsalespersonViewRow(businessentityid = businessentityid.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, jobtitle = jobtitle.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertype = phonenumbertype.toOption.get, emailaddress = emailaddress.toOption.get, emailpromotion = emailpromotion.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovincename = stateprovincename.toOption.get, postalcode = postalcode.toOption.get, countryregionname = countryregionname.toOption.get, territoryname = territoryname.toOption.get, territorygroup = territorygroup.toOption.get, salesquota = salesquota.toOption.get, salesytd = salesytd.toOption.get, saleslastyear = saleslastyear.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, phonenumber, phonenumbertype, emailaddress, emailpromotion, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, territoryname, territorygroup, salesquota, salesytd, saleslastyear).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VsalespersonViewRow] = new JsonEncoder[VsalespersonViewRow] { + override def unsafeEncode(a: VsalespersonViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""phonenumber":""") + JsonEncoder.option(Phone.jsonEncoder).unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertype":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.phonenumbertype, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write(",") + out.write(""""territoryname":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.territoryname, indent, out) + out.write(",") + out.write(""""territorygroup":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.territorygroup, indent, out) + out.write(",") + out.write(""""salesquota":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salesquota, indent, out) + out.write(",") + out.write(""""salesytd":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.salesytd, indent, out) + out.write(",") + out.write(""""saleslastyear":""") + JsonEncoder.scalaBigDecimal.unsafeEncode(a.saleslastyear, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewStructure.scala new file mode 100644 index 0000000000..7af84b60ed --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalesperson/VsalespersonViewStructure.scala @@ -0,0 +1,51 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalesperson + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VsalespersonViewStructure[Row](val prefix: Option[String], val extract: Row => VsalespersonViewRow, val merge: (Row, VsalespersonViewRow) => Row) + extends Relation[VsalespersonViewFields, VsalespersonViewRow, Row] + with VsalespersonViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val phonenumber = new OptField[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertype = new OptField[Name, Row](prefix, "phonenumbertype", None, None)(x => extract(x).phonenumbertype, (row, value) => merge(row, extract(row).copy(phonenumbertype = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + override val territoryname = new OptField[Name, Row](prefix, "territoryname", None, None)(x => extract(x).territoryname, (row, value) => merge(row, extract(row).copy(territoryname = value))) + override val territorygroup = new OptField[/* max 50 chars */ String, Row](prefix, "territorygroup", None, None)(x => extract(x).territorygroup, (row, value) => merge(row, extract(row).copy(territorygroup = value))) + override val salesquota = new OptField[BigDecimal, Row](prefix, "salesquota", None, None)(x => extract(x).salesquota, (row, value) => merge(row, extract(row).copy(salesquota = value))) + override val salesytd = new Field[BigDecimal, Row](prefix, "salesytd", None, None)(x => extract(x).salesytd, (row, value) => merge(row, extract(row).copy(salesytd = value))) + override val saleslastyear = new Field[BigDecimal, Row](prefix, "saleslastyear", None, None)(x => extract(x).saleslastyear, (row, value) => merge(row, extract(row).copy(saleslastyear = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, title, firstname, middlename, lastname, suffix, jobtitle, phonenumber, phonenumbertype, emailaddress, emailpromotion, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname, territoryname, territorygroup, salesquota, salesytd, saleslastyear) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VsalespersonViewRow, merge: (NewRow, VsalespersonViewRow) => NewRow): VsalespersonViewStructure[NewRow] = + new VsalespersonViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewFields.scala new file mode 100644 index 0000000000..2eb635438a --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewFields.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyears + +import typo.dsl.SqlExpr.OptField + +trait VsalespersonsalesbyfiscalyearsViewFields[Row] { + val SalesPersonID: OptField[Int, Row] + val FullName: OptField[String, Row] + val JobTitle: OptField[String, Row] + val SalesTerritory: OptField[String, Row] + val `2012`: OptField[BigDecimal, Row] + val `2013`: OptField[BigDecimal, Row] + val `2014`: OptField[BigDecimal, Row] +} +object VsalespersonsalesbyfiscalyearsViewFields extends VsalespersonsalesbyfiscalyearsViewStructure[VsalespersonsalesbyfiscalyearsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepo.scala new file mode 100644 index 0000000000..0cb5ce6422 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyears + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VsalespersonsalesbyfiscalyearsViewRepo { + def select: SelectBuilder[VsalespersonsalesbyfiscalyearsViewFields, VsalespersonsalesbyfiscalyearsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VsalespersonsalesbyfiscalyearsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepoImpl.scala new file mode 100644 index 0000000000..138ffc4423 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyears + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VsalespersonsalesbyfiscalyearsViewRepoImpl extends VsalespersonsalesbyfiscalyearsViewRepo { + override def select: SelectBuilder[VsalespersonsalesbyfiscalyearsViewFields, VsalespersonsalesbyfiscalyearsViewRow] = { + SelectBuilderSql("sales.vsalespersonsalesbyfiscalyears", VsalespersonsalesbyfiscalyearsViewFields, VsalespersonsalesbyfiscalyearsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VsalespersonsalesbyfiscalyearsViewRow] = { + sql"""select "SalesPersonID", "FullName", "JobTitle", "SalesTerritory", "2012", "2013", "2014" from sales.vsalespersonsalesbyfiscalyears""".query(VsalespersonsalesbyfiscalyearsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRow.scala new file mode 100644 index 0000000000..0427e93736 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewRow.scala @@ -0,0 +1,79 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyears + +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VsalespersonsalesbyfiscalyearsViewRow( + SalesPersonID: /* nullability unknown */ Option[Int], + FullName: /* nullability unknown */ Option[String], + JobTitle: /* nullability unknown */ Option[String], + SalesTerritory: /* nullability unknown */ Option[String], + `2012`: /* nullability unknown */ Option[BigDecimal], + `2013`: /* nullability unknown */ Option[BigDecimal], + `2014`: /* nullability unknown */ Option[BigDecimal] +) + +object VsalespersonsalesbyfiscalyearsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VsalespersonsalesbyfiscalyearsViewRow] = new JdbcDecoder[VsalespersonsalesbyfiscalyearsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VsalespersonsalesbyfiscalyearsViewRow) = + columIndex + 6 -> + VsalespersonsalesbyfiscalyearsViewRow( + SalesPersonID = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 0, rs)._2, + FullName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + JobTitle = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 2, rs)._2, + SalesTerritory = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + `2012` = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 4, rs)._2, + `2013` = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 5, rs)._2, + `2014` = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 6, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VsalespersonsalesbyfiscalyearsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val SalesPersonID = jsonObj.get("SalesPersonID").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val FullName = jsonObj.get("FullName").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val JobTitle = jsonObj.get("JobTitle").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val SalesTerritory = jsonObj.get("SalesTerritory").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val `2012` = jsonObj.get("2012").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val `2013` = jsonObj.get("2013").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val `2014` = jsonObj.get("2014").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + if (SalesPersonID.isRight && FullName.isRight && JobTitle.isRight && SalesTerritory.isRight && `2012`.isRight && `2013`.isRight && `2014`.isRight) + Right(VsalespersonsalesbyfiscalyearsViewRow(SalesPersonID = SalesPersonID.toOption.get, FullName = FullName.toOption.get, JobTitle = JobTitle.toOption.get, SalesTerritory = SalesTerritory.toOption.get, `2012` = `2012`.toOption.get, `2013` = `2013`.toOption.get, `2014` = `2014`.toOption.get)) + else Left(List[Either[String, Any]](SalesPersonID, FullName, JobTitle, SalesTerritory, `2012`, `2013`, `2014`).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VsalespersonsalesbyfiscalyearsViewRow] = new JsonEncoder[VsalespersonsalesbyfiscalyearsViewRow] { + override def unsafeEncode(a: VsalespersonsalesbyfiscalyearsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""SalesPersonID":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.SalesPersonID, indent, out) + out.write(",") + out.write(""""FullName":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.FullName, indent, out) + out.write(",") + out.write(""""JobTitle":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.JobTitle, indent, out) + out.write(",") + out.write(""""SalesTerritory":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.SalesTerritory, indent, out) + out.write(",") + out.write(""""2012":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.`2012`, indent, out) + out.write(",") + out.write(""""2013":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.`2013`, indent, out) + out.write(",") + out.write(""""2014":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.`2014`, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewStructure.scala new file mode 100644 index 0000000000..3485f8108f --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyears/VsalespersonsalesbyfiscalyearsViewStructure.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyears + +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VsalespersonsalesbyfiscalyearsViewStructure[Row](val prefix: Option[String], val extract: Row => VsalespersonsalesbyfiscalyearsViewRow, val merge: (Row, VsalespersonsalesbyfiscalyearsViewRow) => Row) + extends Relation[VsalespersonsalesbyfiscalyearsViewFields, VsalespersonsalesbyfiscalyearsViewRow, Row] + with VsalespersonsalesbyfiscalyearsViewFields[Row] { outer => + + override val SalesPersonID = new OptField[Int, Row](prefix, "SalesPersonID", None, None)(x => extract(x).SalesPersonID, (row, value) => merge(row, extract(row).copy(SalesPersonID = value))) + override val FullName = new OptField[String, Row](prefix, "FullName", None, None)(x => extract(x).FullName, (row, value) => merge(row, extract(row).copy(FullName = value))) + override val JobTitle = new OptField[String, Row](prefix, "JobTitle", None, None)(x => extract(x).JobTitle, (row, value) => merge(row, extract(row).copy(JobTitle = value))) + override val SalesTerritory = new OptField[String, Row](prefix, "SalesTerritory", None, None)(x => extract(x).SalesTerritory, (row, value) => merge(row, extract(row).copy(SalesTerritory = value))) + override val `2012` = new OptField[BigDecimal, Row](prefix, "2012", None, None)(x => extract(x).`2012`, (row, value) => merge(row, extract(row).copy(`2012` = value))) + override val `2013` = new OptField[BigDecimal, Row](prefix, "2013", None, None)(x => extract(x).`2013`, (row, value) => merge(row, extract(row).copy(`2013` = value))) + override val `2014` = new OptField[BigDecimal, Row](prefix, "2014", None, None)(x => extract(x).`2014`, (row, value) => merge(row, extract(row).copy(`2014` = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](SalesPersonID, FullName, JobTitle, SalesTerritory, `2012`, `2013`, `2014`) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VsalespersonsalesbyfiscalyearsViewRow, merge: (NewRow, VsalespersonsalesbyfiscalyearsViewRow) => NewRow): VsalespersonsalesbyfiscalyearsViewStructure[NewRow] = + new VsalespersonsalesbyfiscalyearsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewFields.scala new file mode 100644 index 0000000000..c871064e8e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewFields.scala @@ -0,0 +1,24 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyearsdata + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VsalespersonsalesbyfiscalyearsdataViewFields[Row] { + val salespersonid: OptField[BusinessentityId, Row] + val fullname: OptField[String, Row] + val jobtitle: Field[/* max 50 chars */ String, Row] + val salesterritory: Field[Name, Row] + val salestotal: OptField[BigDecimal, Row] + val fiscalyear: OptField[BigDecimal, Row] +} +object VsalespersonsalesbyfiscalyearsdataViewFields extends VsalespersonsalesbyfiscalyearsdataViewStructure[VsalespersonsalesbyfiscalyearsdataViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepo.scala new file mode 100644 index 0000000000..7d756ad4d5 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyearsdata + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VsalespersonsalesbyfiscalyearsdataViewRepo { + def select: SelectBuilder[VsalespersonsalesbyfiscalyearsdataViewFields, VsalespersonsalesbyfiscalyearsdataViewRow] + def selectAll: ZStream[ZConnection, Throwable, VsalespersonsalesbyfiscalyearsdataViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepoImpl.scala new file mode 100644 index 0000000000..b36d7243c3 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyearsdata + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VsalespersonsalesbyfiscalyearsdataViewRepoImpl extends VsalespersonsalesbyfiscalyearsdataViewRepo { + override def select: SelectBuilder[VsalespersonsalesbyfiscalyearsdataViewFields, VsalespersonsalesbyfiscalyearsdataViewRow] = { + SelectBuilderSql("sales.vsalespersonsalesbyfiscalyearsdata", VsalespersonsalesbyfiscalyearsdataViewFields, VsalespersonsalesbyfiscalyearsdataViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VsalespersonsalesbyfiscalyearsdataViewRow] = { + sql"""select "salespersonid", "fullname", "jobtitle", "salesterritory", "salestotal", "fiscalyear" from sales.vsalespersonsalesbyfiscalyearsdata""".query(VsalespersonsalesbyfiscalyearsdataViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRow.scala new file mode 100644 index 0000000000..43799c87ff --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewRow.scala @@ -0,0 +1,78 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyearsdata + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VsalespersonsalesbyfiscalyearsdataViewRow( + /** Points to [[salesorderheader.SalesorderheaderRow.salespersonid]] */ + salespersonid: Option[BusinessentityId], + fullname: /* nullability unknown */ Option[String], + /** Points to [[humanresources.employee.EmployeeRow.jobtitle]] */ + jobtitle: /* max 50 chars */ String, + /** Points to [[salesterritory.SalesterritoryRow.name]] */ + salesterritory: Name, + salestotal: /* nullability unknown */ Option[BigDecimal], + fiscalyear: /* nullability unknown */ Option[BigDecimal] +) + +object VsalespersonsalesbyfiscalyearsdataViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VsalespersonsalesbyfiscalyearsdataViewRow] = new JdbcDecoder[VsalespersonsalesbyfiscalyearsdataViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VsalespersonsalesbyfiscalyearsdataViewRow) = + columIndex + 5 -> + VsalespersonsalesbyfiscalyearsdataViewRow( + salespersonid = JdbcDecoder.optionDecoder(BusinessentityId.jdbcDecoder).unsafeDecode(columIndex + 0, rs)._2, + fullname = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 1, rs)._2, + jobtitle = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 2, rs)._2, + salesterritory = Name.jdbcDecoder.unsafeDecode(columIndex + 3, rs)._2, + salestotal = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 4, rs)._2, + fiscalyear = JdbcDecoder.optionDecoder(JdbcDecoder.bigDecimalDecoderScala).unsafeDecode(columIndex + 5, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VsalespersonsalesbyfiscalyearsdataViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val salespersonid = jsonObj.get("salespersonid").fold[Either[String, Option[BusinessentityId]]](Right(None))(_.as(JsonDecoder.option(BusinessentityId.jsonDecoder))) + val fullname = jsonObj.get("fullname").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val jobtitle = jsonObj.get("jobtitle").toRight("Missing field 'jobtitle'").flatMap(_.as(JsonDecoder.string)) + val salesterritory = jsonObj.get("salesterritory").toRight("Missing field 'salesterritory'").flatMap(_.as(Name.jsonDecoder)) + val salestotal = jsonObj.get("salestotal").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + val fiscalyear = jsonObj.get("fiscalyear").fold[Either[String, Option[BigDecimal]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.scalaBigDecimal))) + if (salespersonid.isRight && fullname.isRight && jobtitle.isRight && salesterritory.isRight && salestotal.isRight && fiscalyear.isRight) + Right(VsalespersonsalesbyfiscalyearsdataViewRow(salespersonid = salespersonid.toOption.get, fullname = fullname.toOption.get, jobtitle = jobtitle.toOption.get, salesterritory = salesterritory.toOption.get, salestotal = salestotal.toOption.get, fiscalyear = fiscalyear.toOption.get)) + else Left(List[Either[String, Any]](salespersonid, fullname, jobtitle, salesterritory, salestotal, fiscalyear).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VsalespersonsalesbyfiscalyearsdataViewRow] = new JsonEncoder[VsalespersonsalesbyfiscalyearsdataViewRow] { + override def unsafeEncode(a: VsalespersonsalesbyfiscalyearsdataViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""salespersonid":""") + JsonEncoder.option(BusinessentityId.jsonEncoder).unsafeEncode(a.salespersonid, indent, out) + out.write(",") + out.write(""""fullname":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.fullname, indent, out) + out.write(",") + out.write(""""jobtitle":""") + JsonEncoder.string.unsafeEncode(a.jobtitle, indent, out) + out.write(",") + out.write(""""salesterritory":""") + Name.jsonEncoder.unsafeEncode(a.salesterritory, indent, out) + out.write(",") + out.write(""""salestotal":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.salestotal, indent, out) + out.write(",") + out.write(""""fiscalyear":""") + JsonEncoder.option(JsonEncoder.scalaBigDecimal).unsafeEncode(a.fiscalyear, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewStructure.scala new file mode 100644 index 0000000000..98db3bcd8b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vsalespersonsalesbyfiscalyearsdata/VsalespersonsalesbyfiscalyearsdataViewStructure.scala @@ -0,0 +1,33 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vsalespersonsalesbyfiscalyearsdata + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VsalespersonsalesbyfiscalyearsdataViewStructure[Row](val prefix: Option[String], val extract: Row => VsalespersonsalesbyfiscalyearsdataViewRow, val merge: (Row, VsalespersonsalesbyfiscalyearsdataViewRow) => Row) + extends Relation[VsalespersonsalesbyfiscalyearsdataViewFields, VsalespersonsalesbyfiscalyearsdataViewRow, Row] + with VsalespersonsalesbyfiscalyearsdataViewFields[Row] { outer => + + override val salespersonid = new OptField[BusinessentityId, Row](prefix, "salespersonid", None, None)(x => extract(x).salespersonid, (row, value) => merge(row, extract(row).copy(salespersonid = value))) + override val fullname = new OptField[String, Row](prefix, "fullname", None, None)(x => extract(x).fullname, (row, value) => merge(row, extract(row).copy(fullname = value))) + override val jobtitle = new Field[/* max 50 chars */ String, Row](prefix, "jobtitle", None, None)(x => extract(x).jobtitle, (row, value) => merge(row, extract(row).copy(jobtitle = value))) + override val salesterritory = new Field[Name, Row](prefix, "salesterritory", None, None)(x => extract(x).salesterritory, (row, value) => merge(row, extract(row).copy(salesterritory = value))) + override val salestotal = new OptField[BigDecimal, Row](prefix, "salestotal", None, None)(x => extract(x).salestotal, (row, value) => merge(row, extract(row).copy(salestotal = value))) + override val fiscalyear = new OptField[BigDecimal, Row](prefix, "fiscalyear", None, None)(x => extract(x).fiscalyear, (row, value) => merge(row, extract(row).copy(fiscalyear = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](salespersonid, fullname, jobtitle, salesterritory, salestotal, fiscalyear) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VsalespersonsalesbyfiscalyearsdataViewRow, merge: (NewRow, VsalespersonsalesbyfiscalyearsdataViewRow) => NewRow): VsalespersonsalesbyfiscalyearsdataViewStructure[NewRow] = + new VsalespersonsalesbyfiscalyearsdataViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewFields.scala new file mode 100644 index 0000000000..5b34fb540b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewFields.scala @@ -0,0 +1,27 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VstorewithaddressesViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val addresstype: Field[Name, Row] + val addressline1: Field[/* max 60 chars */ String, Row] + val addressline2: OptField[/* max 60 chars */ String, Row] + val city: Field[/* max 30 chars */ String, Row] + val stateprovincename: Field[Name, Row] + val postalcode: Field[/* max 15 chars */ String, Row] + val countryregionname: Field[Name, Row] +} +object VstorewithaddressesViewFields extends VstorewithaddressesViewStructure[VstorewithaddressesViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepo.scala new file mode 100644 index 0000000000..f8572c3ea9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithaddresses + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VstorewithaddressesViewRepo { + def select: SelectBuilder[VstorewithaddressesViewFields, VstorewithaddressesViewRow] + def selectAll: ZStream[ZConnection, Throwable, VstorewithaddressesViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepoImpl.scala new file mode 100644 index 0000000000..5137990ae9 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithaddresses + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VstorewithaddressesViewRepoImpl extends VstorewithaddressesViewRepo { + override def select: SelectBuilder[VstorewithaddressesViewFields, VstorewithaddressesViewRow] = { + SelectBuilderSql("sales.vstorewithaddresses", VstorewithaddressesViewFields, VstorewithaddressesViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VstorewithaddressesViewRow] = { + sql"""select "businessentityid", "name", "addresstype", "addressline1", "addressline2", "city", "stateprovincename", "postalcode", "countryregionname" from sales.vstorewithaddresses""".query(VstorewithaddressesViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRow.scala new file mode 100644 index 0000000000..9cd3f8925e --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewRow.scala @@ -0,0 +1,102 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VstorewithaddressesViewRow( + /** Points to [[store.StoreRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[store.StoreRow.name]] */ + name: Name, + /** Points to [[person.addresstype.AddresstypeRow.name]] */ + addresstype: Name, + /** Points to [[person.address.AddressRow.addressline1]] */ + addressline1: /* max 60 chars */ String, + /** Points to [[person.address.AddressRow.addressline2]] */ + addressline2: Option[/* max 60 chars */ String], + /** Points to [[person.address.AddressRow.city]] */ + city: /* max 30 chars */ String, + /** Points to [[person.stateprovince.StateprovinceRow.name]] */ + stateprovincename: Name, + /** Points to [[person.address.AddressRow.postalcode]] */ + postalcode: /* max 15 chars */ String, + /** Points to [[person.countryregion.CountryregionRow.name]] */ + countryregionname: Name +) + +object VstorewithaddressesViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VstorewithaddressesViewRow] = new JdbcDecoder[VstorewithaddressesViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VstorewithaddressesViewRow) = + columIndex + 8 -> + VstorewithaddressesViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + addresstype = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + addressline1 = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 3, rs)._2, + addressline2 = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + city = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 5, rs)._2, + stateprovincename = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + postalcode = JdbcDecoder.stringDecoder.unsafeDecode(columIndex + 7, rs)._2, + countryregionname = Name.jdbcDecoder.unsafeDecode(columIndex + 8, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VstorewithaddressesViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val addresstype = jsonObj.get("addresstype").toRight("Missing field 'addresstype'").flatMap(_.as(Name.jsonDecoder)) + val addressline1 = jsonObj.get("addressline1").toRight("Missing field 'addressline1'").flatMap(_.as(JsonDecoder.string)) + val addressline2 = jsonObj.get("addressline2").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val city = jsonObj.get("city").toRight("Missing field 'city'").flatMap(_.as(JsonDecoder.string)) + val stateprovincename = jsonObj.get("stateprovincename").toRight("Missing field 'stateprovincename'").flatMap(_.as(Name.jsonDecoder)) + val postalcode = jsonObj.get("postalcode").toRight("Missing field 'postalcode'").flatMap(_.as(JsonDecoder.string)) + val countryregionname = jsonObj.get("countryregionname").toRight("Missing field 'countryregionname'").flatMap(_.as(Name.jsonDecoder)) + if (businessentityid.isRight && name.isRight && addresstype.isRight && addressline1.isRight && addressline2.isRight && city.isRight && stateprovincename.isRight && postalcode.isRight && countryregionname.isRight) + Right(VstorewithaddressesViewRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, addresstype = addresstype.toOption.get, addressline1 = addressline1.toOption.get, addressline2 = addressline2.toOption.get, city = city.toOption.get, stateprovincename = stateprovincename.toOption.get, postalcode = postalcode.toOption.get, countryregionname = countryregionname.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VstorewithaddressesViewRow] = new JsonEncoder[VstorewithaddressesViewRow] { + override def unsafeEncode(a: VstorewithaddressesViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""addresstype":""") + Name.jsonEncoder.unsafeEncode(a.addresstype, indent, out) + out.write(",") + out.write(""""addressline1":""") + JsonEncoder.string.unsafeEncode(a.addressline1, indent, out) + out.write(",") + out.write(""""addressline2":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.addressline2, indent, out) + out.write(",") + out.write(""""city":""") + JsonEncoder.string.unsafeEncode(a.city, indent, out) + out.write(",") + out.write(""""stateprovincename":""") + Name.jsonEncoder.unsafeEncode(a.stateprovincename, indent, out) + out.write(",") + out.write(""""postalcode":""") + JsonEncoder.string.unsafeEncode(a.postalcode, indent, out) + out.write(",") + out.write(""""countryregionname":""") + Name.jsonEncoder.unsafeEncode(a.countryregionname, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewStructure.scala new file mode 100644 index 0000000000..54c832e3d4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithaddresses/VstorewithaddressesViewStructure.scala @@ -0,0 +1,36 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithaddresses + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VstorewithaddressesViewStructure[Row](val prefix: Option[String], val extract: Row => VstorewithaddressesViewRow, val merge: (Row, VstorewithaddressesViewRow) => Row) + extends Relation[VstorewithaddressesViewFields, VstorewithaddressesViewRow, Row] + with VstorewithaddressesViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val addresstype = new Field[Name, Row](prefix, "addresstype", None, None)(x => extract(x).addresstype, (row, value) => merge(row, extract(row).copy(addresstype = value))) + override val addressline1 = new Field[/* max 60 chars */ String, Row](prefix, "addressline1", None, None)(x => extract(x).addressline1, (row, value) => merge(row, extract(row).copy(addressline1 = value))) + override val addressline2 = new OptField[/* max 60 chars */ String, Row](prefix, "addressline2", None, None)(x => extract(x).addressline2, (row, value) => merge(row, extract(row).copy(addressline2 = value))) + override val city = new Field[/* max 30 chars */ String, Row](prefix, "city", None, None)(x => extract(x).city, (row, value) => merge(row, extract(row).copy(city = value))) + override val stateprovincename = new Field[Name, Row](prefix, "stateprovincename", None, None)(x => extract(x).stateprovincename, (row, value) => merge(row, extract(row).copy(stateprovincename = value))) + override val postalcode = new Field[/* max 15 chars */ String, Row](prefix, "postalcode", None, None)(x => extract(x).postalcode, (row, value) => merge(row, extract(row).copy(postalcode = value))) + override val countryregionname = new Field[Name, Row](prefix, "countryregionname", None, None)(x => extract(x).countryregionname, (row, value) => merge(row, extract(row).copy(countryregionname = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, addresstype, addressline1, addressline2, city, stateprovincename, postalcode, countryregionname) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VstorewithaddressesViewRow, merge: (NewRow, VstorewithaddressesViewRow) => NewRow): VstorewithaddressesViewStructure[NewRow] = + new VstorewithaddressesViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewFields.scala new file mode 100644 index 0000000000..39b7c010bf --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewFields.scala @@ -0,0 +1,32 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VstorewithcontactsViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val contacttype: Field[Name, Row] + val title: OptField[/* max 8 chars */ String, Row] + val firstname: Field[/* user-picked */ FirstName, Row] + val middlename: OptField[Name, Row] + val lastname: Field[Name, Row] + val suffix: OptField[/* max 10 chars */ String, Row] + val phonenumber: OptField[Phone, Row] + val phonenumbertype: OptField[Name, Row] + val emailaddress: OptField[/* max 50 chars */ String, Row] + val emailpromotion: Field[Int, Row] +} +object VstorewithcontactsViewFields extends VstorewithcontactsViewStructure[VstorewithcontactsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepo.scala new file mode 100644 index 0000000000..6101083061 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithcontacts + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VstorewithcontactsViewRepo { + def select: SelectBuilder[VstorewithcontactsViewFields, VstorewithcontactsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VstorewithcontactsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepoImpl.scala new file mode 100644 index 0000000000..8d413e5b8d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithcontacts + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VstorewithcontactsViewRepoImpl extends VstorewithcontactsViewRepo { + override def select: SelectBuilder[VstorewithcontactsViewFields, VstorewithcontactsViewRow] = { + SelectBuilderSql("sales.vstorewithcontacts", VstorewithcontactsViewFields, VstorewithcontactsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VstorewithcontactsViewRow] = { + sql"""select "businessentityid", "name", "contacttype", "title", "firstname", "middlename", "lastname", "suffix", "phonenumber", "phonenumbertype", "emailaddress", "emailpromotion" from sales.vstorewithcontacts""".query(VstorewithcontactsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRow.scala new file mode 100644 index 0000000000..509a1d0486 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewRow.scala @@ -0,0 +1,125 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VstorewithcontactsViewRow( + /** Points to [[store.StoreRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[store.StoreRow.name]] */ + name: Name, + /** Points to [[person.contacttype.ContacttypeRow.name]] */ + contacttype: Name, + /** Points to [[person.person.PersonRow.title]] */ + title: Option[/* max 8 chars */ String], + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.middlename]] */ + middlename: Option[Name], + /** Points to [[person.person.PersonRow.lastname]] */ + lastname: Name, + /** Points to [[person.person.PersonRow.suffix]] */ + suffix: Option[/* max 10 chars */ String], + /** Points to [[person.personphone.PersonphoneRow.phonenumber]] */ + phonenumber: Option[Phone], + /** Points to [[person.phonenumbertype.PhonenumbertypeRow.name]] */ + phonenumbertype: Option[Name], + /** Points to [[person.emailaddress.EmailaddressRow.emailaddress]] */ + emailaddress: Option[/* max 50 chars */ String], + /** Points to [[person.person.PersonRow.emailpromotion]] */ + emailpromotion: Int +) + +object VstorewithcontactsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VstorewithcontactsViewRow] = new JdbcDecoder[VstorewithcontactsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VstorewithcontactsViewRow) = + columIndex + 11 -> + VstorewithcontactsViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + contacttype = Name.jdbcDecoder.unsafeDecode(columIndex + 2, rs)._2, + title = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 3, rs)._2, + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 4, rs)._2, + middlename = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 5, rs)._2, + lastname = Name.jdbcDecoder.unsafeDecode(columIndex + 6, rs)._2, + suffix = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + phonenumber = JdbcDecoder.optionDecoder(Phone.jdbcDecoder).unsafeDecode(columIndex + 8, rs)._2, + phonenumbertype = JdbcDecoder.optionDecoder(Name.jdbcDecoder).unsafeDecode(columIndex + 9, rs)._2, + emailaddress = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + emailpromotion = JdbcDecoder.intDecoder.unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VstorewithcontactsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val contacttype = jsonObj.get("contacttype").toRight("Missing field 'contacttype'").flatMap(_.as(Name.jsonDecoder)) + val title = jsonObj.get("title").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val middlename = jsonObj.get("middlename").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val lastname = jsonObj.get("lastname").toRight("Missing field 'lastname'").flatMap(_.as(Name.jsonDecoder)) + val suffix = jsonObj.get("suffix").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val phonenumber = jsonObj.get("phonenumber").fold[Either[String, Option[Phone]]](Right(None))(_.as(JsonDecoder.option(Phone.jsonDecoder))) + val phonenumbertype = jsonObj.get("phonenumbertype").fold[Either[String, Option[Name]]](Right(None))(_.as(JsonDecoder.option(Name.jsonDecoder))) + val emailaddress = jsonObj.get("emailaddress").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val emailpromotion = jsonObj.get("emailpromotion").toRight("Missing field 'emailpromotion'").flatMap(_.as(JsonDecoder.int)) + if (businessentityid.isRight && name.isRight && contacttype.isRight && title.isRight && firstname.isRight && middlename.isRight && lastname.isRight && suffix.isRight && phonenumber.isRight && phonenumbertype.isRight && emailaddress.isRight && emailpromotion.isRight) + Right(VstorewithcontactsViewRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, contacttype = contacttype.toOption.get, title = title.toOption.get, firstname = firstname.toOption.get, middlename = middlename.toOption.get, lastname = lastname.toOption.get, suffix = suffix.toOption.get, phonenumber = phonenumber.toOption.get, phonenumbertype = phonenumbertype.toOption.get, emailaddress = emailaddress.toOption.get, emailpromotion = emailpromotion.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, contacttype, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VstorewithcontactsViewRow] = new JsonEncoder[VstorewithcontactsViewRow] { + override def unsafeEncode(a: VstorewithcontactsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""contacttype":""") + Name.jsonEncoder.unsafeEncode(a.contacttype, indent, out) + out.write(",") + out.write(""""title":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.title, indent, out) + out.write(",") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""middlename":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.middlename, indent, out) + out.write(",") + out.write(""""lastname":""") + Name.jsonEncoder.unsafeEncode(a.lastname, indent, out) + out.write(",") + out.write(""""suffix":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.suffix, indent, out) + out.write(",") + out.write(""""phonenumber":""") + JsonEncoder.option(Phone.jsonEncoder).unsafeEncode(a.phonenumber, indent, out) + out.write(",") + out.write(""""phonenumbertype":""") + JsonEncoder.option(Name.jsonEncoder).unsafeEncode(a.phonenumbertype, indent, out) + out.write(",") + out.write(""""emailaddress":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.emailaddress, indent, out) + out.write(",") + out.write(""""emailpromotion":""") + JsonEncoder.int.unsafeEncode(a.emailpromotion, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewStructure.scala new file mode 100644 index 0000000000..0e2624e4a4 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithcontacts/VstorewithcontactsViewStructure.scala @@ -0,0 +1,41 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithcontacts + +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import adventureworks.public.Phone +import adventureworks.userdefined.FirstName +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VstorewithcontactsViewStructure[Row](val prefix: Option[String], val extract: Row => VstorewithcontactsViewRow, val merge: (Row, VstorewithcontactsViewRow) => Row) + extends Relation[VstorewithcontactsViewFields, VstorewithcontactsViewRow, Row] + with VstorewithcontactsViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val contacttype = new Field[Name, Row](prefix, "contacttype", None, None)(x => extract(x).contacttype, (row, value) => merge(row, extract(row).copy(contacttype = value))) + override val title = new OptField[/* max 8 chars */ String, Row](prefix, "title", None, None)(x => extract(x).title, (row, value) => merge(row, extract(row).copy(title = value))) + override val firstname = new Field[/* user-picked */ FirstName, Row](prefix, "firstname", None, None)(x => extract(x).firstname, (row, value) => merge(row, extract(row).copy(firstname = value))) + override val middlename = new OptField[Name, Row](prefix, "middlename", None, None)(x => extract(x).middlename, (row, value) => merge(row, extract(row).copy(middlename = value))) + override val lastname = new Field[Name, Row](prefix, "lastname", None, None)(x => extract(x).lastname, (row, value) => merge(row, extract(row).copy(lastname = value))) + override val suffix = new OptField[/* max 10 chars */ String, Row](prefix, "suffix", None, None)(x => extract(x).suffix, (row, value) => merge(row, extract(row).copy(suffix = value))) + override val phonenumber = new OptField[Phone, Row](prefix, "phonenumber", None, None)(x => extract(x).phonenumber, (row, value) => merge(row, extract(row).copy(phonenumber = value))) + override val phonenumbertype = new OptField[Name, Row](prefix, "phonenumbertype", None, None)(x => extract(x).phonenumbertype, (row, value) => merge(row, extract(row).copy(phonenumbertype = value))) + override val emailaddress = new OptField[/* max 50 chars */ String, Row](prefix, "emailaddress", None, None)(x => extract(x).emailaddress, (row, value) => merge(row, extract(row).copy(emailaddress = value))) + override val emailpromotion = new Field[Int, Row](prefix, "emailpromotion", None, None)(x => extract(x).emailpromotion, (row, value) => merge(row, extract(row).copy(emailpromotion = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, contacttype, title, firstname, middlename, lastname, suffix, phonenumber, phonenumbertype, emailaddress, emailpromotion) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VstorewithcontactsViewRow, merge: (NewRow, VstorewithcontactsViewRow) => NewRow): VstorewithcontactsViewStructure[NewRow] = + new VstorewithcontactsViewStructure(prefix, extract, merge) +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewFields.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewFields.scala new file mode 100644 index 0000000000..c3d98a97b6 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewFields.scala @@ -0,0 +1,31 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithdemographics + +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.OptField + +trait VstorewithdemographicsViewFields[Row] { + val businessentityid: Field[BusinessentityId, Row] + val name: Field[Name, Row] + val AnnualSales: OptField[TypoMoney, Row] + val AnnualRevenue: OptField[TypoMoney, Row] + val BankName: OptField[/* max 50 chars */ String, Row] + val BusinessType: OptField[/* max 5 chars */ String, Row] + val YearOpened: OptField[Int, Row] + val Specialty: OptField[/* max 50 chars */ String, Row] + val SquareFeet: OptField[Int, Row] + val Brands: OptField[/* max 30 chars */ String, Row] + val Internet: OptField[/* max 30 chars */ String, Row] + val NumberEmployees: OptField[Int, Row] +} +object VstorewithdemographicsViewFields extends VstorewithdemographicsViewStructure[VstorewithdemographicsViewRow](None, identity, (_, x) => x) + diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepo.scala new file mode 100644 index 0000000000..54a000b7e7 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepo.scala @@ -0,0 +1,17 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithdemographics + +import typo.dsl.SelectBuilder +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait VstorewithdemographicsViewRepo { + def select: SelectBuilder[VstorewithdemographicsViewFields, VstorewithdemographicsViewRow] + def selectAll: ZStream[ZConnection, Throwable, VstorewithdemographicsViewRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepoImpl.scala new file mode 100644 index 0000000000..fb71aa349c --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRepoImpl.scala @@ -0,0 +1,23 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithdemographics + +import typo.dsl.SelectBuilder +import typo.dsl.SelectBuilderSql +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object VstorewithdemographicsViewRepoImpl extends VstorewithdemographicsViewRepo { + override def select: SelectBuilder[VstorewithdemographicsViewFields, VstorewithdemographicsViewRow] = { + SelectBuilderSql("sales.vstorewithdemographics", VstorewithdemographicsViewFields, VstorewithdemographicsViewRow.jdbcDecoder) + } + override def selectAll: ZStream[ZConnection, Throwable, VstorewithdemographicsViewRow] = { + sql"""select "businessentityid", "name", "AnnualSales"::numeric, "AnnualRevenue"::numeric, "BankName", "BusinessType", "YearOpened", "Specialty", "SquareFeet", "Brands", "Internet", "NumberEmployees" from sales.vstorewithdemographics""".query(VstorewithdemographicsViewRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRow.scala new file mode 100644 index 0000000000..0398d46994 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewRow.scala @@ -0,0 +1,114 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithdemographics + +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class VstorewithdemographicsViewRow( + /** Points to [[store.StoreRow.businessentityid]] */ + businessentityid: BusinessentityId, + /** Points to [[store.StoreRow.name]] */ + name: Name, + AnnualSales: /* nullability unknown */ Option[TypoMoney], + AnnualRevenue: /* nullability unknown */ Option[TypoMoney], + BankName: /* nullability unknown */ Option[/* max 50 chars */ String], + BusinessType: /* nullability unknown */ Option[/* max 5 chars */ String], + YearOpened: /* nullability unknown */ Option[Int], + Specialty: /* nullability unknown */ Option[/* max 50 chars */ String], + SquareFeet: /* nullability unknown */ Option[Int], + Brands: /* nullability unknown */ Option[/* max 30 chars */ String], + Internet: /* nullability unknown */ Option[/* max 30 chars */ String], + NumberEmployees: /* nullability unknown */ Option[Int] +) + +object VstorewithdemographicsViewRow { + implicit lazy val jdbcDecoder: JdbcDecoder[VstorewithdemographicsViewRow] = new JdbcDecoder[VstorewithdemographicsViewRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, VstorewithdemographicsViewRow) = + columIndex + 11 -> + VstorewithdemographicsViewRow( + businessentityid = BusinessentityId.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + name = Name.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2, + AnnualSales = JdbcDecoder.optionDecoder(TypoMoney.jdbcDecoder).unsafeDecode(columIndex + 2, rs)._2, + AnnualRevenue = JdbcDecoder.optionDecoder(TypoMoney.jdbcDecoder).unsafeDecode(columIndex + 3, rs)._2, + BankName = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 4, rs)._2, + BusinessType = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 5, rs)._2, + YearOpened = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 6, rs)._2, + Specialty = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 7, rs)._2, + SquareFeet = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 8, rs)._2, + Brands = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 9, rs)._2, + Internet = JdbcDecoder.optionDecoder(JdbcDecoder.stringDecoder).unsafeDecode(columIndex + 10, rs)._2, + NumberEmployees = JdbcDecoder.optionDecoder(JdbcDecoder.intDecoder).unsafeDecode(columIndex + 11, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[VstorewithdemographicsViewRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val businessentityid = jsonObj.get("businessentityid").toRight("Missing field 'businessentityid'").flatMap(_.as(BusinessentityId.jsonDecoder)) + val name = jsonObj.get("name").toRight("Missing field 'name'").flatMap(_.as(Name.jsonDecoder)) + val AnnualSales = jsonObj.get("AnnualSales").fold[Either[String, Option[TypoMoney]]](Right(None))(_.as(JsonDecoder.option(TypoMoney.jsonDecoder))) + val AnnualRevenue = jsonObj.get("AnnualRevenue").fold[Either[String, Option[TypoMoney]]](Right(None))(_.as(JsonDecoder.option(TypoMoney.jsonDecoder))) + val BankName = jsonObj.get("BankName").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val BusinessType = jsonObj.get("BusinessType").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val YearOpened = jsonObj.get("YearOpened").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val Specialty = jsonObj.get("Specialty").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val SquareFeet = jsonObj.get("SquareFeet").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + val Brands = jsonObj.get("Brands").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val Internet = jsonObj.get("Internet").fold[Either[String, Option[String]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.string))) + val NumberEmployees = jsonObj.get("NumberEmployees").fold[Either[String, Option[Int]]](Right(None))(_.as(JsonDecoder.option(JsonDecoder.int))) + if (businessentityid.isRight && name.isRight && AnnualSales.isRight && AnnualRevenue.isRight && BankName.isRight && BusinessType.isRight && YearOpened.isRight && Specialty.isRight && SquareFeet.isRight && Brands.isRight && Internet.isRight && NumberEmployees.isRight) + Right(VstorewithdemographicsViewRow(businessentityid = businessentityid.toOption.get, name = name.toOption.get, AnnualSales = AnnualSales.toOption.get, AnnualRevenue = AnnualRevenue.toOption.get, BankName = BankName.toOption.get, BusinessType = BusinessType.toOption.get, YearOpened = YearOpened.toOption.get, Specialty = Specialty.toOption.get, SquareFeet = SquareFeet.toOption.get, Brands = Brands.toOption.get, Internet = Internet.toOption.get, NumberEmployees = NumberEmployees.toOption.get)) + else Left(List[Either[String, Any]](businessentityid, name, AnnualSales, AnnualRevenue, BankName, BusinessType, YearOpened, Specialty, SquareFeet, Brands, Internet, NumberEmployees).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[VstorewithdemographicsViewRow] = new JsonEncoder[VstorewithdemographicsViewRow] { + override def unsafeEncode(a: VstorewithdemographicsViewRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""businessentityid":""") + BusinessentityId.jsonEncoder.unsafeEncode(a.businessentityid, indent, out) + out.write(",") + out.write(""""name":""") + Name.jsonEncoder.unsafeEncode(a.name, indent, out) + out.write(",") + out.write(""""AnnualSales":""") + JsonEncoder.option(TypoMoney.jsonEncoder).unsafeEncode(a.AnnualSales, indent, out) + out.write(",") + out.write(""""AnnualRevenue":""") + JsonEncoder.option(TypoMoney.jsonEncoder).unsafeEncode(a.AnnualRevenue, indent, out) + out.write(",") + out.write(""""BankName":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.BankName, indent, out) + out.write(",") + out.write(""""BusinessType":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.BusinessType, indent, out) + out.write(",") + out.write(""""YearOpened":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.YearOpened, indent, out) + out.write(",") + out.write(""""Specialty":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Specialty, indent, out) + out.write(",") + out.write(""""SquareFeet":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.SquareFeet, indent, out) + out.write(",") + out.write(""""Brands":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Brands, indent, out) + out.write(",") + out.write(""""Internet":""") + JsonEncoder.option(JsonEncoder.string).unsafeEncode(a.Internet, indent, out) + out.write(",") + out.write(""""NumberEmployees":""") + JsonEncoder.option(JsonEncoder.int).unsafeEncode(a.NumberEmployees, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewStructure.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewStructure.scala new file mode 100644 index 0000000000..e9b17f1121 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/sales/vstorewithdemographics/VstorewithdemographicsViewStructure.scala @@ -0,0 +1,40 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package sales +package vstorewithdemographics + +import adventureworks.customtypes.TypoMoney +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.public.Name +import typo.dsl.SqlExpr.Field +import typo.dsl.SqlExpr.FieldLikeNoHkt +import typo.dsl.SqlExpr.OptField +import typo.dsl.Structure.Relation + +class VstorewithdemographicsViewStructure[Row](val prefix: Option[String], val extract: Row => VstorewithdemographicsViewRow, val merge: (Row, VstorewithdemographicsViewRow) => Row) + extends Relation[VstorewithdemographicsViewFields, VstorewithdemographicsViewRow, Row] + with VstorewithdemographicsViewFields[Row] { outer => + + override val businessentityid = new Field[BusinessentityId, Row](prefix, "businessentityid", None, None)(x => extract(x).businessentityid, (row, value) => merge(row, extract(row).copy(businessentityid = value))) + override val name = new Field[Name, Row](prefix, "name", None, None)(x => extract(x).name, (row, value) => merge(row, extract(row).copy(name = value))) + override val AnnualSales = new OptField[TypoMoney, Row](prefix, "AnnualSales", Some("numeric"), None)(x => extract(x).AnnualSales, (row, value) => merge(row, extract(row).copy(AnnualSales = value))) + override val AnnualRevenue = new OptField[TypoMoney, Row](prefix, "AnnualRevenue", Some("numeric"), None)(x => extract(x).AnnualRevenue, (row, value) => merge(row, extract(row).copy(AnnualRevenue = value))) + override val BankName = new OptField[/* max 50 chars */ String, Row](prefix, "BankName", None, None)(x => extract(x).BankName, (row, value) => merge(row, extract(row).copy(BankName = value))) + override val BusinessType = new OptField[/* max 5 chars */ String, Row](prefix, "BusinessType", None, None)(x => extract(x).BusinessType, (row, value) => merge(row, extract(row).copy(BusinessType = value))) + override val YearOpened = new OptField[Int, Row](prefix, "YearOpened", None, None)(x => extract(x).YearOpened, (row, value) => merge(row, extract(row).copy(YearOpened = value))) + override val Specialty = new OptField[/* max 50 chars */ String, Row](prefix, "Specialty", None, None)(x => extract(x).Specialty, (row, value) => merge(row, extract(row).copy(Specialty = value))) + override val SquareFeet = new OptField[Int, Row](prefix, "SquareFeet", None, None)(x => extract(x).SquareFeet, (row, value) => merge(row, extract(row).copy(SquareFeet = value))) + override val Brands = new OptField[/* max 30 chars */ String, Row](prefix, "Brands", None, None)(x => extract(x).Brands, (row, value) => merge(row, extract(row).copy(Brands = value))) + override val Internet = new OptField[/* max 30 chars */ String, Row](prefix, "Internet", None, None)(x => extract(x).Internet, (row, value) => merge(row, extract(row).copy(Internet = value))) + override val NumberEmployees = new OptField[Int, Row](prefix, "NumberEmployees", None, None)(x => extract(x).NumberEmployees, (row, value) => merge(row, extract(row).copy(NumberEmployees = value))) + + override val columns: List[FieldLikeNoHkt[?, Row]] = + List[FieldLikeNoHkt[?, Row]](businessentityid, name, AnnualSales, AnnualRevenue, BankName, BusinessType, YearOpened, Specialty, SquareFeet, Brands, Internet, NumberEmployees) + + override def copy[NewRow](prefix: Option[String], extract: NewRow => VstorewithdemographicsViewRow, merge: (NewRow, VstorewithdemographicsViewRow) => NewRow): VstorewithdemographicsViewStructure[NewRow] = + new VstorewithdemographicsViewStructure(prefix, extract, merge) +} 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 new file mode 100644 index 0000000000..f1ccf03e6d --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/testInsert.scala @@ -0,0 +1,629 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks + +import adventureworks.customtypes.Defaulted +import adventureworks.customtypes.TypoAclItem +import adventureworks.customtypes.TypoAnyArray +import adventureworks.customtypes.TypoBox +import adventureworks.customtypes.TypoBytea +import adventureworks.customtypes.TypoCircle +import adventureworks.customtypes.TypoHStore +import adventureworks.customtypes.TypoInet +import adventureworks.customtypes.TypoInstant +import adventureworks.customtypes.TypoInt2Vector +import adventureworks.customtypes.TypoInterval +import adventureworks.customtypes.TypoJson +import adventureworks.customtypes.TypoJsonb +import adventureworks.customtypes.TypoLine +import adventureworks.customtypes.TypoLineSegment +import adventureworks.customtypes.TypoLocalDate +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.customtypes.TypoLocalTime +import adventureworks.customtypes.TypoMoney +import adventureworks.customtypes.TypoOffsetTime +import adventureworks.customtypes.TypoOidVector +import adventureworks.customtypes.TypoPath +import adventureworks.customtypes.TypoPgNodeTree +import adventureworks.customtypes.TypoPoint +import adventureworks.customtypes.TypoPolygon +import adventureworks.customtypes.TypoRegproc +import adventureworks.customtypes.TypoShort +import adventureworks.customtypes.TypoUUID +import adventureworks.customtypes.TypoUnknownCitext +import adventureworks.customtypes.TypoUnknownPgDependencies +import adventureworks.customtypes.TypoUnknownPgMcvList +import adventureworks.customtypes.TypoUnknownPgNdistinct +import adventureworks.customtypes.TypoUnknownPgStatistic +import adventureworks.customtypes.TypoVector +import adventureworks.customtypes.TypoXid +import adventureworks.customtypes.TypoXml +import adventureworks.humanresources.department.DepartmentId +import adventureworks.humanresources.department.DepartmentRepoImpl +import adventureworks.humanresources.department.DepartmentRow +import adventureworks.humanresources.department.DepartmentRowUnsaved +import adventureworks.humanresources.employee.EmployeeRepoImpl +import adventureworks.humanresources.employee.EmployeeRow +import adventureworks.humanresources.employee.EmployeeRowUnsaved +import adventureworks.humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRepoImpl +import adventureworks.humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRow +import adventureworks.humanresources.employeedepartmenthistory.EmployeedepartmenthistoryRowUnsaved +import adventureworks.humanresources.employeepayhistory.EmployeepayhistoryRepoImpl +import adventureworks.humanresources.employeepayhistory.EmployeepayhistoryRow +import adventureworks.humanresources.employeepayhistory.EmployeepayhistoryRowUnsaved +import adventureworks.humanresources.jobcandidate.JobcandidateId +import adventureworks.humanresources.jobcandidate.JobcandidateRepoImpl +import adventureworks.humanresources.jobcandidate.JobcandidateRow +import adventureworks.humanresources.jobcandidate.JobcandidateRowUnsaved +import adventureworks.humanresources.shift.ShiftId +import adventureworks.humanresources.shift.ShiftRepoImpl +import adventureworks.humanresources.shift.ShiftRow +import adventureworks.humanresources.shift.ShiftRowUnsaved +import adventureworks.information_schema.CardinalNumber +import adventureworks.information_schema.CharacterData +import adventureworks.information_schema.YesOrNo +import adventureworks.information_schema.sql_features.SqlFeaturesRepoImpl +import adventureworks.information_schema.sql_features.SqlFeaturesRow +import adventureworks.information_schema.sql_implementation_info.SqlImplementationInfoRepoImpl +import adventureworks.information_schema.sql_implementation_info.SqlImplementationInfoRow +import adventureworks.information_schema.sql_parts.SqlPartsRepoImpl +import adventureworks.information_schema.sql_parts.SqlPartsRow +import adventureworks.information_schema.sql_sizing.SqlSizingRepoImpl +import adventureworks.information_schema.sql_sizing.SqlSizingRow +import adventureworks.person.address.AddressId +import adventureworks.person.address.AddressRepoImpl +import adventureworks.person.address.AddressRow +import adventureworks.person.address.AddressRowUnsaved +import adventureworks.person.addresstype.AddresstypeId +import adventureworks.person.addresstype.AddresstypeRepoImpl +import adventureworks.person.addresstype.AddresstypeRow +import adventureworks.person.addresstype.AddresstypeRowUnsaved +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.person.businessentity.BusinessentityRepoImpl +import adventureworks.person.businessentity.BusinessentityRow +import adventureworks.person.businessentity.BusinessentityRowUnsaved +import adventureworks.person.businessentityaddress.BusinessentityaddressRepoImpl +import adventureworks.person.businessentityaddress.BusinessentityaddressRow +import adventureworks.person.businessentityaddress.BusinessentityaddressRowUnsaved +import adventureworks.person.businessentitycontact.BusinessentitycontactRepoImpl +import adventureworks.person.businessentitycontact.BusinessentitycontactRow +import adventureworks.person.businessentitycontact.BusinessentitycontactRowUnsaved +import adventureworks.person.contacttype.ContacttypeId +import adventureworks.person.contacttype.ContacttypeRepoImpl +import adventureworks.person.contacttype.ContacttypeRow +import adventureworks.person.contacttype.ContacttypeRowUnsaved +import adventureworks.person.countryregion.CountryregionId +import adventureworks.person.countryregion.CountryregionRepoImpl +import adventureworks.person.countryregion.CountryregionRow +import adventureworks.person.countryregion.CountryregionRowUnsaved +import adventureworks.person.emailaddress.EmailaddressRepoImpl +import adventureworks.person.emailaddress.EmailaddressRow +import adventureworks.person.emailaddress.EmailaddressRowUnsaved +import adventureworks.person.password.PasswordRepoImpl +import adventureworks.person.password.PasswordRow +import adventureworks.person.password.PasswordRowUnsaved +import adventureworks.person.person.PersonRepoImpl +import adventureworks.person.person.PersonRow +import adventureworks.person.person.PersonRowUnsaved +import adventureworks.person.personphone.PersonphoneRepoImpl +import adventureworks.person.personphone.PersonphoneRow +import adventureworks.person.personphone.PersonphoneRowUnsaved +import adventureworks.person.phonenumbertype.PhonenumbertypeId +import adventureworks.person.phonenumbertype.PhonenumbertypeRepoImpl +import adventureworks.person.phonenumbertype.PhonenumbertypeRow +import adventureworks.person.phonenumbertype.PhonenumbertypeRowUnsaved +import adventureworks.person.stateprovince.StateprovinceId +import adventureworks.person.stateprovince.StateprovinceRepoImpl +import adventureworks.person.stateprovince.StateprovinceRow +import adventureworks.person.stateprovince.StateprovinceRowUnsaved +import adventureworks.pg_catalog.pg_aggregate.PgAggregateId +import adventureworks.pg_catalog.pg_aggregate.PgAggregateRepoImpl +import adventureworks.pg_catalog.pg_aggregate.PgAggregateRow +import adventureworks.pg_catalog.pg_am.PgAmId +import adventureworks.pg_catalog.pg_am.PgAmRepoImpl +import adventureworks.pg_catalog.pg_am.PgAmRow +import adventureworks.pg_catalog.pg_amop.PgAmopId +import adventureworks.pg_catalog.pg_amop.PgAmopRepoImpl +import adventureworks.pg_catalog.pg_amop.PgAmopRow +import adventureworks.pg_catalog.pg_amproc.PgAmprocId +import adventureworks.pg_catalog.pg_amproc.PgAmprocRepoImpl +import adventureworks.pg_catalog.pg_amproc.PgAmprocRow +import adventureworks.pg_catalog.pg_attrdef.PgAttrdefId +import adventureworks.pg_catalog.pg_attrdef.PgAttrdefRepoImpl +import adventureworks.pg_catalog.pg_attrdef.PgAttrdefRow +import adventureworks.pg_catalog.pg_attribute.PgAttributeRepoImpl +import adventureworks.pg_catalog.pg_attribute.PgAttributeRow +import adventureworks.pg_catalog.pg_auth_members.PgAuthMembersRepoImpl +import adventureworks.pg_catalog.pg_auth_members.PgAuthMembersRow +import adventureworks.pg_catalog.pg_authid.PgAuthidId +import adventureworks.pg_catalog.pg_authid.PgAuthidRepoImpl +import adventureworks.pg_catalog.pg_authid.PgAuthidRow +import adventureworks.pg_catalog.pg_cast.PgCastId +import adventureworks.pg_catalog.pg_cast.PgCastRepoImpl +import adventureworks.pg_catalog.pg_cast.PgCastRow +import adventureworks.pg_catalog.pg_class.PgClassId +import adventureworks.pg_catalog.pg_class.PgClassRepoImpl +import adventureworks.pg_catalog.pg_class.PgClassRow +import adventureworks.pg_catalog.pg_collation.PgCollationId +import adventureworks.pg_catalog.pg_collation.PgCollationRepoImpl +import adventureworks.pg_catalog.pg_collation.PgCollationRow +import adventureworks.pg_catalog.pg_constraint.PgConstraintId +import adventureworks.pg_catalog.pg_constraint.PgConstraintRepoImpl +import adventureworks.pg_catalog.pg_constraint.PgConstraintRow +import adventureworks.pg_catalog.pg_conversion.PgConversionId +import adventureworks.pg_catalog.pg_conversion.PgConversionRepoImpl +import adventureworks.pg_catalog.pg_conversion.PgConversionRow +import adventureworks.pg_catalog.pg_database.PgDatabaseId +import adventureworks.pg_catalog.pg_database.PgDatabaseRepoImpl +import adventureworks.pg_catalog.pg_database.PgDatabaseRow +import adventureworks.pg_catalog.pg_db_role_setting.PgDbRoleSettingRepoImpl +import adventureworks.pg_catalog.pg_db_role_setting.PgDbRoleSettingRow +import adventureworks.pg_catalog.pg_default_acl.PgDefaultAclId +import adventureworks.pg_catalog.pg_default_acl.PgDefaultAclRepoImpl +import adventureworks.pg_catalog.pg_default_acl.PgDefaultAclRow +import adventureworks.pg_catalog.pg_depend.PgDependRepoImpl +import adventureworks.pg_catalog.pg_depend.PgDependRow +import adventureworks.pg_catalog.pg_description.PgDescriptionRepoImpl +import adventureworks.pg_catalog.pg_description.PgDescriptionRow +import adventureworks.pg_catalog.pg_enum.PgEnumId +import adventureworks.pg_catalog.pg_enum.PgEnumRepoImpl +import adventureworks.pg_catalog.pg_enum.PgEnumRow +import adventureworks.pg_catalog.pg_event_trigger.PgEventTriggerId +import adventureworks.pg_catalog.pg_event_trigger.PgEventTriggerRepoImpl +import adventureworks.pg_catalog.pg_event_trigger.PgEventTriggerRow +import adventureworks.pg_catalog.pg_extension.PgExtensionId +import adventureworks.pg_catalog.pg_extension.PgExtensionRepoImpl +import adventureworks.pg_catalog.pg_extension.PgExtensionRow +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperId +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRepoImpl +import adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRow +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerId +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerRepoImpl +import adventureworks.pg_catalog.pg_foreign_server.PgForeignServerRow +import adventureworks.pg_catalog.pg_foreign_table.PgForeignTableId +import adventureworks.pg_catalog.pg_foreign_table.PgForeignTableRepoImpl +import adventureworks.pg_catalog.pg_foreign_table.PgForeignTableRow +import adventureworks.pg_catalog.pg_index.PgIndexId +import adventureworks.pg_catalog.pg_index.PgIndexRepoImpl +import adventureworks.pg_catalog.pg_index.PgIndexRow +import adventureworks.pg_catalog.pg_inherits.PgInheritsRepoImpl +import adventureworks.pg_catalog.pg_inherits.PgInheritsRow +import adventureworks.pg_catalog.pg_init_privs.PgInitPrivsRepoImpl +import adventureworks.pg_catalog.pg_init_privs.PgInitPrivsRow +import adventureworks.pg_catalog.pg_language.PgLanguageId +import adventureworks.pg_catalog.pg_language.PgLanguageRepoImpl +import adventureworks.pg_catalog.pg_language.PgLanguageRow +import adventureworks.pg_catalog.pg_largeobject.PgLargeobjectRepoImpl +import adventureworks.pg_catalog.pg_largeobject.PgLargeobjectRow +import adventureworks.pg_catalog.pg_largeobject_metadata.PgLargeobjectMetadataId +import adventureworks.pg_catalog.pg_largeobject_metadata.PgLargeobjectMetadataRepoImpl +import adventureworks.pg_catalog.pg_largeobject_metadata.PgLargeobjectMetadataRow +import adventureworks.pg_catalog.pg_namespace.PgNamespaceId +import adventureworks.pg_catalog.pg_namespace.PgNamespaceRepoImpl +import adventureworks.pg_catalog.pg_namespace.PgNamespaceRow +import adventureworks.pg_catalog.pg_opclass.PgOpclassId +import adventureworks.pg_catalog.pg_opclass.PgOpclassRepoImpl +import adventureworks.pg_catalog.pg_opclass.PgOpclassRow +import adventureworks.pg_catalog.pg_operator.PgOperatorId +import adventureworks.pg_catalog.pg_operator.PgOperatorRepoImpl +import adventureworks.pg_catalog.pg_operator.PgOperatorRow +import adventureworks.pg_catalog.pg_opfamily.PgOpfamilyId +import adventureworks.pg_catalog.pg_opfamily.PgOpfamilyRepoImpl +import adventureworks.pg_catalog.pg_opfamily.PgOpfamilyRow +import adventureworks.pg_catalog.pg_partitioned_table.PgPartitionedTableId +import adventureworks.pg_catalog.pg_partitioned_table.PgPartitionedTableRepoImpl +import adventureworks.pg_catalog.pg_partitioned_table.PgPartitionedTableRow +import adventureworks.pg_catalog.pg_policy.PgPolicyId +import adventureworks.pg_catalog.pg_policy.PgPolicyRepoImpl +import adventureworks.pg_catalog.pg_policy.PgPolicyRow +import adventureworks.pg_catalog.pg_proc.PgProcId +import adventureworks.pg_catalog.pg_proc.PgProcRepoImpl +import adventureworks.pg_catalog.pg_proc.PgProcRow +import adventureworks.pg_catalog.pg_publication.PgPublicationId +import adventureworks.pg_catalog.pg_publication.PgPublicationRepoImpl +import adventureworks.pg_catalog.pg_publication.PgPublicationRow +import adventureworks.pg_catalog.pg_publication_rel.PgPublicationRelId +import adventureworks.pg_catalog.pg_publication_rel.PgPublicationRelRepoImpl +import adventureworks.pg_catalog.pg_publication_rel.PgPublicationRelRow +import adventureworks.pg_catalog.pg_range.PgRangeId +import adventureworks.pg_catalog.pg_range.PgRangeRepoImpl +import adventureworks.pg_catalog.pg_range.PgRangeRow +import adventureworks.pg_catalog.pg_replication_origin.PgReplicationOriginId +import adventureworks.pg_catalog.pg_replication_origin.PgReplicationOriginRepoImpl +import adventureworks.pg_catalog.pg_replication_origin.PgReplicationOriginRow +import adventureworks.pg_catalog.pg_rewrite.PgRewriteId +import adventureworks.pg_catalog.pg_rewrite.PgRewriteRepoImpl +import adventureworks.pg_catalog.pg_rewrite.PgRewriteRow +import adventureworks.pg_catalog.pg_seclabel.PgSeclabelRepoImpl +import adventureworks.pg_catalog.pg_seclabel.PgSeclabelRow +import adventureworks.pg_catalog.pg_sequence.PgSequenceId +import adventureworks.pg_catalog.pg_sequence.PgSequenceRepoImpl +import adventureworks.pg_catalog.pg_sequence.PgSequenceRow +import adventureworks.pg_catalog.pg_shdepend.PgShdependRepoImpl +import adventureworks.pg_catalog.pg_shdepend.PgShdependRow +import adventureworks.pg_catalog.pg_shdescription.PgShdescriptionRepoImpl +import adventureworks.pg_catalog.pg_shdescription.PgShdescriptionRow +import adventureworks.pg_catalog.pg_shseclabel.PgShseclabelRepoImpl +import adventureworks.pg_catalog.pg_shseclabel.PgShseclabelRow +import adventureworks.pg_catalog.pg_statistic.PgStatisticRepoImpl +import adventureworks.pg_catalog.pg_statistic.PgStatisticRow +import adventureworks.pg_catalog.pg_statistic_ext.PgStatisticExtId +import adventureworks.pg_catalog.pg_statistic_ext.PgStatisticExtRepoImpl +import adventureworks.pg_catalog.pg_statistic_ext.PgStatisticExtRow +import adventureworks.pg_catalog.pg_statistic_ext_data.PgStatisticExtDataId +import adventureworks.pg_catalog.pg_statistic_ext_data.PgStatisticExtDataRepoImpl +import adventureworks.pg_catalog.pg_statistic_ext_data.PgStatisticExtDataRow +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionId +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionRepoImpl +import adventureworks.pg_catalog.pg_subscription.PgSubscriptionRow +import adventureworks.pg_catalog.pg_subscription_rel.PgSubscriptionRelRepoImpl +import adventureworks.pg_catalog.pg_subscription_rel.PgSubscriptionRelRow +import adventureworks.pg_catalog.pg_tablespace.PgTablespaceId +import adventureworks.pg_catalog.pg_tablespace.PgTablespaceRepoImpl +import adventureworks.pg_catalog.pg_tablespace.PgTablespaceRow +import adventureworks.pg_catalog.pg_transform.PgTransformId +import adventureworks.pg_catalog.pg_transform.PgTransformRepoImpl +import adventureworks.pg_catalog.pg_transform.PgTransformRow +import adventureworks.pg_catalog.pg_trigger.PgTriggerId +import adventureworks.pg_catalog.pg_trigger.PgTriggerRepoImpl +import adventureworks.pg_catalog.pg_trigger.PgTriggerRow +import adventureworks.pg_catalog.pg_ts_config.PgTsConfigId +import adventureworks.pg_catalog.pg_ts_config.PgTsConfigRepoImpl +import adventureworks.pg_catalog.pg_ts_config.PgTsConfigRow +import adventureworks.pg_catalog.pg_ts_config_map.PgTsConfigMapRepoImpl +import adventureworks.pg_catalog.pg_ts_config_map.PgTsConfigMapRow +import adventureworks.pg_catalog.pg_ts_dict.PgTsDictId +import adventureworks.pg_catalog.pg_ts_dict.PgTsDictRepoImpl +import adventureworks.pg_catalog.pg_ts_dict.PgTsDictRow +import adventureworks.pg_catalog.pg_ts_parser.PgTsParserId +import adventureworks.pg_catalog.pg_ts_parser.PgTsParserRepoImpl +import adventureworks.pg_catalog.pg_ts_parser.PgTsParserRow +import adventureworks.pg_catalog.pg_ts_template.PgTsTemplateId +import adventureworks.pg_catalog.pg_ts_template.PgTsTemplateRepoImpl +import adventureworks.pg_catalog.pg_ts_template.PgTsTemplateRow +import adventureworks.pg_catalog.pg_type.PgTypeId +import adventureworks.pg_catalog.pg_type.PgTypeRepoImpl +import adventureworks.pg_catalog.pg_type.PgTypeRow +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingId +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingRepoImpl +import adventureworks.pg_catalog.pg_user_mapping.PgUserMappingRow +import adventureworks.production.billofmaterials.BillofmaterialsId +import adventureworks.production.billofmaterials.BillofmaterialsRepoImpl +import adventureworks.production.billofmaterials.BillofmaterialsRow +import adventureworks.production.billofmaterials.BillofmaterialsRowUnsaved +import adventureworks.production.culture.CultureId +import adventureworks.production.culture.CultureRepoImpl +import adventureworks.production.culture.CultureRow +import adventureworks.production.culture.CultureRowUnsaved +import adventureworks.production.document.DocumentId +import adventureworks.production.document.DocumentRepoImpl +import adventureworks.production.document.DocumentRow +import adventureworks.production.document.DocumentRowUnsaved +import adventureworks.production.illustration.IllustrationId +import adventureworks.production.illustration.IllustrationRepoImpl +import adventureworks.production.illustration.IllustrationRow +import adventureworks.production.illustration.IllustrationRowUnsaved +import adventureworks.production.location.LocationId +import adventureworks.production.location.LocationRepoImpl +import adventureworks.production.location.LocationRow +import adventureworks.production.location.LocationRowUnsaved +import adventureworks.production.product.ProductId +import adventureworks.production.product.ProductRepoImpl +import adventureworks.production.product.ProductRow +import adventureworks.production.product.ProductRowUnsaved +import adventureworks.production.productcategory.ProductcategoryId +import adventureworks.production.productcategory.ProductcategoryRepoImpl +import adventureworks.production.productcategory.ProductcategoryRow +import adventureworks.production.productcategory.ProductcategoryRowUnsaved +import adventureworks.production.productcosthistory.ProductcosthistoryRepoImpl +import adventureworks.production.productcosthistory.ProductcosthistoryRow +import adventureworks.production.productcosthistory.ProductcosthistoryRowUnsaved +import adventureworks.production.productdescription.ProductdescriptionId +import adventureworks.production.productdescription.ProductdescriptionRepoImpl +import adventureworks.production.productdescription.ProductdescriptionRow +import adventureworks.production.productdescription.ProductdescriptionRowUnsaved +import adventureworks.production.productdocument.ProductdocumentRepoImpl +import adventureworks.production.productdocument.ProductdocumentRow +import adventureworks.production.productdocument.ProductdocumentRowUnsaved +import adventureworks.production.productinventory.ProductinventoryRepoImpl +import adventureworks.production.productinventory.ProductinventoryRow +import adventureworks.production.productinventory.ProductinventoryRowUnsaved +import adventureworks.production.productlistpricehistory.ProductlistpricehistoryRepoImpl +import adventureworks.production.productlistpricehistory.ProductlistpricehistoryRow +import adventureworks.production.productlistpricehistory.ProductlistpricehistoryRowUnsaved +import adventureworks.production.productmodel.ProductmodelId +import adventureworks.production.productmodel.ProductmodelRepoImpl +import adventureworks.production.productmodel.ProductmodelRow +import adventureworks.production.productmodel.ProductmodelRowUnsaved +import adventureworks.production.productmodelillustration.ProductmodelillustrationRepoImpl +import adventureworks.production.productmodelillustration.ProductmodelillustrationRow +import adventureworks.production.productmodelillustration.ProductmodelillustrationRowUnsaved +import adventureworks.production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRepoImpl +import adventureworks.production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRow +import adventureworks.production.productmodelproductdescriptionculture.ProductmodelproductdescriptioncultureRowUnsaved +import adventureworks.production.productphoto.ProductphotoId +import adventureworks.production.productphoto.ProductphotoRepoImpl +import adventureworks.production.productphoto.ProductphotoRow +import adventureworks.production.productphoto.ProductphotoRowUnsaved +import adventureworks.production.productproductphoto.ProductproductphotoRepoImpl +import adventureworks.production.productproductphoto.ProductproductphotoRow +import adventureworks.production.productproductphoto.ProductproductphotoRowUnsaved +import adventureworks.production.productreview.ProductreviewId +import adventureworks.production.productreview.ProductreviewRepoImpl +import adventureworks.production.productreview.ProductreviewRow +import adventureworks.production.productreview.ProductreviewRowUnsaved +import adventureworks.production.productsubcategory.ProductsubcategoryId +import adventureworks.production.productsubcategory.ProductsubcategoryRepoImpl +import adventureworks.production.productsubcategory.ProductsubcategoryRow +import adventureworks.production.productsubcategory.ProductsubcategoryRowUnsaved +import adventureworks.production.scrapreason.ScrapreasonId +import adventureworks.production.scrapreason.ScrapreasonRepoImpl +import adventureworks.production.scrapreason.ScrapreasonRow +import adventureworks.production.scrapreason.ScrapreasonRowUnsaved +import adventureworks.production.transactionhistory.TransactionhistoryId +import adventureworks.production.transactionhistory.TransactionhistoryRepoImpl +import adventureworks.production.transactionhistory.TransactionhistoryRow +import adventureworks.production.transactionhistory.TransactionhistoryRowUnsaved +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveId +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveRepoImpl +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveRow +import adventureworks.production.transactionhistoryarchive.TransactionhistoryarchiveRowUnsaved +import adventureworks.production.unitmeasure.UnitmeasureId +import adventureworks.production.unitmeasure.UnitmeasureRepoImpl +import adventureworks.production.unitmeasure.UnitmeasureRow +import adventureworks.production.unitmeasure.UnitmeasureRowUnsaved +import adventureworks.production.workorder.WorkorderId +import adventureworks.production.workorder.WorkorderRepoImpl +import adventureworks.production.workorder.WorkorderRow +import adventureworks.production.workorder.WorkorderRowUnsaved +import adventureworks.production.workorderrouting.WorkorderroutingRepoImpl +import adventureworks.production.workorderrouting.WorkorderroutingRow +import adventureworks.production.workorderrouting.WorkorderroutingRowUnsaved +import adventureworks.public.AccountNumber +import adventureworks.public.Flag +import adventureworks.public.Mydomain +import adventureworks.public.Myenum +import adventureworks.public.Name +import adventureworks.public.NameStyle +import adventureworks.public.OrderNumber +import adventureworks.public.Phone +import adventureworks.public.pgtest.PgtestRepoImpl +import adventureworks.public.pgtest.PgtestRow +import adventureworks.public.pgtestnull.PgtestnullRepoImpl +import adventureworks.public.pgtestnull.PgtestnullRow +import adventureworks.public.users.UsersId +import adventureworks.public.users.UsersRepoImpl +import adventureworks.public.users.UsersRow +import adventureworks.public.users.UsersRowUnsaved +import adventureworks.purchasing.productvendor.ProductvendorRepoImpl +import adventureworks.purchasing.productvendor.ProductvendorRow +import adventureworks.purchasing.productvendor.ProductvendorRowUnsaved +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderId +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderRepoImpl +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderRow +import adventureworks.purchasing.purchaseorderheader.PurchaseorderheaderRowUnsaved +import adventureworks.purchasing.shipmethod.ShipmethodId +import adventureworks.purchasing.shipmethod.ShipmethodRepoImpl +import adventureworks.purchasing.shipmethod.ShipmethodRow +import adventureworks.purchasing.shipmethod.ShipmethodRowUnsaved +import adventureworks.purchasing.vendor.VendorRepoImpl +import adventureworks.purchasing.vendor.VendorRow +import adventureworks.purchasing.vendor.VendorRowUnsaved +import adventureworks.sales.countryregioncurrency.CountryregioncurrencyRepoImpl +import adventureworks.sales.countryregioncurrency.CountryregioncurrencyRow +import adventureworks.sales.countryregioncurrency.CountryregioncurrencyRowUnsaved +import adventureworks.sales.creditcard.CreditcardRepoImpl +import adventureworks.sales.creditcard.CreditcardRow +import adventureworks.sales.creditcard.CreditcardRowUnsaved +import adventureworks.sales.currency.CurrencyId +import adventureworks.sales.currency.CurrencyRepoImpl +import adventureworks.sales.currency.CurrencyRow +import adventureworks.sales.currency.CurrencyRowUnsaved +import adventureworks.sales.currencyrate.CurrencyrateId +import adventureworks.sales.currencyrate.CurrencyrateRepoImpl +import adventureworks.sales.currencyrate.CurrencyrateRow +import adventureworks.sales.currencyrate.CurrencyrateRowUnsaved +import adventureworks.sales.customer.CustomerId +import adventureworks.sales.customer.CustomerRepoImpl +import adventureworks.sales.customer.CustomerRow +import adventureworks.sales.customer.CustomerRowUnsaved +import adventureworks.sales.personcreditcard.PersoncreditcardRepoImpl +import adventureworks.sales.personcreditcard.PersoncreditcardRow +import adventureworks.sales.personcreditcard.PersoncreditcardRowUnsaved +import adventureworks.sales.salesorderdetail.SalesorderdetailRepoImpl +import adventureworks.sales.salesorderdetail.SalesorderdetailRow +import adventureworks.sales.salesorderdetail.SalesorderdetailRowUnsaved +import adventureworks.sales.salesorderheader.SalesorderheaderId +import adventureworks.sales.salesorderheader.SalesorderheaderRepoImpl +import adventureworks.sales.salesorderheader.SalesorderheaderRow +import adventureworks.sales.salesorderheader.SalesorderheaderRowUnsaved +import adventureworks.sales.salesorderheadersalesreason.SalesorderheadersalesreasonRepoImpl +import adventureworks.sales.salesorderheadersalesreason.SalesorderheadersalesreasonRow +import adventureworks.sales.salesorderheadersalesreason.SalesorderheadersalesreasonRowUnsaved +import adventureworks.sales.salesperson.SalespersonRepoImpl +import adventureworks.sales.salesperson.SalespersonRow +import adventureworks.sales.salesperson.SalespersonRowUnsaved +import adventureworks.sales.salespersonquotahistory.SalespersonquotahistoryRepoImpl +import adventureworks.sales.salespersonquotahistory.SalespersonquotahistoryRow +import adventureworks.sales.salespersonquotahistory.SalespersonquotahistoryRowUnsaved +import adventureworks.sales.salesreason.SalesreasonId +import adventureworks.sales.salesreason.SalesreasonRepoImpl +import adventureworks.sales.salesreason.SalesreasonRow +import adventureworks.sales.salesreason.SalesreasonRowUnsaved +import adventureworks.sales.salestaxrate.SalestaxrateId +import adventureworks.sales.salestaxrate.SalestaxrateRepoImpl +import adventureworks.sales.salestaxrate.SalestaxrateRow +import adventureworks.sales.salestaxrate.SalestaxrateRowUnsaved +import adventureworks.sales.salesterritory.SalesterritoryId +import adventureworks.sales.salesterritory.SalesterritoryRepoImpl +import adventureworks.sales.salesterritory.SalesterritoryRow +import adventureworks.sales.salesterritory.SalesterritoryRowUnsaved +import adventureworks.sales.salesterritoryhistory.SalesterritoryhistoryRepoImpl +import adventureworks.sales.salesterritoryhistory.SalesterritoryhistoryRow +import adventureworks.sales.salesterritoryhistory.SalesterritoryhistoryRowUnsaved +import adventureworks.sales.shoppingcartitem.ShoppingcartitemId +import adventureworks.sales.shoppingcartitem.ShoppingcartitemRepoImpl +import adventureworks.sales.shoppingcartitem.ShoppingcartitemRow +import adventureworks.sales.shoppingcartitem.ShoppingcartitemRowUnsaved +import adventureworks.sales.specialoffer.SpecialofferId +import adventureworks.sales.specialoffer.SpecialofferRepoImpl +import adventureworks.sales.specialoffer.SpecialofferRow +import adventureworks.sales.specialoffer.SpecialofferRowUnsaved +import adventureworks.sales.specialofferproduct.SpecialofferproductRepoImpl +import adventureworks.sales.specialofferproduct.SpecialofferproductRow +import adventureworks.sales.specialofferproduct.SpecialofferproductRowUnsaved +import adventureworks.sales.store.StoreRepoImpl +import adventureworks.sales.store.StoreRow +import adventureworks.sales.store.StoreRowUnsaved +import adventureworks.userdefined.CustomCreditcardId +import adventureworks.userdefined.FirstName +import java.time.Instant +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime +import java.time.ZoneOffset +import scala.util.Random +import zio.ZIO +import zio.jdbc.ZConnection + +class testInsert(random: Random) { + def humanresourcesDepartment(name: Name = Name(random.alphanumeric.take(20).mkString), groupname: Name = Name(random.alphanumeric.take(20).mkString), departmentid: Defaulted[DepartmentId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, DepartmentRow] = DepartmentRepoImpl.insert(new DepartmentRowUnsaved(name = name, groupname = groupname, departmentid = departmentid, modifieddate = modifieddate)) + def humanresourcesEmployee(businessentityid: BusinessentityId, nationalidnumber: /* max 15 chars */ String = random.alphanumeric.take(15).mkString, loginid: /* max 256 chars */ String = random.alphanumeric.take(20).mkString, jobtitle: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, birthdate: TypoLocalDate = TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong)), maritalstatus: /* bpchar, max 1 chars */ String = random.alphanumeric.take(1).mkString, gender: /* bpchar, max 1 chars */ String = random.alphanumeric.take(1).mkString, hiredate: TypoLocalDate = TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong)), salariedflag: Defaulted[Flag] = Defaulted.UseDefault, vacationhours: Defaulted[TypoShort] = Defaulted.UseDefault, sickleavehours: Defaulted[TypoShort] = Defaulted.UseDefault, currentflag: Defaulted[Flag] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, organizationnode: Defaulted[Option[String]] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, EmployeeRow] = EmployeeRepoImpl.insert(new EmployeeRowUnsaved(businessentityid = businessentityid, nationalidnumber = nationalidnumber, loginid = loginid, jobtitle = jobtitle, birthdate = birthdate, maritalstatus = maritalstatus, gender = gender, hiredate = hiredate, salariedflag = salariedflag, vacationhours = vacationhours, sickleavehours = sickleavehours, currentflag = currentflag, rowguid = rowguid, modifieddate = modifieddate, organizationnode = organizationnode)) + def humanresourcesEmployeedepartmenthistory(businessentityid: BusinessentityId, departmentid: DepartmentId, shiftid: ShiftId, startdate: TypoLocalDate = TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong)), enddate: Option[TypoLocalDate] = if (random.nextBoolean()) None else Some(TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong))), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, EmployeedepartmenthistoryRow] = EmployeedepartmenthistoryRepoImpl.insert(new EmployeedepartmenthistoryRowUnsaved(businessentityid = businessentityid, departmentid = departmentid, shiftid = shiftid, startdate = startdate, enddate = enddate, modifieddate = modifieddate)) + def humanresourcesEmployeepayhistory(businessentityid: BusinessentityId, ratechangedate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), rate: BigDecimal = BigDecimal.decimal(random.nextDouble()), payfrequency: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, EmployeepayhistoryRow] = EmployeepayhistoryRepoImpl.insert(new EmployeepayhistoryRowUnsaved(businessentityid = businessentityid, ratechangedate = ratechangedate, rate = rate, payfrequency = payfrequency, modifieddate = modifieddate)) + def humanresourcesJobcandidate(businessentityid: Option[BusinessentityId] = None, resume: Option[TypoXml] = None, jobcandidateid: Defaulted[JobcandidateId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, JobcandidateRow] = JobcandidateRepoImpl.insert(new JobcandidateRowUnsaved(businessentityid = businessentityid, resume = resume, jobcandidateid = jobcandidateid, modifieddate = modifieddate)) + def humanresourcesShift(name: Name = Name(random.alphanumeric.take(20).mkString), starttime: TypoLocalTime = TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)), endtime: TypoLocalTime = TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)), shiftid: Defaulted[ShiftId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ShiftRow] = ShiftRepoImpl.insert(new ShiftRowUnsaved(name = name, starttime = starttime, endtime = endtime, shiftid = shiftid, modifieddate = modifieddate)) + def informationSchemaSqlFeatures(featureId: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), featureName: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), subFeatureId: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), subFeatureName: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), isSupported: Option[YesOrNo] = if (random.nextBoolean()) None else Some(YesOrNo(random.alphanumeric.take(20).mkString)), isVerifiedBy: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), comments: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, SqlFeaturesRow] = SqlFeaturesRepoImpl.insert(new SqlFeaturesRow(featureId = featureId, featureName = featureName, subFeatureId = subFeatureId, subFeatureName = subFeatureName, isSupported = isSupported, isVerifiedBy = isVerifiedBy, comments = comments)) + def informationSchemaSqlImplementationInfo(implementationInfoId: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), implementationInfoName: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), integerValue: Option[CardinalNumber] = if (random.nextBoolean()) None else Some(CardinalNumber(random.nextInt())), characterValue: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), comments: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, SqlImplementationInfoRow] = SqlImplementationInfoRepoImpl.insert(new SqlImplementationInfoRow(implementationInfoId = implementationInfoId, implementationInfoName = implementationInfoName, integerValue = integerValue, characterValue = characterValue, comments = comments)) + def informationSchemaSqlParts(featureId: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), featureName: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), isSupported: Option[YesOrNo] = if (random.nextBoolean()) None else Some(YesOrNo(random.alphanumeric.take(20).mkString)), isVerifiedBy: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), comments: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, SqlPartsRow] = SqlPartsRepoImpl.insert(new SqlPartsRow(featureId = featureId, featureName = featureName, isSupported = isSupported, isVerifiedBy = isVerifiedBy, comments = comments)) + def informationSchemaSqlSizing(sizingId: Option[CardinalNumber] = if (random.nextBoolean()) None else Some(CardinalNumber(random.nextInt())), sizingName: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString)), supportedValue: Option[CardinalNumber] = if (random.nextBoolean()) None else Some(CardinalNumber(random.nextInt())), comments: Option[CharacterData] = if (random.nextBoolean()) None else Some(CharacterData(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, SqlSizingRow] = SqlSizingRepoImpl.insert(new SqlSizingRow(sizingId = sizingId, sizingName = sizingName, supportedValue = supportedValue, comments = comments)) + def personAddress(stateprovinceid: StateprovinceId, addressline1: /* max 60 chars */ String = random.alphanumeric.take(20).mkString, addressline2: Option[/* max 60 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), city: /* max 30 chars */ String = random.alphanumeric.take(20).mkString, postalcode: /* max 15 chars */ String = random.alphanumeric.take(15).mkString, spatiallocation: Option[TypoBytea] = None, addressid: Defaulted[AddressId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, AddressRow] = AddressRepoImpl.insert(new AddressRowUnsaved(stateprovinceid = stateprovinceid, addressline1 = addressline1, addressline2 = addressline2, city = city, postalcode = postalcode, spatiallocation = spatiallocation, addressid = addressid, rowguid = rowguid, modifieddate = modifieddate)) + def personAddresstype(name: Name = Name(random.alphanumeric.take(20).mkString), addresstypeid: Defaulted[AddresstypeId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, AddresstypeRow] = AddresstypeRepoImpl.insert(new AddresstypeRowUnsaved(name = name, addresstypeid = addresstypeid, rowguid = rowguid, modifieddate = modifieddate)) + def personBusinessentity(businessentityid: Defaulted[BusinessentityId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, BusinessentityRow] = BusinessentityRepoImpl.insert(new BusinessentityRowUnsaved(businessentityid = businessentityid, rowguid = rowguid, modifieddate = modifieddate)) + def personBusinessentityaddress(businessentityid: BusinessentityId, addressid: AddressId, addresstypeid: AddresstypeId, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, BusinessentityaddressRow] = BusinessentityaddressRepoImpl.insert(new BusinessentityaddressRowUnsaved(businessentityid = businessentityid, addressid = addressid, addresstypeid = addresstypeid, rowguid = rowguid, modifieddate = modifieddate)) + def personBusinessentitycontact(businessentityid: BusinessentityId, personid: BusinessentityId, contacttypeid: ContacttypeId, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, BusinessentitycontactRow] = BusinessentitycontactRepoImpl.insert(new BusinessentitycontactRowUnsaved(businessentityid = businessentityid, personid = personid, contacttypeid = contacttypeid, rowguid = rowguid, modifieddate = modifieddate)) + def personContacttype(name: Name = Name(random.alphanumeric.take(20).mkString), contacttypeid: Defaulted[ContacttypeId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ContacttypeRow] = ContacttypeRepoImpl.insert(new ContacttypeRowUnsaved(name = name, contacttypeid = contacttypeid, modifieddate = modifieddate)) + def personCountryregion(countryregioncode: CountryregionId, name: Name = Name(random.alphanumeric.take(20).mkString), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CountryregionRow] = CountryregionRepoImpl.insert(new CountryregionRowUnsaved(countryregioncode = countryregioncode, name = name, modifieddate = modifieddate)) + def personEmailaddress(businessentityid: BusinessentityId, emailaddress: Option[/* max 50 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), emailaddressid: Defaulted[Int] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, EmailaddressRow] = EmailaddressRepoImpl.insert(new EmailaddressRowUnsaved(businessentityid = businessentityid, emailaddress = emailaddress, emailaddressid = emailaddressid, rowguid = rowguid, modifieddate = modifieddate)) + def personPassword(businessentityid: BusinessentityId, passwordhash: /* max 128 chars */ String = random.alphanumeric.take(20).mkString, passwordsalt: /* max 10 chars */ String = random.alphanumeric.take(10).mkString, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PasswordRow] = PasswordRepoImpl.insert(new PasswordRowUnsaved(businessentityid = businessentityid, passwordhash = passwordhash, passwordsalt = passwordsalt, rowguid = rowguid, modifieddate = modifieddate)) + def personPerson(businessentityid: BusinessentityId, firstname: /* user-picked */ FirstName, persontype: /* bpchar, max 2 chars */ String = random.alphanumeric.take(2).mkString, title: Option[/* max 8 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(8).mkString), middlename: Option[Name] = if (random.nextBoolean()) None else Some(Name(random.alphanumeric.take(20).mkString)), lastname: Name = Name(random.alphanumeric.take(20).mkString), suffix: Option[/* max 10 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(10).mkString), additionalcontactinfo: Option[TypoXml] = None, demographics: Option[TypoXml] = None, namestyle: Defaulted[NameStyle] = Defaulted.UseDefault, emailpromotion: Defaulted[Int] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersonRow] = PersonRepoImpl.insert(new PersonRowUnsaved(businessentityid = businessentityid, firstname = firstname, persontype = persontype, title = title, middlename = middlename, lastname = lastname, suffix = suffix, additionalcontactinfo = additionalcontactinfo, demographics = demographics, namestyle = namestyle, emailpromotion = emailpromotion, rowguid = rowguid, modifieddate = modifieddate)) + def personPersonphone(businessentityid: BusinessentityId, phonenumbertypeid: PhonenumbertypeId, phonenumber: Phone = Phone(random.alphanumeric.take(20).mkString), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersonphoneRow] = PersonphoneRepoImpl.insert(new PersonphoneRowUnsaved(businessentityid = businessentityid, phonenumbertypeid = phonenumbertypeid, phonenumber = phonenumber, modifieddate = modifieddate)) + def personPhonenumbertype(name: Name = Name(random.alphanumeric.take(20).mkString), phonenumbertypeid: Defaulted[PhonenumbertypeId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PhonenumbertypeRow] = PhonenumbertypeRepoImpl.insert(new PhonenumbertypeRowUnsaved(name = name, phonenumbertypeid = phonenumbertypeid, modifieddate = modifieddate)) + def personStateprovince(countryregioncode: CountryregionId, territoryid: SalesterritoryId, stateprovincecode: /* bpchar, max 3 chars */ String = random.alphanumeric.take(3).mkString, name: Name = Name(random.alphanumeric.take(20).mkString), stateprovinceid: Defaulted[StateprovinceId] = Defaulted.UseDefault, isonlystateprovinceflag: Defaulted[Flag] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, StateprovinceRow] = StateprovinceRepoImpl.insert(new StateprovinceRowUnsaved(countryregioncode = countryregioncode, territoryid = territoryid, stateprovincecode = stateprovincecode, name = name, stateprovinceid = stateprovinceid, isonlystateprovinceflag = isonlystateprovinceflag, rowguid = rowguid, modifieddate = modifieddate)) + def pgCatalogPgAggregate(aggfnoid: PgAggregateId, aggtransfn: TypoRegproc, aggfinalfn: TypoRegproc, aggcombinefn: TypoRegproc, aggserialfn: TypoRegproc, aggdeserialfn: TypoRegproc, aggmtransfn: TypoRegproc, aggminvtransfn: TypoRegproc, aggmfinalfn: TypoRegproc, aggkind: String = random.alphanumeric.take(20).mkString, aggnumdirectargs: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), aggfinalextra: Boolean = random.nextBoolean(), aggmfinalextra: Boolean = random.nextBoolean(), aggfinalmodify: String = random.alphanumeric.take(20).mkString, aggmfinalmodify: String = random.alphanumeric.take(20).mkString, aggsortop: /* oid */ Long = random.nextLong(), aggtranstype: /* oid */ Long = random.nextLong(), aggtransspace: Int = random.nextInt(), aggmtranstype: /* oid */ Long = random.nextLong(), aggmtransspace: Int = random.nextInt(), agginitval: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), aggminitval: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgAggregateRow] = PgAggregateRepoImpl.insert(new PgAggregateRow(aggfnoid = aggfnoid, aggtransfn = aggtransfn, aggfinalfn = aggfinalfn, aggcombinefn = aggcombinefn, aggserialfn = aggserialfn, aggdeserialfn = aggdeserialfn, aggmtransfn = aggmtransfn, aggminvtransfn = aggminvtransfn, aggmfinalfn = aggmfinalfn, aggkind = aggkind, aggnumdirectargs = aggnumdirectargs, aggfinalextra = aggfinalextra, aggmfinalextra = aggmfinalextra, aggfinalmodify = aggfinalmodify, aggmfinalmodify = aggmfinalmodify, aggsortop = aggsortop, aggtranstype = aggtranstype, aggtransspace = aggtransspace, aggmtranstype = aggmtranstype, aggmtransspace = aggmtransspace, agginitval = agginitval, aggminitval = aggminitval)) + def pgCatalogPgAm(oid: PgAmId, amhandler: TypoRegproc, amname: String = random.alphanumeric.take(20).mkString, amtype: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgAmRow] = PgAmRepoImpl.insert(new PgAmRow(oid = oid, amhandler = amhandler, amname = amname, amtype = amtype)) + def pgCatalogPgAmop(oid: PgAmopId, amopfamily: /* oid */ Long = random.nextLong(), amoplefttype: /* oid */ Long = random.nextLong(), amoprighttype: /* oid */ Long = random.nextLong(), amopstrategy: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), amoppurpose: String = random.alphanumeric.take(20).mkString, amopopr: /* oid */ Long = random.nextLong(), amopmethod: /* oid */ Long = random.nextLong(), amopsortfamily: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgAmopRow] = PgAmopRepoImpl.insert(new PgAmopRow(oid = oid, amopfamily = amopfamily, amoplefttype = amoplefttype, amoprighttype = amoprighttype, amopstrategy = amopstrategy, amoppurpose = amoppurpose, amopopr = amopopr, amopmethod = amopmethod, amopsortfamily = amopsortfamily)) + def pgCatalogPgAmproc(oid: PgAmprocId, amproc: TypoRegproc, amprocfamily: /* oid */ Long = random.nextLong(), amproclefttype: /* oid */ Long = random.nextLong(), amprocrighttype: /* oid */ Long = random.nextLong(), amprocnum: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort)): ZIO[ZConnection, Throwable, PgAmprocRow] = PgAmprocRepoImpl.insert(new PgAmprocRow(oid = oid, amproc = amproc, amprocfamily = amprocfamily, amproclefttype = amproclefttype, amprocrighttype = amprocrighttype, amprocnum = amprocnum)) + def pgCatalogPgAttrdef(oid: PgAttrdefId, adbin: TypoPgNodeTree, adrelid: /* oid */ Long = random.nextLong(), adnum: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort)): ZIO[ZConnection, Throwable, PgAttrdefRow] = PgAttrdefRepoImpl.insert(new PgAttrdefRow(oid = oid, adbin = adbin, adrelid = adrelid, adnum = adnum)) + def pgCatalogPgAttribute(attrelid: /* oid */ Long = random.nextLong(), attname: String = random.alphanumeric.take(20).mkString, atttypid: /* oid */ Long = random.nextLong(), attstattarget: Int = random.nextInt(), attlen: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), attnum: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), attndims: Int = random.nextInt(), attcacheoff: Int = random.nextInt(), atttypmod: Int = random.nextInt(), attbyval: Boolean = random.nextBoolean(), attalign: String = random.alphanumeric.take(20).mkString, attstorage: String = random.alphanumeric.take(20).mkString, attcompression: String = random.alphanumeric.take(20).mkString, attnotnull: Boolean = random.nextBoolean(), atthasdef: Boolean = random.nextBoolean(), atthasmissing: Boolean = random.nextBoolean(), attidentity: String = random.alphanumeric.take(20).mkString, attgenerated: String = random.alphanumeric.take(20).mkString, attisdropped: Boolean = random.nextBoolean(), attislocal: Boolean = random.nextBoolean(), attinhcount: Int = random.nextInt(), attcollation: /* oid */ Long = random.nextLong(), attacl: Option[Array[TypoAclItem]] = None, attoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), attfdwoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), attmissingval: Option[TypoAnyArray] = None): ZIO[ZConnection, Throwable, PgAttributeRow] = PgAttributeRepoImpl.insert(new PgAttributeRow(attrelid = attrelid, attname = attname, atttypid = atttypid, attstattarget = attstattarget, attlen = attlen, attnum = attnum, attndims = attndims, attcacheoff = attcacheoff, atttypmod = atttypmod, attbyval = attbyval, attalign = attalign, attstorage = attstorage, attcompression = attcompression, attnotnull = attnotnull, atthasdef = atthasdef, atthasmissing = atthasmissing, attidentity = attidentity, attgenerated = attgenerated, attisdropped = attisdropped, attislocal = attislocal, attinhcount = attinhcount, attcollation = attcollation, attacl = attacl, attoptions = attoptions, attfdwoptions = attfdwoptions, attmissingval = attmissingval)) + def pgCatalogPgAuthMembers(roleid: /* oid */ Long = random.nextLong(), member: /* oid */ Long = random.nextLong(), grantor: /* oid */ Long = random.nextLong(), adminOption: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgAuthMembersRow] = PgAuthMembersRepoImpl.insert(new PgAuthMembersRow(roleid = roleid, member = member, grantor = grantor, adminOption = adminOption)) + def pgCatalogPgAuthid(oid: PgAuthidId, rolname: String = random.alphanumeric.take(20).mkString, rolsuper: Boolean = random.nextBoolean(), rolinherit: Boolean = random.nextBoolean(), rolcreaterole: Boolean = random.nextBoolean(), rolcreatedb: Boolean = random.nextBoolean(), rolcanlogin: Boolean = random.nextBoolean(), rolreplication: Boolean = random.nextBoolean(), rolbypassrls: Boolean = random.nextBoolean(), rolconnlimit: Int = random.nextInt(), rolpassword: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), rolvaliduntil: Option[TypoInstant] = if (random.nextBoolean()) None else Some(TypoInstant(Instant.ofEpochMilli(random.nextLong())))): ZIO[ZConnection, Throwable, PgAuthidRow] = PgAuthidRepoImpl.insert(new PgAuthidRow(oid = oid, rolname = rolname, rolsuper = rolsuper, rolinherit = rolinherit, rolcreaterole = rolcreaterole, rolcreatedb = rolcreatedb, rolcanlogin = rolcanlogin, rolreplication = rolreplication, rolbypassrls = rolbypassrls, rolconnlimit = rolconnlimit, rolpassword = rolpassword, rolvaliduntil = rolvaliduntil)) + def pgCatalogPgCast(oid: PgCastId, castsource: /* oid */ Long = random.nextLong(), casttarget: /* oid */ Long = random.nextLong(), castfunc: /* oid */ Long = random.nextLong(), castcontext: String = random.alphanumeric.take(20).mkString, castmethod: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgCastRow] = PgCastRepoImpl.insert(new PgCastRow(oid = oid, castsource = castsource, casttarget = casttarget, castfunc = castfunc, castcontext = castcontext, castmethod = castmethod)) + def pgCatalogPgClass(oid: PgClassId, relfrozenxid: TypoXid, relminmxid: TypoXid, relname: String = random.alphanumeric.take(20).mkString, relnamespace: /* oid */ Long = random.nextLong(), reltype: /* oid */ Long = random.nextLong(), reloftype: /* oid */ Long = random.nextLong(), relowner: /* oid */ Long = random.nextLong(), relam: /* oid */ Long = random.nextLong(), relfilenode: /* oid */ Long = random.nextLong(), reltablespace: /* oid */ Long = random.nextLong(), relpages: Int = random.nextInt(), reltuples: Float = random.nextFloat(), relallvisible: Int = random.nextInt(), reltoastrelid: /* oid */ Long = random.nextLong(), relhasindex: Boolean = random.nextBoolean(), relisshared: Boolean = random.nextBoolean(), relpersistence: String = random.alphanumeric.take(20).mkString, relkind: String = random.alphanumeric.take(20).mkString, relnatts: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), relchecks: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), relhasrules: Boolean = random.nextBoolean(), relhastriggers: Boolean = random.nextBoolean(), relhassubclass: Boolean = random.nextBoolean(), relrowsecurity: Boolean = random.nextBoolean(), relforcerowsecurity: Boolean = random.nextBoolean(), relispopulated: Boolean = random.nextBoolean(), relreplident: String = random.alphanumeric.take(20).mkString, relispartition: Boolean = random.nextBoolean(), relrewrite: /* oid */ Long = random.nextLong(), relacl: Option[Array[TypoAclItem]] = None, reloptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), relpartbound: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgClassRow] = PgClassRepoImpl.insert(new PgClassRow(oid = oid, relfrozenxid = relfrozenxid, relminmxid = relminmxid, relname = relname, relnamespace = relnamespace, reltype = reltype, reloftype = reloftype, relowner = relowner, relam = relam, relfilenode = relfilenode, reltablespace = reltablespace, relpages = relpages, reltuples = reltuples, relallvisible = relallvisible, reltoastrelid = reltoastrelid, relhasindex = relhasindex, relisshared = relisshared, relpersistence = relpersistence, relkind = relkind, relnatts = relnatts, relchecks = relchecks, relhasrules = relhasrules, relhastriggers = relhastriggers, relhassubclass = relhassubclass, relrowsecurity = relrowsecurity, relforcerowsecurity = relforcerowsecurity, relispopulated = relispopulated, relreplident = relreplident, relispartition = relispartition, relrewrite = relrewrite, relacl = relacl, reloptions = reloptions, relpartbound = relpartbound)) + def pgCatalogPgCollation(oid: PgCollationId, collname: String = random.alphanumeric.take(20).mkString, collnamespace: /* oid */ Long = random.nextLong(), collowner: /* oid */ Long = random.nextLong(), collprovider: String = random.alphanumeric.take(20).mkString, collisdeterministic: Boolean = random.nextBoolean(), collencoding: Int = random.nextInt(), collcollate: String = random.alphanumeric.take(20).mkString, collctype: String = random.alphanumeric.take(20).mkString, collversion: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgCollationRow] = PgCollationRepoImpl.insert(new PgCollationRow(oid = oid, collname = collname, collnamespace = collnamespace, collowner = collowner, collprovider = collprovider, collisdeterministic = collisdeterministic, collencoding = collencoding, collcollate = collcollate, collctype = collctype, collversion = collversion)) + def pgCatalogPgConstraint(oid: PgConstraintId, conname: String = random.alphanumeric.take(20).mkString, connamespace: /* oid */ Long = random.nextLong(), contype: String = random.alphanumeric.take(20).mkString, condeferrable: Boolean = random.nextBoolean(), condeferred: Boolean = random.nextBoolean(), convalidated: Boolean = random.nextBoolean(), conrelid: /* oid */ Long = random.nextLong(), contypid: /* oid */ Long = random.nextLong(), conindid: /* oid */ Long = random.nextLong(), conparentid: /* oid */ Long = random.nextLong(), confrelid: /* oid */ Long = random.nextLong(), confupdtype: String = random.alphanumeric.take(20).mkString, confdeltype: String = random.alphanumeric.take(20).mkString, confmatchtype: String = random.alphanumeric.take(20).mkString, conislocal: Boolean = random.nextBoolean(), coninhcount: Int = random.nextInt(), connoinherit: Boolean = random.nextBoolean(), conkey: Option[Array[TypoShort]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoShort(random.nextInt(Short.MaxValue).toShort))), confkey: Option[Array[TypoShort]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoShort(random.nextInt(Short.MaxValue).toShort))), conpfeqop: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), conppeqop: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), conffeqop: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), conexclop: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), conbin: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgConstraintRow] = PgConstraintRepoImpl.insert(new PgConstraintRow(oid = oid, conname = conname, connamespace = connamespace, contype = contype, condeferrable = condeferrable, condeferred = condeferred, convalidated = convalidated, conrelid = conrelid, contypid = contypid, conindid = conindid, conparentid = conparentid, confrelid = confrelid, confupdtype = confupdtype, confdeltype = confdeltype, confmatchtype = confmatchtype, conislocal = conislocal, coninhcount = coninhcount, connoinherit = connoinherit, conkey = conkey, confkey = confkey, conpfeqop = conpfeqop, conppeqop = conppeqop, conffeqop = conffeqop, conexclop = conexclop, conbin = conbin)) + def pgCatalogPgConversion(oid: PgConversionId, conproc: TypoRegproc, conname: String = random.alphanumeric.take(20).mkString, connamespace: /* oid */ Long = random.nextLong(), conowner: /* oid */ Long = random.nextLong(), conforencoding: Int = random.nextInt(), contoencoding: Int = random.nextInt(), condefault: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgConversionRow] = PgConversionRepoImpl.insert(new PgConversionRow(oid = oid, conproc = conproc, conname = conname, connamespace = connamespace, conowner = conowner, conforencoding = conforencoding, contoencoding = contoencoding, condefault = condefault)) + def pgCatalogPgDatabase(oid: PgDatabaseId, datfrozenxid: TypoXid, datminmxid: TypoXid, datname: String = random.alphanumeric.take(20).mkString, datdba: /* oid */ Long = random.nextLong(), encoding: Int = random.nextInt(), datcollate: String = random.alphanumeric.take(20).mkString, datctype: String = random.alphanumeric.take(20).mkString, datistemplate: Boolean = random.nextBoolean(), datallowconn: Boolean = random.nextBoolean(), datconnlimit: Int = random.nextInt(), datlastsysoid: /* oid */ Long = random.nextLong(), dattablespace: /* oid */ Long = random.nextLong(), datacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgDatabaseRow] = PgDatabaseRepoImpl.insert(new PgDatabaseRow(oid = oid, datfrozenxid = datfrozenxid, datminmxid = datminmxid, datname = datname, datdba = datdba, encoding = encoding, datcollate = datcollate, datctype = datctype, datistemplate = datistemplate, datallowconn = datallowconn, datconnlimit = datconnlimit, datlastsysoid = datlastsysoid, dattablespace = dattablespace, datacl = datacl)) + def pgCatalogPgDbRoleSetting(setdatabase: /* oid */ Long = random.nextLong(), setrole: /* oid */ Long = random.nextLong(), setconfig: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgDbRoleSettingRow] = PgDbRoleSettingRepoImpl.insert(new PgDbRoleSettingRow(setdatabase = setdatabase, setrole = setrole, setconfig = setconfig)) + def pgCatalogPgDefaultAcl(oid: PgDefaultAclId, defaclacl: Array[TypoAclItem], defaclrole: /* oid */ Long = random.nextLong(), defaclnamespace: /* oid */ Long = random.nextLong(), defaclobjtype: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgDefaultAclRow] = PgDefaultAclRepoImpl.insert(new PgDefaultAclRow(oid = oid, defaclacl = defaclacl, defaclrole = defaclrole, defaclnamespace = defaclnamespace, defaclobjtype = defaclobjtype)) + def pgCatalogPgDepend(classid: /* oid */ Long = random.nextLong(), objid: /* oid */ Long = random.nextLong(), objsubid: Int = random.nextInt(), refclassid: /* oid */ Long = random.nextLong(), refobjid: /* oid */ Long = random.nextLong(), refobjsubid: Int = random.nextInt(), deptype: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgDependRow] = PgDependRepoImpl.insert(new PgDependRow(classid = classid, objid = objid, objsubid = objsubid, refclassid = refclassid, refobjid = refobjid, refobjsubid = refobjsubid, deptype = deptype)) + def pgCatalogPgDescription(objoid: /* oid */ Long = random.nextLong(), classoid: /* oid */ Long = random.nextLong(), objsubid: Int = random.nextInt(), description: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgDescriptionRow] = PgDescriptionRepoImpl.insert(new PgDescriptionRow(objoid = objoid, classoid = classoid, objsubid = objsubid, description = description)) + def pgCatalogPgEnum(oid: PgEnumId, enumtypid: /* oid */ Long = random.nextLong(), enumsortorder: Float = random.nextFloat(), enumlabel: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgEnumRow] = PgEnumRepoImpl.insert(new PgEnumRow(oid = oid, enumtypid = enumtypid, enumsortorder = enumsortorder, enumlabel = enumlabel)) + def pgCatalogPgEventTrigger(oid: PgEventTriggerId, evtname: String = random.alphanumeric.take(20).mkString, evtevent: String = random.alphanumeric.take(20).mkString, evtowner: /* oid */ Long = random.nextLong(), evtfoid: /* oid */ Long = random.nextLong(), evtenabled: String = random.alphanumeric.take(20).mkString, evttags: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgEventTriggerRow] = PgEventTriggerRepoImpl.insert(new PgEventTriggerRow(oid = oid, evtname = evtname, evtevent = evtevent, evtowner = evtowner, evtfoid = evtfoid, evtenabled = evtenabled, evttags = evttags)) + def pgCatalogPgExtension(oid: PgExtensionId, extname: String = random.alphanumeric.take(20).mkString, extowner: /* oid */ Long = random.nextLong(), extnamespace: /* oid */ Long = random.nextLong(), extrelocatable: Boolean = random.nextBoolean(), extversion: String = random.alphanumeric.take(20).mkString, extconfig: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), extcondition: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgExtensionRow] = PgExtensionRepoImpl.insert(new PgExtensionRow(oid = oid, extname = extname, extowner = extowner, extnamespace = extnamespace, extrelocatable = extrelocatable, extversion = extversion, extconfig = extconfig, extcondition = extcondition)) + def pgCatalogPgForeignDataWrapper(oid: PgForeignDataWrapperId, fdwname: String = random.alphanumeric.take(20).mkString, fdwowner: /* oid */ Long = random.nextLong(), fdwhandler: /* oid */ Long = random.nextLong(), fdwvalidator: /* oid */ Long = random.nextLong(), fdwacl: Option[Array[TypoAclItem]] = None, fdwoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgForeignDataWrapperRow] = PgForeignDataWrapperRepoImpl.insert(new PgForeignDataWrapperRow(oid = oid, fdwname = fdwname, fdwowner = fdwowner, fdwhandler = fdwhandler, fdwvalidator = fdwvalidator, fdwacl = fdwacl, fdwoptions = fdwoptions)) + def pgCatalogPgForeignServer(oid: PgForeignServerId, srvname: String = random.alphanumeric.take(20).mkString, srvowner: /* oid */ Long = random.nextLong(), srvfdw: /* oid */ Long = random.nextLong(), srvtype: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), srvversion: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), srvacl: Option[Array[TypoAclItem]] = None, srvoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgForeignServerRow] = PgForeignServerRepoImpl.insert(new PgForeignServerRow(oid = oid, srvname = srvname, srvowner = srvowner, srvfdw = srvfdw, srvtype = srvtype, srvversion = srvversion, srvacl = srvacl, srvoptions = srvoptions)) + def pgCatalogPgForeignTable(ftrelid: PgForeignTableId, ftserver: /* oid */ Long = random.nextLong(), ftoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgForeignTableRow] = PgForeignTableRepoImpl.insert(new PgForeignTableRow(ftrelid = ftrelid, ftserver = ftserver, ftoptions = ftoptions)) + def pgCatalogPgIndex(indexrelid: PgIndexId, indkey: TypoInt2Vector, indcollation: TypoOidVector, indclass: TypoOidVector, indoption: TypoInt2Vector, indrelid: /* oid */ Long = random.nextLong(), indnatts: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), indnkeyatts: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), indisunique: Boolean = random.nextBoolean(), indisprimary: Boolean = random.nextBoolean(), indisexclusion: Boolean = random.nextBoolean(), indimmediate: Boolean = random.nextBoolean(), indisclustered: Boolean = random.nextBoolean(), indisvalid: Boolean = random.nextBoolean(), indcheckxmin: Boolean = random.nextBoolean(), indisready: Boolean = random.nextBoolean(), indislive: Boolean = random.nextBoolean(), indisreplident: Boolean = random.nextBoolean(), indexprs: Option[TypoPgNodeTree] = None, indpred: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgIndexRow] = PgIndexRepoImpl.insert(new PgIndexRow(indexrelid = indexrelid, indkey = indkey, indcollation = indcollation, indclass = indclass, indoption = indoption, indrelid = indrelid, indnatts = indnatts, indnkeyatts = indnkeyatts, indisunique = indisunique, indisprimary = indisprimary, indisexclusion = indisexclusion, indimmediate = indimmediate, indisclustered = indisclustered, indisvalid = indisvalid, indcheckxmin = indcheckxmin, indisready = indisready, indislive = indislive, indisreplident = indisreplident, indexprs = indexprs, indpred = indpred)) + def pgCatalogPgInherits(inhrelid: /* oid */ Long = random.nextLong(), inhparent: /* oid */ Long = random.nextLong(), inhseqno: Int = random.nextInt(), inhdetachpending: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgInheritsRow] = PgInheritsRepoImpl.insert(new PgInheritsRow(inhrelid = inhrelid, inhparent = inhparent, inhseqno = inhseqno, inhdetachpending = inhdetachpending)) + def pgCatalogPgInitPrivs(initprivs: Array[TypoAclItem], objoid: /* oid */ Long = random.nextLong(), classoid: /* oid */ Long = random.nextLong(), objsubid: Int = random.nextInt(), privtype: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgInitPrivsRow] = PgInitPrivsRepoImpl.insert(new PgInitPrivsRow(initprivs = initprivs, objoid = objoid, classoid = classoid, objsubid = objsubid, privtype = privtype)) + def pgCatalogPgLanguage(oid: PgLanguageId, lanname: String = random.alphanumeric.take(20).mkString, lanowner: /* oid */ Long = random.nextLong(), lanispl: Boolean = random.nextBoolean(), lanpltrusted: Boolean = random.nextBoolean(), lanplcallfoid: /* oid */ Long = random.nextLong(), laninline: /* oid */ Long = random.nextLong(), lanvalidator: /* oid */ Long = random.nextLong(), lanacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgLanguageRow] = PgLanguageRepoImpl.insert(new PgLanguageRow(oid = oid, lanname = lanname, lanowner = lanowner, lanispl = lanispl, lanpltrusted = lanpltrusted, lanplcallfoid = lanplcallfoid, laninline = laninline, lanvalidator = lanvalidator, lanacl = lanacl)) + def pgCatalogPgLargeobject(data: TypoBytea, loid: /* oid */ Long = random.nextLong(), pageno: Int = random.nextInt()): ZIO[ZConnection, Throwable, PgLargeobjectRow] = PgLargeobjectRepoImpl.insert(new PgLargeobjectRow(data = data, loid = loid, pageno = pageno)) + def pgCatalogPgLargeobjectMetadata(oid: PgLargeobjectMetadataId, lomowner: /* oid */ Long = random.nextLong(), lomacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgLargeobjectMetadataRow] = PgLargeobjectMetadataRepoImpl.insert(new PgLargeobjectMetadataRow(oid = oid, lomowner = lomowner, lomacl = lomacl)) + def pgCatalogPgNamespace(oid: PgNamespaceId, nspname: String = random.alphanumeric.take(20).mkString, nspowner: /* oid */ Long = random.nextLong(), nspacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgNamespaceRow] = PgNamespaceRepoImpl.insert(new PgNamespaceRow(oid = oid, nspname = nspname, nspowner = nspowner, nspacl = nspacl)) + def pgCatalogPgOpclass(oid: PgOpclassId, opcmethod: /* oid */ Long = random.nextLong(), opcname: String = random.alphanumeric.take(20).mkString, opcnamespace: /* oid */ Long = random.nextLong(), opcowner: /* oid */ Long = random.nextLong(), opcfamily: /* oid */ Long = random.nextLong(), opcintype: /* oid */ Long = random.nextLong(), opcdefault: Boolean = random.nextBoolean(), opckeytype: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgOpclassRow] = PgOpclassRepoImpl.insert(new PgOpclassRow(oid = oid, opcmethod = opcmethod, opcname = opcname, opcnamespace = opcnamespace, opcowner = opcowner, opcfamily = opcfamily, opcintype = opcintype, opcdefault = opcdefault, opckeytype = opckeytype)) + def pgCatalogPgOperator(oid: PgOperatorId, oprcode: TypoRegproc, oprrest: TypoRegproc, oprjoin: TypoRegproc, oprname: String = random.alphanumeric.take(20).mkString, oprnamespace: /* oid */ Long = random.nextLong(), oprowner: /* oid */ Long = random.nextLong(), oprkind: String = random.alphanumeric.take(20).mkString, oprcanmerge: Boolean = random.nextBoolean(), oprcanhash: Boolean = random.nextBoolean(), oprleft: /* oid */ Long = random.nextLong(), oprright: /* oid */ Long = random.nextLong(), oprresult: /* oid */ Long = random.nextLong(), oprcom: /* oid */ Long = random.nextLong(), oprnegate: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgOperatorRow] = PgOperatorRepoImpl.insert(new PgOperatorRow(oid = oid, oprcode = oprcode, oprrest = oprrest, oprjoin = oprjoin, oprname = oprname, oprnamespace = oprnamespace, oprowner = oprowner, oprkind = oprkind, oprcanmerge = oprcanmerge, oprcanhash = oprcanhash, oprleft = oprleft, oprright = oprright, oprresult = oprresult, oprcom = oprcom, oprnegate = oprnegate)) + def pgCatalogPgOpfamily(oid: PgOpfamilyId, opfmethod: /* oid */ Long = random.nextLong(), opfname: String = random.alphanumeric.take(20).mkString, opfnamespace: /* oid */ Long = random.nextLong(), opfowner: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgOpfamilyRow] = PgOpfamilyRepoImpl.insert(new PgOpfamilyRow(oid = oid, opfmethod = opfmethod, opfname = opfname, opfnamespace = opfnamespace, opfowner = opfowner)) + def pgCatalogPgPartitionedTable(partrelid: PgPartitionedTableId, partattrs: TypoInt2Vector, partclass: TypoOidVector, partcollation: TypoOidVector, partstrat: String = random.alphanumeric.take(20).mkString, partnatts: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), partdefid: /* oid */ Long = random.nextLong(), partexprs: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgPartitionedTableRow] = PgPartitionedTableRepoImpl.insert(new PgPartitionedTableRow(partrelid = partrelid, partattrs = partattrs, partclass = partclass, partcollation = partcollation, partstrat = partstrat, partnatts = partnatts, partdefid = partdefid, partexprs = partexprs)) + def pgCatalogPgPolicy(oid: PgPolicyId, polname: String = random.alphanumeric.take(20).mkString, polrelid: /* oid */ Long = random.nextLong(), polcmd: String = random.alphanumeric.take(20).mkString, polpermissive: Boolean = random.nextBoolean(), polroles: Array[/* oid */ Long] = Array.fill(random.nextInt(3))(random.nextLong()), polqual: Option[TypoPgNodeTree] = None, polwithcheck: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgPolicyRow] = PgPolicyRepoImpl.insert(new PgPolicyRow(oid = oid, polname = polname, polrelid = polrelid, polcmd = polcmd, polpermissive = polpermissive, polroles = polroles, polqual = polqual, polwithcheck = polwithcheck)) + def pgCatalogPgProc(oid: PgProcId, prosupport: TypoRegproc, proargtypes: TypoOidVector, proname: String = random.alphanumeric.take(20).mkString, pronamespace: /* oid */ Long = random.nextLong(), proowner: /* oid */ Long = random.nextLong(), prolang: /* oid */ Long = random.nextLong(), procost: Float = random.nextFloat(), prorows: Float = random.nextFloat(), provariadic: /* oid */ Long = random.nextLong(), prokind: String = random.alphanumeric.take(20).mkString, prosecdef: Boolean = random.nextBoolean(), proleakproof: Boolean = random.nextBoolean(), proisstrict: Boolean = random.nextBoolean(), proretset: Boolean = random.nextBoolean(), provolatile: String = random.alphanumeric.take(20).mkString, proparallel: String = random.alphanumeric.take(20).mkString, pronargs: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), pronargdefaults: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), prorettype: /* oid */ Long = random.nextLong(), proallargtypes: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), proargmodes: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), proargnames: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), proargdefaults: Option[TypoPgNodeTree] = None, protrftypes: Option[Array[/* oid */ Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), prosrc: String = random.alphanumeric.take(20).mkString, probin: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), prosqlbody: Option[TypoPgNodeTree] = None, proconfig: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), proacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgProcRow] = PgProcRepoImpl.insert(new PgProcRow(oid = oid, prosupport = prosupport, proargtypes = proargtypes, proname = proname, pronamespace = pronamespace, proowner = proowner, prolang = prolang, procost = procost, prorows = prorows, provariadic = provariadic, prokind = prokind, prosecdef = prosecdef, proleakproof = proleakproof, proisstrict = proisstrict, proretset = proretset, provolatile = provolatile, proparallel = proparallel, pronargs = pronargs, pronargdefaults = pronargdefaults, prorettype = prorettype, proallargtypes = proallargtypes, proargmodes = proargmodes, proargnames = proargnames, proargdefaults = proargdefaults, protrftypes = protrftypes, prosrc = prosrc, probin = probin, prosqlbody = prosqlbody, proconfig = proconfig, proacl = proacl)) + def pgCatalogPgPublication(oid: PgPublicationId, pubname: String = random.alphanumeric.take(20).mkString, pubowner: /* oid */ Long = random.nextLong(), puballtables: Boolean = random.nextBoolean(), pubinsert: Boolean = random.nextBoolean(), pubupdate: Boolean = random.nextBoolean(), pubdelete: Boolean = random.nextBoolean(), pubtruncate: Boolean = random.nextBoolean(), pubviaroot: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgPublicationRow] = PgPublicationRepoImpl.insert(new PgPublicationRow(oid = oid, pubname = pubname, pubowner = pubowner, puballtables = puballtables, pubinsert = pubinsert, pubupdate = pubupdate, pubdelete = pubdelete, pubtruncate = pubtruncate, pubviaroot = pubviaroot)) + def pgCatalogPgPublicationRel(oid: PgPublicationRelId, prpubid: /* oid */ Long = random.nextLong(), prrelid: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgPublicationRelRow] = PgPublicationRelRepoImpl.insert(new PgPublicationRelRow(oid = oid, prpubid = prpubid, prrelid = prrelid)) + def pgCatalogPgRange(rngtypid: PgRangeId, rngcanonical: TypoRegproc, rngsubdiff: TypoRegproc, rngsubtype: /* oid */ Long = random.nextLong(), rngmultitypid: /* oid */ Long = random.nextLong(), rngcollation: /* oid */ Long = random.nextLong(), rngsubopc: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgRangeRow] = PgRangeRepoImpl.insert(new PgRangeRow(rngtypid = rngtypid, rngcanonical = rngcanonical, rngsubdiff = rngsubdiff, rngsubtype = rngsubtype, rngmultitypid = rngmultitypid, rngcollation = rngcollation, rngsubopc = rngsubopc)) + def pgCatalogPgReplicationOrigin(roident: PgReplicationOriginId, roname: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgReplicationOriginRow] = PgReplicationOriginRepoImpl.insert(new PgReplicationOriginRow(roident = roident, roname = roname)) + def pgCatalogPgRewrite(oid: PgRewriteId, evQual: TypoPgNodeTree, evAction: TypoPgNodeTree, rulename: String = random.alphanumeric.take(20).mkString, evClass: /* oid */ Long = random.nextLong(), evType: String = random.alphanumeric.take(20).mkString, evEnabled: String = random.alphanumeric.take(20).mkString, isInstead: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgRewriteRow] = PgRewriteRepoImpl.insert(new PgRewriteRow(oid = oid, evQual = evQual, evAction = evAction, rulename = rulename, evClass = evClass, evType = evType, evEnabled = evEnabled, isInstead = isInstead)) + def pgCatalogPgSeclabel(objoid: /* oid */ Long = random.nextLong(), classoid: /* oid */ Long = random.nextLong(), objsubid: Int = random.nextInt(), provider: String = random.alphanumeric.take(20).mkString, label: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgSeclabelRow] = PgSeclabelRepoImpl.insert(new PgSeclabelRow(objoid = objoid, classoid = classoid, objsubid = objsubid, provider = provider, label = label)) + def pgCatalogPgSequence(seqrelid: PgSequenceId, seqtypid: /* oid */ Long = random.nextLong(), seqstart: Long = random.nextLong(), seqincrement: Long = random.nextLong(), seqmax: Long = random.nextLong(), seqmin: Long = random.nextLong(), seqcache: Long = random.nextLong(), seqcycle: Boolean = random.nextBoolean()): ZIO[ZConnection, Throwable, PgSequenceRow] = PgSequenceRepoImpl.insert(new PgSequenceRow(seqrelid = seqrelid, seqtypid = seqtypid, seqstart = seqstart, seqincrement = seqincrement, seqmax = seqmax, seqmin = seqmin, seqcache = seqcache, seqcycle = seqcycle)) + def pgCatalogPgShdepend(dbid: /* oid */ Long = random.nextLong(), classid: /* oid */ Long = random.nextLong(), objid: /* oid */ Long = random.nextLong(), objsubid: Int = random.nextInt(), refclassid: /* oid */ Long = random.nextLong(), refobjid: /* oid */ Long = random.nextLong(), deptype: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgShdependRow] = PgShdependRepoImpl.insert(new PgShdependRow(dbid = dbid, classid = classid, objid = objid, objsubid = objsubid, refclassid = refclassid, refobjid = refobjid, deptype = deptype)) + def pgCatalogPgShdescription(objoid: /* oid */ Long = random.nextLong(), classoid: /* oid */ Long = random.nextLong(), description: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgShdescriptionRow] = PgShdescriptionRepoImpl.insert(new PgShdescriptionRow(objoid = objoid, classoid = classoid, description = description)) + def pgCatalogPgShseclabel(objoid: /* oid */ Long = random.nextLong(), classoid: /* oid */ Long = random.nextLong(), provider: String = random.alphanumeric.take(20).mkString, label: String = random.alphanumeric.take(20).mkString): ZIO[ZConnection, Throwable, PgShseclabelRow] = PgShseclabelRepoImpl.insert(new PgShseclabelRow(objoid = objoid, classoid = classoid, provider = provider, label = label)) + def pgCatalogPgStatistic(starelid: /* oid */ Long = random.nextLong(), staattnum: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), stainherit: Boolean = random.nextBoolean(), stanullfrac: Float = random.nextFloat(), stawidth: Int = random.nextInt(), stadistinct: Float = random.nextFloat(), stakind1: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), stakind2: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), stakind3: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), stakind4: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), stakind5: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), staop1: /* oid */ Long = random.nextLong(), staop2: /* oid */ Long = random.nextLong(), staop3: /* oid */ Long = random.nextLong(), staop4: /* oid */ Long = random.nextLong(), staop5: /* oid */ Long = random.nextLong(), stacoll1: /* oid */ Long = random.nextLong(), stacoll2: /* oid */ Long = random.nextLong(), stacoll3: /* oid */ Long = random.nextLong(), stacoll4: /* oid */ Long = random.nextLong(), stacoll5: /* oid */ Long = random.nextLong(), stanumbers1: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), stanumbers2: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), stanumbers3: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), stanumbers4: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), stanumbers5: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), stavalues1: Option[TypoAnyArray] = None, stavalues2: Option[TypoAnyArray] = None, stavalues3: Option[TypoAnyArray] = None, stavalues4: Option[TypoAnyArray] = None, stavalues5: Option[TypoAnyArray] = None): ZIO[ZConnection, Throwable, PgStatisticRow] = PgStatisticRepoImpl.insert(new PgStatisticRow(starelid = starelid, staattnum = staattnum, stainherit = stainherit, stanullfrac = stanullfrac, stawidth = stawidth, stadistinct = stadistinct, stakind1 = stakind1, stakind2 = stakind2, stakind3 = stakind3, stakind4 = stakind4, stakind5 = stakind5, staop1 = staop1, staop2 = staop2, staop3 = staop3, staop4 = staop4, staop5 = staop5, stacoll1 = stacoll1, stacoll2 = stacoll2, stacoll3 = stacoll3, stacoll4 = stacoll4, stacoll5 = stacoll5, stanumbers1 = stanumbers1, stanumbers2 = stanumbers2, stanumbers3 = stanumbers3, stanumbers4 = stanumbers4, stanumbers5 = stanumbers5, stavalues1 = stavalues1, stavalues2 = stavalues2, stavalues3 = stavalues3, stavalues4 = stavalues4, stavalues5 = stavalues5)) + def pgCatalogPgStatisticExt(oid: PgStatisticExtId, stxkeys: TypoInt2Vector, stxrelid: /* oid */ Long = random.nextLong(), stxname: String = random.alphanumeric.take(20).mkString, stxnamespace: /* oid */ Long = random.nextLong(), stxowner: /* oid */ Long = random.nextLong(), stxstattarget: Int = random.nextInt(), stxkind: Array[String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString), stxexprs: Option[TypoPgNodeTree] = None): ZIO[ZConnection, Throwable, PgStatisticExtRow] = PgStatisticExtRepoImpl.insert(new PgStatisticExtRow(oid = oid, stxkeys = stxkeys, stxrelid = stxrelid, stxname = stxname, stxnamespace = stxnamespace, stxowner = stxowner, stxstattarget = stxstattarget, stxkind = stxkind, stxexprs = stxexprs)) + def pgCatalogPgStatisticExtData(stxoid: PgStatisticExtDataId, stxdndistinct: Option[TypoUnknownPgNdistinct] = None, stxddependencies: Option[TypoUnknownPgDependencies] = None, stxdmcv: Option[TypoUnknownPgMcvList] = None, stxdexpr: Option[Array[TypoUnknownPgStatistic]] = None): ZIO[ZConnection, Throwable, PgStatisticExtDataRow] = PgStatisticExtDataRepoImpl.insert(new PgStatisticExtDataRow(stxoid = stxoid, stxdndistinct = stxdndistinct, stxddependencies = stxddependencies, stxdmcv = stxdmcv, stxdexpr = stxdexpr)) + def pgCatalogPgSubscription(oid: PgSubscriptionId, subdbid: /* oid */ Long = random.nextLong(), subname: String = random.alphanumeric.take(20).mkString, subowner: /* oid */ Long = random.nextLong(), subenabled: Boolean = random.nextBoolean(), subbinary: Boolean = random.nextBoolean(), substream: Boolean = random.nextBoolean(), subconninfo: String = random.alphanumeric.take(20).mkString, subslotname: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), subsynccommit: String = random.alphanumeric.take(20).mkString, subpublications: Array[String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgSubscriptionRow] = PgSubscriptionRepoImpl.insert(new PgSubscriptionRow(oid = oid, subdbid = subdbid, subname = subname, subowner = subowner, subenabled = subenabled, subbinary = subbinary, substream = substream, subconninfo = subconninfo, subslotname = subslotname, subsynccommit = subsynccommit, subpublications = subpublications)) + def pgCatalogPgSubscriptionRel(srsubid: /* oid */ Long = random.nextLong(), srrelid: /* oid */ Long = random.nextLong(), srsubstate: String = random.alphanumeric.take(20).mkString, srsublsn: Option[/* pg_lsn */ Long] = if (random.nextBoolean()) None else Some(random.nextLong())): ZIO[ZConnection, Throwable, PgSubscriptionRelRow] = PgSubscriptionRelRepoImpl.insert(new PgSubscriptionRelRow(srsubid = srsubid, srrelid = srrelid, srsubstate = srsubstate, srsublsn = srsublsn)) + def pgCatalogPgTablespace(oid: PgTablespaceId, spcname: String = random.alphanumeric.take(20).mkString, spcowner: /* oid */ Long = random.nextLong(), spcacl: Option[Array[TypoAclItem]] = None, spcoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgTablespaceRow] = PgTablespaceRepoImpl.insert(new PgTablespaceRow(oid = oid, spcname = spcname, spcowner = spcowner, spcacl = spcacl, spcoptions = spcoptions)) + def pgCatalogPgTransform(oid: PgTransformId, trffromsql: TypoRegproc, trftosql: TypoRegproc, trftype: /* oid */ Long = random.nextLong(), trflang: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgTransformRow] = PgTransformRepoImpl.insert(new PgTransformRow(oid = oid, trffromsql = trffromsql, trftosql = trftosql, trftype = trftype, trflang = trflang)) + def pgCatalogPgTrigger(oid: PgTriggerId, tgattr: TypoInt2Vector, tgargs: TypoBytea, tgrelid: /* oid */ Long = random.nextLong(), tgparentid: /* oid */ Long = random.nextLong(), tgname: String = random.alphanumeric.take(20).mkString, tgfoid: /* oid */ Long = random.nextLong(), tgtype: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), tgenabled: String = random.alphanumeric.take(20).mkString, tgisinternal: Boolean = random.nextBoolean(), tgconstrrelid: /* oid */ Long = random.nextLong(), tgconstrindid: /* oid */ Long = random.nextLong(), tgconstraint: /* oid */ Long = random.nextLong(), tgdeferrable: Boolean = random.nextBoolean(), tginitdeferred: Boolean = random.nextBoolean(), tgnargs: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), tgqual: Option[TypoPgNodeTree] = None, tgoldtable: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), tgnewtable: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgTriggerRow] = PgTriggerRepoImpl.insert(new PgTriggerRow(oid = oid, tgattr = tgattr, tgargs = tgargs, tgrelid = tgrelid, tgparentid = tgparentid, tgname = tgname, tgfoid = tgfoid, tgtype = tgtype, tgenabled = tgenabled, tgisinternal = tgisinternal, tgconstrrelid = tgconstrrelid, tgconstrindid = tgconstrindid, tgconstraint = tgconstraint, tgdeferrable = tgdeferrable, tginitdeferred = tginitdeferred, tgnargs = tgnargs, tgqual = tgqual, tgoldtable = tgoldtable, tgnewtable = tgnewtable)) + def pgCatalogPgTsConfig(oid: PgTsConfigId, cfgname: String = random.alphanumeric.take(20).mkString, cfgnamespace: /* oid */ Long = random.nextLong(), cfgowner: /* oid */ Long = random.nextLong(), cfgparser: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgTsConfigRow] = PgTsConfigRepoImpl.insert(new PgTsConfigRow(oid = oid, cfgname = cfgname, cfgnamespace = cfgnamespace, cfgowner = cfgowner, cfgparser = cfgparser)) + def pgCatalogPgTsConfigMap(mapcfg: /* oid */ Long = random.nextLong(), maptokentype: Int = random.nextInt(), mapseqno: Int = random.nextInt(), mapdict: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgTsConfigMapRow] = PgTsConfigMapRepoImpl.insert(new PgTsConfigMapRow(mapcfg = mapcfg, maptokentype = maptokentype, mapseqno = mapseqno, mapdict = mapdict)) + def pgCatalogPgTsDict(oid: PgTsDictId, dictname: String = random.alphanumeric.take(20).mkString, dictnamespace: /* oid */ Long = random.nextLong(), dictowner: /* oid */ Long = random.nextLong(), dicttemplate: /* oid */ Long = random.nextLong(), dictinitoption: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgTsDictRow] = PgTsDictRepoImpl.insert(new PgTsDictRow(oid = oid, dictname = dictname, dictnamespace = dictnamespace, dictowner = dictowner, dicttemplate = dicttemplate, dictinitoption = dictinitoption)) + def pgCatalogPgTsParser(oid: PgTsParserId, prsstart: TypoRegproc, prstoken: TypoRegproc, prsend: TypoRegproc, prsheadline: TypoRegproc, prslextype: TypoRegproc, prsname: String = random.alphanumeric.take(20).mkString, prsnamespace: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgTsParserRow] = PgTsParserRepoImpl.insert(new PgTsParserRow(oid = oid, prsstart = prsstart, prstoken = prstoken, prsend = prsend, prsheadline = prsheadline, prslextype = prslextype, prsname = prsname, prsnamespace = prsnamespace)) + def pgCatalogPgTsTemplate(oid: PgTsTemplateId, tmplinit: TypoRegproc, tmpllexize: TypoRegproc, tmplname: String = random.alphanumeric.take(20).mkString, tmplnamespace: /* oid */ Long = random.nextLong()): ZIO[ZConnection, Throwable, PgTsTemplateRow] = PgTsTemplateRepoImpl.insert(new PgTsTemplateRow(oid = oid, tmplinit = tmplinit, tmpllexize = tmpllexize, tmplname = tmplname, tmplnamespace = tmplnamespace)) + def pgCatalogPgType(oid: PgTypeId, typsubscript: TypoRegproc, typinput: TypoRegproc, typoutput: TypoRegproc, typreceive: TypoRegproc, typsend: TypoRegproc, typmodin: TypoRegproc, typmodout: TypoRegproc, typanalyze: TypoRegproc, typname: String = random.alphanumeric.take(20).mkString, typnamespace: /* oid */ Long = random.nextLong(), typowner: /* oid */ Long = random.nextLong(), typlen: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), typbyval: Boolean = random.nextBoolean(), typtype: String = random.alphanumeric.take(20).mkString, typcategory: String = random.alphanumeric.take(20).mkString, typispreferred: Boolean = random.nextBoolean(), typisdefined: Boolean = random.nextBoolean(), typdelim: String = random.alphanumeric.take(20).mkString, typrelid: /* oid */ Long = random.nextLong(), typelem: /* oid */ Long = random.nextLong(), typarray: /* oid */ Long = random.nextLong(), typalign: String = random.alphanumeric.take(20).mkString, typstorage: String = random.alphanumeric.take(20).mkString, typnotnull: Boolean = random.nextBoolean(), typbasetype: /* oid */ Long = random.nextLong(), typtypmod: Int = random.nextInt(), typndims: Int = random.nextInt(), typcollation: /* oid */ Long = random.nextLong(), typdefaultbin: Option[TypoPgNodeTree] = None, typdefault: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), typacl: Option[Array[TypoAclItem]] = None): ZIO[ZConnection, Throwable, PgTypeRow] = PgTypeRepoImpl.insert(new PgTypeRow(oid = oid, typsubscript = typsubscript, typinput = typinput, typoutput = typoutput, typreceive = typreceive, typsend = typsend, typmodin = typmodin, typmodout = typmodout, typanalyze = typanalyze, typname = typname, typnamespace = typnamespace, typowner = typowner, typlen = typlen, typbyval = typbyval, typtype = typtype, typcategory = typcategory, typispreferred = typispreferred, typisdefined = typisdefined, typdelim = typdelim, typrelid = typrelid, typelem = typelem, typarray = typarray, typalign = typalign, typstorage = typstorage, typnotnull = typnotnull, typbasetype = typbasetype, typtypmod = typtypmod, typndims = typndims, typcollation = typcollation, typdefaultbin = typdefaultbin, typdefault = typdefault, typacl = typacl)) + def pgCatalogPgUserMapping(oid: PgUserMappingId, umuser: /* oid */ Long = random.nextLong(), umserver: /* oid */ Long = random.nextLong(), umoptions: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString))): ZIO[ZConnection, Throwable, PgUserMappingRow] = PgUserMappingRepoImpl.insert(new PgUserMappingRow(oid = oid, umuser = umuser, umserver = umserver, umoptions = umoptions)) + def productionBillofmaterials(componentid: ProductId, unitmeasurecode: UnitmeasureId, 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, startdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, perassemblyqty: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, BillofmaterialsRow] = BillofmaterialsRepoImpl.insert(new BillofmaterialsRowUnsaved(componentid = componentid, unitmeasurecode = unitmeasurecode, productassemblyid = productassemblyid, enddate = enddate, bomlevel = bomlevel, billofmaterialsid = billofmaterialsid, startdate = startdate, perassemblyqty = perassemblyqty, modifieddate = modifieddate)) + def productionCulture(cultureid: CultureId, name: Name = Name(random.alphanumeric.take(20).mkString), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CultureRow] = CultureRepoImpl.insert(new CultureRowUnsaved(cultureid = cultureid, name = name, modifieddate = modifieddate)) + def productionDocument(owner: BusinessentityId, title: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, filename: /* max 400 chars */ String = random.alphanumeric.take(20).mkString, fileextension: Option[/* max 8 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(8).mkString), revision: /* bpchar, max 5 chars */ String = random.alphanumeric.take(5).mkString, status: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), documentsummary: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), document: Option[TypoBytea] = None, folderflag: Defaulted[Flag] = Defaulted.UseDefault, changenumber: Defaulted[Int] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, documentnode: Defaulted[DocumentId] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, DocumentRow] = DocumentRepoImpl.insert(new DocumentRowUnsaved(owner = owner, title = title, filename = filename, fileextension = fileextension, revision = revision, status = status, documentsummary = documentsummary, document = document, folderflag = folderflag, changenumber = changenumber, rowguid = rowguid, modifieddate = modifieddate, documentnode = documentnode)) + def productionIllustration(diagram: Option[TypoXml] = None, illustrationid: Defaulted[IllustrationId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, IllustrationRow] = IllustrationRepoImpl.insert(new IllustrationRowUnsaved(diagram = diagram, illustrationid = illustrationid, modifieddate = modifieddate)) + def productionLocation(name: Name = Name(random.alphanumeric.take(20).mkString), locationid: Defaulted[LocationId] = Defaulted.UseDefault, costrate: Defaulted[BigDecimal] = Defaulted.UseDefault, availability: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, LocationRow] = LocationRepoImpl.insert(new LocationRowUnsaved(name = name, locationid = locationid, costrate = costrate, availability = availability, modifieddate = modifieddate)) + def productionProduct(name: Name = Name(random.alphanumeric.take(20).mkString), productnumber: /* max 25 chars */ String = random.alphanumeric.take(20).mkString, color: Option[/* max 15 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(15).mkString), safetystocklevel: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), reorderpoint: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), standardcost: BigDecimal = BigDecimal.decimal(random.nextDouble()), listprice: BigDecimal = BigDecimal.decimal(random.nextDouble()), size: Option[/* max 5 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(5).mkString), sizeunitmeasurecode: Option[UnitmeasureId] = None, weightunitmeasurecode: Option[UnitmeasureId] = None, weight: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), daystomanufacture: Int = random.nextInt(), productline: Option[/* bpchar, max 2 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(2).mkString), `class`: Option[/* bpchar, max 2 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(2).mkString), style: Option[/* bpchar, max 2 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(2).mkString), productsubcategoryid: Option[ProductsubcategoryId] = None, productmodelid: Option[ProductmodelId] = None, sellstartdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), sellenddate: 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)))), discontinueddate: 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)))), productid: Defaulted[ProductId] = Defaulted.UseDefault, makeflag: Defaulted[Flag] = Defaulted.UseDefault, finishedgoodsflag: Defaulted[Flag] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductRow] = ProductRepoImpl.insert(new ProductRowUnsaved(name = name, productnumber = productnumber, color = color, safetystocklevel = safetystocklevel, reorderpoint = reorderpoint, standardcost = standardcost, listprice = listprice, size = size, sizeunitmeasurecode = sizeunitmeasurecode, weightunitmeasurecode = weightunitmeasurecode, weight = weight, daystomanufacture = daystomanufacture, productline = productline, `class` = `class`, style = style, productsubcategoryid = productsubcategoryid, productmodelid = productmodelid, sellstartdate = sellstartdate, sellenddate = sellenddate, discontinueddate = discontinueddate, productid = productid, makeflag = makeflag, finishedgoodsflag = finishedgoodsflag, rowguid = rowguid, modifieddate = modifieddate)) + def productionProductcategory(name: Name = Name(random.alphanumeric.take(20).mkString), productcategoryid: Defaulted[ProductcategoryId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductcategoryRow] = ProductcategoryRepoImpl.insert(new ProductcategoryRowUnsaved(name = name, productcategoryid = productcategoryid, rowguid = rowguid, modifieddate = modifieddate)) + def productionProductcosthistory(productid: ProductId, startdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), 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)))), standardcost: BigDecimal = BigDecimal.decimal(random.nextDouble()), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductcosthistoryRow] = ProductcosthistoryRepoImpl.insert(new ProductcosthistoryRowUnsaved(productid = productid, startdate = startdate, enddate = enddate, standardcost = standardcost, modifieddate = modifieddate)) + def productionProductdescription(description: /* max 400 chars */ String = random.alphanumeric.take(20).mkString, productdescriptionid: Defaulted[ProductdescriptionId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductdescriptionRow] = ProductdescriptionRepoImpl.insert(new ProductdescriptionRowUnsaved(description = description, productdescriptionid = productdescriptionid, rowguid = rowguid, modifieddate = modifieddate)) + def productionProductdocument(productid: ProductId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, documentnode: Defaulted[DocumentId] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductdocumentRow] = ProductdocumentRepoImpl.insert(new ProductdocumentRowUnsaved(productid = productid, modifieddate = modifieddate, documentnode = documentnode)) + def productionProductinventory(productid: ProductId, locationid: LocationId, shelf: /* max 10 chars */ String = random.alphanumeric.take(10).mkString, bin: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), quantity: Defaulted[TypoShort] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductinventoryRow] = ProductinventoryRepoImpl.insert(new ProductinventoryRowUnsaved(productid = productid, locationid = locationid, shelf = shelf, bin = bin, quantity = quantity, rowguid = rowguid, modifieddate = modifieddate)) + def productionProductlistpricehistory(productid: ProductId, startdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), 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)))), listprice: BigDecimal = BigDecimal.decimal(random.nextDouble()), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductlistpricehistoryRow] = ProductlistpricehistoryRepoImpl.insert(new ProductlistpricehistoryRowUnsaved(productid = productid, startdate = startdate, enddate = enddate, listprice = listprice, modifieddate = modifieddate)) + def productionProductmodel(name: Name = Name(random.alphanumeric.take(20).mkString), catalogdescription: Option[TypoXml] = None, instructions: Option[TypoXml] = None, productmodelid: Defaulted[ProductmodelId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductmodelRow] = ProductmodelRepoImpl.insert(new ProductmodelRowUnsaved(name = name, catalogdescription = catalogdescription, instructions = instructions, productmodelid = productmodelid, rowguid = rowguid, modifieddate = modifieddate)) + def productionProductmodelillustration(productmodelid: ProductmodelId, illustrationid: IllustrationId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductmodelillustrationRow] = ProductmodelillustrationRepoImpl.insert(new ProductmodelillustrationRowUnsaved(productmodelid = productmodelid, illustrationid = illustrationid, modifieddate = modifieddate)) + def productionProductmodelproductdescriptionculture(productmodelid: ProductmodelId, productdescriptionid: ProductdescriptionId, cultureid: CultureId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductmodelproductdescriptioncultureRow] = ProductmodelproductdescriptioncultureRepoImpl.insert(new ProductmodelproductdescriptioncultureRowUnsaved(productmodelid = productmodelid, productdescriptionid = productdescriptionid, cultureid = cultureid, modifieddate = modifieddate)) + def productionProductphoto(thumbnailphoto: Option[TypoBytea] = None, thumbnailphotofilename: Option[/* max 50 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), largephoto: Option[TypoBytea] = None, largephotofilename: Option[/* max 50 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), productphotoid: Defaulted[ProductphotoId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductphotoRow] = ProductphotoRepoImpl.insert(new ProductphotoRowUnsaved(thumbnailphoto = thumbnailphoto, thumbnailphotofilename = thumbnailphotofilename, largephoto = largephoto, largephotofilename = largephotofilename, productphotoid = productphotoid, modifieddate = modifieddate)) + def productionProductproductphoto(productid: ProductId, productphotoid: ProductphotoId, primary: Defaulted[Flag] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductproductphotoRow] = ProductproductphotoRepoImpl.insert(new ProductproductphotoRowUnsaved(productid = productid, productphotoid = productphotoid, primary = primary, modifieddate = modifieddate)) + def productionProductreview(productid: ProductId, reviewername: Name = Name(random.alphanumeric.take(20).mkString), emailaddress: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, rating: Int = random.nextInt(), comments: Option[/* max 3850 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), productreviewid: Defaulted[ProductreviewId] = Defaulted.UseDefault, reviewdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductreviewRow] = ProductreviewRepoImpl.insert(new ProductreviewRowUnsaved(productid = productid, reviewername = reviewername, emailaddress = emailaddress, rating = rating, comments = comments, productreviewid = productreviewid, reviewdate = reviewdate, modifieddate = modifieddate)) + def productionProductsubcategory(productcategoryid: ProductcategoryId, name: Name = Name(random.alphanumeric.take(20).mkString), productsubcategoryid: Defaulted[ProductsubcategoryId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductsubcategoryRow] = ProductsubcategoryRepoImpl.insert(new ProductsubcategoryRowUnsaved(productcategoryid = productcategoryid, name = name, productsubcategoryid = productsubcategoryid, rowguid = rowguid, modifieddate = modifieddate)) + def productionScrapreason(name: Name = Name(random.alphanumeric.take(20).mkString), scrapreasonid: Defaulted[ScrapreasonId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ScrapreasonRow] = ScrapreasonRepoImpl.insert(new ScrapreasonRowUnsaved(name = name, scrapreasonid = scrapreasonid, modifieddate = modifieddate)) + def productionTransactionhistory(productid: ProductId, referenceorderid: Int = random.nextInt(), transactiontype: /* bpchar, max 1 chars */ String = random.alphanumeric.take(1).mkString, quantity: Int = random.nextInt(), actualcost: BigDecimal = BigDecimal.decimal(random.nextDouble()), transactionid: Defaulted[TransactionhistoryId] = Defaulted.UseDefault, referenceorderlineid: Defaulted[Int] = Defaulted.UseDefault, transactiondate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, TransactionhistoryRow] = TransactionhistoryRepoImpl.insert(new TransactionhistoryRowUnsaved(productid = productid, referenceorderid = referenceorderid, transactiontype = transactiontype, quantity = quantity, actualcost = actualcost, transactionid = transactionid, referenceorderlineid = referenceorderlineid, transactiondate = transactiondate, modifieddate = modifieddate)) + def productionTransactionhistoryarchive(transactionid: TransactionhistoryarchiveId, productid: Int = random.nextInt(), referenceorderid: Int = random.nextInt(), transactiontype: /* bpchar, max 1 chars */ String = random.alphanumeric.take(1).mkString, quantity: Int = random.nextInt(), actualcost: BigDecimal = BigDecimal.decimal(random.nextDouble()), referenceorderlineid: Defaulted[Int] = Defaulted.UseDefault, transactiondate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, TransactionhistoryarchiveRow] = TransactionhistoryarchiveRepoImpl.insert(new TransactionhistoryarchiveRowUnsaved(transactionid = transactionid, productid = productid, referenceorderid = referenceorderid, transactiontype = transactiontype, quantity = quantity, actualcost = actualcost, referenceorderlineid = referenceorderlineid, transactiondate = transactiondate, modifieddate = modifieddate)) + def productionUnitmeasure(unitmeasurecode: UnitmeasureId, name: Name = Name(random.alphanumeric.take(20).mkString), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, UnitmeasureRow] = UnitmeasureRepoImpl.insert(new UnitmeasureRowUnsaved(unitmeasurecode = unitmeasurecode, name = name, modifieddate = modifieddate)) + def productionWorkorder(productid: ProductId, orderqty: Int = random.nextInt(), scrappedqty: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), startdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), 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)))), duedate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), scrapreasonid: Option[ScrapreasonId] = None, workorderid: Defaulted[WorkorderId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, WorkorderRow] = WorkorderRepoImpl.insert(new WorkorderRowUnsaved(productid = productid, orderqty = orderqty, scrappedqty = scrappedqty, startdate = startdate, enddate = enddate, duedate = duedate, scrapreasonid = scrapreasonid, workorderid = workorderid, modifieddate = modifieddate)) + def productionWorkorderrouting(workorderid: WorkorderId, locationid: LocationId, productid: Int = random.nextInt(), operationsequence: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), scheduledstartdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), scheduledenddate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), actualstartdate: 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)))), actualenddate: 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)))), actualresourcehrs: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), plannedcost: BigDecimal = BigDecimal.decimal(random.nextDouble()), actualcost: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, WorkorderroutingRow] = WorkorderroutingRepoImpl.insert(new WorkorderroutingRowUnsaved(workorderid = workorderid, locationid = locationid, productid = productid, operationsequence = operationsequence, scheduledstartdate = scheduledstartdate, scheduledenddate = scheduledenddate, actualstartdate = actualstartdate, actualenddate = actualenddate, actualresourcehrs = actualresourcehrs, plannedcost = plannedcost, actualcost = actualcost, modifieddate = modifieddate)) + def publicPgtest(box: TypoBox, bytea: TypoBytea, circle: TypoCircle, hstore: TypoHStore, inet: TypoInet, int2vector: TypoInt2Vector, interval: TypoInterval, json: TypoJson, jsonb: TypoJsonb, line: TypoLine, lseg: TypoLineSegment, money: TypoMoney, path: TypoPath, point: TypoPoint, polygon: TypoPolygon, uuid: TypoUUID, vector: TypoVector, xml: TypoXml, boxes: Array[TypoBox], circlees: Array[TypoCircle], inetes: Array[TypoInet], int2vectores: Array[TypoInt2Vector], intervales: Array[TypoInterval], jsones: Array[TypoJson], jsonbes: Array[TypoJsonb], linees: Array[TypoLine], lseges: Array[TypoLineSegment], moneyes: Array[TypoMoney], pathes: Array[TypoPath], pointes: Array[TypoPoint], polygones: Array[TypoPolygon], uuides: Array[TypoUUID], xmles: Array[TypoXml], bool: Boolean = random.nextBoolean(), bpchar: /* bpchar, max 3 chars */ String = random.alphanumeric.take(3).mkString, char: /* bpchar, max 1 chars */ String = random.alphanumeric.take(1).mkString, date: TypoLocalDate = TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong)), float4: Float = random.nextFloat(), float8: Double = random.nextDouble(), int2: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), int4: Int = random.nextInt(), int8: Long = random.nextLong(), mydomain: Mydomain = Mydomain(random.alphanumeric.take(20).mkString), myenum: Myenum = Myenum.All(random.nextInt(Myenum.All.length)), name: String = random.alphanumeric.take(20).mkString, numeric: BigDecimal = BigDecimal.decimal(random.nextDouble()), text: String = random.alphanumeric.take(20).mkString, time: TypoLocalTime = TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)), timestamp: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), timestampz: TypoInstant = TypoInstant(Instant.ofEpochMilli(random.nextLong())), timez: TypoOffsetTime = TypoOffsetTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong).atOffset(ZoneOffset.ofHours(random.nextInt(24) - 12))), varchar: String = random.alphanumeric.take(20).mkString, bpchares: Array[/* bpchar */ String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString), chares: Array[/* bpchar */ String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString), datees: Array[TypoLocalDate] = Array.fill(random.nextInt(3))(TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong))), float4es: Array[Float] = Array.fill(random.nextInt(3))(random.nextFloat()), float8es: Array[Double] = Array.fill(random.nextInt(3))(random.nextDouble()), int2es: Array[TypoShort] = Array.fill(random.nextInt(3))(TypoShort(random.nextInt(Short.MaxValue).toShort)), int4es: Array[Int] = Array.fill(random.nextInt(3))(random.nextInt()), int8es: Array[Long] = Array.fill(random.nextInt(3))(random.nextLong()), myenumes: Array[Myenum] = Array.fill(random.nextInt(3))(Myenum.All(random.nextInt(Myenum.All.length))), namees: Array[String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString), numerices: Array[BigDecimal] = Array.fill(random.nextInt(3))(BigDecimal.decimal(random.nextDouble())), textes: Array[String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString), timees: Array[TypoLocalTime] = Array.fill(random.nextInt(3))(TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), timestampes: Array[TypoLocalDateTime] = Array.fill(random.nextInt(3))(TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)))), timestampzes: Array[TypoInstant] = Array.fill(random.nextInt(3))(TypoInstant(Instant.ofEpochMilli(random.nextLong()))), timezes: Array[TypoOffsetTime] = Array.fill(random.nextInt(3))(TypoOffsetTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong).atOffset(ZoneOffset.ofHours(random.nextInt(24) - 12)))), varchares: Array[String] = Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)): ZIO[ZConnection, Throwable, PgtestRow] = PgtestRepoImpl.insert(new PgtestRow(box = box, bytea = bytea, circle = circle, hstore = hstore, inet = inet, int2vector = int2vector, interval = interval, json = json, jsonb = jsonb, line = line, lseg = lseg, money = money, path = path, point = point, polygon = polygon, uuid = uuid, vector = vector, xml = xml, boxes = boxes, circlees = circlees, inetes = inetes, int2vectores = int2vectores, intervales = intervales, jsones = jsones, jsonbes = jsonbes, linees = linees, lseges = lseges, moneyes = moneyes, pathes = pathes, pointes = pointes, polygones = polygones, uuides = uuides, xmles = xmles, bool = bool, bpchar = bpchar, char = char, date = date, float4 = float4, float8 = float8, int2 = int2, int4 = int4, int8 = int8, mydomain = mydomain, myenum = myenum, name = name, numeric = numeric, text = text, time = time, timestamp = timestamp, timestampz = timestampz, timez = timez, varchar = varchar, bpchares = bpchares, chares = chares, datees = datees, float4es = float4es, float8es = float8es, int2es = int2es, int4es = int4es, int8es = int8es, myenumes = myenumes, namees = namees, numerices = numerices, textes = textes, timees = timees, timestampes = timestampes, timestampzes = timestampzes, timezes = timezes, varchares = varchares)) + def publicPgtestnull(bool: Option[Boolean] = if (random.nextBoolean()) None else Some(random.nextBoolean()), box: Option[TypoBox] = None, bpchar: Option[/* bpchar, max 3 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(3).mkString), bytea: Option[TypoBytea] = None, char: Option[/* bpchar, max 1 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(1).mkString), circle: Option[TypoCircle] = None, date: Option[TypoLocalDate] = if (random.nextBoolean()) None else Some(TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong))), float4: Option[Float] = if (random.nextBoolean()) None else Some(random.nextFloat()), float8: Option[Double] = if (random.nextBoolean()) None else Some(random.nextDouble()), hstore: Option[TypoHStore] = None, inet: Option[TypoInet] = None, int2: Option[TypoShort] = if (random.nextBoolean()) None else Some(TypoShort(random.nextInt(Short.MaxValue).toShort)), int2vector: Option[TypoInt2Vector] = None, int4: Option[Int] = if (random.nextBoolean()) None else Some(random.nextInt()), int8: Option[Long] = if (random.nextBoolean()) None else Some(random.nextLong()), interval: Option[TypoInterval] = None, json: Option[TypoJson] = None, jsonb: Option[TypoJsonb] = None, line: Option[TypoLine] = None, lseg: Option[TypoLineSegment] = None, money: Option[TypoMoney] = None, mydomain: Option[Mydomain] = if (random.nextBoolean()) None else Some(Mydomain(random.alphanumeric.take(20).mkString)), myenum: Option[Myenum] = if (random.nextBoolean()) None else Some(Myenum.All(random.nextInt(Myenum.All.length))), name: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), numeric: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), path: Option[TypoPath] = None, point: Option[TypoPoint] = None, polygon: Option[TypoPolygon] = None, text: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), time: Option[TypoLocalTime] = if (random.nextBoolean()) None else Some(TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), timestamp: 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)))), timestampz: Option[TypoInstant] = if (random.nextBoolean()) None else Some(TypoInstant(Instant.ofEpochMilli(random.nextLong()))), timez: Option[TypoOffsetTime] = if (random.nextBoolean()) None else Some(TypoOffsetTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong).atOffset(ZoneOffset.ofHours(random.nextInt(24) - 12)))), uuid: Option[TypoUUID] = None, varchar: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), vector: Option[TypoVector] = None, xml: Option[TypoXml] = None, boxes: Option[Array[TypoBox]] = None, bpchares: Option[Array[/* bpchar */ String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), chares: Option[Array[/* bpchar */ String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), circlees: Option[Array[TypoCircle]] = None, datees: Option[Array[TypoLocalDate]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoLocalDate(LocalDate.ofEpochDay(random.nextInt(30000).toLong)))), float4es: Option[Array[Float]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextFloat())), float8es: Option[Array[Double]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextDouble())), inetes: Option[Array[TypoInet]] = None, int2es: Option[Array[TypoShort]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoShort(random.nextInt(Short.MaxValue).toShort))), int2vectores: Option[Array[TypoInt2Vector]] = None, int4es: Option[Array[Int]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextInt())), int8es: Option[Array[Long]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.nextLong())), intervales: Option[Array[TypoInterval]] = None, jsones: Option[Array[TypoJson]] = None, jsonbes: Option[Array[TypoJsonb]] = None, linees: Option[Array[TypoLine]] = None, lseges: Option[Array[TypoLineSegment]] = None, moneyes: Option[Array[TypoMoney]] = None, myenumes: Option[Array[Myenum]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(Myenum.All(random.nextInt(Myenum.All.length)))), namees: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), numerices: Option[Array[BigDecimal]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(BigDecimal.decimal(random.nextDouble()))), pathes: Option[Array[TypoPath]] = None, pointes: Option[Array[TypoPoint]] = None, polygones: Option[Array[TypoPolygon]] = None, textes: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), timees: Option[Array[TypoLocalTime]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoLocalTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong)))), timestampes: Option[Array[TypoLocalDateTime]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))))), timestampzes: Option[Array[TypoInstant]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoInstant(Instant.ofEpochMilli(random.nextLong())))), timezes: Option[Array[TypoOffsetTime]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(TypoOffsetTime(LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong).atOffset(ZoneOffset.ofHours(random.nextInt(24) - 12))))), uuides: Option[Array[TypoUUID]] = None, varchares: Option[Array[String]] = if (random.nextBoolean()) None else Some(Array.fill(random.nextInt(3))(random.alphanumeric.take(20).mkString)), xmles: Option[Array[TypoXml]] = None): ZIO[ZConnection, Throwable, PgtestnullRow] = PgtestnullRepoImpl.insert(new PgtestnullRow(bool = bool, box = box, bpchar = bpchar, bytea = bytea, char = char, circle = circle, date = date, float4 = float4, float8 = float8, hstore = hstore, inet = inet, int2 = int2, int2vector = int2vector, int4 = int4, int8 = int8, interval = interval, json = json, jsonb = jsonb, line = line, lseg = lseg, money = money, mydomain = mydomain, myenum = myenum, name = name, numeric = numeric, path = path, point = point, polygon = polygon, text = text, time = time, timestamp = timestamp, timestampz = timestampz, timez = timez, uuid = uuid, varchar = varchar, vector = vector, xml = xml, boxes = boxes, bpchares = bpchares, chares = chares, circlees = circlees, datees = datees, float4es = float4es, float8es = float8es, inetes = inetes, int2es = int2es, int2vectores = int2vectores, int4es = int4es, int8es = int8es, intervales = intervales, jsones = jsones, jsonbes = jsonbes, linees = linees, lseges = lseges, moneyes = moneyes, myenumes = myenumes, namees = namees, numerices = numerices, pathes = pathes, pointes = pointes, polygones = polygones, textes = textes, timees = timees, timestampes = timestampes, timestampzes = timestampzes, timezes = timezes, uuides = uuides, varchares = varchares, xmles = xmles)) + def publicUsers(userId: UsersId, email: TypoUnknownCitext, name: String = random.alphanumeric.take(20).mkString, lastName: Option[String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), password: String = random.alphanumeric.take(20).mkString, verifiedOn: Option[TypoInstant] = if (random.nextBoolean()) None else Some(TypoInstant(Instant.ofEpochMilli(random.nextLong()))), createdAt: Defaulted[TypoInstant] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, UsersRow] = UsersRepoImpl.insert(new UsersRowUnsaved(userId = userId, email = email, name = name, lastName = lastName, password = password, verifiedOn = verifiedOn, createdAt = createdAt)) + def purchasingProductvendor(productid: ProductId, businessentityid: BusinessentityId, unitmeasurecode: UnitmeasureId, averageleadtime: Int = random.nextInt(), standardprice: BigDecimal = BigDecimal.decimal(random.nextDouble()), lastreceiptcost: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), lastreceiptdate: 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)))), minorderqty: Int = random.nextInt(), maxorderqty: Int = random.nextInt(), onorderqty: Option[Int] = if (random.nextBoolean()) None else Some(random.nextInt()), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ProductvendorRow] = ProductvendorRepoImpl.insert(new ProductvendorRowUnsaved(productid = productid, businessentityid = businessentityid, unitmeasurecode = unitmeasurecode, averageleadtime = averageleadtime, standardprice = standardprice, lastreceiptcost = lastreceiptcost, lastreceiptdate = lastreceiptdate, minorderqty = minorderqty, maxorderqty = maxorderqty, onorderqty = onorderqty, modifieddate = modifieddate)) + def purchasingPurchaseorderheader(employeeid: BusinessentityId, vendorid: BusinessentityId, shipmethodid: ShipmethodId, shipdate: 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)))), purchaseorderid: Defaulted[PurchaseorderheaderId] = Defaulted.UseDefault, revisionnumber: Defaulted[TypoShort] = Defaulted.UseDefault, status: Defaulted[TypoShort] = Defaulted.UseDefault, orderdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, subtotal: Defaulted[BigDecimal] = Defaulted.UseDefault, taxamt: Defaulted[BigDecimal] = Defaulted.UseDefault, freight: Defaulted[BigDecimal] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PurchaseorderheaderRow] = PurchaseorderheaderRepoImpl.insert(new PurchaseorderheaderRowUnsaved(employeeid = employeeid, vendorid = vendorid, shipmethodid = shipmethodid, shipdate = shipdate, purchaseorderid = purchaseorderid, revisionnumber = revisionnumber, status = status, orderdate = orderdate, subtotal = subtotal, taxamt = taxamt, freight = freight, modifieddate = modifieddate)) + def purchasingShipmethod(name: Name = Name(random.alphanumeric.take(20).mkString), shipmethodid: Defaulted[ShipmethodId] = Defaulted.UseDefault, shipbase: Defaulted[BigDecimal] = Defaulted.UseDefault, shiprate: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ShipmethodRow] = ShipmethodRepoImpl.insert(new ShipmethodRowUnsaved(name = name, shipmethodid = shipmethodid, shipbase = shipbase, shiprate = shiprate, rowguid = rowguid, modifieddate = modifieddate)) + def purchasingVendor(businessentityid: BusinessentityId, accountnumber: AccountNumber = AccountNumber(random.alphanumeric.take(20).mkString), name: Name = Name(random.alphanumeric.take(20).mkString), creditrating: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), purchasingwebserviceurl: Option[/* max 1024 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), preferredvendorstatus: Defaulted[Flag] = Defaulted.UseDefault, activeflag: Defaulted[Flag] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, VendorRow] = VendorRepoImpl.insert(new VendorRowUnsaved(businessentityid = businessentityid, accountnumber = accountnumber, name = name, creditrating = creditrating, purchasingwebserviceurl = purchasingwebserviceurl, preferredvendorstatus = preferredvendorstatus, activeflag = activeflag, modifieddate = modifieddate)) + def salesCountryregioncurrency(countryregioncode: CountryregionId, currencycode: CurrencyId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CountryregioncurrencyRow] = CountryregioncurrencyRepoImpl.insert(new CountryregioncurrencyRowUnsaved(countryregioncode = countryregioncode, currencycode = currencycode, modifieddate = modifieddate)) + def salesCreditcard(cardtype: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, cardnumber: /* max 25 chars */ String = random.alphanumeric.take(20).mkString, expmonth: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), expyear: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), creditcardid: Defaulted[/* user-picked */ CustomCreditcardId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CreditcardRow] = CreditcardRepoImpl.insert(new CreditcardRowUnsaved(cardtype = cardtype, cardnumber = cardnumber, expmonth = expmonth, expyear = expyear, creditcardid = creditcardid, modifieddate = modifieddate)) + def salesCurrency(currencycode: CurrencyId, name: Name = Name(random.alphanumeric.take(20).mkString), modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CurrencyRow] = CurrencyRepoImpl.insert(new CurrencyRowUnsaved(currencycode = currencycode, name = name, modifieddate = modifieddate)) + def salesCurrencyrate(fromcurrencycode: CurrencyId, tocurrencycode: CurrencyId, currencyratedate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), averagerate: BigDecimal = BigDecimal.decimal(random.nextDouble()), endofdayrate: BigDecimal = BigDecimal.decimal(random.nextDouble()), currencyrateid: Defaulted[CurrencyrateId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CurrencyrateRow] = CurrencyrateRepoImpl.insert(new CurrencyrateRowUnsaved(fromcurrencycode = fromcurrencycode, tocurrencycode = tocurrencycode, currencyratedate = currencyratedate, averagerate = averagerate, endofdayrate = endofdayrate, currencyrateid = currencyrateid, modifieddate = modifieddate)) + def salesCustomer(personid: Option[BusinessentityId] = None, storeid: Option[BusinessentityId] = None, territoryid: Option[SalesterritoryId] = None, customerid: Defaulted[CustomerId] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, CustomerRow] = CustomerRepoImpl.insert(new CustomerRowUnsaved(personid = personid, storeid = storeid, territoryid = territoryid, customerid = customerid, rowguid = rowguid, modifieddate = modifieddate)) + def salesPersoncreditcard(businessentityid: BusinessentityId, creditcardid: /* user-picked */ CustomCreditcardId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, PersoncreditcardRow] = PersoncreditcardRepoImpl.insert(new PersoncreditcardRowUnsaved(businessentityid = businessentityid, creditcardid = creditcardid, modifieddate = modifieddate)) + def salesSalesorderdetail(salesorderid: SalesorderheaderId, productid: ProductId, specialofferid: SpecialofferId, carriertrackingnumber: Option[/* max 25 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), orderqty: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), unitprice: BigDecimal = BigDecimal.decimal(random.nextDouble()), salesorderdetailid: Defaulted[Int] = Defaulted.UseDefault, unitpricediscount: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesorderdetailRow] = SalesorderdetailRepoImpl.insert(new SalesorderdetailRowUnsaved(salesorderid = salesorderid, productid = productid, specialofferid = specialofferid, carriertrackingnumber = carriertrackingnumber, orderqty = orderqty, unitprice = unitprice, salesorderdetailid = salesorderdetailid, unitpricediscount = unitpricediscount, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalesorderheader(customerid: CustomerId, billtoaddressid: AddressId, shiptoaddressid: AddressId, shipmethodid: ShipmethodId, duedate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), shipdate: 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)))), purchaseordernumber: Option[OrderNumber] = if (random.nextBoolean()) None else Some(OrderNumber(random.alphanumeric.take(20).mkString)), accountnumber: Option[AccountNumber] = if (random.nextBoolean()) None else Some(AccountNumber(random.alphanumeric.take(20).mkString)), salespersonid: Option[BusinessentityId] = None, territoryid: Option[SalesterritoryId] = None, creditcardid: Option[/* user-picked */ CustomCreditcardId] = None, creditcardapprovalcode: Option[/* max 15 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(15).mkString), currencyrateid: Option[CurrencyrateId] = None, totaldue: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), comment: Option[/* max 128 chars */ String] = if (random.nextBoolean()) None else Some(random.alphanumeric.take(20).mkString), salesorderid: Defaulted[SalesorderheaderId] = Defaulted.UseDefault, revisionnumber: Defaulted[TypoShort] = Defaulted.UseDefault, orderdate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, status: Defaulted[TypoShort] = Defaulted.UseDefault, onlineorderflag: Defaulted[Flag] = Defaulted.UseDefault, subtotal: Defaulted[BigDecimal] = Defaulted.UseDefault, taxamt: Defaulted[BigDecimal] = Defaulted.UseDefault, freight: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesorderheaderRow] = SalesorderheaderRepoImpl.insert(new SalesorderheaderRowUnsaved(customerid = customerid, billtoaddressid = billtoaddressid, shiptoaddressid = shiptoaddressid, shipmethodid = shipmethodid, duedate = duedate, shipdate = shipdate, purchaseordernumber = purchaseordernumber, accountnumber = accountnumber, salespersonid = salespersonid, territoryid = territoryid, creditcardid = creditcardid, creditcardapprovalcode = creditcardapprovalcode, currencyrateid = currencyrateid, totaldue = totaldue, comment = comment, salesorderid = salesorderid, revisionnumber = revisionnumber, orderdate = orderdate, status = status, onlineorderflag = onlineorderflag, subtotal = subtotal, taxamt = taxamt, freight = freight, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalesorderheadersalesreason(salesorderid: SalesorderheaderId, salesreasonid: SalesreasonId, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesorderheadersalesreasonRow] = SalesorderheadersalesreasonRepoImpl.insert(new SalesorderheadersalesreasonRowUnsaved(salesorderid = salesorderid, salesreasonid = salesreasonid, modifieddate = modifieddate)) + def salesSalesperson(businessentityid: BusinessentityId, territoryid: Option[SalesterritoryId] = None, salesquota: Option[BigDecimal] = if (random.nextBoolean()) None else Some(BigDecimal.decimal(random.nextDouble())), bonus: Defaulted[BigDecimal] = Defaulted.UseDefault, commissionpct: Defaulted[BigDecimal] = Defaulted.UseDefault, salesytd: Defaulted[BigDecimal] = Defaulted.UseDefault, saleslastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalespersonRow] = SalespersonRepoImpl.insert(new SalespersonRowUnsaved(businessentityid = businessentityid, territoryid = territoryid, salesquota = salesquota, bonus = bonus, commissionpct = commissionpct, salesytd = salesytd, saleslastyear = saleslastyear, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalespersonquotahistory(businessentityid: BusinessentityId, quotadate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), salesquota: BigDecimal = BigDecimal.decimal(random.nextDouble()), rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalespersonquotahistoryRow] = SalespersonquotahistoryRepoImpl.insert(new SalespersonquotahistoryRowUnsaved(businessentityid = businessentityid, quotadate = quotadate, salesquota = salesquota, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalesreason(name: Name = Name(random.alphanumeric.take(20).mkString), reasontype: Name = Name(random.alphanumeric.take(20).mkString), salesreasonid: Defaulted[SalesreasonId] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesreasonRow] = SalesreasonRepoImpl.insert(new SalesreasonRowUnsaved(name = name, reasontype = reasontype, salesreasonid = salesreasonid, modifieddate = modifieddate)) + def salesSalestaxrate(stateprovinceid: StateprovinceId, taxtype: TypoShort = TypoShort(random.nextInt(Short.MaxValue).toShort), name: Name = Name(random.alphanumeric.take(20).mkString), salestaxrateid: Defaulted[SalestaxrateId] = Defaulted.UseDefault, taxrate: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalestaxrateRow] = SalestaxrateRepoImpl.insert(new SalestaxrateRowUnsaved(stateprovinceid = stateprovinceid, taxtype = taxtype, name = name, salestaxrateid = salestaxrateid, taxrate = taxrate, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalesterritory(countryregioncode: CountryregionId, name: Name = Name(random.alphanumeric.take(20).mkString), group: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, territoryid: Defaulted[SalesterritoryId] = Defaulted.UseDefault, salesytd: Defaulted[BigDecimal] = Defaulted.UseDefault, saleslastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, costytd: Defaulted[BigDecimal] = Defaulted.UseDefault, costlastyear: Defaulted[BigDecimal] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesterritoryRow] = SalesterritoryRepoImpl.insert(new SalesterritoryRowUnsaved(countryregioncode = countryregioncode, name = name, group = group, territoryid = territoryid, salesytd = salesytd, saleslastyear = saleslastyear, costytd = costytd, costlastyear = costlastyear, rowguid = rowguid, modifieddate = modifieddate)) + def salesSalesterritoryhistory(businessentityid: BusinessentityId, territoryid: SalesterritoryId, startdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), 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)))), rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SalesterritoryhistoryRow] = SalesterritoryhistoryRepoImpl.insert(new SalesterritoryhistoryRowUnsaved(businessentityid = businessentityid, territoryid = territoryid, startdate = startdate, enddate = enddate, rowguid = rowguid, modifieddate = modifieddate)) + def salesShoppingcartitem(productid: ProductId, shoppingcartid: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, shoppingcartitemid: Defaulted[ShoppingcartitemId] = Defaulted.UseDefault, quantity: Defaulted[Int] = Defaulted.UseDefault, datecreated: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, ShoppingcartitemRow] = ShoppingcartitemRepoImpl.insert(new ShoppingcartitemRowUnsaved(productid = productid, shoppingcartid = shoppingcartid, shoppingcartitemid = shoppingcartitemid, quantity = quantity, datecreated = datecreated, modifieddate = modifieddate)) + def salesSpecialoffer(description: /* max 255 chars */ String = random.alphanumeric.take(20).mkString, `type`: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, category: /* max 50 chars */ String = random.alphanumeric.take(20).mkString, startdate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), enddate: TypoLocalDateTime = TypoLocalDateTime(LocalDateTime.of(LocalDate.ofEpochDay(random.nextInt(30000).toLong), LocalTime.ofSecondOfDay(random.nextInt(24 * 60 * 60).toLong))), maxqty: Option[Int] = if (random.nextBoolean()) None else Some(random.nextInt()), specialofferid: Defaulted[SpecialofferId] = Defaulted.UseDefault, discountpct: Defaulted[BigDecimal] = Defaulted.UseDefault, minqty: Defaulted[Int] = Defaulted.UseDefault, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SpecialofferRow] = SpecialofferRepoImpl.insert(new SpecialofferRowUnsaved(description = description, `type` = `type`, category = category, startdate = startdate, enddate = enddate, maxqty = maxqty, specialofferid = specialofferid, discountpct = discountpct, minqty = minqty, rowguid = rowguid, modifieddate = modifieddate)) + def salesSpecialofferproduct(specialofferid: SpecialofferId, productid: ProductId, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, SpecialofferproductRow] = SpecialofferproductRepoImpl.insert(new SpecialofferproductRowUnsaved(specialofferid = specialofferid, productid = productid, rowguid = rowguid, modifieddate = modifieddate)) + def salesStore(businessentityid: BusinessentityId, name: Name = Name(random.alphanumeric.take(20).mkString), salespersonid: Option[BusinessentityId] = None, demographics: Option[TypoXml] = None, rowguid: Defaulted[TypoUUID] = Defaulted.UseDefault, modifieddate: Defaulted[TypoLocalDateTime] = Defaulted.UseDefault): ZIO[ZConnection, Throwable, StoreRow] = StoreRepoImpl.insert(new StoreRowUnsaved(businessentityid = businessentityid, name = name, salespersonid = salespersonid, demographics = demographics, rowguid = rowguid, modifieddate = modifieddate)) +} \ No newline at end of file diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepo.scala new file mode 100644 index 0000000000..4660752abb --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepo.scala @@ -0,0 +1,15 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package update_person + +import adventureworks.customtypes.TypoLocalDateTime +import zio.ZIO +import zio.jdbc.ZConnection + +trait UpdatePersonSqlRepo { + def apply(suffix: String, cutoff: Option[TypoLocalDateTime]): ZIO[ZConnection, Throwable, Long] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepoImpl.scala new file mode 100644 index 0000000000..0ac86132bd --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person/UpdatePersonSqlRepoImpl.scala @@ -0,0 +1,22 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package update_person + +import adventureworks.customtypes.TypoLocalDateTime +import zio.ZIO +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator + +object UpdatePersonSqlRepoImpl extends UpdatePersonSqlRepo { + override def apply(suffix: String, cutoff: Option[TypoLocalDateTime]): ZIO[ZConnection, Throwable, Long] = { + sql"""update person.person + set firstname = firstname || '-' || ${Segment.paramSegment(suffix)(Setter.stringSetter)} + where modifieddate < ${Segment.paramSegment(cutoff)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp""".update + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepo.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepo.scala new file mode 100644 index 0000000000..ba6fefe2da --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepo.scala @@ -0,0 +1,15 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package update_person_returning + +import adventureworks.customtypes.TypoLocalDateTime +import zio.jdbc.ZConnection +import zio.stream.ZStream + +trait UpdatePersonReturningSqlRepo { + def apply(suffix: /* nullability unknown */ Option[String], cutoff: /* nullability unknown */ Option[TypoLocalDateTime]): ZStream[ZConnection, Throwable, UpdatePersonReturningSqlRow] +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepoImpl.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepoImpl.scala new file mode 100644 index 0000000000..74db02b31b --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRepoImpl.scala @@ -0,0 +1,29 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package update_person_returning + +import adventureworks.customtypes.TypoLocalDateTime +import zio.jdbc.SqlFragment.Segment +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.ZConnection +import zio.jdbc.sqlInterpolator +import zio.stream.ZStream + +object UpdatePersonReturningSqlRepoImpl extends UpdatePersonReturningSqlRepo { + override def apply(suffix: /* nullability unknown */ Option[String], cutoff: /* nullability unknown */ Option[TypoLocalDateTime]): ZStream[ZConnection, Throwable, UpdatePersonReturningSqlRow] = { + val sql = + sql"""with row as ( + update person.person + set firstname = firstname || '-' || ${Segment.paramSegment(suffix)(Setter.optionParamSetter(Setter.stringSetter))} + where modifieddate < ${Segment.paramSegment(cutoff)(Setter.optionParamSetter(TypoLocalDateTime.setter))}::timestamp + returning firstname, modifieddate + ) + select row."firstname", row."modifieddate"::text + from row""" + sql.query(UpdatePersonReturningSqlRow.jdbcDecoder).selectStream + } +} diff --git a/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRow.scala b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRow.scala new file mode 100644 index 0000000000..f79281a406 --- /dev/null +++ b/typo-tester-zio-jdbc/generated-and-checked-in/adventureworks/update_person_returning/UpdatePersonReturningSqlRow.scala @@ -0,0 +1,52 @@ +/** + * File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks +package update_person_returning + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.userdefined.FirstName +import java.sql.ResultSet +import zio.jdbc.JdbcDecoder +import zio.json.JsonDecoder +import zio.json.JsonEncoder +import zio.json.ast.Json +import zio.json.internal.Write + +case class UpdatePersonReturningSqlRow( + /** Points to [[person.person.PersonRow.firstname]] */ + firstname: /* user-picked */ FirstName, + /** Points to [[person.person.PersonRow.modifieddate]] */ + modifieddate: TypoLocalDateTime +) + +object UpdatePersonReturningSqlRow { + implicit lazy val jdbcDecoder: JdbcDecoder[UpdatePersonReturningSqlRow] = new JdbcDecoder[UpdatePersonReturningSqlRow] { + override def unsafeDecode(columIndex: Int, rs: ResultSet): (Int, UpdatePersonReturningSqlRow) = + columIndex + 1 -> + UpdatePersonReturningSqlRow( + firstname = FirstName.jdbcDecoder.unsafeDecode(columIndex + 0, rs)._2, + modifieddate = TypoLocalDateTime.jdbcDecoder.unsafeDecode(columIndex + 1, rs)._2 + ) + } + implicit lazy val jsonDecoder: JsonDecoder[UpdatePersonReturningSqlRow] = JsonDecoder[Json.Obj].mapOrFail { jsonObj => + val firstname = jsonObj.get("firstname").toRight("Missing field 'firstname'").flatMap(_.as(FirstName.jsonDecoder)) + val modifieddate = jsonObj.get("modifieddate").toRight("Missing field 'modifieddate'").flatMap(_.as(TypoLocalDateTime.jsonDecoder)) + if (firstname.isRight && modifieddate.isRight) + Right(UpdatePersonReturningSqlRow(firstname = firstname.toOption.get, modifieddate = modifieddate.toOption.get)) + else Left(List[Either[String, Any]](firstname, modifieddate).flatMap(_.left.toOption).mkString(", ")) + } + implicit lazy val jsonEncoder: JsonEncoder[UpdatePersonReturningSqlRow] = new JsonEncoder[UpdatePersonReturningSqlRow] { + override def unsafeEncode(a: UpdatePersonReturningSqlRow, indent: Option[Int], out: Write): Unit = { + out.write("{") + out.write(""""firstname":""") + FirstName.jsonEncoder.unsafeEncode(a.firstname, indent, out) + out.write(",") + out.write(""""modifieddate":""") + TypoLocalDateTime.jsonEncoder.unsafeEncode(a.modifieddate, indent, out) + out.write("}") + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/ArrayTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/ArrayTest.scala new file mode 100644 index 0000000000..044739fd2e --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/ArrayTest.scala @@ -0,0 +1,387 @@ +package adventureworks + +import adventureworks.customtypes.* +import adventureworks.public.{Mydomain, Myenum} +import adventureworks.public.pgtest.{PgtestRepoImpl, PgtestRow} +import adventureworks.public.pgtestnull.{PgtestnullRepoImpl, PgtestnullRow} +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite + +import scala.annotation.nowarn + +class ArrayTest extends AnyFunSuite with TypeCheckedTripleEquals { + test("works") { + withConnection { + val before = new PgtestRow( + bool = true, + box = TypoBox(3.0, 4.0, 1.0, 2.0), + bpchar = "abc", + bytea = TypoBytea(Array[Byte](1, 2, 3)), + char = "a", + circle = TypoCircle(TypoPoint(1.0, 2.0), 3.0), + date = TypoLocalDate.now, + float4 = 1.0f, + float8 = 2.45, + hstore = TypoHStore(Map("a" -> "1", "b" -> "2")), + inet = TypoInet("::10.2.3.4"), + int2 = TypoShort(1), + int2vector = TypoInt2Vector("1 2 3"), + int4 = 4, + int8 = Int.MaxValue.toLong + 1, + interval = TypoInterval(1, 2, 3, 4, 5, 6.5), + json = TypoJson("""{"a": 1}"""), + jsonb = TypoJsonb("""{"a": 2}"""), + line = TypoLine(3.0, 4.5, 5.5), + lseg = TypoLineSegment(TypoPoint(6.5, 4.3), TypoPoint(1.5, 2.3)), + money = TypoMoney(BigDecimal("22.50")), + mydomain = Mydomain("a"), + myenum = Myenum.c, + name = "foo", + numeric = BigDecimal("3.14159"), + path = TypoPath(open = true, List(TypoPoint(6.5, 4.3), TypoPoint(8.5, 4.3))), + point = TypoPoint(6.5, 4.3), + polygon = TypoPolygon(List(TypoPoint(6.5, 4.3), TypoPoint(10.5, 4.3), TypoPoint(-6.5, 4.3))), + text = "flaff", + time = TypoLocalTime.now, + timestamp = TypoLocalDateTime.now, + timestampz = TypoInstant.now, + timez = TypoOffsetTime.now, + uuid = TypoUUID.randomUUID, + varchar = "asd asd ", + vector = TypoVector(Array(1.0f, 2.2f, 3.3f)), + xml = TypoXml(""), + boxes = Array(TypoBox(3.0, 4.0, 1.0, 2.0)), + bpchares = Array("abc"), + chares = Array("a"), + circlees = Array(TypoCircle(TypoPoint(1.0, 2.0), 3.0)), + datees = Array(TypoLocalDate.now), + float4es = Array(1.0f), + float8es = Array(2.45), + inetes = Array(TypoInet("::10.2.3.4")), + int2es = Array(TypoShort(1)), + int2vectores = Array(TypoInt2Vector("1 2 3")), + int4es = Array(4), + int8es = Array(Int.MaxValue.toLong + 1), + intervales = Array(TypoInterval(1, 2, 3, 4, 5, 6.5)), + jsones = Array(TypoJson("""{"a": 1}""")), + jsonbes = Array(TypoJsonb("""{"a": 2}""")), + linees = Array(TypoLine(3.0, 4.5, 5.5)), + lseges = Array(TypoLineSegment(TypoPoint(6.5, 4.3), TypoPoint(1.5, 2.3))), + moneyes = Array(TypoMoney(BigDecimal("22.50"))), + myenumes = Array(Myenum.c), + namees = Array("foo"), + numerices = Array(BigDecimal("3.14159")), + pathes = Array(TypoPath(open = true, List(TypoPoint(6.5, 4.3), TypoPoint(8.5, 4.3)))), + pointes = Array(TypoPoint(6.5, 4.3)), + polygones = Array(TypoPolygon(List(TypoPoint(6.5, 4.3), TypoPoint(10.5, 4.3), TypoPoint(-6.5, 4.3)))), + textes = Array("flaff"), + timees = Array(TypoLocalTime.now), + timestampes = Array(TypoLocalDateTime.now), + timestampzes = Array(TypoInstant.now), + timezes = Array(TypoOffsetTime.now), + uuides = Array(TypoUUID.randomUUID), + varchares = Array("asd asd "), + xmles = Array(TypoXml("")) + ) + + PgtestRepoImpl.insert(before).map { after => + assert(after.bool === before.bool): @nowarn + assert(after.box === before.box): @nowarn + assert(after.bpchar === before.bpchar): @nowarn + assert(after.bytea.value === before.bytea.value): @nowarn + assert(after.char === before.char): @nowarn + assert(after.circle === before.circle): @nowarn + assert(after.date === before.date): @nowarn + assert(after.float4 === before.float4): @nowarn + assert(after.float8 === before.float8): @nowarn + assert(after.hstore === before.hstore): @nowarn + assert(after.inet === before.inet): @nowarn + assert(after.int2 === before.int2): @nowarn + assert(after.int2vector === before.int2vector): @nowarn + assert(after.int4 === before.int4): @nowarn + assert(after.int8 === before.int8): @nowarn + assert(after.interval === before.interval): @nowarn + assert(after.json === before.json): @nowarn + assert(after.jsonb === before.jsonb): @nowarn + assert(after.line === before.line): @nowarn + assert(after.lseg === before.lseg): @nowarn + assert(after.money === before.money): @nowarn + assert(after.mydomain === before.mydomain): @nowarn + assert(after.myenum === before.myenum): @nowarn + assert(after.name === before.name): @nowarn + assert(after.numeric === before.numeric): @nowarn + assert(after.path === before.path): @nowarn + assert(after.point === before.point): @nowarn + assert(after.polygon === before.polygon): @nowarn + assert(after.text === before.text): @nowarn + assert(after.time === before.time): @nowarn + assert(after.timestamp === before.timestamp): @nowarn + assert(after.timestampz === before.timestampz): @nowarn + assert(after.timez === before.timez): @nowarn + assert(after.uuid === before.uuid): @nowarn + assert(after.varchar === before.varchar): @nowarn + assert(after.vector.value === before.vector.value): @nowarn + assert(after.xml === before.xml): @nowarn + assert(after.boxes === before.boxes): @nowarn + assert(after.bpchares === before.bpchares): @nowarn + assert(after.chares === before.chares): @nowarn + assert(after.circlees === before.circlees): @nowarn + assert(after.datees === before.datees): @nowarn + assert(after.float4es === before.float4es): @nowarn + assert(after.float8es === before.float8es): @nowarn + assert(after.inetes === before.inetes): @nowarn + assert(after.int2es === before.int2es): @nowarn + assert(after.int2vectores === before.int2vectores): @nowarn + assert(after.int4es === before.int4es): @nowarn + assert(after.int8es === before.int8es): @nowarn + assert(after.intervales === before.intervales): @nowarn + assert(after.jsones === before.jsones): @nowarn + assert(after.jsonbes === before.jsonbes): @nowarn + assert(after.linees === before.linees): @nowarn + assert(after.lseges === before.lseges): @nowarn + assert(after.moneyes === before.moneyes): @nowarn + assert(after.myenumes === before.myenumes): @nowarn + assert(after.namees === before.namees): @nowarn + assert(after.numerices === before.numerices): @nowarn + assert(after.pathes === before.pathes): @nowarn + assert(after.pointes === before.pointes): @nowarn + assert(after.polygones === before.polygones): @nowarn + assert(after.textes === before.textes): @nowarn + assert(after.timees === before.timees): @nowarn + assert(after.timestampes === before.timestampes): @nowarn + assert(after.timestampzes === before.timestampzes): @nowarn + assert(after.timezes === before.timezes): @nowarn + assert(after.uuides === before.uuides): @nowarn + assert(after.varchares === before.varchares): @nowarn + assert(after.xmles === before.xmles) + } + } + } + // https://github.com/zio/zio-jdbc/issues/188 +// test("nulls") { +// withConnection { +// val before = new PgtestnullRow( +// bool = None, +// box = None, +// bpchar = None, +// bytea = None, +// char = None, +// circle = None, +// date = None, +// float4 = None, +// float8 = None, +// hstore = None, +// inet = None, +// int2 = None, +// int2vector = None, +// int4 = None, +// int8 = None, +// interval = None, +// json = None, +// jsonb = None, +// line = None, +// lseg = None, +// money = None, +// mydomain = None, +// myenum = None, +// name = None, +// numeric = None, +// path = None, +// point = None, +// polygon = None, +// text = None, +// time = None, +// timestamp = None, +// timestampz = None, +// timez = None, +// uuid = None, +// varchar = None, +// vector = None, +// xml = None, +// boxes = None, +// bpchares = None, +// chares = None, +// circlees = None, +// datees = None, +// float4es = None, +// float8es = None, +// inetes = None, +// int2es = None, +// int2vectores = None, +// int4es = None, +// int8es = None, +// intervales = None, +// jsones = None, +// jsonbes = None, +// linees = None, +// lseges = None, +// moneyes = None, +// myenumes = None, +// namees = None, +// numerices = None, +// pathes = None, +// pointes = None, +// polygones = None, +// textes = None, +// timees = None, +// timestampes = None, +// timestampzes = None, +// timezes = None, +// uuides = None, +// varchares = None, +// xmles = None +// ) +// PgtestnullRepoImpl.insert(before).map { after => +// assert(after === before) +// } +// } +// } + + test("not nulls") { + withConnection { + val before = new PgtestnullRow( + bool = Some(true), + box = Some(TypoBox(3.0, 4.0, 1.0, 2.0)), + bpchar = Some("abc"), + bytea = Some(TypoBytea(Array[Byte](1, 2, 3))), + char = Some("a"), + circle = Some(TypoCircle(TypoPoint(1.0, 2.0), 3.0)), + date = Some(TypoLocalDate.now), + float4 = Some(1.0f), + float8 = Some(2.45), + hstore = Some(TypoHStore(Map("a" -> "1", "b" -> "2"))), + inet = Some(TypoInet("::10.2.3.4")), + int2 = Some(TypoShort(1)), + int2vector = Some(TypoInt2Vector("1 2 3")), + int4 = Some(4), + int8 = Some(Int.MaxValue.toLong + 1), + interval = Some(TypoInterval(1, 2, 3, 4, 5, 6.5)), + json = Some(TypoJson("""{"a": 1}""")), + jsonb = Some(TypoJsonb("""{"a": 2}""")), + line = Some(TypoLine(3.0, 4.5, 5.5)), + lseg = Some(TypoLineSegment(TypoPoint(6.5, 4.3), TypoPoint(1.5, 2.3))), + money = Some(TypoMoney(BigDecimal("22.50"))), + mydomain = Some(Mydomain("a")), + myenum = Some(Myenum.c), + name = Some("foo"), + numeric = Some(BigDecimal("3.14159")), + path = Some(TypoPath(open = true, List(TypoPoint(6.5, 4.3), TypoPoint(8.5, 4.3)))), + point = Some(TypoPoint(6.5, 4.3)), + polygon = Some(TypoPolygon(List(TypoPoint(6.5, 4.3), TypoPoint(10.5, 4.3), TypoPoint(-6.5, 4.3)))), + text = Some("flaff"), + time = Some(TypoLocalTime.now), + timestamp = Some(TypoLocalDateTime.now), + timestampz = Some(TypoInstant.now), + timez = Some(TypoOffsetTime.now), + uuid = Some(TypoUUID.randomUUID), + varchar = Some("asd asd "), + vector = Some(TypoVector(Array(1.0f, 2.2f, 3.3f))), + xml = Some(TypoXml("")), + boxes = Some(Array(TypoBox(3.0, 4.0, 1.0, 2.0))), + bpchares = Some(Array("abc")), + chares = Some(Array("a")), + circlees = Some(Array(TypoCircle(TypoPoint(1.0, 2.0), 3.0))), + datees = Some(Array(TypoLocalDate.now)), + float4es = Some(Array(1.0f)), + float8es = Some(Array(2.45)), + inetes = Some(Array(TypoInet("::10.2.3.4"))), + int2es = Some(Array(TypoShort(1))), + int2vectores = Some(Array(TypoInt2Vector("1 2 3"))), + int4es = Some(Array(4)), + int8es = Some(Array(Int.MaxValue.toLong + 1)), + intervales = Some(Array(TypoInterval(1, 2, 3, 4, 5, 6.5))), + jsones = Some(Array(TypoJson("""{"a": 1}"""))), + jsonbes = Some(Array(TypoJsonb("""{"a": 2}"""))), + linees = Some(Array(TypoLine(3.0, 4.5, 5.5))), + lseges = Some(Array(TypoLineSegment(TypoPoint(6.5, 4.3), TypoPoint(1.5, 2.3)))), + moneyes = Some(Array(TypoMoney(BigDecimal("22.50")))), + myenumes = Some(Array(Myenum.c)), + namees = Some(Array("foo")), + numerices = Some(Array(BigDecimal("3.14159"))), + pathes = Some(Array(TypoPath(open = true, List(TypoPoint(6.5, 4.3), TypoPoint(8.5, 4.3))))), + pointes = Some(Array(TypoPoint(6.5, 4.3))), + polygones = Some(Array(TypoPolygon(List(TypoPoint(6.5, 4.3), TypoPoint(10.5, 4.3), TypoPoint(-6.5, 4.3))))), + textes = Some(Array("flaff")), + timees = Some(Array(TypoLocalTime.now)), + timestampes = Some(Array(TypoLocalDateTime.now)), + timestampzes = Some(Array(TypoInstant.now)), + timezes = Some(Array(TypoOffsetTime.now)), + uuides = Some(Array(TypoUUID.randomUUID)), + varchares = Some(Array("asd asd ")), + xmles = Some(Array(TypoXml(""))) + ) + + PgtestnullRepoImpl.insert(before).map { after => + assert(after.bool === before.bool): @nowarn + assert(after.box === before.box): @nowarn + assert(after.bpchar === before.bpchar): @nowarn + assert(after.bytea.map(_.value.toList) === before.bytea.map(_.value.toList)): @nowarn + assert(after.char === before.char): @nowarn + assert(after.circle === before.circle): @nowarn + assert(after.date === before.date): @nowarn + assert(after.float4 === before.float4): @nowarn + assert(after.float8 === before.float8): @nowarn + assert(after.hstore === before.hstore): @nowarn + assert(after.inet === before.inet): @nowarn + assert(after.int2 === before.int2): @nowarn + assert(after.int2vector === before.int2vector): @nowarn + assert(after.int4 === before.int4): @nowarn + assert(after.int8 === before.int8): @nowarn + assert(after.interval === before.interval): @nowarn + assert(after.json === before.json): @nowarn + assert(after.jsonb === before.jsonb): @nowarn + assert(after.line === before.line): @nowarn + assert(after.lseg === before.lseg): @nowarn + assert(after.money === before.money): @nowarn + assert(after.mydomain === before.mydomain): @nowarn + assert(after.myenum === before.myenum): @nowarn + assert(after.name === before.name): @nowarn + assert(after.numeric === before.numeric): @nowarn + assert(after.path === before.path): @nowarn + assert(after.point === before.point): @nowarn + assert(after.polygon === before.polygon): @nowarn + assert(after.text === before.text): @nowarn + assert(after.time === before.time): @nowarn + assert(after.timestamp === before.timestamp): @nowarn + assert(after.timestampz === before.timestampz): @nowarn + assert(after.timez === before.timez): @nowarn + assert(after.uuid === before.uuid): @nowarn + assert(after.varchar === before.varchar): @nowarn + assert(after.vector.map(_.value.toList) === before.vector.map(_.value.toList)): @nowarn + assert(after.xml === before.xml): @nowarn + assert(after.boxes.map(_.toList) === before.boxes.map(_.toList)): @nowarn + assert(after.bpchares.map(_.toList) === before.bpchares.map(_.toList)): @nowarn + assert(after.chares.map(_.toList) === before.chares.map(_.toList)): @nowarn + assert(after.circlees.map(_.toList) === before.circlees.map(_.toList)): @nowarn + assert(after.datees.map(_.toList) === before.datees.map(_.toList)): @nowarn + assert(after.float4es.map(_.toList) === before.float4es.map(_.toList)): @nowarn + assert(after.float8es.map(_.toList) === before.float8es.map(_.toList)): @nowarn + assert(after.inetes.map(_.toList) === before.inetes.map(_.toList)): @nowarn + assert(after.int2es.map(_.toList) === before.int2es.map(_.toList)): @nowarn + assert(after.int2vectores.map(_.toList) === before.int2vectores.map(_.toList)): @nowarn + assert(after.int4es.map(_.toList) === before.int4es.map(_.toList)): @nowarn + assert(after.int8es.map(_.toList) === before.int8es.map(_.toList)): @nowarn + assert(after.intervales.map(_.toList) === before.intervales.map(_.toList)): @nowarn + assert(after.jsones.map(_.toList) === before.jsones.map(_.toList)): @nowarn + assert(after.jsonbes.map(_.toList) === before.jsonbes.map(_.toList)): @nowarn + assert(after.linees.map(_.toList) === before.linees.map(_.toList)): @nowarn + assert(after.lseges.map(_.toList) === before.lseges.map(_.toList)): @nowarn + assert(after.moneyes.map(_.toList) === before.moneyes.map(_.toList)): @nowarn + assert(after.myenumes.map(_.toList) === before.myenumes.map(_.toList)): @nowarn + assert(after.namees.map(_.toList) === before.namees.map(_.toList)): @nowarn + assert(after.numerices.map(_.toList) === before.numerices.map(_.toList)): @nowarn + assert(after.pathes.map(_.toList) === before.pathes.map(_.toList)): @nowarn + assert(after.pointes.map(_.toList) === before.pointes.map(_.toList)): @nowarn + assert(after.polygones.map(_.toList) === before.polygones.map(_.toList)): @nowarn + assert(after.textes.map(_.toList) === before.textes.map(_.toList)): @nowarn + assert(after.timees.map(_.toList) === before.timees.map(_.toList)): @nowarn + assert(after.timestampes.map(_.toList) === before.timestampes.map(_.toList)): @nowarn + assert(after.timestampzes.map(_.toList) === before.timestampzes.map(_.toList)): @nowarn + assert(after.timezes.map(_.toList) === before.timezes.map(_.toList)): @nowarn + assert(after.uuides.map(_.toList) === before.uuides.map(_.toList)): @nowarn + assert(after.varchares.map(_.toList) === before.varchares.map(_.toList)): @nowarn + assert(after.xmles.map(_.toList) === before.xmles.map(_.toList)) + } + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/ReadPostgresTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/ReadPostgresTest.scala new file mode 100644 index 0000000000..241f97fae9 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/ReadPostgresTest.scala @@ -0,0 +1,223 @@ +package adventureworks + +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite +import zio.{Chunk, ZIO} +import zio.stream.ZStream + +class ReadPostgresTest extends AnyFunSuite with TypeCheckedTripleEquals { + test("don't fail while reading rows from postgres tables") { + withConnection( + ZStream + .fromChunk( + Chunk( + adventureworks.information_schema.administrable_role_authorizations.AdministrableRoleAuthorizationsViewRepoImpl.selectAll, + adventureworks.information_schema._pg_foreign_servers.PgForeignServersViewRepoImpl.selectAll, + adventureworks.information_schema.sql_features.SqlFeaturesRepoImpl.selectAll, + adventureworks.information_schema.sql_parts.SqlPartsRepoImpl.selectAll, + adventureworks.information_schema.tables.TablesViewRepoImpl.selectAll, + adventureworks.information_schema.check_constraint_routine_usage.CheckConstraintRoutineUsageViewRepoImpl.selectAll, + adventureworks.information_schema.column_domain_usage.ColumnDomainUsageViewRepoImpl.selectAll, + adventureworks.information_schema._pg_foreign_data_wrappers.PgForeignDataWrappersViewRepoImpl.selectAll, + adventureworks.information_schema.domains.DomainsViewRepoImpl.selectAll, + adventureworks.information_schema.key_column_usage.KeyColumnUsageViewRepoImpl.selectAll, + adventureworks.information_schema.view_column_usage.ViewColumnUsageViewRepoImpl.selectAll, + adventureworks.information_schema.foreign_servers.ForeignServersViewRepoImpl.selectAll, + adventureworks.information_schema.column_column_usage.ColumnColumnUsageViewRepoImpl.selectAll, + adventureworks.information_schema.character_sets.CharacterSetsViewRepoImpl.selectAll, + adventureworks.information_schema.routine_column_usage.RoutineColumnUsageViewRepoImpl.selectAll, + adventureworks.information_schema.column_options.ColumnOptionsViewRepoImpl.selectAll, + adventureworks.information_schema.user_defined_types.UserDefinedTypesViewRepoImpl.selectAll, + adventureworks.information_schema.element_types.ElementTypesViewRepoImpl.selectAll, + adventureworks.information_schema.collation_character_set_applicability.CollationCharacterSetApplicabilityViewRepoImpl.selectAll, + adventureworks.information_schema.triggers.TriggersViewRepoImpl.selectAll, + adventureworks.information_schema.applicable_roles.ApplicableRolesViewRepoImpl.selectAll, + adventureworks.information_schema.usage_privileges.UsagePrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.table_privileges.TablePrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.role_usage_grants.RoleUsageGrantsViewRepoImpl.selectAll, + adventureworks.information_schema.role_table_grants.RoleTableGrantsViewRepoImpl.selectAll, + adventureworks.information_schema.view_table_usage.ViewTableUsageViewRepoImpl.selectAll, + adventureworks.information_schema._pg_foreign_tables.PgForeignTablesViewRepoImpl.selectAll, + adventureworks.information_schema.routine_table_usage.RoutineTableUsageViewRepoImpl.selectAll, + adventureworks.information_schema.user_mapping_options.UserMappingOptionsViewRepoImpl.selectAll, + adventureworks.information_schema.referential_constraints.ReferentialConstraintsViewRepoImpl.selectAll, + adventureworks.information_schema.user_mappings.UserMappingsViewRepoImpl.selectAll, + adventureworks.information_schema.routine_sequence_usage.RoutineSequenceUsageViewRepoImpl.selectAll, + adventureworks.information_schema.enabled_roles.EnabledRolesViewRepoImpl.selectAll, + adventureworks.information_schema.table_constraints.TableConstraintsViewRepoImpl.selectAll, + adventureworks.information_schema.view_routine_usage.ViewRoutineUsageViewRepoImpl.selectAll, + adventureworks.information_schema.attributes.AttributesViewRepoImpl.selectAll, + adventureworks.information_schema.constraint_column_usage.ConstraintColumnUsageViewRepoImpl.selectAll, + adventureworks.information_schema.domain_constraints.DomainConstraintsViewRepoImpl.selectAll, + adventureworks.information_schema.routines.RoutinesViewRepoImpl.selectAll, + adventureworks.information_schema.triggered_update_columns.TriggeredUpdateColumnsViewRepoImpl.selectAll, + adventureworks.information_schema.domain_udt_usage.DomainUdtUsageViewRepoImpl.selectAll, + adventureworks.information_schema._pg_user_mappings.PgUserMappingsViewRepoImpl.selectAll, + adventureworks.information_schema.transforms.TransformsViewRepoImpl.selectAll, + adventureworks.information_schema.foreign_table_options.ForeignTableOptionsViewRepoImpl.selectAll, + adventureworks.information_schema._pg_foreign_table_columns.PgForeignTableColumnsViewRepoImpl.selectAll, + adventureworks.information_schema.information_schema_catalog_name.InformationSchemaCatalogNameViewRepoImpl.selectAll, + adventureworks.information_schema.sequences.SequencesViewRepoImpl.selectAll, + adventureworks.information_schema.foreign_tables.ForeignTablesViewRepoImpl.selectAll, + adventureworks.information_schema.parameters.ParametersViewRepoImpl.selectAll, + adventureworks.information_schema.routine_routine_usage.RoutineRoutineUsageViewRepoImpl.selectAll, + adventureworks.information_schema.schemata.SchemataViewRepoImpl.selectAll, + adventureworks.information_schema.foreign_data_wrapper_options.ForeignDataWrapperOptionsViewRepoImpl.selectAll, + adventureworks.information_schema.data_type_privileges.DataTypePrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.sql_sizing.SqlSizingRepoImpl.selectAll, + adventureworks.information_schema.constraint_table_usage.ConstraintTableUsageViewRepoImpl.selectAll, + adventureworks.information_schema.check_constraints.CheckConstraintsViewRepoImpl.selectAll, + adventureworks.information_schema.role_udt_grants.RoleUdtGrantsViewRepoImpl.selectAll, + adventureworks.information_schema.columns.ColumnsViewRepoImpl.selectAll, + adventureworks.information_schema.routine_privileges.RoutinePrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.role_routine_grants.RoleRoutineGrantsViewRepoImpl.selectAll, + adventureworks.information_schema.collations.CollationsViewRepoImpl.selectAll, + adventureworks.information_schema.column_privileges.ColumnPrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.sql_implementation_info.SqlImplementationInfoRepoImpl.selectAll, + adventureworks.information_schema.foreign_data_wrappers.ForeignDataWrappersViewRepoImpl.selectAll, + adventureworks.information_schema.column_udt_usage.ColumnUdtUsageViewRepoImpl.selectAll, + adventureworks.information_schema.views.ViewsViewRepoImpl.selectAll, + adventureworks.information_schema.foreign_server_options.ForeignServerOptionsViewRepoImpl.selectAll, + adventureworks.information_schema.udt_privileges.UdtPrivilegesViewRepoImpl.selectAll, + adventureworks.information_schema.role_column_grants.RoleColumnGrantsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_bgwriter.PgStatBgwriterViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_user_tables.PgStatUserTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_slru.PgStatSlruViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_sequence.PgSequenceRepoImpl.selectAll, + adventureworks.pg_catalog.pg_timezone_abbrevs.PgTimezoneAbbrevsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_sys_tables.PgStatioSysTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_seclabels.PgSeclabelsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_copy.PgStatProgressCopyViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_file_settings.PgFileSettingsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_archiver.PgStatArchiverViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_subscription.PgStatSubscriptionViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_replication_slots.PgReplicationSlotsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_wal_receiver.PgStatWalReceiverViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_prepared_statements.PgPreparedStatementsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_opfamily.PgOpfamilyRepoImpl.selectAll, + adventureworks.pg_catalog.pg_foreign_server.PgForeignServerRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_analyze.PgStatProgressAnalyzeViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_user_indexes.PgStatUserIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_amop.PgAmopRepoImpl.selectAll, + adventureworks.pg_catalog.pg_range.PgRangeRepoImpl.selectAll, + adventureworks.pg_catalog.pg_shadow.PgShadowViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_operator.PgOperatorRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_database_conflicts.PgStatDatabaseConflictsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_indexes.PgIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_foreign_table.PgForeignTableRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_sys_indexes.PgStatioSysIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_all_indexes.PgStatioAllIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_activity.PgStatActivityViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_all_tables.PgStatAllTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_views.PgViewsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_authid.PgAuthidRepoImpl.selectAll, + adventureworks.pg_catalog.pg_backend_memory_contexts.PgBackendMemoryContextsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_basebackup.PgStatProgressBasebackupViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_cursors.PgCursorsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_event_trigger.PgEventTriggerRepoImpl.selectAll, + adventureworks.pg_catalog.pg_available_extensions.PgAvailableExtensionsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_attribute.PgAttributeRepoImpl.selectAll, + adventureworks.pg_catalog.pg_extension.PgExtensionRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stats.PgStatsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_sys_sequences.PgStatioSysSequencesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_publication_rel.PgPublicationRelRepoImpl.selectAll, + adventureworks.pg_catalog.pg_publication.PgPublicationRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_replication.PgStatReplicationViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stats_ext.PgStatsExtViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_type.PgTypeRepoImpl.selectAll, + adventureworks.pg_catalog.pg_config.PgConfigViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_auth_members.PgAuthMembersRepoImpl.selectAll, + adventureworks.pg_catalog.pg_opclass.PgOpclassRepoImpl.selectAll, + adventureworks.pg_catalog.pg_user_mappings.PgUserMappingsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_aggregate.PgAggregateRepoImpl.selectAll, + adventureworks.pg_catalog.pg_tables.PgTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_all_sequences.PgStatioAllSequencesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_user_sequences.PgStatioUserSequencesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_database.PgStatDatabaseViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_ts_template.PgTsTemplateRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_xact_all_tables.PgStatXactAllTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_db_role_setting.PgDbRoleSettingRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statistic_ext.PgStatisticExtRepoImpl.selectAll, + adventureworks.pg_catalog.pg_subscription.PgSubscriptionRepoImpl.selectAll, + adventureworks.pg_catalog.pg_index.PgIndexRepoImpl.selectAll, + adventureworks.pg_catalog.pg_attrdef.PgAttrdefRepoImpl.selectAll, + adventureworks.pg_catalog.pg_shseclabel.PgShseclabelRepoImpl.selectAll, + adventureworks.pg_catalog.pg_class.PgClassRepoImpl.selectAll, + adventureworks.pg_catalog.pg_rules.PgRulesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_replication_slots.PgStatReplicationSlotsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_namespace.PgNamespaceRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_vacuum.PgStatProgressVacuumViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_tablespace.PgTablespaceRepoImpl.selectAll, + adventureworks.pg_catalog.pg_shdescription.PgShdescriptionRepoImpl.selectAll, + adventureworks.pg_catalog.pg_policy.PgPolicyRepoImpl.selectAll, + adventureworks.pg_catalog.pg_enum.PgEnumRepoImpl.selectAll, + adventureworks.pg_catalog.pg_inherits.PgInheritsRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_user_tables.PgStatioUserTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_shdepend.PgShdependRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statistic_ext_data.PgStatisticExtDataRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_all_tables.PgStatioAllTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_group.PgGroupViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_prepared_xacts.PgPreparedXactsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_timezone_names.PgTimezoneNamesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statio_user_indexes.PgStatioUserIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_largeobject_metadata.PgLargeobjectMetadataRepoImpl.selectAll, + adventureworks.pg_catalog.pg_depend.PgDependRepoImpl.selectAll, + adventureworks.pg_catalog.pg_ts_config.PgTsConfigRepoImpl.selectAll, + adventureworks.pg_catalog.pg_cast.PgCastRepoImpl.selectAll, + adventureworks.pg_catalog.pg_seclabel.PgSeclabelRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_wal.PgStatWalViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_foreign_data_wrapper.PgForeignDataWrapperRepoImpl.selectAll, + adventureworks.pg_catalog.pg_user_mapping.PgUserMappingRepoImpl.selectAll, + adventureworks.pg_catalog.pg_conversion.PgConversionRepoImpl.selectAll, + adventureworks.pg_catalog.pg_am.PgAmRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_all_indexes.PgStatAllIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_roles.PgRolesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stats_ext_exprs.PgStatsExtExprsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_partitioned_table.PgPartitionedTableRepoImpl.selectAll, + adventureworks.pg_catalog.pg_policies.PgPoliciesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_ts_config_map.PgTsConfigMapRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_sys_tables.PgStatSysTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_init_privs.PgInitPrivsRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_create_index.PgStatProgressCreateIndexViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_sys_indexes.PgStatSysIndexesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_sequences.PgSequencesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_user.PgUserViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_replication_origin.PgReplicationOriginRepoImpl.selectAll, + adventureworks.pg_catalog.pg_subscription_rel.PgSubscriptionRelRepoImpl.selectAll, + adventureworks.pg_catalog.pg_matviews.PgMatviewsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_ssl.PgStatSslViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_progress_cluster.PgStatProgressClusterViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_language.PgLanguageRepoImpl.selectAll, + adventureworks.pg_catalog.pg_locks.PgLocksViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_rewrite.PgRewriteRepoImpl.selectAll, + adventureworks.pg_catalog.pg_largeobject.PgLargeobjectRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_user_functions.PgStatUserFunctionsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_available_extension_versions.PgAvailableExtensionVersionsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_xact_user_functions.PgStatXactUserFunctionsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_publication_tables.PgPublicationTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_shmem_allocations.PgShmemAllocationsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_statistic.PgStatisticRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_xact_user_tables.PgStatXactUserTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_collation.PgCollationRepoImpl.selectAll, + adventureworks.pg_catalog.pg_database.PgDatabaseRepoImpl.selectAll, + adventureworks.pg_catalog.pg_settings.PgSettingsViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_ts_parser.PgTsParserRepoImpl.selectAll, + adventureworks.pg_catalog.pg_proc.PgProcRepoImpl.selectAll, + adventureworks.pg_catalog.pg_hba_file_rules.PgHbaFileRulesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_gssapi.PgStatGssapiViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_default_acl.PgDefaultAclRepoImpl.selectAll, + adventureworks.pg_catalog.pg_ts_dict.PgTsDictRepoImpl.selectAll, + adventureworks.pg_catalog.pg_replication_origin_status.PgReplicationOriginStatusViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_stat_xact_sys_tables.PgStatXactSysTablesViewRepoImpl.selectAll, + adventureworks.pg_catalog.pg_transform.PgTransformRepoImpl.selectAll, + adventureworks.pg_catalog.pg_description.PgDescriptionRepoImpl.selectAll, + adventureworks.pg_catalog.pg_amproc.PgAmprocRepoImpl.selectAll, + adventureworks.pg_catalog.pg_constraint.PgConstraintRepoImpl.selectAll, + adventureworks.pg_catalog.pg_trigger.PgTriggerRepoImpl.selectAll + ) + ) + .flatMap(_.take(1)) + .foreach(v => ZIO.succeed(println(v))) + ) + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/department/DepartmentTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/department/DepartmentTest.scala new file mode 100644 index 0000000000..42fa9d501a --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/department/DepartmentTest.scala @@ -0,0 +1,57 @@ +package adventureworks.humanresources.department + +import adventureworks.customtypes.{Defaulted, TypoLocalDateTime} +import adventureworks.public.Name +import adventureworks.withConnection +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite +import zio.ZIO + +class DepartmentTest extends AnyFunSuite with TypeCheckedTripleEquals { + val repo = DepartmentRepoImpl + + test("works") { + withConnection { + // setup + val unsaved = DepartmentRowUnsaved( + name = Name("foo"), + groupname = Name("bar"), + modifieddate = Defaulted.Provided(TypoLocalDateTime.now) + ) + for { + // insert and round trip check + saved1 <- repo.insert(unsaved) + saved2 = unsaved.toRow(departmentidDefault = saved1.departmentid, modifieddateDefault = saved1.modifieddate) + _ <- ZIO.succeed(assert(saved1 === saved2)) + // check field values + _ <- repo.update(saved1.copy(name = Name("baz"))) + saved3 <- repo.selectAll.runLast + _ <- ZIO.succeed(assert(saved3.map(_.name).contains(Name("baz")))) + // delete + _ <- repo.selectAll.runCollect.map(x => assert(x.size === 1)) + _ <- repo.delete(saved1.departmentid) + _ <- repo.selectAll.runCollect.map(x => assert(x.isEmpty)) + } yield succeed + } + } + + test("upserts works") { + withConnection { + // setup + val unsaved = DepartmentRowUnsaved( + name = Name("foo"), + groupname = Name("bar"), + modifieddate = Defaulted.Provided(TypoLocalDateTime.now) + ) + for { + // insert and round trip check + saved1 <- repo.insert(unsaved) + newName = Name("baz") + inserted2 <- repo.upsert(saved1.copy(name = newName)) + _ <- ZIO.succeed(assert(inserted2.rowsUpdated === 1L)) + saved2 = inserted2.updatedKeys.head + _ <- ZIO.succeed(assert(saved2.name === newName)) + } yield succeed + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/employee/EmployeeTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/employee/EmployeeTest.scala new file mode 100644 index 0000000000..1f1199d009 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/humanresources/employee/EmployeeTest.scala @@ -0,0 +1,150 @@ +package adventureworks +package humanresources +package employee + +import adventureworks.customtypes.* +import adventureworks.person.businessentity.{BusinessentityId, BusinessentityRepoImpl, BusinessentityRowUnsaved} +import adventureworks.person.person.{PersonRepoImpl, PersonRowUnsaved} +import adventureworks.public.{Flag, Name} +import adventureworks.userdefined.FirstName +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite +import zio.ZIO + +import java.time.LocalDate + +class EmployeeTest extends AnyFunSuite with TypeCheckedTripleEquals { + val repo = EmployeeRepoImpl + + test("json") { + val initial = PersonRowUnsaved( + businessentityid = BusinessentityId(1), + persontype = "SC", + title = None, + firstname = FirstName("firstname"), + middlename = Some(Name("middlename")), + lastname = Name("lastname"), + suffix = Some("suffix"), + additionalcontactinfo = Some(TypoXml("")), + demographics = None, + namestyle = Defaulted.UseDefault, + emailpromotion = Defaulted.UseDefault, + rowguid = Defaulted.UseDefault, + modifieddate = Defaulted.UseDefault + ) + + // the xml structure doesn't have a stable equals method, so we need to use the json representation + import zio.json.* + val encoded = initial.toJson + val decoded = encoded.fromJson[PersonRowUnsaved] + decoded match { + case Right(roundtripped) => + val roundtrippedAsJson = roundtripped.toJson + assert(roundtrippedAsJson === encoded) + case Left(error) => fail(error) + } + } + + test("works") { + withConnection { + for { + businessentityRow <- BusinessentityRepoImpl.insert( + BusinessentityRowUnsaved( + businessentityid = Defaulted.UseDefault, + rowguid = Defaulted.UseDefault, + modifieddate = Defaulted.UseDefault + ) + ) + personRowUnsaved = PersonRowUnsaved( + businessentityid = businessentityRow.businessentityid, + persontype = "SC", + title = None, + firstname = FirstName("firstname"), + middlename = Some(Name("middlename")), + lastname = Name("lastname"), + suffix = Some("suffix"), + additionalcontactinfo = Some(TypoXml("")), + demographics = None, + namestyle = Defaulted.UseDefault, + emailpromotion = Defaulted.UseDefault, + rowguid = Defaulted.UseDefault, + modifieddate = Defaulted.UseDefault + ) + personRow <- PersonRepoImpl.insert(personRowUnsaved) + // setup + unsaved = EmployeeRowUnsaved( + businessentityid = personRow.businessentityid, + nationalidnumber = "9912312312", + loginid = "loginid", + jobtitle = "jobtitle", + birthdate = TypoLocalDate(LocalDate.of(1950, 1, 1)), + maritalstatus = "M", + gender = "F", + hiredate = TypoLocalDate(LocalDate.now().minusYears(1)), + salariedflag = Defaulted.Provided(Flag(true)), + vacationhours = Defaulted.Provided(TypoShort(1)), + sickleavehours = Defaulted.Provided(TypoShort(2)), + currentflag = Defaulted.Provided(Flag(true)), + rowguid = Defaulted.Provided(TypoUUID.randomUUID), + modifieddate = Defaulted.Provided(TypoLocalDateTime.now), + organizationnode = Defaulted.Provided(Some("/")) + ) + // insert and round trip check + saved1 <- repo.insert(unsaved) + saved2 = unsaved.toRow(???, ???, ???, ???, ???, ???, ???) + _ <- ZIO.succeed(assert(saved1 === saved2)) + // check field values + _ <- repo.update(saved1.copy(gender = "M")) + saved3_1 <- repo.selectAll.runLast + saved3_2 <- repo.selectByIds(Array(saved1.businessentityid, BusinessentityId(22))).runLast + _ <- ZIO.succeed(assert(saved3_1 == saved3_2)) + _ <- ZIO.succeed(assert(saved3_2.exists(_.gender == "M"))) + // delete + _ <- repo.delete(saved1.businessentityid) + _ <- repo.selectAll.runCollect.map(_.toList).map { + case Nil => () + case nonEmpty => throw new MatchError(nonEmpty) + } + employeeRowUnsaved = EmployeeRowUnsaved( + businessentityid = personRow.businessentityid, + nationalidnumber = "9912312312", + loginid = "loginid", + jobtitle = "jobtitle", + birthdate = TypoLocalDate(LocalDate.of(1950, 1, 1)), + maritalstatus = "M", + gender = "F", + hiredate = TypoLocalDate(LocalDate.now().minusYears(1)), + salariedflag = Defaulted.UseDefault, + vacationhours = Defaulted.UseDefault, + sickleavehours = Defaulted.UseDefault, + currentflag = Defaulted.UseDefault, + rowguid = Defaulted.UseDefault, + modifieddate = Defaulted.UseDefault, + organizationnode = Defaulted.UseDefault + ) + _ <- repo.insert(employeeRowUnsaved).map { + case EmployeeRow( + personRow.businessentityid, + employeeRowUnsaved.nationalidnumber, + employeeRowUnsaved.loginid, + employeeRowUnsaved.jobtitle, + employeeRowUnsaved.birthdate, + employeeRowUnsaved.maritalstatus, + employeeRowUnsaved.gender, + employeeRowUnsaved.hiredate, + // below: these are assertions for the static default values + Flag(true), + TypoShort(0), + TypoShort(0), + Flag(true), + _, + _, + Some("/") + ) => + () + case other => throw new MatchError(other) + } + } yield succeed + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/person/MultiRepoTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/person/MultiRepoTest.scala new file mode 100644 index 0000000000..b79cf54799 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/person/MultiRepoTest.scala @@ -0,0 +1,65 @@ +package adventureworks.person + +import adventureworks.person.address.* +import adventureworks.person.addresstype.* +import adventureworks.person.businessentityaddress.* +import adventureworks.person.person.* +import adventureworks.public.Name +import zio.{Chunk, ZIO} +import zio.jdbc.ZConnection +import zio.prelude.ForEachOps // necessary for 2.12 + +case class PersonWithAddresses(person: PersonRow, addresses: Map[Name, AddressRow]) + +case class PersonWithAddressesRepo( + personRepo: PersonRepo, + businessentityAddressRepo: BusinessentityaddressRepo, + addresstypeRepo: AddresstypeRepo, + addressRepo: AddressRepo +) { + + /** A person can have a bunch of addresses registered, and they each have their own type. + * + * This method syncs [[PersonWithAddresses#addresses]] to postgres, so that old attached addresses are removed, + * + * and the given addresses are attached with the chosen type + */ + def upsert(pa: PersonWithAddresses): ZIO[ZConnection, Throwable, Chunk[BusinessentityaddressRow]] = { + for { + // update person + _ <- personRepo.upsert(pa.person) + // update stored addresses + _ <- Chunk.fromIterable(pa.addresses.values).forEach { address => addressRepo.update(address) } + // addresses are stored in `PersonWithAddress` by a `Name` which means what type of address it is. + // this address type is stored in addresstypeRepo. + // In order for foreign keys to align, we need to translate from names to ids, and create rows as necessary + oldStoredAddressTypes <- addresstypeRepo.select.where(r => r.name in pa.addresses.keys.toArray).toChunk + currentAddressesWithAddresstype <- Chunk.fromIterable(pa.addresses).forEach { case (addressTypeName, wanted) => + oldStoredAddressTypes.find(_.name == addressTypeName) match { + case Some(found) => ZIO.succeed((found.addresstypeid, wanted)) + case None => addresstypeRepo.insert(AddresstypeRowUnsaved(name = addressTypeName)).map(row => (row.addresstypeid, wanted)) + } + } + currentAddressesByAddresstype = currentAddressesWithAddresstype.toMap + // discover existing addresses attached to person + oldAttachedAddresses <- businessentityAddressRepo.select.where(x => x.businessentityid === pa.person.businessentityid).toChunk + // unattach old attached rows + _ <- oldAttachedAddresses.forEach { ba => + currentAddressesByAddresstype.get(ba.addresstypeid) match { + case Some(address) if address.addressid == ba.addressid => ZIO.succeed(false) + case _ => businessentityAddressRepo.delete(ba.compositeId) + } + } + currentAttachedAddresses <- currentAddressesWithAddresstype.forEach { case (addresstypeId, address) => + oldAttachedAddresses.find(x => x.addressid == address.addressid && x.addresstypeid == addresstypeId) match { + case Some(bea) => ZIO.succeed(bea) + case None => + businessentityAddressRepo + .insert( + BusinessentityaddressRowUnsaved(pa.person.businessentityid, address.addressid, addresstypeId) + ) + } + } + } yield currentAttachedAddresses + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/person/businessentityaddress/BusinessentityaddressTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/person/businessentityaddress/BusinessentityaddressTest.scala new file mode 100644 index 0000000000..bf63ae0518 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/person/businessentityaddress/BusinessentityaddressTest.scala @@ -0,0 +1,105 @@ +package adventureworks.person.businessentityaddress + +import adventureworks.customtypes.{Defaulted, TypoLocalDateTime, TypoUUID} +import adventureworks.person.address.{AddressRepoImpl, AddressRowUnsaved} +import adventureworks.person.addresstype.{AddresstypeRepoImpl, AddresstypeRowUnsaved} +import adventureworks.person.businessentity.{BusinessentityRepoImpl, BusinessentityRowUnsaved} +import adventureworks.person.countryregion.{CountryregionId, CountryregionRepoImpl, CountryregionRowUnsaved} +import adventureworks.person.stateprovince.{StateprovinceId, StateprovinceRepoImpl, StateprovinceRowUnsaved} +import adventureworks.public.Name +import adventureworks.sales.salesterritory.{SalesterritoryRepoImpl, SalesterritoryRowUnsaved} +import adventureworks.withConnection +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite +import zio.ZIO +import zio.json.{DecoderOps, EncoderOps} + +class BusinessentityaddressTest extends AnyFunSuite with TypeCheckedTripleEquals { + private val repo = BusinessentityaddressRepoImpl + + test("json") { + val initial = AddressRowUnsaved( + addressline1 = "addressline1", + addressline2 = Some("addressline2"), + city = "city", + stateprovinceid = StateprovinceId(1), + postalcode = "postalcode", + spatiallocation = None + ) + initial.toJson.fromJson[AddressRowUnsaved] match { + case Right(roundtripped) => assert(roundtripped === initial) + case Left(error) => fail(error) + } + + } + test("works") { + withConnection { + for { + // setup + businessentityRow <- BusinessentityRepoImpl.insert(BusinessentityRowUnsaved()) + countryregion <- CountryregionRepoImpl.insert( + CountryregionRowUnsaved( + countryregioncode = CountryregionId("max"), + name = Name("max") + ) + ) + salesTerritory <- SalesterritoryRepoImpl.insert( + SalesterritoryRowUnsaved( + name = Name("name"), + countryregioncode = countryregion.countryregioncode, + group = "flaff", + salesytd = Defaulted.Provided(1) + ) + ) + stateProvidence <- StateprovinceRepoImpl.insert( + StateprovinceRowUnsaved( + stateprovincecode = "cde", + countryregioncode = countryregion.countryregioncode, + name = Name("name"), + territoryid = salesTerritory.territoryid + ) + ) + address <- AddressRepoImpl.insert( + AddressRowUnsaved( + addressline1 = "addressline1", + addressline2 = Some("addressline2"), + city = "city", + stateprovinceid = stateProvidence.stateprovinceid, + postalcode = "postalcode", + spatiallocation = None + ) + ) + addressType <- AddresstypeRepoImpl.insert( + AddresstypeRowUnsaved( + name = Name("name") + ) + ) + unsaved1 = BusinessentityaddressRowUnsaved( + businessentityid = businessentityRow.businessentityid, + addressid = address.addressid, + addresstypeid = addressType.addresstypeid, + rowguid = Defaulted.Provided(TypoUUID.randomUUID), + modifieddate = Defaulted.Provided(TypoLocalDateTime.now) + ) + // insert and round trip check + saved1 <- repo.insert(unsaved1) + saved2 = unsaved1.toRow(???, ???) + _ <- ZIO.succeed(assert(saved1 === saved2)) + // check field values + newModifiedDate = TypoLocalDateTime(saved1.modifieddate.value.minusDays(1)) + _ <- repo.update(saved1.copy(modifieddate = newModifiedDate)) + saved3 <- repo.selectAll.runCollect.map(_.toList).map { + case List(x) => x + case other => throw new MatchError(other) + } + _ <- ZIO.succeed(assert(saved3.modifieddate == newModifiedDate)) + // delete + _ <- repo.delete(saved1.compositeId) + _ <- repo.selectAll.runCollect.map(_.toList).map { + case Nil => () + case other => throw new MatchError(other) + } + } yield succeed + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/person_detail/PersonDetailTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/person_detail/PersonDetailTest.scala new file mode 100644 index 0000000000..256b95c8e2 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/person_detail/PersonDetailTest.scala @@ -0,0 +1,15 @@ +package adventureworks.person_detail + +import adventureworks.customtypes.TypoLocalDateTime +import adventureworks.person.businessentity.BusinessentityId +import adventureworks.withConnection +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.funsuite.AnyFunSuite + +class PersonDetailTest extends AnyFunSuite with TypeCheckedTripleEquals { + test("timestamp works") { + withConnection { + PersonDetailSqlRepoImpl(BusinessentityId(1), TypoLocalDateTime.now).runCollect + } + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/production/product/ProductTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/production/product/ProductTest.scala new file mode 100644 index 0000000000..baf6b7fb40 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/production/product/ProductTest.scala @@ -0,0 +1,204 @@ +package adventureworks.production.product + +import adventureworks.customtypes.* +import adventureworks.production.productcategory.* +import adventureworks.production.productmodel.* +import adventureworks.production.productsubcategory.* +import adventureworks.production.unitmeasure.* +import adventureworks.public.{Flag, Name} +import adventureworks.withConnection +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.Assertion +import org.scalatest.funsuite.AnyFunSuite +import zio.{Chunk, ZIO} + +import java.time.LocalDateTime + +class ProductTest extends AnyFunSuite with TypeCheckedTripleEquals { + // for scala 2.12 + implicit val `Ordering[LocalDateTime]` : Ordering[LocalDateTime] = (x: LocalDateTime, y: LocalDateTime) => x.compareTo(y) + + def runTest( + productRepo: ProductRepo, + projectModelRepo: ProductmodelRepo, + unitmeasureRepo: UnitmeasureRepo, + productcategoryRepo: ProductcategoryRepo, + productsubcategoryRepo: ProductsubcategoryRepo + ): Assertion = { + withConnection { + for { + // setup + unitmeasure <- unitmeasureRepo.insert( + UnitmeasureRowUnsaved( + unitmeasurecode = UnitmeasureId("kgg"), + name = Name("name") + ) + ) + productCategory <- productcategoryRepo.insert( + ProductcategoryRowUnsaved( + name = Name("name") + ) + ) + productSubcategory <- productsubcategoryRepo.insert( + ProductsubcategoryRowUnsaved( + productcategoryid = productCategory.productcategoryid, + name = Name("name") + ) + ) + productmodel <- ProductmodelRepoImpl.insert( + ProductmodelRowUnsaved( + name = Name("name"), + catalogdescription = Some(new TypoXml("")), + instructions = Some(new TypoXml("")) + ) + ) + unsaved1 = ProductRowUnsaved( + name = Name("name"), + productnumber = "productnumber", + color = Some("color"), + safetystocklevel = TypoShort(16), + reorderpoint = TypoShort(18), + standardcost = 20, + listprice = 22, + size = Some("size"), + sizeunitmeasurecode = Some(unitmeasure.unitmeasurecode), + weightunitmeasurecode = Some(unitmeasure.unitmeasurecode), + weight = Some(1.00), + daystomanufacture = 26, + productline = Some("T "), + `class` = Some("H "), + style = Some("W "), + productsubcategoryid = Some(productSubcategory.productsubcategoryid), + productmodelid = Some(productmodel.productmodelid), + sellstartdate = TypoLocalDateTime(LocalDateTime.now().plusDays(1).withNano(0)), + sellenddate = Some(TypoLocalDateTime(LocalDateTime.now().plusDays(10).withNano(0))), + discontinueddate = Some(TypoLocalDateTime(LocalDateTime.now().plusDays(100).withNano(0))), + productid = Defaulted.UseDefault, + makeflag = Defaulted.Provided(Flag(true)), + finishedgoodsflag = Defaulted.Provided(Flag(true)), + rowguid = Defaulted.Provided(TypoUUID.randomUUID), + modifieddate = Defaulted.Provided(TypoLocalDateTime.now) + ) + // insert and round trip check + saved1 <- productRepo.insert(unsaved1) + saved2 = unsaved1.toRow(saved1.productid, ???, ???, ???, ???) + _ <- ZIO.succeed(assert(saved1 === saved2)) + + // check field values + newModifiedDate = TypoLocalDateTime(saved1.modifieddate.value.minusDays(1)) + _ <- productRepo.update(saved1.copy(modifieddate = newModifiedDate)) + saved3 <- productRepo.selectAll.runCollect.map(_.toList).map { + case List(x) => x + case other => throw new MatchError(other) + } + _ <- ZIO.succeed(assert(saved3.modifieddate == newModifiedDate)) + _ <- productRepo.update(saved3.copy(size = None)).map(res => assert(res)) + query = productRepo.select + .where(_.`class` === "H ") + .where(x => x.daystomanufacture > 25 or x.daystomanufacture <= 0) + .where(x => x.productline === "foo") + .join(unitmeasureRepo.select.where(_.name.like("name%"))) + .on { case (p, um) => p.sizeunitmeasurecode === um.unitmeasurecode } + .join(projectModelRepo.select) + .leftOn { case ((product, _), productModel) => product.productmodelid === productModel.productmodelid } + .where { case ((product, _), productModel) => product.productmodelid === productModel(_.productmodelid) } + .orderBy { case ((product, _), _) => product.productmodelid.asc } + .orderBy { case ((_, _), productModel) => productModel(_.name).desc.withNullsFirst } + + _ <- ZIO.succeed(query.sql.foreach(f => println(f))) + _ <- query.toChunk.map(println(_)) + leftJoined = productRepo.select.join(projectModelRepo.select).leftOn { case (p, pm) => p.productmodelid === pm.productmodelid } + _ <- ZIO.succeed(leftJoined.sql.foreach(println)) + _ <- leftJoined.toChunk.map(println) + + update = productRepo.update + .setComputedValue(_.name)(p => (p.reverse.upper || Name("flaff")).substring(2, 4)) + .setValue(_.listprice)(BigDecimal(2)) + .setComputedValue(_.reorderpoint)(_ plus TypoShort(22)) +// .setComputedValue(_.sizeunitmeasurecode)(_ => Some(unitmeasure.unitmeasurecode)) + .where(_.productid === saved1.productid) + + _ <- ZIO.succeed(update.sql(returning = true).foreach(println(_))) + foo <- update.executeReturnChanged + Chunk(updated) = foo + _ <- ZIO.succeed(assert(updated.name === Name("MANf"))) + _ <- ZIO.succeed(assert(updated.listprice === BigDecimal(2))) + _ <- ZIO.succeed(assert(updated.reorderpoint === TypoShort(40))) + _ <- { + val q = productRepo.select + .where(p => !p.name.like("foo%")) + .where(p => !(p.name.underlying || p.color).like("foo%")) + .where(p => p.daystomanufacture > 0) + .where(p => p.modifieddate < TypoLocalDateTime.now) + .join(projectModelRepo.select.where(p => p.modifieddate < TypoLocalDateTime.now)) + .on { case (p, pm) => p.productmodelid === pm.productmodelid } + .where { case (_, pm) => !pm.instructions.isNull } + + q.sql.foreach(f => println(f)) + q.toChunk.map(list => list.foreach(println)) + } + _ <- { + val q = productRepo.select + // select from id, arrays work + .where(p => p.productid.in(Array(saved1.productid, new ProductId(22)))) + // call `length` function and compare result + .where(p => p.name.strLength > 3) + // concatenate two strings (one of which is a wrapped type in scala) + // and compare result + .where(p => !(p.name.underlying || p.color).like("foo%")) + // tracks nullability + .whereStrict(p => p.color.strLength.coalesce(1) > 0) + // compare dates + .where(p => p.modifieddate < TypoLocalDateTime.now) + // join, filter table we join with as well + .join(projectModelRepo.select.where(pm => !pm.name.like("foo%"))) + .on { case (p, pm) => p.productmodelid === pm.productmodelid } + // additional predicates for joined rows. + .where { case (_, pm) => pm.productmodelid.underlying > 0 } + // works arbitrarily deep + .join(projectModelRepo.select.where(pm => !pm.name.like("foo%"))) + .leftOn { case ((p, _), pm2) => p.productmodelid === pm2.productmodelid and false } + // order by + .orderBy { case ((p, _), _) => p.name.asc } + .orderBy { case ((_, pm), _) => pm.rowguid.desc.withNullsFirst } + .orderBy { case ((_, _), pm2) => pm2(_.rowguid).asc } + +// q.sql.foreach(f => println(f.sql)) + q.toChunk.map { + _.map { case ((p, pm1), pm2) => + println(p) + println(pm1) + println(pm2) + } + } + } + // delete + _ <- productRepo.delete(saved1.productid) + _ <- productRepo.selectAll.runCollect.map(_.toList).map { + case Nil => () + case other => throw new MatchError(other) + } + } yield succeed + } + } + + test("in-memory") { + runTest( + productRepo = new ProductRepoMock(_.toRow(ProductId(0), Flag.apply(true), Flag.apply(false), TypoUUID.randomUUID, TypoLocalDateTime.now)), + projectModelRepo = new ProductmodelRepoMock(_.toRow(ProductmodelId(0), TypoUUID.randomUUID, TypoLocalDateTime.now)), + unitmeasureRepo = new UnitmeasureRepoMock(_.toRow(TypoLocalDateTime.now)), + productcategoryRepo = new ProductcategoryRepoMock(_.toRow(ProductcategoryId(0), TypoUUID.randomUUID, TypoLocalDateTime.now)), + productsubcategoryRepo = new ProductsubcategoryRepoMock(_.toRow(ProductsubcategoryId(0), TypoUUID.randomUUID, TypoLocalDateTime.now)) + ) + } + + test("pg") { + runTest( + productRepo = ProductRepoImpl, + projectModelRepo = ProductmodelRepoImpl, + unitmeasureRepo = UnitmeasureRepoImpl, + productcategoryRepo = ProductcategoryRepoImpl, + productsubcategoryRepo = ProductsubcategoryRepoImpl + ) + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/publicc/UsersRepoTest.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/publicc/UsersRepoTest.scala new file mode 100644 index 0000000000..037a3f1f03 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/publicc/UsersRepoTest.scala @@ -0,0 +1,38 @@ +package adventureworks.publicc + +import adventureworks.customtypes.* +import adventureworks.public.users.* +import adventureworks.withConnection +import org.scalactic.TypeCheckedTripleEquals +import org.scalatest.Assertion +import org.scalatest.funsuite.AnyFunSuite + +class UsersRepoTest extends AnyFunSuite with TypeCheckedTripleEquals { + def runTest(usersRepo: UsersRepo): Assertion = { + withConnection { + val unsaved = UsersRowUnsaved( + userId = UsersId(TypoUUID.randomUUID), + name = "name", + lastName = Some("last_name"), + email = TypoUnknownCitext("email@asd.no"), + password = "password", + verifiedOn = Some(TypoInstant.now), + createdAt = Defaulted.Provided(TypoInstant.now) + ) + for { + _ <- usersRepo.insert(unsaved) + all <- usersRepo.select.where(p => p.userId === unsaved.userId).toChunk + } yield { + assert(unsaved.toRow(???) === all.head) + } + } + } + + test("in-memory") { + runTest(usersRepo = new UsersRepoMock(_.toRow(TypoInstant.now))) + } + + test("pg") { + runTest(usersRepo = UsersRepoImpl) + } +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/CustomCreditcardId.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/CustomCreditcardId.scala new file mode 100644 index 0000000000..a3038f4daa --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/CustomCreditcardId.scala @@ -0,0 +1,23 @@ +/** File has been automatically generated by `typo`. + * + * IF YOU CHANGE THIS FILE YOUR CHANGES WILL BE OVERWRITTEN. + */ +package adventureworks.userdefined + +import typo.dsl.Bijection +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.{JdbcDecoder, JdbcEncoder} +import zio.json.* + +/** Type for the primary key of table `sales.creditcard` */ +case class CustomCreditcardId(value: Int) extends AnyVal +object CustomCreditcardId { + implicit lazy val arraySetter: Setter[Array[CustomCreditcardId]] = adventureworks.IntArraySetter.contramap(_.map(_.value)) + implicit lazy val bijection: Bijection[CustomCreditcardId, Int] = Bijection[CustomCreditcardId, Int](_.value)(CustomCreditcardId.apply) + implicit lazy val jsonDecoder: JsonDecoder[CustomCreditcardId] = JsonDecoder.int.map(CustomCreditcardId.apply) + implicit lazy val jsonEncoder: JsonEncoder[CustomCreditcardId] = JsonEncoder.int.contramap(_.value) + implicit lazy val jdbcDecoder: JdbcDecoder[CustomCreditcardId] = JdbcDecoder.intDecoder.map(CustomCreditcardId.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[CustomCreditcardId] = JdbcEncoder.intEncoder.contramap(_.value) + implicit lazy val ordering: Ordering[CustomCreditcardId] = Ordering.by(_.value) + implicit lazy val setter: Setter[CustomCreditcardId] = Setter.intSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/FirstName.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/FirstName.scala new file mode 100644 index 0000000000..b9ef656a7f --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/userdefined/FirstName.scala @@ -0,0 +1,17 @@ +package adventureworks.userdefined + +import typo.dsl.Bijection +import zio.jdbc.SqlFragment.Setter +import zio.jdbc.{JdbcDecoder, JdbcEncoder} +import zio.json.* + +case class FirstName(value: String) extends AnyVal +object FirstName { + implicit lazy val bijection: Bijection[FirstName, String] = Bijection[FirstName, String](_.value)(FirstName.apply) + implicit lazy val jsonDecoder: JsonDecoder[FirstName] = JsonDecoder.string.map(FirstName.apply) + implicit lazy val jsonEncoder: JsonEncoder[FirstName] = JsonEncoder.string.contramap(_.value) + implicit lazy val jdbcDecoder: JdbcDecoder[FirstName] = JdbcDecoder.stringDecoder.map(FirstName.apply) + implicit lazy val jdbcEncoder: JdbcEncoder[FirstName] = JdbcEncoder.stringEncoder.contramap(_.value) + implicit lazy val ordering: Ordering[FirstName] = Ordering.by(_.value) + implicit lazy val setter: Setter[FirstName] = Setter.stringSetter.contramap(_.value) +} diff --git a/typo-tester-zio-jdbc/src/scala/adventureworks/withConnection.scala b/typo-tester-zio-jdbc/src/scala/adventureworks/withConnection.scala new file mode 100644 index 0000000000..341a585a36 --- /dev/null +++ b/typo-tester-zio-jdbc/src/scala/adventureworks/withConnection.scala @@ -0,0 +1,44 @@ +package adventureworks + +import zio.jdbc.* +import zio.{Schedule, Unsafe, ZIO, ZLayer, durationInt} + +object withConnection { + lazy val connectionPool: ZLayer[Any, Throwable, ZConnectionPool] = { + ZLayer.succeed( + // See https://github.com/zio/zio-jdbc/pull/174/ + ZConnectionPoolConfig.default.copy(retryPolicy = Schedule.recurs(10) && Schedule.exponential(15.millis)) + ) >>> + ZConnectionPool.postgres( + "localhost", + 6432, + "Adventureworks", + Map( + "user" -> "postgres", + "password" -> "password" + ) + ) + } + + def apply[T](f: ZIO[ZConnection, Throwable, T]): T = { + Unsafe + .unsafe { implicit u => + zio.Runtime.default.unsafe + .run { + ZIO + .scoped[ZConnectionPool] { + for { + connectionPool <- ZIO.service[ZConnectionPool] + c <- connectionPool.transaction.build + _ <- c.get.access(_.setAutoCommit(false)) + r <- f.provideEnvironment(c) + _ <- c.get.rollback + } yield r + } + .provideLayer(connectionPool) + } + .getOrThrow() + } + + } +} diff --git a/typo/src/scala/typo/DbLibName.scala b/typo/src/scala/typo/DbLibName.scala index 84f0d78c38..11fa8479a2 100644 --- a/typo/src/scala/typo/DbLibName.scala +++ b/typo/src/scala/typo/DbLibName.scala @@ -5,4 +5,5 @@ sealed trait DbLibName object DbLibName { case object Anorm extends DbLibName case object Doobie extends DbLibName + case object ZioJdbc extends DbLibName } diff --git a/typo/src/scala/typo/JsonLibName.scala b/typo/src/scala/typo/JsonLibName.scala index af21092810..6b896a92ca 100644 --- a/typo/src/scala/typo/JsonLibName.scala +++ b/typo/src/scala/typo/JsonLibName.scala @@ -5,4 +5,5 @@ sealed trait JsonLibName object JsonLibName { case object Circe extends JsonLibName case object PlayJson extends JsonLibName + case object ZioJson extends JsonLibName } diff --git a/typo/src/scala/typo/internal/codegen/DbLibZioJdbc.scala b/typo/src/scala/typo/internal/codegen/DbLibZioJdbc.scala new file mode 100644 index 0000000000..c1acccd347 --- /dev/null +++ b/typo/src/scala/typo/internal/codegen/DbLibZioJdbc.scala @@ -0,0 +1,843 @@ +package typo.internal.codegen + +import typo.internal.* +import typo.internal.analysis.MaybeReturnsRows +import typo.sc.Type +import typo.{NonEmptyList, sc} + +class DbLibZioJdbc(pkg: sc.QIdent, inlineImplicits: Boolean, dslEnabled: Boolean) extends DbLib { + private val ZConnection = sc.Type.Qualified("zio.jdbc.ZConnection") + private val Throwable = sc.Type.Qualified("java.lang.Throwable") + private val ZStream = sc.Type.Qualified("zio.stream.ZStream") + private val ZIO = sc.Type.Qualified("zio.ZIO") + private val JdbcEncoder = sc.Type.Qualified("zio.jdbc.JdbcEncoder") + private val JdbcDecoder = sc.Type.Qualified("zio.jdbc.JdbcDecoder") + private val SqlFragment = sc.Type.Qualified("zio.jdbc.SqlFragment") + private val Segment = sc.Type.Qualified("zio.jdbc.SqlFragment.Segment") + private val Setter = sc.Type.Qualified("zio.jdbc.SqlFragment.Setter") + private val UpdateResult = sc.Type.Qualified("zio.jdbc.UpdateResult") + private val Chunk = sc.Type.Qualified("zio.Chunk") + private val NonEmptyChunk = sc.Type.Qualified("zio.NonEmptyChunk") + private val sqlInterpolator = sc.Type.Qualified("zio.jdbc.sqlInterpolator") + private val JdbcDecoderError = sc.Type.Qualified("zio.jdbc.JdbcDecoderError") + + /** This type is basically a mapping from scala type to jdbc type name. zio-jdbc seems to use jdbc type number instead of the (potentially database-specific) type name. In the DSL we need to + * generate some sql casts based on scala type, so it's unavoidable to have this mapping. + * + * A bit unfortunate maybe, but it's not the end of the world to provide it ourselves. + */ + private val ParameterMetaData = sc.Type.Qualified("typo.dsl.ParameterMetaData") + + def ifDsl(g: sc.Given): Option[sc.Given] = + if (dslEnabled) Some(g) else None + + private def SQL(content: sc.Code) = sc.StringInterpolate(sqlInterpolator, sc.Ident("sql"), content) + + private val arraySetterName: sc.Ident = sc.Ident("arraySetter") + private val arrayJdbcDecoderName: sc.Ident = sc.Ident("arrayJdbcDecoder") + private val arrayJdbcEncoderName: sc.Ident = sc.Ident("arrayJdbcEncoder") + private val jdbcDecoderName: sc.Ident = sc.Ident("jdbcDecoder") + private val jdbcEncoderName: sc.Ident = sc.Ident("jdbcEncoder") + private val setterName: sc.Ident = sc.Ident("setter") + private val parameterMetadataName: sc.Ident = sc.Ident("parameterMetadata") + + private def dbNames(cols: NonEmptyList[ComputedColumn], isRead: Boolean): sc.Code = + cols + .map(c => code"${c.dbName}" ++ (if (isRead) sqlCast.fromPgCode(c) else sc.Code.Empty)) + .mkCode(", ") + + private val missingInstancesByType: Map[sc.Type, sc.QIdent] = + missingInstances.collect { case x: sc.Given => (x.tpe, pkg / x.name) }.toMap + + /** Resolve known implicits at generation-time instead of at compile-time */ + private def lookupJdbcDecoder(tpe: sc.Type): sc.Code = + if (!inlineImplicits) JdbcDecoder.of(tpe) + else + sc.Type.base(tpe) match { + case sc.Type.BigDecimal => code"$JdbcDecoder.bigDecimalDecoderScala" + case sc.Type.Boolean => code"$JdbcDecoder.booleanDecoder" + case sc.Type.Byte => code"$JdbcDecoder.byteDecoder" + case sc.Type.Double => code"$JdbcDecoder.doubleDecoder" + case sc.Type.Float => code"$JdbcDecoder.floatDecoder" + case sc.Type.Int => code"$JdbcDecoder.intDecoder" + case sc.Type.Long => code"$JdbcDecoder.longDecoder" + case sc.Type.String => code"$JdbcDecoder.stringDecoder" + case sc.Type.UUID => code"$JdbcDecoder.uuidDecoder" + case sc.Type.Optional(targ) => code"$JdbcDecoder.optionDecoder(${lookupJdbcDecoder(targ)})" + case sc.Type.TApply(sc.Type.Array, List(sc.Type.Byte)) => code"$JdbcDecoder.byteArrayDecoder" + // generated type + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => + code"$x.$jdbcDecoderName" + case x if missingInstancesByType.contains(JdbcDecoder.of(x)) => + code"${missingInstancesByType(JdbcDecoder.of(x))}" + case other => + code"${JdbcDecoder.of(other)}" + } + + /** Resolve known implicits at generation-time instead of at compile-time */ + private def lookupJdbcEncoder(tpe: sc.Type): sc.Code = + if (!inlineImplicits) JdbcEncoder.of(tpe) + else + sc.Type.base(tpe) match { + case sc.Type.BigDecimal => code"$JdbcEncoder.bigDecimalEncoderScala" + case sc.Type.Boolean => code"$JdbcEncoder.booleanEncoder" + case sc.Type.Byte => code"$JdbcEncoder.byteEncoder" + case sc.Type.Double => code"$JdbcEncoder.doubleEncoder" + case sc.Type.Float => code"$JdbcEncoder.floatEncoder" + case sc.Type.Int => code"$JdbcEncoder.intEncoder" + case sc.Type.Long => code"$JdbcEncoder.longEncoder" + case sc.Type.String => code"$JdbcEncoder.stringEncoder" + case sc.Type.UUID => code"$JdbcEncoder.uuidEncoder" + case sc.Type.Optional(targ) => code"$JdbcEncoder.optionEncoder(${lookupJdbcEncoder(targ)})" + case sc.Type.TApply(sc.Type.Array, List(sc.Type.Byte)) => code"$JdbcEncoder.byteArrayEncoder" + // generated type + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => + code"$x.$jdbcEncoderName" + case x if missingInstancesByType.contains(JdbcDecoder.of(x)) => + code"${missingInstancesByType(JdbcEncoder.of(x))}" + case other => + code"${JdbcEncoder.of(other)}" + } + + /** Resolve known implicits at generation-time instead of at compile-time */ + private def lookupSetter(tpe: sc.Type): sc.Code = + if (!inlineImplicits) Setter.of(tpe) + else + sc.Type.base(tpe) match { + case sc.Type.BigDecimal => code"$Setter.bigDecimalScalaSetter" + case sc.Type.Boolean => code"$Setter.booleanSetter" + case sc.Type.Byte => code"$Setter.byteSetter" + case sc.Type.Double => code"$Setter.doubleSetter" + case sc.Type.Float => code"$Setter.floatSetter" + case sc.Type.Int => code"$Setter.intSetter" + case sc.Type.Long => code"$Setter.longSetter" + case sc.Type.String => code"$Setter.stringSetter" + case sc.Type.UUID => code"$Setter.uuidParamSetter" + case sc.Type.Optional(targ) => code"$Setter.optionParamSetter(${lookupSetter(targ)})" + case sc.Type.TApply(sc.Type.Array, List(sc.Type.Byte)) => code"$Setter.byteArraySetter" + // generated type + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => + code"$tpe.$setterName" + case sc.Type.TApply(sc.Type.Array, List(targ: sc.Type.Qualified)) if targ.value.idents.startsWith(pkg.idents) => + code"$targ.$arraySetterName" + case x if missingInstancesByType.contains(Setter.of(x)) => + code"${missingInstancesByType(Setter.of(x))}" + case other => + code"${Setter.of(other)}" + } + + /** Resolve known implicits at generation-time instead of at compile-time */ + def lookupParameterMetaDataFor(tpe: sc.Type): sc.Code = + if (!inlineImplicits) sc.Summon(ParameterMetaData.of(tpe)).code + else + sc.Type.base(tpe) match { + case sc.Type.BigDecimal => code"$ParameterMetaData.BigDecimalParameterMetaData" + case sc.Type.Boolean => code"$ParameterMetaData.BooleanParameterMetaData" + case sc.Type.Byte => code"$ParameterMetaData.ByteParameterMetaData" + case sc.Type.Double => code"$ParameterMetaData.DoubleParameterMetaData" + case sc.Type.Float => code"$ParameterMetaData.FloatParameterMetaData" + case sc.Type.Int => code"$ParameterMetaData.IntParameterMetaData" + case sc.Type.Long => code"$ParameterMetaData.LongParameterMetaData" + case sc.Type.String => code"$ParameterMetaData.StringParameterMetaData" + case sc.Type.UUID => code"$ParameterMetaData.UUIDParameterMetaData" + // case sc.Type.Optional(targ) => lookupParameterMetaDataFor(targ) + // generated type + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => + code"$tpe.$parameterMetadataName" + // customized type mapping + case x if missingInstancesByType.contains(ParameterMetaData.of(x)) => + code"${missingInstancesByType(ParameterMetaData.of(x))}" + case sc.Type.TApply(sc.Type.Array, List(sc.Type.Byte)) => code"$ParameterMetaData.ByteArrayParameterMetaData" + // fallback array case. + case sc.Type.TApply(sc.Type.Array, List(targ)) => code"$ParameterMetaData.arrayParameterMetaData(${lookupParameterMetaDataFor(targ)})" + case other => sc.Summon(ParameterMetaData.of(other)).code + } + + private def runtimeInterpolateValue(name: sc.Code, tpe: sc.Type, forbidInline: Boolean = false): sc.Code = { + if (inlineImplicits && !forbidInline) + code"$${$Segment.paramSegment($name)(${lookupSetter(tpe)})}" + else code"$$$name" + } + + private def matchId(id: IdComputed): sc.Code = + id match { + case id: IdComputed.Unary => + code"${id.col.dbName} = ${runtimeInterpolateValue(id.paramName, id.tpe)}" + case composite: IdComputed.Composite => + code"${composite.cols.map(cc => code"${cc.dbName} = ${runtimeInterpolateValue(code"${composite.paramName}.${cc.name}", cc.tpe)}").mkCode(" AND ")}" + } + + override def repoSig(repoMethod: RepoMethod): sc.Code = repoMethod match { + case RepoMethod.SelectBuilder(_, fieldsType, rowType) => + code"def select: ${sc.Type.dsl.SelectBuilder.of(fieldsType, rowType)}" + case RepoMethod.SelectAll(_, _, rowType) => + code"def selectAll: ${ZStream.of(ZConnection, Throwable, rowType)}" + case RepoMethod.SelectById(_, _, id, rowType) => + code"def selectById(${id.param}): ${ZIO.of(ZConnection, Throwable, sc.Type.Option.of(rowType))}" + case RepoMethod.SelectAllByIds(_, _, unaryId, idsParam, rowType) => + unaryId match { + case IdComputed.UnaryUserSpecified(_, tpe) => + code"def selectByIds($idsParam)(implicit encoder: ${JdbcEncoder.of(sc.Type.Array.of(tpe))}): ${ZStream.of(ZConnection, Throwable, rowType)}" + case _ => + code"def selectByIds($idsParam): ${ZStream.of(ZConnection, Throwable, rowType)}" + } + case RepoMethod.SelectByUnique(_, params, rowType) => + code"def selectByUnique(${params.map(_.param.code).mkCode(", ")}): ${ZIO.of(ZConnection, Throwable, sc.Type.Option.of(rowType))}" + case RepoMethod.SelectByFieldValues(_, _, _, fieldValueOrIdsParam, rowType) => + code"def selectByFieldValues($fieldValueOrIdsParam): ${ZStream.of(ZConnection, Throwable, rowType)}" + case RepoMethod.UpdateBuilder(_, fieldsType, rowType) => + code"def update: ${sc.Type.dsl.UpdateBuilder.of(fieldsType, rowType)}" + case RepoMethod.UpdateFieldValues(_, id, varargs, _, _, _) => + code"def updateFieldValues(${id.param}, $varargs): ${ZIO.of(ZConnection, Throwable, sc.Type.Boolean)}" + case RepoMethod.Update(_, _, _, param, _) => + code"def update($param): ${ZIO.of(ZConnection, Throwable, sc.Type.Boolean)}" + case RepoMethod.Insert(_, _, unsavedParam, rowType) => + code"def insert($unsavedParam): ${ZIO.of(ZConnection, Throwable, rowType)}" + case RepoMethod.InsertUnsaved(_, _, _, unsavedParam, _, rowType) => + code"def insert($unsavedParam): ${ZIO.of(ZConnection, Throwable, rowType)}" + case RepoMethod.Upsert(_, _, _, unsavedParam, rowType) => + code"def upsert($unsavedParam): ${ZIO.of(ZConnection, Throwable, UpdateResult.of(rowType))}" + case RepoMethod.DeleteBuilder(_, fieldsType, rowType) => + code"def delete: ${sc.Type.dsl.DeleteBuilder.of(fieldsType, rowType)}" + case RepoMethod.Delete(_, id) => + code"def delete(${id.param}): ${ZIO.of(ZConnection, Throwable, sc.Type.Boolean)}" + case RepoMethod.SqlFile(sqlScript) => + val params = sc.Params(sqlScript.params.map(p => sc.Param(p.name, p.tpe, None))) + + val retType = sqlScript.maybeRowName match { + case MaybeReturnsRows.Query(rowName) => ZStream.of(ZConnection, Throwable, rowName) + case MaybeReturnsRows.Update => ZIO.of(ZConnection, Throwable, sc.Type.Long) + } + + code"def apply$params: $retType" + } + + override def repoImpl(repoMethod: RepoMethod): sc.Code = + repoMethod match { + case RepoMethod.SelectBuilder(relName, fieldsType, rowType) => + code"""${sc.Type.dsl.SelectBuilderSql}(${sc.StrLit(relName.value)}, $fieldsType, ${lookupJdbcDecoder(rowType)})""" + + case RepoMethod.SelectAll(relName, cols, rowType) => + val joinedColNames = dbNames(cols, isRead = true) + val sql = SQL(code"""select $joinedColNames from $relName""") + code"""$sql.query(${lookupJdbcDecoder(rowType)}).selectStream""" + + case RepoMethod.SelectById(relName, cols, id, rowType) => + val joinedColNames = dbNames(cols, isRead = true) + val sql = SQL(code"""select $joinedColNames from $relName where ${matchId(id)}""") + code"""$sql.query(${lookupJdbcDecoder(rowType)}).selectOne""" + + case RepoMethod.SelectAllByIds(relName, cols, unaryId, idsParam, rowType) => + val joinedColNames = dbNames(cols, isRead = true) + + val sql = SQL( + code"""select $joinedColNames from $relName where ${unaryId.col.dbName} = ANY(${runtimeInterpolateValue(idsParam.name, idsParam.tpe)})""" + ) + code"""$sql.query(${lookupJdbcDecoder(rowType)}).selectStream""" + case RepoMethod.SelectByUnique(relName, cols, rowType) => + val sql = SQL { + code"""|select ${dbNames(cols, isRead = true)} + |from $relName + |where ${cols.map(c => code"${c.dbName} = ${runtimeInterpolateValue(c.name, c.tpe)}").mkCode(" AND ")} + |""".stripMargin + } + code"""$sql.query(${lookupJdbcDecoder(rowType)}).selectOne""" + + case RepoMethod.SelectByFieldValues(relName, cols, fieldValue, fieldValueOrIdsParam, rowType) => + val cases = + cols.map { col => + val fr = SQL(code"${col.dbName} = ${runtimeInterpolateValue(sc.Ident("value"), col.tpe)}") + code"case $fieldValue.${col.name}(value) => $fr" + } + + code"""${fieldValueOrIdsParam.name} match { + | case Nil => selectAll + | case nonEmpty => + | val wheres = $SqlFragment.empty.and( + | nonEmpty.map { + | ${cases.mkCode("\n")} + | } + | ) + | ${SQL(code"""select ${dbNames(cols, isRead = true)} from $relName where $$wheres""")}.query(${lookupJdbcDecoder(rowType)}).selectStream + |}""".stripMargin + + case RepoMethod.UpdateFieldValues(relName, id, varargs, fieldValue, cases0, _) => + val cases: NonEmptyList[sc.Code] = + cases0.map { col => + val sql = SQL(code"${col.dbName} = ${runtimeInterpolateValue(sc.Ident("value"), col.tpe)}${sqlCast.toPgCode(col)}") + code"case $fieldValue.${col.name}(value) => $sql" + } + + val sql = SQL { + code"""|update $relName + |set $$updates + |where ${matchId(id)} + |""".stripMargin + } + + code"""$NonEmptyChunk.fromIterableOption(${varargs.name}) match { + | case None => $ZIO.succeed(false) + | case Some(nonEmpty) => + | val updates = nonEmpty.map { ${cases.mkCode("\n")} }.mkFragment($SqlFragment(", ")) + | $sql.update.map(_ > 0) + |}""".stripMargin + + case RepoMethod.UpdateBuilder(relName, fieldsType, rowType) => + code"${sc.Type.dsl.UpdateBuilder}(${sc.StrLit(relName.value)}, $fieldsType, ${lookupJdbcDecoder(rowType)})" + + case RepoMethod.Update(relName, _, id, param, colsNotId) => + val sql = SQL( + code"""update $relName + |set ${colsNotId.map { col => code"${col.dbName} = ${runtimeInterpolateValue(code"${param.name}.${col.name}", col.tpe)}${sqlCast.toPgCode(col)}" }.mkCode(",\n")} + |where ${matchId(id)}""".stripMargin + ) + code"""|val ${id.paramName} = ${param.name}.${id.paramName} + |$sql.update.map(_ > 0)""" + + case RepoMethod.InsertUnsaved(relName, cols, unsaved, unsavedParam, default, rowType) => + val cases0 = unsaved.restCols.map { col => + val set = SQL(code"${runtimeInterpolateValue(code"${unsavedParam.name}.${col.name}", col.tpe)}${sqlCast.toPgCode(col)}") + code"""Some((${SQL(col.dbName)}, $set))""" + } + val cases1 = unsaved.defaultCols.map { case (col @ ComputedColumn(_, ident, _, _), origType) => + val setValue = SQL(code"${runtimeInterpolateValue(code"value: $origType", origType)}${sqlCast.toPgCode(col)}") + code"""|${unsavedParam.name}.$ident match { + | case ${default.Defaulted}.${default.UseDefault} => None + | case ${default.Defaulted}.${default.Provided}(value) => Some((${SQL(col.dbName)}, $setValue)) + |}""" + } + + val sqlEmpty = SQL { + code"""|insert into $relName default values + |returning ${dbNames(cols, isRead = true)} + |""".stripMargin + } + + code"""|val fs = List( + | ${(cases0 ++ cases1.toList).mkCode(",\n")} + |).flatten + | + |val q = if (fs.isEmpty) { + | $sqlEmpty + |} else { + | val names = fs.map { case (n, _) => n }.mkFragment($SqlFragment(", ")) + | val values = fs.map { case (_, f) => f }.mkFragment($SqlFragment(", ")) + | ${SQL(code"insert into $relName($$names) values ($$values) returning ${dbNames(cols, isRead = true)}")} + |} + |q.insertReturning(${lookupJdbcDecoder(rowType)}).map(_.updatedKeys.head) + |""" + case RepoMethod.Upsert(relName, cols, id, unsavedParam, rowType) => + val values = cols.map { c => + code"${runtimeInterpolateValue(code"${unsavedParam.name}.${c.name}", c.tpe)}${sqlCast.toPgCode(c)}" + } + + val pickExcludedCols = cols.toList + .filterNot(c => id.cols.exists(_.name == c.name)) + .map { c => code"${c.dbName} = EXCLUDED.${c.dbName}" } + + val base: sc.Code = + code"""|insert into $relName(${dbNames(cols, isRead = false)}) + |values ( + | ${values.mkCode(",\n")} + |) + |on conflict (${dbNames(id.cols, isRead = false)})""".stripMargin + + val exclusion: Option[sc.Code] = + if (pickExcludedCols.isEmpty) None + else + Some { + code"""|do update set + | ${pickExcludedCols.mkCode(",\n")}""".stripMargin + } + + val returning: sc.Code = code"returning ${dbNames(cols, isRead = true)}" + + val sql = SQL { + List( + Some(base), + exclusion, + Some(returning) + ).flatten.mkCode("\n") + } + + code"$sql.insertReturning(${lookupJdbcDecoder(rowType)})" + + case RepoMethod.Insert(relName, cols, unsavedParam, rowType) => + val values = cols.map { c => + code"${runtimeInterpolateValue(code"${unsavedParam.name}.${c.name}", c.tpe)}${sqlCast.toPgCode(c)}" + } + val sql = SQL { + code"""|insert into $relName(${dbNames(cols, isRead = false)}) + |values (${values.mkCode(", ")}) + |returning ${dbNames(cols, isRead = true)} + |""".stripMargin + } + + code"$sql.insertReturning(${lookupJdbcDecoder(rowType)}).map(_.updatedKeys.head)" + + case RepoMethod.DeleteBuilder(relName, fieldsType, _) => + code"${sc.Type.dsl.DeleteBuilder}(${sc.StrLit(relName.value)}, $fieldsType)" + case RepoMethod.Delete(relName, id) => + val sql = SQL(code"""delete from $relName where ${matchId(id)}""") + code"$sql.delete.map(_ > 0)" + + case RepoMethod.SqlFile(sqlScript) => + val renderedScript: sc.Code = sqlScript.sqlFile.decomposedSql.renderCode { (paramAtIndex: Int) => + val param = sqlScript.params.find(_.indices.contains(paramAtIndex)).get + val cast = sqlCast.toPg(param).fold("")(udtType => s"::$udtType") + code"${runtimeInterpolateValue(param.name, param.tpe)}$cast" + } + val ret = for { + cols <- sqlScript.maybeCols.toOption + rowName <- sqlScript.maybeRowName.toOption + } yield { + // this is necessary to make custom types work with sql scripts, unfortunately. + val renderedWithCasts: sc.Code = + cols.toList.flatMap(c => sqlCast.fromPg(c.dbCol)) match { + case Nil => renderedScript.code + case _ => + val row = sc.Ident("row") + + code"""|with $row as ( + | $renderedScript + |) + |select ${cols.map(c => code"$row.${c.dbCol.parsedName.originalName.code}${sqlCast.fromPgCode(c)}").mkCode(", ")} + |from $row""".stripMargin + } + + code"""|val sql = + | ${SQL(renderedWithCasts)} + |sql.query(${lookupJdbcDecoder(rowName)}).selectStream""".stripMargin + } + ret.getOrElse { + code"${SQL(renderedScript)}.update" + } + } + + override def mockRepoImpl(id: IdComputed, repoMethod: RepoMethod, maybeToRow: Option[sc.Param]): sc.Code = + repoMethod match { + case RepoMethod.SelectBuilder(_, fieldsType, _) => + code"${sc.Type.dsl.SelectBuilderMock}($fieldsType, $ZIO.succeed($Chunk.fromIterable(map.values)), ${sc.Type.dsl.SelectParams}.empty)" + case RepoMethod.SelectAll(_, _, _) => + code"$ZStream.fromIterable(map.values)" + case RepoMethod.SelectById(_, _, id, _) => + code"$ZIO.succeed(map.get(${id.paramName}))" + case RepoMethod.SelectAllByIds(_, _, _, idsParam, _) => + code"$ZStream.fromIterable(${idsParam.name}.flatMap(map.get))" + case RepoMethod.SelectByUnique(_, cols, _) => + code"$ZIO.succeed(map.values.find(v => ${cols.map(c => code"${c.name} == v.${c.name}").mkCode(" && ")}))" + + case RepoMethod.SelectByFieldValues(_, cols, fieldValue, fieldValueOrIdsParam, _) => + val cases = cols.map { col => + code"case (acc, $fieldValue.${col.name}(value)) => acc.filter(_.${col.name} == value)" + } + code"""$ZStream.fromIterable { + | ${fieldValueOrIdsParam.name}.foldLeft(map.values) { + | ${cases.mkCode("\n")} + | } + |}""".stripMargin + case RepoMethod.UpdateBuilder(_, fieldsType, _) => + code"${sc.Type.dsl.UpdateBuilderMock}(${sc.Type.dsl.UpdateParams}.empty, $fieldsType, map)" + case RepoMethod.UpdateFieldValues(_, id, varargs, fieldValue, cases0, _) => + val cases = cases0.map { col => + code"case (acc, $fieldValue.${col.name}(value)) => acc.copy(${col.name} = value)" + } + + code"""|$ZIO.succeed { + | map.get(${id.paramName}) match { + | case ${sc.Type.Some}(oldRow) => + | val updatedRow = ${varargs.name}.foldLeft(oldRow) { + | ${cases.mkCode("\n")} + | } + | if (updatedRow != oldRow) { + | map.put(${id.paramName}, updatedRow): @${sc.Type.nowarn} + | true + | } else { + | false + | } + | case ${sc.Type.None} => false + | } + |}""".stripMargin + case RepoMethod.Update(_, _, _, param, _) => + code"""$ZIO.succeed { + | map.get(${param.name}.${id.paramName}) match { + | case ${sc.Type.Some}(`${param.name}`) => false + | case ${sc.Type.Some}(_) => + | map.put(${param.name}.${id.paramName}, ${param.name}): @${sc.Type.nowarn} + | true + | case ${sc.Type.None} => false + | } + |}""".stripMargin + case RepoMethod.Insert(_, _, unsavedParam, _) => + code"""|$ZIO.succeed { + | val _ = + | if (map.contains(${unsavedParam.name}.${id.paramName})) + | sys.error(s"id $${${unsavedParam.name}.${id.paramName}} already exists") + | else + | map.put(${unsavedParam.name}.${id.paramName}, ${unsavedParam.name}) + | + | ${unsavedParam.name} + |}""" + case RepoMethod.Upsert(_, _, _, unsavedParam, _) => + code"""|$ZIO.succeed { + | map.put(${unsavedParam.name}.${id.paramName}, ${unsavedParam.name}): @${sc.Type.nowarn} + | $UpdateResult(1, $Chunk.single(${unsavedParam.name})) + |}""".stripMargin + case RepoMethod.InsertUnsaved(_, _, _, unsavedParam, _, _) => + code"insert(${maybeToRow.get.name}(${unsavedParam.name}))" + + case RepoMethod.DeleteBuilder(_, fieldsType, _) => + code"${sc.Type.dsl.DeleteBuilderMock}(${sc.Type.dsl.DeleteParams}.empty, $fieldsType, map)" + case RepoMethod.Delete(_, id) => + code"$ZIO.succeed(map.remove(${id.paramName}).isDefined)" + case RepoMethod.SqlFile(_) => + // should not happen (tm) + code"???" + } + + override def testInsertMethod(x: ComputedTestInserts.InsertMethod): sc.Value = + sc.Value( + Nil, + x.name, + x.params, + Nil, + ZIO.of(ZConnection, Throwable, x.table.names.RowName), + code"${x.table.names.RepoImplName}.insert(new ${x.cls}(${x.params.map(p => code"${p.name} = ${p.name}").mkCode(", ")}))" + ) + + override def stringEnumInstances(wrapperType: sc.Type, underlying: sc.Type): List[sc.ClassMember] = { + val arraySetter = sc.Given( + tparams = Nil, + name = arraySetterName, + implicitParams = Nil, + tpe = Setter.of(sc.Type.Array.of(wrapperType)), + body = code"""${lookupSetter(sc.Type.Array.of(underlying))}.contramap(_.map(_.value))""" + ) + val arrayJdbcDecoder = sc.Given( + tparams = Nil, + name = arrayJdbcDecoderName, + implicitParams = Nil, + tpe = JdbcDecoder.of(sc.Type.Array.of(wrapperType)), + body = code"""${lookupJdbcDecoder(sc.Type.Array.of(underlying))}.map(a => if (a == null) null else a.map(force))""" + ) + val arrayJdbcEncoder = sc.Given( + tparams = Nil, + name = arrayJdbcEncoderName, + implicitParams = Nil, + tpe = JdbcEncoder.of(sc.Type.Array.of(wrapperType)), + // JdbcEncoder for unary types defined in terms of `Setter` + body = code"""$JdbcEncoder.singleParamEncoder(${arraySetterName})""" + ) + val jdbcEncoder = sc.Given( + tparams = Nil, + name = jdbcEncoderName, + implicitParams = Nil, + tpe = JdbcEncoder.of(wrapperType), + body = code"""${lookupJdbcEncoder(underlying)}.contramap(_.value)""" + ) + val jdbcDecoder = { + val body = + code"""|${lookupJdbcDecoder(underlying)}.flatMap { s => + | new ${JdbcDecoder.of(wrapperType)} { + | override def unsafeDecode(columIndex: ${sc.Type.Int}, rs: ${sc.Type.ResultSet}): (${sc.Type.Int}, $wrapperType) = { + | def error(msg: ${sc.Type.String}): $JdbcDecoderError = + | $JdbcDecoderError( + | message = s"Error decoding $wrapperType from ResultSet", + | cause = new RuntimeException(msg), + | metadata = rs.getMetaData, + | row = rs.getRow + | ) + | + | $wrapperType.apply(s).fold(e => throw error(e), (columIndex, _)) + | } + | } + |}""".stripMargin + sc.Given(tparams = Nil, name = jdbcDecoderName, implicitParams = Nil, tpe = JdbcDecoder.of(wrapperType), body = body) + } + + val setter = sc.Given( + tparams = Nil, + name = setterName, + implicitParams = Nil, + tpe = Setter.of(wrapperType), + body = code"""${lookupSetter(underlying)}.contramap(_.value)""" + ) + + val parameterMetadata = { + val body = + code"$ParameterMetaData.instance[$wrapperType](${lookupParameterMetaDataFor(underlying)}.sqlType, ${lookupParameterMetaDataFor(underlying)}.jdbcType)" + sc.Given(tparams = Nil, name = parameterMetadataName, implicitParams = Nil, tpe = ParameterMetaData.of(wrapperType), body = body) + } + + List(Option(arraySetter), Option(arrayJdbcDecoder), Option(arrayJdbcEncoder), Option(jdbcEncoder), Option(jdbcDecoder), Option(setter), ifDsl(parameterMetadata)).flatten + } + + override def anyValInstances(wrapperType: Type.Qualified, underlying: sc.Type): List[sc.ClassMember] = + List( + Option( + sc.Given( + tparams = Nil, + name = jdbcEncoderName, + implicitParams = Nil, + tpe = JdbcEncoder.of(wrapperType), + body = code"""${lookupJdbcEncoder(underlying)}.contramap(_.value)""" + ) + ), + Option( + sc.Given( + tparams = Nil, + name = jdbcDecoderName, + implicitParams = Nil, + tpe = JdbcDecoder.of(wrapperType), + body = code"""${lookupJdbcDecoder(underlying)}.map($wrapperType.apply)""" + ) + ), + Option( + sc.Given( + tparams = Nil, + name = setterName, + implicitParams = Nil, + tpe = Setter.of(wrapperType), + body = code"""${lookupSetter(underlying)}.contramap(_.value)""" + ) + ), + Option( + sc.Given( + tparams = Nil, + name = arraySetterName, + implicitParams = Nil, + tpe = Setter.of(sc.Type.Array.of(wrapperType)), + body = code"""${lookupSetter(sc.Type.Array.of(underlying))}.contramap(_.map(_.value))""" + ) + ), + ifDsl( + sc.Given( + tparams = Nil, + name = parameterMetadataName, + implicitParams = Nil, + tpe = ParameterMetaData.of(wrapperType), + body = code"$ParameterMetaData.instance[$wrapperType](${lookupParameterMetaDataFor(underlying)}.sqlType, ${lookupParameterMetaDataFor(underlying)}.jdbcType)" + ) + ) + ).flatten + + override def missingInstances: List[sc.ClassMember] = { + + /** Adapted from Quill implementation + * + * Works for primitive types but not for more complex types + */ + def primitiveArrayDecoder(T: sc.Type.Qualified) = { + val body = + code"""|new ${JdbcDecoder.of(sc.Type.Array.of(T))} { + | override def unsafeDecode(columIndex: ${sc.Type.Int}, rs: ${sc.Type.ResultSet}): (${sc.Type.Int}, ${sc.Type.Array.of(T)}) = { + | val arr = rs.getArray(columIndex) + | if (arr eq null) columIndex -> null + | else { + | columIndex -> + | arr + | .getArray + | .asInstanceOf[Array[Any]] + | .foldLeft(Array.newBuilder[${T.value}]) { + | case (b, x: ${T.value}) => b += x + | case (b, x: java.lang.Number) => b += x.asInstanceOf[${T.value}] + | case (_, x) => + | throw $JdbcDecoderError( + | message = s"Error decoding ${sc.Type.Array}(${T.value}) from ResultSet", + | cause = new IllegalStateException( + | s"Retrieved $${x.getClass.getCanonicalName} type from JDBC array, but expected (${T.value}). Re-check your decoder implementation" + | ), + | metadata = rs.getMetaData, + | row = rs.getRow + | ) + | } + | .result() + | } + | } + |}""".stripMargin + sc.Given(tparams = Nil, name = sc.Ident(s"${T.name.value}ArrayDecoder"), implicitParams = Nil, tpe = JdbcDecoder.of(sc.Type.Array.of(T)), body = body) + } + + def primitiveArraySetter(T: sc.Type.Qualified, sqlType: sc.StrLit, asAnyRef: sc.Code => sc.Code) = { + val v = sc.Ident("v") + val body = + code"""|$Setter.forSqlType[${sc.Type.Array.of(T)}]( + | (ps, i, $v) => { + | ps.setArray(i, ps.getConnection.createArrayOf($sqlType, ${asAnyRef(v)})) + | }, + | ${sc.Type.Types}.ARRAY + |)""".stripMargin + sc.Given(tparams = Nil, name = sc.Ident(s"${T.name.value}ArraySetter"), implicitParams = Nil, tpe = Setter.of(sc.Type.Array.of(T)), body = body) + } + + def primitiveArrayEncoder(T: sc.Type.Qualified) = { + sc.Given( + tparams = Nil, + name = sc.Ident(s"${T.name.value}ArrayEncoder"), + implicitParams = Nil, + tpe = JdbcEncoder.of(sc.Type.Array.of(T)), + body = code"""$JdbcEncoder.singleParamEncoder(${T.name.value}ArraySetter)""" + ) + } + + def ScalaBigDecimal = + List( + sc.Given( + tparams = Nil, + name = sc.Ident("ScalaBigDecimalArrayEncoder"), + implicitParams = Nil, + tpe = JdbcEncoder.of(sc.Type.Array.of(sc.Type.BigDecimal)), + body = code"""BigDecimalArrayEncoder.contramap(_.map(_.bigDecimal))""" + ), + sc.Given( + tparams = Nil, + name = sc.Ident("ScalaBigDecimalArrayDecoder"), + implicitParams = Nil, + tpe = JdbcDecoder.of(sc.Type.Array.of(sc.Type.BigDecimal)), + body = code"""BigDecimalArrayDecoder.map(v => if (v eq null) null else v.map(${sc.Type.BigDecimal}.apply))""" + ), + sc.Given( + tparams = Nil, + name = sc.Ident("ScalaBigDecimalArraySetter"), + implicitParams = Nil, + tpe = Setter.of(sc.Type.Array.of(sc.Type.BigDecimal)), + body = code"""BigDecimalArraySetter.contramap(_.map(_.bigDecimal))""" + ) + ) + + def all(T: sc.Type.Qualified, sqlType: String, asAnyRef: sc.Code => sc.Code) = { + List(primitiveArrayDecoder(T), primitiveArraySetter(T, sc.StrLit(sqlType), asAnyRef), primitiveArrayEncoder(T)) + } + + all(sc.Type.String, "varchar", array => code"$array.map(x => x: ${sc.Type.AnyRef})") ++ + all(sc.Type.Int, "int4", array => code"$array.map(x => int2Integer(x): ${sc.Type.AnyRef})") ++ + all(sc.Type.Long, "int8", array => code"$array.map(x => long2Long(x): ${sc.Type.AnyRef})") ++ + all(sc.Type.Float, "float4", array => code"$array.map(x => float2Float(x): ${sc.Type.AnyRef})") ++ + all(sc.Type.Double, "float8", array => code"$array.map(x => double2Double(x): ${sc.Type.AnyRef})") ++ + all(sc.Type.JavaBigDecimal, "numeric", array => code"$array.map(x => x: ${sc.Type.AnyRef})") ++ + ScalaBigDecimal ++ + all(sc.Type.Boolean, "bool", array => code"$array.map(x => boolean2Boolean(x): ${sc.Type.AnyRef})") + } + + override def rowInstances(tpe: sc.Type, cols: NonEmptyList[ComputedColumn]): List[sc.ClassMember] = { + val decoder = { + val body = + if (cols.length == 1) + code"""${lookupJdbcDecoder(cols.head.tpe)}.map(v => $tpe(${cols.head.name} = v))""".stripMargin + else { + val namedParams = cols.zipWithIndex.map { case (c, idx) => + code"${c.name} = ${lookupJdbcDecoder(c.tpe)}.unsafeDecode(columIndex + $idx, rs)._2" + } + + code"""|new ${JdbcDecoder.of(tpe)} { + | override def unsafeDecode(columIndex: ${sc.Type.Int}, rs: ${sc.Type.ResultSet}): (${sc.Type.Int}, $tpe) = + | columIndex + ${cols.length - 1} -> + | $tpe( + | ${namedParams.mkCode(",\n")} + | ) + |}""".stripMargin + } + sc.Given(tparams = Nil, name = jdbcDecoderName, implicitParams = Nil, tpe = JdbcDecoder.of(tpe), body = body) + } + + List(decoder) + } + + override def customTypeInstances(ct: CustomType): List[sc.ClassMember] = + customTypeOne(ct) ++ (if (ct.forbidArray) Nil else customTypeArray(ct)) + + def customTypeOne(ct: CustomType): List[sc.Given] = { + + val jdbcEncoder = sc.Given( + tparams = Nil, + name = jdbcEncoderName, + implicitParams = Nil, + tpe = JdbcEncoder.of(ct.typoType), + // JdbcEncoder for unary types defined in terms of `Setter` + body = code"""$JdbcEncoder.singleParamEncoder($setterName)""" + ) + + val jdbcDecoder = { + val expectedType = sc.StrLit(ct.fromTypo.jdbcType.render.asString) + val body = + code"""|${JdbcDecoder.of(ct.typoType)}( + | (rs: ${sc.Type.ResultSet}) => (i: ${sc.Type.Int}) => { + | val v = rs.getObject(i) + | if (v eq null) null else ${ct.toTypo0(code"v.asInstanceOf[${ct.toTypo.jdbcType}]")} + | }, + | $expectedType + |)""".stripMargin + sc.Given(tparams = Nil, name = jdbcDecoderName, implicitParams = Nil, tpe = JdbcDecoder.of(ct.typoType), body = body) + } + + val setter = { + val v = sc.Ident("v") + val body = + code"""|$Setter.other( + | (ps, i, $v) => { + | ps.setObject( + | i, + | ${ct.fromTypo0(v)} + | ) + | }, + | ${sc.StrLit(ct.sqlType)} + |)""".stripMargin + sc.Given(tparams = Nil, name = setterName, implicitParams = Nil, tpe = Setter.of(ct.typoType), body = body) + } + + val parameterMetadata = { + val body = code"$ParameterMetaData.instance[${ct.typoType}](${sc.StrLit(ct.sqlType)}, ${sc.Type.Types}.OTHER)" + sc.Given(Nil, parameterMetadataName, Nil, ParameterMetaData.of(ct.typoType), body) + } + + List(Option(jdbcEncoder), Option(jdbcDecoder), Option(setter), ifDsl(parameterMetadata)).flatten + } + + def customTypeArray(ct: CustomType): List[sc.Given] = { + val fromTypo = ct.fromTypoInArray.getOrElse(ct.fromTypo) + val toTypo = ct.toTypoInArray.getOrElse(ct.toTypo) + val jdbcEncoder = sc.Given( + tparams = Nil, + name = arrayJdbcEncoderName, + implicitParams = Nil, + tpe = JdbcEncoder.of(sc.Type.Array.of(ct.typoType)), + // JdbcEncoder for unary types defined in terms of `Setter` + body = code"""$JdbcEncoder.singleParamEncoder(${arraySetterName})""" + ) + + val jdbcDecoder = { + val expectedType = sc.StrLit(sc.Type.Array.of(ct.fromTypo.jdbcType).render.asString) + val body = + code"""|${JdbcDecoder.of(sc.Type.Array.of(ct.typoType))}((rs: ${sc.Type.ResultSet}) => (i: ${sc.Type.Int}) => + | rs.getArray(i) match { + | case null => null + | case arr => arr.getArray.asInstanceOf[Array[AnyRef]].map(x => ${toTypo.toTypo(code"x.asInstanceOf[${toTypo.jdbcType}]", ct.typoType)}) + | }, + | $expectedType + |)""".stripMargin + sc.Given(tparams = Nil, name = arrayJdbcDecoderName, implicitParams = Nil, tpe = JdbcDecoder.of(sc.Type.Array.of(ct.typoType)), body = body) + } + + val setter = { + val v = sc.Ident("v") + val vv = sc.Ident("vv") + val body = + code"""|$Setter.forSqlType((ps, i, $v) => + | ps.setArray( + | i, + | ps.getConnection.createArrayOf( + | ${sc.StrLit(ct.sqlType)}, + | $v.map { $vv => + | ${fromTypo.fromTypo0(vv)} + | } + | ) + | ), + | ${sc.Type.Types}.ARRAY + |)""".stripMargin + + sc.Given(tparams = Nil, name = arraySetterName, implicitParams = Nil, tpe = Setter.of(sc.Type.Array.of(ct.typoType)), body = body) + } + + List(jdbcEncoder, jdbcDecoder, setter) + } +} diff --git a/typo/src/scala/typo/internal/codegen/JsonLibZioJson.scala b/typo/src/scala/typo/internal/codegen/JsonLibZioJson.scala new file mode 100644 index 0000000000..0d7cff6600 --- /dev/null +++ b/typo/src/scala/typo/internal/codegen/JsonLibZioJson.scala @@ -0,0 +1,204 @@ +package typo.internal.codegen + +import typo.internal.ComputedDefault +import typo.sc.Type +import typo.{NonEmptyList, sc} + +final case class JsonLibZioJson(pkg: sc.QIdent, default: ComputedDefault, inlineImplicits: Boolean) extends JsonLib { + private val JsonDecoder = sc.Type.Qualified("zio.json.JsonDecoder") + private val JsonEncoder = sc.Type.Qualified("zio.json.JsonEncoder") + private val Write = sc.Type.Qualified("zio.json.internal.Write") + private val JsonError = sc.Type.Qualified("zio.json.JsonError") + private val RetractReader = sc.Type.Qualified("zio.json.internal.RetractReader") + private val Success = sc.Type.Qualified("scala.util.Success") + private val Json = sc.Type.Qualified("zio.json.ast.Json") + + private val encoderName = sc.Ident("jsonEncoder") + private val decoderName = sc.Ident("jsonDecoder") + + /** Resolve known implicits at generation-time instead of at compile-time */ + private def lookupDecoderFor(tpe: sc.Type): sc.Code = { + def go(tpe: sc.Type): sc.Code = + tpe match { + case sc.Type.BigDecimal => code"$JsonDecoder.scalaBigDecimal" + case sc.Type.Boolean => code"$JsonDecoder.boolean" + case sc.Type.Byte => code"$JsonDecoder.byte" + case sc.Type.Double => code"$JsonDecoder.double" + case sc.Type.Float => code"$JsonDecoder.float" + case sc.Type.Instant => code"$JsonDecoder.instant" + case sc.Type.Int => code"$JsonDecoder.int" + case sc.Type.LocalDate => code"$JsonDecoder.localDate" + case sc.Type.LocalDateTime => code"$JsonDecoder.localDateTime" + case sc.Type.LocalTime => code"$JsonDecoder.localTime" + case sc.Type.Long => code"$JsonDecoder.long" + case sc.Type.OffsetDateTime => code"$JsonDecoder.offsetDateTime" + case sc.Type.OffsetTime => code"$JsonDecoder.offsetTime" + case sc.Type.String => code"$JsonDecoder.string" + case sc.Type.UUID => code"$JsonDecoder.uuid" + case sc.Type.TApply(sc.Type.Array, List(targ)) => code"$JsonDecoder.array[$targ](${go(targ)}, implicitly)" + case sc.Type.TApply(default.Defaulted, List(targ)) => code"${default.Defaulted}.$decoderName(${go(targ)})" + case sc.Type.Optional(targ) => code"$JsonDecoder.option(${go(targ)})" + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => code"$tpe.$decoderName" + case other => code"${JsonDecoder.of(other)}" + } + + if (inlineImplicits) go(sc.Type.base(tpe)) else JsonDecoder.of(tpe).code + } + + /** Resolve known implicits at generation-time instead of at compile-time */ + def lookupEncoderFor(tpe: sc.Type): sc.Code = { + def go(tpe: sc.Type): sc.Code = + tpe match { + case sc.Type.BigDecimal => code"$JsonEncoder.scalaBigDecimal" + case sc.Type.Boolean => code"$JsonEncoder.boolean" + case sc.Type.Byte => code"$JsonEncoder.byte" + case sc.Type.Double => code"$JsonEncoder.double" + case sc.Type.Float => code"$JsonEncoder.float" + case sc.Type.Instant => code"$JsonEncoder.instant" + case sc.Type.Int => code"$JsonEncoder.int" + case sc.Type.LocalDate => code"$JsonEncoder.localDate" + case sc.Type.LocalDateTime => code"$JsonEncoder.localDateTime" + case sc.Type.LocalTime => code"$JsonEncoder.localTime" + case sc.Type.Long => code"$JsonEncoder.long" + case sc.Type.OffsetDateTime => code"$JsonEncoder.offsetDateTime" + case sc.Type.OffsetTime => code"$JsonEncoder.offsetTime" + case sc.Type.String => code"$JsonEncoder.string" + case sc.Type.UUID => code"$JsonEncoder.uuid" + case sc.Type.TApply(sc.Type.Array, List(targ)) => code"$JsonEncoder.array[$targ](${go(targ)}, implicitly)" + case sc.Type.TApply(default.Defaulted, List(targ)) => code"${default.Defaulted}.$encoderName(${go(targ)})" + case sc.Type.Optional(targ) => code"$JsonEncoder.option(${go(targ)})" + case x: sc.Type.Qualified if x.value.idents.startsWith(pkg.idents) => code"$tpe.$encoderName" + case other => code"${JsonEncoder.of(other)}" + } + + if (inlineImplicits) go(sc.Type.base(tpe)) else JsonEncoder.of(tpe).code + } + + override def defaultedInstance(d: ComputedDefault): List[sc.Given] = { + val T = sc.Type.Abstract(sc.Ident("T")) + List( + sc.Given( + tparams = List(T), + name = decoderName, + implicitParams = List(sc.Param(sc.Ident("T"), JsonDecoder.of(T), None)), + tpe = JsonDecoder.of(d.Defaulted.of(T)), + body = code"""|new ${JsonDecoder.of(d.Defaulted.of(T))} { + | override def unsafeDecode(trace: ${sc.Type.List.of(JsonError)}, in: $RetractReader): ${d.Defaulted.of(T)} = + | ${sc.Type.Try}($JsonDecoder.string.unsafeDecode(trace, in)) match { + | case $Success("defaulted") => UseDefault + | case _ => Provided(T.unsafeDecode(trace, in)) + | } + | }""".stripMargin + ), + sc.Given( + tparams = List(T), + name = encoderName, + implicitParams = List(sc.Param(sc.Ident("T"), JsonEncoder.of(T), None)), + tpe = JsonEncoder.of(d.Defaulted.of(T)), + body = code"""|new ${JsonEncoder.of(d.Defaulted.of(T))} { + | override def unsafeEncode(a: ${d.Defaulted.of(T)}, indent: ${sc.Type.Option.of(sc.Type.Int)}, out: $Write): Unit = + | a match { + | case ${d.Provided}(value) => + | out.write("{") + | out.write("\\"provided\\":") + | ${sc.Ident("T")}.unsafeEncode(value, None, out) + | out.write("}") + | case ${d.UseDefault} => out.write("\\"defaulted\\"") + | } + |}""".stripMargin + ) + ) + } + + override def stringEnumInstances(wrapperType: sc.Type, underlying: sc.Type): List[sc.Given] = + List( + sc.Given( + tparams = Nil, + name = decoderName, + implicitParams = Nil, + tpe = JsonDecoder.of(wrapperType), + body = code"""${lookupDecoderFor(underlying)}.mapOrFail($wrapperType.apply)""" + ), + sc.Given( + tparams = Nil, + name = encoderName, + implicitParams = Nil, + tpe = JsonEncoder.of(wrapperType), + body = code"${lookupEncoderFor(underlying)}.contramap(_.value)" + ) + ) + + override def anyValInstances(wrapperType: Type.Qualified, fieldName: sc.Ident, underlying: sc.Type): List[sc.Given] = + List( + sc.Given( + tparams = Nil, + name = encoderName, + implicitParams = Nil, + tpe = JsonEncoder.of(wrapperType), + body = code"${lookupEncoderFor(underlying)}.contramap(_.$fieldName)" + ), + sc.Given( + tparams = Nil, + name = decoderName, + implicitParams = Nil, + tpe = JsonDecoder.of(wrapperType), + body = code"${lookupDecoderFor(underlying)}.map($wrapperType.apply)" + ) + ) + + override def productInstances(tpe: sc.Type, fields: NonEmptyList[JsonLib.Field]): List[sc.Given] = { + val decoder = + sc.Given( + tparams = Nil, + name = decoderName, + implicitParams = Nil, + tpe = JsonDecoder.of(tpe), + body = { + val vals = + fields.map(f => + f.tpe match { + case sc.Type.Optional(targ) => + val either = sc.Type.Either.of(sc.Type.String, sc.Type.Option.of(sc.Type.base(targ))) + code"""val ${f.scalaName} = jsonObj.get(${f.jsonName}).fold[$either](${sc.Type.Right}(${sc.Type.None}))(_.as(${lookupDecoderFor(f.tpe)}))""" + case _ => + code"""val ${f.scalaName} = jsonObj.get(${f.jsonName}).toRight("Missing field '${f.jsonName.str}'").flatMap(_.as(${lookupDecoderFor(f.tpe)}))""" + } + ) + + // specify `Any` explicitly to save the compiler from LUBbing + val list = sc.Type.List.of(sc.Type.Either.of(sc.Type.String, sc.Type.Any)) + code"""|$JsonDecoder[$Json.Obj].mapOrFail { jsonObj => + | ${vals.mkCode("\n")} + | if (${fields.map(f => code"${f.scalaName}.isRight").mkCode(" && ")}) + | ${sc.Type.Right}($tpe(${fields.map(v => code"${v.scalaName} = ${v.scalaName}.toOption.get").mkCode(", ")})) + | else ${sc.Type.Left}($list(${fields.map(f => code"${f.scalaName}").mkCode(", ")}).flatMap(_.left.toOption).mkString(", ")) + |}""".stripMargin + } + ) + + val encoder = + sc.Given( + tparams = Nil, + name = encoderName, + implicitParams = Nil, + tpe = JsonEncoder.of(tpe), + body = { + val params = + fields.map(f => code"""|out.write(\"\"\"${f.jsonName}:\"\"\") + |${lookupEncoderFor(f.tpe)}.unsafeEncode(a.${f.scalaName}, indent, out)""".stripMargin) + + code"""|new $JsonEncoder[$tpe] { + | override def unsafeEncode(a: $tpe, indent: Option[Int], out: $Write): Unit = { + | out.write("{") + | ${params.mkCode(code"""\nout.write(",")\n""")} + | out.write("}") + | } + |}""".stripMargin + } + ) + + List(decoder, encoder) + } + + override def missingInstances: List[sc.ClassMember] = List.empty +} diff --git a/typo/src/scala/typo/internal/generate.scala b/typo/src/scala/typo/internal/generate.scala index 590edfa8fc..ad60159838 100644 --- a/typo/src/scala/typo/internal/generate.scala +++ b/typo/src/scala/typo/internal/generate.scala @@ -24,10 +24,12 @@ object generate { jsonLibs = publicOptions.jsonLibs.map { case JsonLibName.Circe => JsonLibCirce(pkg, default, publicOptions.inlineImplicits) case JsonLibName.PlayJson => JsonLibPlay(pkg, default, publicOptions.inlineImplicits) + case JsonLibName.ZioJson => JsonLibZioJson(pkg, default, publicOptions.inlineImplicits) }, dbLib = publicOptions.dbLib.map { - case DbLibName.Anorm => new DbLibAnorm(pkg, publicOptions.inlineImplicits) - case DbLibName.Doobie => new DbLibDoobie(pkg, publicOptions.inlineImplicits) + case DbLibName.Anorm => new DbLibAnorm(pkg, publicOptions.inlineImplicits) + case DbLibName.Doobie => new DbLibDoobie(pkg, publicOptions.inlineImplicits) + case DbLibName.ZioJdbc => new DbLibZioJdbc(pkg, publicOptions.inlineImplicits, dslEnabled = publicOptions.enableDsl) }, logger = publicOptions.logger, naming = naming, diff --git a/typo/src/scala/typo/sc.scala b/typo/src/scala/typo/sc.scala index 4d06984ff0..06c9cce8c0 100644 --- a/typo/src/scala/typo/sc.scala +++ b/typo/src/scala/typo/sc.scala @@ -168,6 +168,7 @@ object sc { val ChronoUnit = Qualified("java.time.temporal.ChronoUnit") val Numeric = Qualified("scala.math.Numeric") val nowarn = Qualified("scala.annotation.nowarn") + val Throwable = sc.Type.Qualified("java.lang.Throwable") object dsl { val Bijection = Qualified("typo.dsl.Bijection") @@ -219,7 +220,8 @@ object sc { Some, String, StringContext, - Unit + Unit, + Throwable ) .map(x => (x.value.name, x)) .toMap